Skip to content

test(guard): stabilize spawn-race fixtures#178

Open
eggrollofchaos wants to merge 2 commits into
Ruya-AI:mainfrom
eggrollofchaos:codex-guard/race-test-stability
Open

test(guard): stabilize spawn-race fixtures#178
eggrollofchaos wants to merge 2 commits into
Ruya-AI:mainfrom
eggrollofchaos:codex-guard/race-test-stability

Conversation

@eggrollofchaos

Copy link
Copy Markdown

Summary

  • model mocked guard processes as live in claim-focused contention tests
  • keep fresh dead-PID protection covered by a deterministic unit test

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

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
eggrollofchaos marked this pull request as ready for review July 15, 2026 06:27

@eggrollofchaos eggrollofchaos left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings

High

  1. tests/test_spawn_lock.py:455-463 — The new "fresh dead PID" regression test is not deterministic under the supported COZEMPIC_PIDFILE_FRESH_SECONDS configuration. 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 setting COZEMPIC_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_SECONDS to a known value for this unit or deriving a mocked age strictly inside the active imported window.

Low

  1. 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 only claim.__enter__() (or an equivalent single helper call) inside assertRaises; assertRaises already fails if no exception is raised, so the explicit self.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.
@sonarqubecloud

Copy link
Copy Markdown

@eggrollofchaos eggrollofchaos left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_SECONDS value, so it remains strictly inside every supported positive window. Independent probes passed at 0.1, 1e-9, and 300 seconds.
  • 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, and 300 each passed.
  • Exact head: b6fea7251c191f2c422a794d639f79cbec12a3ce over base fd41e95b85f283286eaca9419c19825abb6d053b.
  • 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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant