fix(tests): pin session id in the three session-filtered job-listing tests - #45
Conversation
…tests
`status` and `result` without an explicit job id filter the job list down to
the current Claude session (filterJobsForCurrentSession, job-control.mjs:22).
That filter is a no-op only when CODEX_COMPANION_SESSION_ID is unset.
Three tests wrote fixture jobs with no `sessionId` and invoked run() with no
`env`, so the child inherited whatever the host exported. In CI and a bare
shell the variable is unset, the filter is a no-op, and they pass. Inside a
Claude Code session the host exports a real session id, every fixture job is
filtered away, and all three fail:
✖ status shows phases, hints, and the latest finished job
✖ status preserves adversarial review kind labels
✖ result returns the stored output for the latest finished job by default
AssertionError: No finished Codex jobs found for this repository yet.
These were previously described as pre-existing flakes. They are not flaky —
they are deterministic given the ambient environment.
Fix follows the pattern already used by "status without a job id only shows
jobs from the current Claude session" (runtime.test.mjs:1703): pin
sessionId: "sess-current" on the fixture jobs and pass a matching
CODEX_COMPANION_SESSION_ID to the child. Production code is untouched.
Scrubbing the variable in helpers.mjs run() was tried first and rejected: it
makes the filter a no-op, so the listing then includes unrelated jobs and
breaks four other tests that rely on the filtering being active (status
--wait, both cancel tests, the stop-hook gate test).
Full suite is now 95/95 with the variable exported, where it was 92/95 before.
Refs #43
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FQBJirbWNKWhnpFUnWogB8
ed63724 to
ff072aa
Compare
🔍 Local review (cycle 1)Reviewed locally (
Totals: 0 FIX, 0 UNVERIFIED, 1 SKIP (deferred to follow-up). Verification performed during triageThe diagnosis was re-verified against production source rather than taken from the PR body:
Generalization check (beyond the PR's own claim): the PR reports 96/96 with the author's session id exported. Re-ran the full suite with a synthetic value ( Codex's Deferred finding
|
Summary
Fixes the three test failures that #41's PR body described as "pre-existing
status/resultjob-listing flakes reproducing identically on unmodifiedmain". They are not flakes — they fail deterministically whenever the suite runs inside a Claude Code session, and pass everywhere else.Tracked as Finding 3 in #43.
Root cause
statusandresultwithout an explicit job id filter the job list down to the current Claude session viafilterJobsForCurrentSession(job-control.mjs:22-28). That filter is a no-op only whenCODEX_COMPANION_SESSION_IDis unset:Three tests wrote fixture jobs carrying no
sessionIdand calledrun()with noenv, so the child inherited whatever the host exported:Note the earlier hypothesis recorded in #43 —
CLAUDE_PLUGIN_DATAleaking throughrun()— was wrong and is corrected there. The test still fails with that variable unset, andresolveStateDirreturns an identical path in-process and in the child.Fix
Follow the pattern already established by "status without a job id only shows jobs from the current Claude session" (
runtime.test.mjs:1703), which does this correctly: pinsessionId: "sess-current"on the fixture jobs and pass a matchingCODEX_COMPANION_SESSION_IDto the child.Tests only — no production code is touched.
Rejected alternative
Scrubbing
CODEX_COMPANION_SESSION_IDcentrally inrun()(tests/helpers.mjs) looks tidier and is wrong: it makes the filter a no-op, so listings then include unrelated jobs, breaking four tests that depend on the filter being active —status --wait times out cleanly, bothcanceltests, and the stop-hook review-gate test. Measured 3 failures before, 7 after. Recorded in #43 so it isn't retried.Test plan
All runs with
CODEX_COMPANION_SESSION_IDexported (i.e. the condition that used to be red):node --test tests/runtime.test.mjs→ 96 tests, 96 pass, 0 fail, rebased onto currentmain(includes fix: measure turn timeout as agent idle time, not total wall-clock #41 and fix: forward turnTimeoutMs to adversarial-review's runAppServerTurn call #44). On the original base this was 95/95, up from 92/95.mainunder identical conditions → 92/95, failing exactly the three tests aboveenv -u CODEX_COMPANION_SESSION_IDon cleanmain→ those three green, confirming the mechanismnpm run build— passesnpm run check-version— all metadata matches1.0.6-fork.6Version
No bump — test-only change.
🤖 Generated with Claude Code
https://claude.ai/code/session_01FQBJirbWNKWhnpFUnWogB8