Repository navigation
test(fm-turnend-guard): make adapter tests hermetic; add env-leak regression guard - #46
Conversation
…be the fixture
'healthy no-supervision-needed native stop must allow' failed on a clean
origin/main worktree on macOS while passing in CI (robots-qgcg).
The guard resolves its home as FM_HOME > FM_ROOT_OVERRIDE > the guard
script's own repo root (bin/fm-turnend-guard.sh:62-66). Every fixture here
installs the guard into its own <fixture>/bin/, so with those unset each
fixture self-resolves to its own state/. run_hook pins FM_HOME per-fixture,
which is why the direct-guard tests were always immune - but the harness
adapter tests invoke the hook the way the real Grok/codex adapters do, with
no per-call pin, so they inherited the ambient environment.
An agent session running inside a live firstmate home exports FM_HOME. The
grok adapter then handed the shared guard that REAL home, which had an
in-flight task and a fresh beacon, so the assertion's idle fixture reported
"1 task(s) in flight ... last beat: 13s ago" and exited 2. CI exports no
FM_HOME, so nothing leaked there. The sibling adapter cases that expect exit
2 were passing for the wrong reason on such a box - the host state also read
as in-flight - and now pass for the right one.
This is a test-hermeticity defect, not a product one: FM_HOME winning over
repo-root state is the guard's designed precedence, asserted by its own
passing tests ("blocks from active FM_HOME state, not only repo-root state"
and "ignores stale repo-root state when FM_HOME is set"), and no adapter -
Grok, codex, or Claude - pins it. So the fix restores the file's stated
"all hermetic over temp dirs" invariant rather than changing the guard.
Adds test_suite_environment_is_hermetic to pin the invariant, so a future
leak fails loudly and names the variable instead of silently making every
adapter verdict describe the developer's own home.
Verified: 51/51 pass, including under a deliberately hostile
FM_HOME + FM_STATE_OVERRIDE; dropping the unset reproduces the original
failure and trips the new guard first. bin/fm-lint.sh and
bin/fm-test-run.sh --check-coverage both clean.
Fixes robots-qgcg
|
Warning Review limit reached
Next review available in: 34 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Intent
Fix robots-qgcg: the test 'healthy no-supervision-needed native stop must allow' in tests/fm-turnend-guard.test.sh fails on a clean origin/main worktree on macOS (exit 2, expected 0) while passing in CI, which masks real regressions in the turn-end guard suite and forces every branch touching supervision to hand-baseline the test.
Root cause found: bin/fm-turnend-guard.sh:62-66 resolves its home as FM_HOME > FM_ROOT_OVERRIDE > the guard script's own repo root. Every fixture installs the guard into its own /bin/, so with those unset each fixture self-resolves to its own state/. run_hook (line 186) pins FM_HOME per-fixture, which is why the direct-guard tests were always immune; the harness-adapter tests (Grok/codex) invoke the hook the way the REAL adapters do, with no per-call pin, so they inherit the ambient environment. An agent session running inside a live firstmate home exports FM_HOME, so the grok adapter handed the shared guard that real home - which had an in-flight task and a fresh beacon - and the idle fixture reported '1 task(s) in flight ... last beat: 13s ago' and exited 2. CI exports no FM_HOME, so nothing leaked there.
DELIBERATE DECISION - fix the test, not the guard: FM_HOME winning over repo-root state is the guard's designed precedence, asserted by its own passing tests ('blocks from active FM_HOME state, not only repo-root state' and 'ignores stale repo-root state when FM_HOME is set'), and no adapter - Grok, codex, or Claude - pins it. So the product behavior is correct and must NOT be changed. This restores the file's own stated line-10 invariant ('All hermetic over temp dirs'). Reviewers should not propose changing bin/fm-turnend-guard.sh or making the adapters pin FM_HOME; that would break the designed precedence.
Change is test-only, +33 lines: (1) unset FM_HOME FM_ROOT_OVERRIDE FM_STATE_OVERRIDE FM_CONFIG_OVERRIDE at file scope; (2) a new test_suite_environment_is_hermetic that asserts none of those leak in, so a future regression fails loudly and names the offending variable instead of silently making every adapter verdict describe the developer's own live home.
Also noted deliberately: the sibling adapter cases that expect exit 2 were previously passing for the WRONG reason on such a box (host state also read as in-flight) and now pass for the right one.
Scope was audited: every sibling test file invoking a guard/supervision script pins FM_HOME except tests/fm-wake-queue.test.sh, which pins FM_STATE_OVERRIDE (the highest-precedence state selector) on every invocation and is therefore already hermetic - so no collateral changes were made on purpose.
Verified before pushing: 51/51 pass; 51/51 still pass under a deliberately hostile FM_HOME + FM_STATE_OVERRIDE; dropping the unset reproduces the original failure and trips the new guard first; bin/fm-lint.sh clean; bin/fm-test-run.sh --check-coverage clean (total=124 parallel=24 serial=89 herdr=11).
What Changed
unset FM_HOME FM_ROOT_OVERRIDE FM_STATE_OVERRIDE FM_CONFIG_OVERRIDEat file scope intests/fm-turnend-guard.test.shso harness-adapter tests (Grok/codex) no longer inherit an ambient developer home and produce verdicts about the fixture rather than the live session.test_suite_environment_is_hermetic— a regression guard that explicitly asserts none of those four variables are set when the suite runs, naming the offending variable on failure so future leaks are caught loudly instead of silently flipping adapter exits.docs/turnend-guard.mdregression coverage list to include suite environment hermeticity as a documented test dimension.Risk Assessment
✅ Low: Test-only change (+33 lines) that fixes a real hermeticity bug: the file-scope
unsetclears leaked env vars at script startup, the new hermetic regression test checks observable runtime state (not source text), placement in execution order is correct, and no guard or adapter behavior is touched.Testing
Ran
tests/fm-turnend-guard.test.shboth in a normal environment and under a hostileFM_HOME=/tmp/fake-hostile-fm-home(simulating a live firstmate session); 51/51 pass in both cases. Separately reproduced the pre-fix failure by running a copy of the file without theunsetline under the hostile FM_HOME — the suite correctly exits attest_suite_environment_is_hermeticwithnot ok - FM_HOME leaked into the suite, proving the fix is both correct and guarded by the new regression test.Evidence: Normal run — 51/51 pass
Evidence: Regression proof — without unset, hermetic guard catches FM_HOME leak
Evidence: Hermetic guard output (hostile env, with fix)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
FM_HOME=/tmp/fake-hostile-fm-home bash tests/fm-turnend-guard.test.sh— 51/51 pass; the unset at line 27 clears the leaked var before any test runs, including the grok adapter tests that previously failedbash tests/fm-turnend-guard.test.sh— 51/51 pass in a clean environmentbash tests/_regression-test-$$.sh(copy with unset line removed) withFM_HOME=/tmp/fake-hostile-fm-home— 29 ok thennot ok - FM_HOME leaked into the suite (=/tmp/fake-hostile-fm-home)+ exit 1, reproducing the original leak and confirming the new hermetic guard catches it✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.