You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: test_inject_assigned_credentials leaks a stubbed services.agent_service.helpers into sys.modules, breaking runtime filtering in later tests #2140
tests/unit/test_inject_assigned_credentials.py installs stub modules directly into sys.modules (services.agent_service, services.agent_service.helpers, .read_only, .file_sharing, services.credential_encryption) at import time and never restores them. The stubs outlive the module.
services/compatibility/spec.py::applies_to_runtime() resolves its dependency lazily:
defapplies_to_runtime(check, runtime):
ifnotcheck.claude_only:
returnTruefromservices.agent_service.helpersimportis_claude_runtime# <- picks up the stubreturnis_claude_runtime(runtime)
so any test that runs aftertest_inject_assigned_credentials gets the stubbed is_claude_runtime and loses claude_only filtering.
E AssertionError: assert 'C-001' not in {'A-001', ..., 'C-001', ...}
FAILED tests/unit/test_compatibility_checks.py::TestBuildReport::test_codex_runtime_omits_claude_only_checks
Each file passes on its own. Confirmed pre-existing on dev (reproduced in a clean dev worktree), and confirmed still present on the #2137 branch — it is not caused by either.
Why it matters
The repo runs pytest-randomly, so file order varies per run. This is therefore a latent CI flake, not a deterministic failure: it only fires when the polluting module happens to sort before test_compatibility_checks.py. The test it breaks (test_codex_runtime_omits_claude_only_checks) guards the #1187 multi-runtime property that Codex/Gemini agents are not flagged with false HARD CLAUDE.md findings — so the flake masquerades as a real compatibility regression.
Suggested fix
Either restore the pre-existing entries in a fixture teardown (monkeypatch.setitem(sys.modules, ...) gets this for free), or scope the stubbing to the tests that need it rather than doing it at module import.
Acceptance Criteria
sys.modules is restored after test_inject_assigned_credentials completes
The reproduction command above passes
A guard asserts no test leaves a stub for services.agent_service.helpers in sys.modules (or the stubbing moves to monkeypatch.setitem, which makes leakage structurally impossible)
Extra context on why CI is green today despite this.
tests/lint_sys_modules.py (the lint (sys.modules pollution check) job, #762) is baseline-ratcheted — it blocks new bare sys.modules mutations but permits pre-existing ones. test_inject_assigned_credentials.py is in that baseline, so the lint passes on it by design.
Backend unit CI also runs pytest as a base-vs-head matrix at 3 seeds each (backend-unit-test.yml, seeds 12345/67890/99999). That is what keeps this from being a blocking red: when a seed orders the polluting module first, the failure appears on base and head alike and is correctly read as pre-existing. It also means the flake is genuinely reachable in CI, not just locally — it simply never looks like a regression.
So the two mechanisms that should have caught it each have a principled reason not to. The fix is still the one above: restore sys.modules (or switch to monkeypatch.setitem, which makes leakage structurally impossible and would also let the file come off the #762 baseline).
Activity
vybe commentedon Aug 12, 2026
Extra context on why CI is green today despite this.
tests/lint_sys_modules.py(thelint (sys.modules pollution check)job, #762) is baseline-ratcheted — it blocks new baresys.modulesmutations but permits pre-existing ones.test_inject_assigned_credentials.pyis in that baseline, so the lint passes on it by design.Backend unit CI also runs
pytestas a base-vs-head matrix at 3 seeds each (backend-unit-test.yml, seeds 12345/67890/99999). That is what keeps this from being a blocking red: when a seed orders the polluting module first, the failure appears on base and head alike and is correctly read as pre-existing. It also means the flake is genuinely reachable in CI, not just locally — it simply never looks like a regression.So the two mechanisms that should have caught it each have a principled reason not to. The fix is still the one above: restore
sys.modules(or switch tomonkeypatch.setitem, which makes leakage structurally impossible and would also let the file come off the #762 baseline).fix(tests): fix the OTHER two polluters — the first attempt did not fix
fix(tests): scope the #612 module stubs to the load that needs them (#…