test(guard): stabilize spawn-race fixtures#178
Conversation
Model the mocked daemon as live and bypass process-table probing in claim-focused contention tests. Keep freshness handling covered by a deterministic dead-PID test, so scheduler delays cannot turn fake child PIDs into apparent second spawns.
eggrollofchaos
left a comment
There was a problem hiding this comment.
Findings
High
tests/test_spawn_lock.py:455-463— The new "fresh dead PID" regression test is not deterministic under the supportedCOZEMPIC_PIDFILE_FRESH_SECONDSconfiguration. The implementation accepts any finite value in(0, 300], but the test advances its mocked clock by a fixed 1.0 second. With the valid settingCOZEMPIC_PIDFILE_FRESH_SECONDS=0.1, the file is correctly classified as stale, the claim is reclaimed, and this new test fails. Reproducer:COZEMPIC_PIDFILE_FRESH_SECONDS=0.1 env -u COZEMPIC_NO_AUTO_INIT uv run --frozen --with pytest pytest tests/test_spawn_lock.py::TestFreshClaimProtection::test_fresh_dead_pid_is_not_reclaimed -q. Fix by patching_FRESH_PIDFILE_SECONDSto a known value for this unit or deriving a mocked age strictly inside the active imported window.
Low
tests/test_spawn_lock.py:457-463— The new exception assertion leaves two calls in the expected-exception region and triggers the sole Sonar annotation on this PR. Construct the claim outside the assertion, then put onlyclaim.__enter__()(or an equivalent single helper call) insideassertRaises;assertRaisesalready fails if no exception is raised, so the explicitself.fail(...)is unnecessary.
Verification
- Packet command: 4 passed in 20.81s.
- Valid short-window probe above: 1 failed, reproducing the High finding.
- Valid long-window probe (
COZEMPIC_PIDFILE_FRESH_SECONDS=300): 1 passed. git diff --check fd41e95b85f283286eaca9419c19825abb6d053b..605aa1341c06859f186d198dd89c061de04f26d5: passed.- PR context checked at head
605aa1341c06859f186d198dd89c061de04f26d5: 1 top-level bot comment, 0 inline comments, 0 review threads (0 active), 0 prior reviews. The Sonar quality gate passed with the one Low annotation described above.
Counts: 0 Critical, 1 High, 0 Medium, 1 Low, 0 Nit.
Verdict: Critical/High findings remain.
Derive the mocked clock from the configured PID-file freshness window and keep only the claim operation in the expected-exception assertion.
|
eggrollofchaos
left a comment
There was a problem hiding this comment.
Self-review verdict: LGTM — approve.
The v2 continuation closes both prior findings:
- The fresh-dead-PID test now derives its mocked age from the active
_FRESH_PIDFILE_SECONDSvalue, so it remains strictly inside every supported positive window. Independent probes passed at0.1,1e-9, and300seconds. - The expected-exception block now contains only
claim.__enter__(), removing the multi-call assertion ambiguity and the prior static-analysis concern.
I also re-read both changed test files in full and traced the fixtures through start_guard_daemon, DaemonSpawnClaim, _is_process_alive, and the shared freshness gate. Treating the synthetic positive PIDs as alive correctly models the peer hand-off and makes the two-, three-, and ten-process contention fixtures independent of host PID state without weakening the production assertion.
Findings: none.
Verification:
- Exact-head targeted suite: 4 passed in 16.84s.
- Fresh-window probes:
0.1,1e-9, and300each passed. - Exact head:
b6fea7251c191f2c422a794d639f79cbec12a3ceover basefd41e95b85f283286eaca9419c19825abb6d053b. - PR context checked immediately before verdict: SonarCloud passed with 0 new issues; 1 top-level bot comment; 0 inline comments; 0 review threads; no unresolved current-head feedback; merge state CLEAN.
Counts: 0 Critical, 0 High, 0 Medium, 0 Low, 0 Nit.
Merge blocker: none from this review. This is a neutral confirmation only; no approval or merge action was performed.



Summary
Verification
uv run --frozen --with pytest pytest tests/test_guard_race_2026_05_18.py::TestR1_DaemonProcessRace::test_two_processes_one_winner tests/test_spawn_lock.py::TestThreeProcessContention::test_three_process_contention tests/test_spawn_lock.py::TestV4TenProcessContention::test_ten_process_contention_30x tests/test_spawn_lock.py::TestFreshClaimProtection::test_fresh_dead_pid_is_not_reclaimed -q