Skip to content

test isolation: dev push unit suite red since #2487, 13 test_ent615_token_free_remotes failures from tests that reset services.git_service without its submodules #2859

Closed

Description

@vybe

Summary

The pytest (push, absolute failures) job in backend-unit-test has been red on every dev push since 5c4dc4b2a (#2487, the #1028 split of services/git_service.py into a package, 2026-09-16). All 13 failures are in tests/unit/test_ent615_token_free_remotes.py. They are order-dependent: the file passes on its own (89 passed), and four other test files each make it fail when they run first. The product code is fine. The defect is test isolation.

Failing tests

All 13 fail with AttributeError: module 'services.git_service' has no attribute 'token_scrub', except the two TestDegradesHonestly tests, which fail with ... no attribute 'conflicts'.

test_ent615_token_free_remotes.py::TestAnUnreadableSweepReachesAnOperator::test_it_alarms_when_the_sweep_could_not_look
test_ent615_token_free_remotes.py::TestAnUnreadableSweepReachesAnOperator::test_it_stays_quiet_on_an_ordinary_clean_pass
test_ent615_token_free_remotes.py::TestDegradesHonestly::test_a_bare_403_is_NOT_treated_as_an_auth_failure
test_ent615_token_free_remotes.py::TestDegradesHonestly::test_the_marker_is_classified_as_an_auth_failure
test_ent615_token_free_remotes.py::TestInitializeSeedsRatherThanOrphaning::test_a_supplied_pat_is_seeded_before_any_remote_is_written
test_ent615_token_free_remotes.py::TestInitializeSeedsRatherThanOrphaning::test_a_tokenless_agent_is_not_failed
test_ent615_token_free_remotes.py::TestInitializeSeedsRatherThanOrphaning::test_it_fails_honestly_when_the_credential_cannot_be_placed
test_ent615_token_free_remotes.py::TestRotationWithoutARecreate::test_update_remote_pat_writes_the_env_file_over_docker_exec
test_ent615_token_free_remotes.py::TestTheCredentialNeverTouchesArgv::test_nothing_is_re_pointed_when_no_credential_resolves
test_ent615_token_free_remotes.py::TestTheCredentialNeverTouchesArgv::test_the_env_write_and_the_sweep_run_as_root
test_ent615_token_free_remotes.py::TestTheCredentialNeverTouchesArgv::test_the_re_pointed_origin_is_credential_less
test_ent615_token_free_remotes.py::TestTheCredentialNeverTouchesArgv::test_the_sweep_is_bounded_in_the_container_too
test_ent615_token_free_remotes.py::TestTheCredentialNeverTouchesArgv::test_update_remote_pat_carries_the_token_in_the_exec_environment

The same 13 IDs appear on three dev push runs: 5c4dc4b2a (run 35116218599), 4196a6d52 (run 35151192819) and 3a47f7440 (run 35203443016). The last green push run was 888c3866a, the commit before #2487.

Test files that cause it

Each file below, run immediately before the ent615 file with random ordering off, reproduces all 13 failures on dev @ 3a47f7440:

Test that runs first Result with test_ent615_token_free_remotes.py after it
tests/unit/test_1704_git_service_plugins.py 13 failed, 89 passed
tests/unit/test_data_paths_allowlist.py 13 failed, 88 passed
tests/unit/test_data_paths_gitignore.py 13 failed, 80 passed
tests/unit/test_2075_detect_git_dir.py 13 failed, 88 passed

Six other files that also stub services.git_service do not cause it, because they use patch.dict(sys.modules, ...) or monkeypatch, which restore the original entry: test_1484_create_agent_characterization, test_ent109_git_env_seam, test_ent123_tokenless_clone, test_ent128a_catalog_resilience, test_fork_to_own, test_1759_local_template_not_found.

Repro

cd tests
python -m pytest -q -p no:randomly unit/test_ent615_token_free_remotes.py                 # 89 passed
python -m pytest -q -p no:randomly unit/test_1704_git_service_plugins.py \
                                   unit/test_ent615_token_free_remotes.py                 # 13 failed

Mechanism

Before #1028, services.git_service was a single module, so sys.modules.pop("services.git_service", None) removed all of it. It is now a package, and that call removes only the package entry. Its submodules (services.git_service.token_scrub, .conflicts, ...) stay in sys.modules.

On the next import services.git_service, Python creates a new package object and runs its __init__.py. That __init__ does from .token_scrub import ..., which finds the submodule already in sys.modules. Python binds a submodule as an attribute of its parent only when it first loads the submodule, so the new package never gets a token_scrub attribute. The ent615 fixture then reads gs.token_scrub, gs.remotes, gs.gitignore and gs.conflicts, and each read raises AttributeError.

The same thing happens with a plain two-file package:

first import, has sub: True
after pop(pkg) + reimport, has sub: False | pkg.sub still cached: True

The four files fail in two ways:

  • test_1704_git_service_plugins.py, test_data_paths_allowlist.py and test_data_paths_gitignore.py call sys.modules.pop("services.git_service", None). Only the package key is removed.
  • test_2075_detect_git_dir.py clears every services.git_service* key. But it records only the package key for undo, so teardown removes the package and leaves behind the submodules the test imported.

Several files already clear the package and its submodules correctly with k.startswith("services.git_service") and restore them afterwards, for example tests/unit/test_github_init_push.py.

Why PR CI didn't catch it

The seeded per-PR jobs run with || true, and the workflow fails only on the head-vs-base regression diff. A failure that exists on both sides produces an empty diff and a green check. Only the push-side absolute check (scripts/ci/check-failure-baseline.py, #2247) sees it. So every PR merged since #2487 has shown green, and any new dev failure now lands behind an already-red gate. The v0.9.5-rc4 tag cut (#2838) also sits on this red.

Acceptance Criteria

  • The four listed files restore sys.modules for services.git_service and every services.git_service.* submodule on teardown. Either use a shared helper or match the startswith pattern plus restore used in test_github_init_push.py.
  • Each command in the repro table passes (89 / 88 / 80 / 88 passed, 0 failed).
  • A regression test named for this issue fails when a test pops only the package key and leaves its submodules cached.
  • pytest (push, absolute failures) is green on the dev push after the fix, with the 13 IDs not added to tests/unit_failure_baseline.txt.

Technical Notes

Activity

  1. added
    priority-p1
    type-bug
    theme-devex
    complexity-low
    status-ready
    on Sep 17, 2026
  2. added
    status-in-progress
    and removed
    status-ready
    on Sep 17, 2026
  3. self-assigned this
    on Sep 17, 2026
  4. added
    status-in-dev
    and removed
    status-in-progress
    on Sep 17, 2026
  5. removed
    status-in-dev
    on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-lowpriority-p1theme-devextype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions