Skip to content

cargo-target-janitor: owner_changed tests never run — defined after unittest.main(), outside the test class #5710

Closed

Description

@dezren39

cargo-target-janitor: the two owner_changed tests never run — they are defined after unittest.main(), outside the test class

Evidence (verified this run @ af0847d)

infra/cargo-target-janitor/tests/test_cargo_target_janitor.py:

  • Line 191-192: the file ends its class body and closes with
    if __name__ == "__main__":
        unittest.main()
  • Lines 194 and 208: test_owner_changed_when_worktree_switched_branch and
    test_owner_changed_ignores_adhoc_targets are defined after that call,
    indented inside the if __name__ block — not as methods of JanitorTests.
    unittest.main() also exits the process, so the two defs are never even
    reached at runtime, and unittest discovery never sees them either way.

Reproduction (run against the file as committed):

$ python3 tests/test_cargo_target_janitor.py -v
...
Ran 11 tests in 0.053s
OK

An AST walk of the file finds 13 test_* functions; only the 11 class
methods run. The two dead tests are the only coverage for
owner_changed() (infra/cargo-target-janitor/bin/cargo_target_janitor.py:69),
the guard the --apply path re-checks immediately before shutil.rmtree
(same file, line 548): if the worktree owning a target switched branch/task
since the plan, deletion must stop (the #4175 Codex P2 fix).

The function itself is currently correct — calling it directly with the dead
tests' fixtures gives the expected results (switched → True, same → False,
unregistered → True, ad-hoc → False) — so this is illusory coverage, not a
live logic bug: any future regression in owner_changed would pass CI green
while the file appears to test it.

Why it matters

This tool deletes directory trees (shutil.rmtree) under ~/git/fleet.
owner_changed is one of the last-moment safety re-checks that keep it from
removing a target whose checkout was repurposed after planning. A safety
guard whose tests silently never execute is exactly the kind of coverage
that fails only when it is needed.

Acceptance criteria

  • test_owner_changed_when_worktree_switched_branch and
    test_owner_changed_ignores_adhoc_targets are methods of
    JanitorTests (moved above the if __name__ == "__main__": guard).
  • python3 tests/test_cargo_target_janitor.py reports 13 tests and
    passes (previously 11).
  • No change to bin/cargo_target_janitor.py behavior is needed; if the
    rescued tests fail against the current implementation, that failure is
    reported on this issue rather than edited away in the tests.

Activity

  1. added
    kind/testTest coverage, test infrastructure, or test-only fixes
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    queue/queuedHas a queued task in the Supabase agent queue
    app/cargo-target-janitorPackage/app: cargo-target-janitor (infra/ in this repo)
    on Nov 4, 2026
  2. dezren39 commented on Nov 4, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator-code-b (Lane B, developing-today/code)
    • Session / ID: cron job new-issue-creator-code-b, run 2026-11-04T23:38Z
    • Found via: filed this run
    • Task: Filed issue cargo-target-janitor: owner_changed tests never run — defined after unittest.main(), outside the test class #5710 — the cargo-target-janitor's two owner_changed tests are defined after unittest.main(), outside JanitorTests, so they never run (suite reports 11 tests, file defines 13 test functions). Verified by executing the suite and by calling owner_changed directly with the dead tests' fixtures (all expectations pass — illusory coverage, not a live logic bug).
    • Expectation: effort xs — move the two methods into the class; suite then reports 13 tests, green.
    • Links: body file hidden_files/issue-janitor-dead-owner-changed-tests.md; queue packet hidden_files/packet-5710-fix.json
  3. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed
    queue/queuedHas a queued task in the Supabase agent queue
    on Nov 5, 2026
  4. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    event: picked_up
    task: 9759
    worker: repo-worker-code (lane code-f)
    stage: claimed
    summary: Triage claimed by lane code-f (direct execution lane). Verifying the dead-test claim against current main: AST count of test_* functions vs the count unittest actually runs, on the laptop clone.

  5. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    event: triaged
    task: 9759
    worker: repo-worker-code (lane code-f)
    stage: bookkeeping_complete
    summary: Triage verdict: CONFIRMED on current main 03032fd. Verified fresh on the laptop clone: infra/cargo-target-janitor/tests/test_cargo_target_janitor.py line 16 class JanitorTests; lines 191-192 if __name__ == "__main__": unittest.main(); the two test_owner_changed_* defs sit at lines 194/208 indented inside that if-block, after main(). AST walk: 13 test_* functions in the file, only 11 are JanitorTests methods. Running the file reports "Ran 11 tests OK". The function under test (owner_changed, bin/cargo_target_janitor.py:69) is the --apply path's last-moment re-check before shutil.rmtree (line 548), so this is illusory coverage on a safety guard, exactly as filed. Follow-up fix enqueued as task 9772 (small_fix, repo-health-code-pilot): move both tests into JanitorTests; acceptance is 13 tests running and passing, with any rescued-test failure reported here rather than edited away.

  6. added
    queue/queuedHas a queued task in the Supabase agent queue
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    queue/queuedHas a queued task in the Supabase agent queue
    on Nov 5, 2026
  7. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    event: picked_up
    task: 9772
    worker: repo-worker-code (lane code-l)
    stage: claimed
    summary: Fix claimed by lane code-l (direct execution lane). Moving the two dead test_owner_changed_* functions into JanitorTests so the suite runs 13 tests; no change to bin/cargo_target_janitor.py behavior.

  8. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    event: done
    task: 9772
    worker: repo-worker-code (lane code-l)
    stage: bookkeeping_complete
    summary: Fixed and merged via PR #5729 (merge a719a69). Moved the main guard to EOF in infra/cargo-target-janitor/tests/test_cargo_target_janitor.py so both test_owner_changed_* are JanitorTests methods. Verified on laptop: suite went from Ran 11 tests to Ran 13 tests, all OK; no change to bin/cargo_target_janitor.py. Codex review on PR #5729 completed with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/cargo-target-janitorPackage/app: cargo-target-janitor (infra/ in this repo)kind/testTest coverage, test infrastructure, or test-only fixespriority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions