Skip to content

fix: make Tests CI green (py3.9 collection + Hermes classifier determinism)#192

Open
saschabuehrle wants to merge 2 commits into
mainfrom
fix/ci-green-tests
Open

fix: make Tests CI green (py3.9 collection + Hermes classifier determinism)#192
saschabuehrle wants to merge 2 commits into
mainfrom
fix/ci-green-tests

Conversation

@saschabuehrle

Copy link
Copy Markdown
Collaborator

Why

The Tests badge on main has been red. Two independent failures in the test.yml Python matrix:

  1. Collection error (Python 3.9 leg)tests/test_provider_tool_retry.py
    TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'
    The file used str | None in method signatures. Python 3.9 evaluates annotations at definition time, so this raised at import → the whole file failed to collect. (3.10+ legs were unaffected.)

  2. Nondeterministic failuretests/integrations/test_hermes_classifier.py::test_high_stakes_domains_are_detected
    AssertionError: assert 'ops' == 'finance'
    The test picks a keyword via next(iter(DOMAIN_KEYWORDS[domain])) on a set, so the choice depends on PYTHONHASHSEED and varies per CI run. When it picked "financial", the classifier's naive substring match "ci" in lowered matched the ci inside "financial", giving the ops domain a tying hit that won on dict order. Red only on unlucky seeds.

Fix

  1. Add from __future__ import annotations to test_provider_tool_retry.py (defers annotation eval; matches the rest of the suite — 40+ files already do this).
  2. Match domain keywords on word boundaries in HermesTaskClassifier so short keywords (ci, api, law) no longer match inside unrelated words. This fixes the real over-matching bug and makes the test deterministic. Multi-word keywords (stack trace, pull request) still match.

Verification (local, Python 3.9.6 — the affected leg)

  • Exact CI command: pytest tests/ -m "not integration and not requires_api and not requires_ollama and not requires_vllm"1332 passed, 12 skipped, 59 deselected, 0 failed.
  • test_high_stakes_domains_are_detected passes across PYTHONHASHSEED = 0/1/2/42/123 (was seed-dependent before).
  • Lint job clean on changed files: black==25.11.0 --check ✓, ruff==0.15.0 check ✓, mypy --ignore-missing-imports ✓.

Two focused commits; no behavior change beyond the classifier keyword-matching correctness.

tests/test_provider_tool_retry.py used 'str | None' in method signatures,
which Python 3.9 evaluates at definition time and rejects with
'TypeError: unsupported operand type(s) for |'. This broke test collection
on the 3.9 CI matrix leg. Add 'from __future__ import annotations' to defer
annotation evaluation, matching the rest of the suite.
The classifier scored domains with naive substring matching, so short
keywords matched inside unrelated words -- e.g. 'ci' (ops) matched inside
'financial', tying with the finance hit and winning on dict order. This
made test_high_stakes_domains_are_detected fail nondeterministically
depending on PYTHONHASHSEED (which keyword next(iter(set)) picked).

Use word-boundary regex matching so 'ci'/'api'/'law' no longer match
inside 'financial'/'always'; multi-word keywords still match. The
classifier is now correct and the test deterministic across seeds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant