Repository navigation
Description
Two Python suites carry unittest.main() mid-file — direct-script runs silently skip every test class defined after it
Verified on main af0847d00a2231c71f6ebb59eba4cc7db197599e (2026-11-04, gh api raw reads + executed copies of the committed files).
Evidence
1. pkgs/cold-store-reaper/tests/test_cold_store.py
- Lines 3223–3224:
if __name__ == "__main__": unittest.main(verbosity=2)— mid-file. - Line 3227:
class TestResumableUploadStalls(ColdStoreTestBase)is defined after that guard, with 3 tests (lines 3252, 3261, 3270). They are the regression tests for closed cold-store-reaper: resumable upload loops forever on a 308 whose Range stops advancing — no progress check or retry cap, and a Range-less 308 counts unacknowledged bytes as sent #2797: a resumable-upload 308 whose Range stops advancing must raise instead of looping forever, and a Range-less 308 must not count unacknowledged bytes as sent. - The file's own header (lines 4–5) documents two run modes:
python3 -m unittest discover -s pkgs/cold-store-reaper/tests -vorpython3 pkgs/cold-store-reaper/tests/test_cold_store.py. - Executed this run from a verbatim copy of the committed files (+
cold_store.py,schema.sql):- Direct:
python3 tests/test_cold_store.py→ Ran 109 tests; zeroTestResumableUploadStallstests appear. - Discover:
python3 -m unittest discover -s tests -v→ Ran 112 tests; all 3 stall tests run and pass. - (13 failures in both modes in the verification copy are an artifact of the partial copy — missing
scripts/drill_compare.py/ export-turso fixtures — identical in both modes and unrelated.)
- Direct:
- CI (
.github/workflows/cold-store-reaper.yml) uses discover, so CI is not affected; the documented direct-script mode silently is.
2. scripts/tests/test_update_nixpkgs_inputs.py
- Lines 377–378:
if __name__ == "__main__": unittest.main()— mid-file, followed by a freshimportblock (line ~380) and the entire fix(scripts): gate nixpkgs-unstable input updates on the Hydra channel (cached) revision #4553 section. - Defined after the guard:
TestHydraGateParsing(line 473, 2 tests),TestGatedPinEndToEnd(line 611, 2 tests),TestHttpsContext(line 671, 1 test) — 5 tests pinning the fix(scripts): gate nixpkgs-unstable input updates on the Hydra channel (cached) revision #4553 Hydra cache-gate contract and the HTTPS-verification-stays-on contract for both copies ofupdate-nixpkgs-inputs. - Executed this run from a verbatim copy (with both script copies in place):
- Direct:
python3 scripts/tests/test_update_nixpkgs_inputs.py→ Ran 9 tests. - Discover:
python3 -m unittest discover -s scripts/tests -p 'test_update_nixpkgs_inputs.py'→ Ran 14 tests; the 5 after-guard tests run and pass. - (1 identical error in both modes is the verification copy's missing repo-root
flake.lock— unrelated.)
- Direct:
- CI (
.github/workflows/scripts-test.ymlline 31) uses discover, so CI is not affected; a direct run silently is.
Why it matters
unittest.main() raises SystemExit when the module is executed as a script, so any class defined below the guard is never even defined in that process — the suite reports a smaller, green-looking run with no warning. In both files the stranded tests are safety contracts (#2797 upload-stall protection; #4553 pin gating). Anyone verifying a change with the documented/quick direct invocation — exactly what the cold-store header offers — gets illusory coverage. Sibling instance, filed separately because its mechanism differs (dead defs are outside any class, so they never run in any mode): #5710.
A repo-wide scan this run (all 41 Python test files) found exactly these two remaining mid-file-guard instances besides #5710's file.
Acceptance criteria
- In both files, the
if __name__ == "__main__": unittest.main()block is the last executable statement in the file (nothing defined after it). -
python3 pkgs/cold-store-reaper/tests/test_cold_store.pyreports 112 tests (was 109), including the 3TestResumableUploadStallstests. -
python3 scripts/tests/test_update_nixpkgs_inputs.pyreports 14 tests (was 9), includingTestHydraGateParsing,TestGatedPinEndToEnd, andTestHttpsContext. - Discover invocations report the same counts as before the change (112 / 14) and no test outcome changes; no production code is modified.
Activity
dezren39 commentedon Nov 5, 2026
🤖 Agent note · filed
unittest.main()mid-file: inpkgs/cold-store-reaper/tests/test_cold_store.py(guard at 3223–3224,TestResumableUploadStallsat 3227) andscripts/tests/test_update_nixpkgs_inputs.py(guard at 377–378, three fix(scripts): gate nixpkgs-unstable input updates on the Hydra channel (cached) revision #4553/HTTPS classes after it). Verified by executing verbatim copies both ways: cold-store direct run reports 109 tests vs 112 under discover; nixpkgs-inputs direct reports 9 vs 14 under discover. The after-guard tests all pass under discover, and CI uses discover for both files — this is illusory coverage on the direct-script path (documented in the cold-store file header), not a CI gap. Sibling of cargo-target-janitor: owner_changed tests never run — defined after unittest.main(), outside the test class #5710 (different mechanism: those defs are outside any class and never run in any mode).__main__guard to end-of-file; direct runs then report 112 / 14 tests, discover counts unchanged, no production code touched.dezren39 commentedon Nov 5, 2026
🤖 Agent note · picked up
unittest.main()guards at current main and route the fix.dezren39 commentedon Nov 5, 2026
🤖 Agent note · done
Triage findings (task 9761, verified 2026-11-05)
Confirmed — still present at current main. Fresh
gh apicontents reads this run:pkgs/cold-store-reaper/tests/test_cold_store.py— blobb4a5ef254951e12e20f9deb6f6778d58b371ed88, 3289 lines;if __name__ == "__main__": unittest.main(verbosity=2)at lines 3223–3224, withTestResumableUploadStalls(the cold-store-reaper: resumable upload loops forever on a 308 whose Range stops advancing — no progress check or retry cap, and a Range-less 308 counts unacknowledged bytes as sent #2797 stall tests) defined after it.scripts/tests/test_update_nixpkgs_inputs.py— blobcd190b259cfa39eb8dbbab43b1bae142f1c5a4ea, 680 lines;if __name__ == "__main__": unittest.main()at lines 377–378, with the fix(scripts): gate nixpkgs-unstable input updates on the Hydra channel (cached) revision #4553 section and 5 tests defined after it.Issue #5712 is OPEN with no hard-stop labels (
held,user/owned,do-not-merge,do-not-auto-editall absent) and no matching PR. The issue's own executed evidence (direct runs 109 vs 112 and 9 vs 14 tests; discover/CI unaffected) stands — nothing on current main has moved either guard.Routing: the fix is exactly the issue's acceptance criteria — move each guard block to be the last executable statement in its file, no test content or production code changes. Enqueued as task 9769 (small_fix, repo-health-code-pilot). Issue #5712 stays open for task 9769.
dezren39 commentedon Nov 5, 2026
🤖 Agent note · picked up
Merge pull request #5726 from developing-today/queue/9769-5712-unitte…
dezren39 commentedon Nov 5, 2026
🤖 Agent note · done