Repository navigation
fix: harden test fixtures and Herdr recovery - #24
Merged
Merged
Conversation
`bin/fm-test-run.sh --all` failed ten scripts on main, all of them on this host rather than in CI. Four root causes, none of them a weakened assertion. Non-canonical fixture roots (six scripts: fm-bearings-board, fm-captain-hold-lifecycle, fm-watch-triage, fm-chrome-bridge-sweep, fm-procevent-when, fm-procevent). macOS puts TMPDIR under /var, which is a symlink to /private/var, so `mktemp -d` handed every fixture a state root that still traverses a symlink. Firstmate deliberately refuses a state root whose recorded path is not already its own symlink-free physical path, so those fixtures exercised that refusal instead of the behavior under test. `fm_test_tmproot` now resolves the root once. Confirmed by running those six against the pre-change helper (all exit 1) and against the new one (all exit 0) on an otherwise quiet host. BSD grep's fixed-pattern limit (fm-wake-queue). The oversized-status case asserts a 20 KB line survives whole, and macOS `/usr/bin/grep -Fx` aborts with "out of memory" past roughly 4 KB, turning a real comparison into a tool failure. A new `assert_exact_line` helper compares with awk through the environment instead, with both operands forced to strings so awk cannot compare two numeric-looking lines numerically. A machine-global, inverted injection probe (fm-procevent). The argv probe asserted /tmp/nope was absent after passing `second; rm -rf /tmp/nope` as one literal argument. That path is outside the fixture, so an unrelated file on this host failed the test, and the probe proved nothing anyway: a removed file is equally absent when nothing interpreted the argument. The probe now names a fixture-owned sentinel that must survive. A wall-clock budget standing in for a blocking check (fm-secondmate-reconcile). The busy-lock case slept 0.2 seconds and then required the run to have already exited, so a slow but unblocked run on a loaded machine failed. It now polls for that exit by iteration while the lock is still held, which proves the same property without the load sensitivity. A mutation that makes the run genuinely wait for the lock is still caught. The tenth (fm-backend-herdr-presentation-e2e) was a product defect, not a fixture one. Presentation-journal recovery waits 5 seconds for the shared session lock and then refuses the spawn, but a peer holds that lock from its own acquisition through worktree creation, projected pane creation, and launch delivery: measured at 9 seconds here. Every genuinely concurrent recovery therefore refused. The recovery path now waits 60 seconds while the degrading fresh-create and abort-cleanup paths keep their short budget, so the documented refusal still fires on a lock that is contended after waiting out its holder. fm-remote-secondmate-trace-context was named in the original list but does not fail on this host at this commit's parent, and is unchanged here.
TastyTom13
force-pushed
the
fm/fm-firstmate-main-test-failures
branch
from
September 7, 2026 17:57
bb3aa95 to
09b86dc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Goal: make the firstmate test suite green on main so that a red run means something again. The 10 test scripts that already failed on
bin/fm-test-run.sh --allbefore PR 20 must pass, and no test may be weakened. This work touches firstmate's own shared tracked material, so the firstmate-coding-guidelines skill applies.Requirements as given by the user:
Deliberate decisions a reviewer reading only the diff would not know:
Four distinct root causes were found, and each was fixed at its own owner rather than by relaxing a test.
Six of the ten (fm-bearings-board, fm-captain-hold-lifecycle, fm-watch-triage, fm-chrome-bridge-sweep, fm-procevent-when, fm-procevent) failed because macOS puts TMPDIR under /var, a symlink to /private/var, so
mktemp -dhanded every fixture a state root that still traverses a symlink. Firstmate deliberately refuses a state root whose recorded path is not already its own symlink-free physical path (fm_procevent_claim_state_root_identity), so those fixtures were exercising that refusal instead of the behavior under test. The fix canonicalises the root once infm_test_tmproot, which is the single shared owner, rather than patching six scripts. This was proved causal by running those six against the pre-change helper (all exit 1) and the new one (all exit 0) on a quiet host. Deliberately NOT changed: the product's refusal itself, which is a real safety property, and every test that builds a symlink INSIDE its fixture still does so and still passes.fm-wake-queue asserts that a 20 KB status line survives a drain whole, using
grep -Fxwith that whole line as the pattern. macOS/usr/bin/grepaborts with "out of memory" on a fixed pattern past roughly 4 KB (measured: 4000 chars pass, 8000 fail), so the assertion was failing as a tool error, not a real comparison. A new sharedassert_exact_linehelper compares with awk, passing the wanted text through the environment so awk never reinterprets a backslash, and concatenating "" onto both operands so awk cannot compare two numeric-looking lines numerically. Equivalence togrep -Fxwas checked empirically for backslashes, leading and trailing whitespace, a file with no trailing newline, and partial matches.fm-procevent's shell-injection probe passed
second; rm -rf /tmp/nopeas one literal argument and then asserted /tmp/nope was absent. That path is outside the fixture, so an unrelated pre-existing file on the host failed the test; worse, the probe was vacuous, because a removed file is equally absent when nothing interpreted the argument at all. The probe now creates a fixture-owned sentinel and asserts it SURVIVES, which is a genuine negative control and strictly stronger than what it replaced.fm-secondmate-reconcile's busy-lock case slept 0.2 seconds and then required the run to have already exited, so a slow but unblocked run on a loaded machine failed. CONTRIBUTING.md explicitly warns against exactly this wall-clock shape. It now polls for that exit by iteration while the lock is STILL held, which proves the same property (the busy lock never held the run up) without the load sensitivity. A mutation that makes the run genuinely wait for the lock was injected and is still caught, so the case is not vacuous.
fm-backend-herdr-presentation-e2e was a product defect, not a fixture one, and is the only production change here. Presentation-journal recovery waited 5 seconds (50 polls of 0.1s) for the shared Herdr session lock and then refused the spawn outright. A peer holds that same lock from its own acquisition through worktree creation, projected pane creation, and launch delivery, measured at 9 seconds on an idle macOS host, so every genuinely concurrent recovery in two homes refused. The recovery call site now passes a 60-second budget through a new optional attempts parameter, while the two degrading call sites (fresh projected-create and abort cleanup) keep the old 5-second budget on purpose: contention there falls back to the ordinary flat layout, so waiting long would only delay a spawn that continues anyway. docs/herdr-backend.md's bullet was amended in place (one-owner rule) to say the refusal fires on a lock still contended after a bounded wait sized to outlast one peer spawn. Deliberately NOT changed: the documented refusal semantics themselves.
fm-remote-secondmate-trace-context was named in the original list but does not fail on this host at this commit's parent, and is left unchanged. It contains no sleep and no wall-clock budget. Reported rather than silently dropped.
No new portable regression test was added for the Herdr lock budget: the behaviour needs a live Herdr session and an existing presentation journal, so it cannot be exercised portably, and
.github/workflows/ci.ymlalready runs tests/fm-backend-herdr-presentation-e2e.test.sh in a required real-Herdr lane that hard-fails on a skip.Known follow-up deliberately left out of scope: tests/fm-on.test.sh:142 asserts on the machine-global path /tmp/fm-on-injected. That probe is logically sound (a
touchthat must not happen) and currently passes, but it is not hermetic, so it is reported rather than changed here.Verification already performed locally, twice, on this exact change:
bin/fm-test-run.sh --allreports total=187 failed=0 skipped_gate=27, with all ten named scripts at exit=0 and gate_skip=false.bin/fm-lint.sh(ShellCheck 0.11.0 plus actionlint 1.7.12) andbin/fm-doc-audience-check.shboth pass.Test step scope, which matters because this host's no-mistakes agent test budget is a machine-global 30 minutes shared by every lane and this repository's full suite takes over three hours. Run EXACTLY this one command for the Test step and nothing broader:
bin/fm-test-run.sh tests/fm-bearings-board.test.sh tests/fm-captain-hold-lifecycle.test.sh tests/fm-chrome-bridge-sweep.test.sh tests/fm-procevent-when.test.sh tests/fm-procevent.test.sh tests/fm-secondmate-reconcile.test.sh tests/fm-wake-queue.test.sh
It was measured at 476 seconds on this host and reports FM_TEST_SUMMARY total=7 failed=0 skipped_gate=0. Do NOT run
bin/fm-test-run.sh --all,--family,--lane, or any broader walk: two earlier runs of this pipeline (01M1YA204VGBSGV8AM4T1QDYT0 and 01M1YBYVBWEF6RDRAFT6HF399H) died on the 30-minute agent cap doing exactly that, with no test actually failing. The two named scripts left out of that command are deliberate: tests/fm-backend-herdr-presentation-e2e.test.sh needs a live Herdr session and takes about 10 minutes, and tests/fm-watch-triage.test.sh takes about 5 minutes;.github/workflows/ci.ymlruns both in required lanes..no-mistakes.yamlin this repository states this division explicitly: local Test is intent-targeted validation, CI owns broad regression.Evidence already on record for this exact content:
bin/fm-test-run.sh --allwas run twice locally and reported total=187 failed=0 skipped_gate=27 both times, with all ten named scripts at exit=0 and gate_skip=false. CI on pull request 24 for this same content reported 14 of 15 checks passing, including every portable behaviour shard, the required real-Herdr lane, Lint, the coverage guard, stock macOS Bash compatibility, and repo invariants; the single failure was the attestation check refusing a skipped Test step, which is why the Test step runs for real this time.bin/fm-lint.sh(ShellCheck 0.11.0 plus actionlint 1.7.12) andbin/fm-doc-audience-check.shboth pass locally.The PR body should carry the per-test hermeticity notes from decisions 2 to 5 above, as the requester asked for a note per environmental failure.
What Changed
Risk Assessment
✅ Low: The changes are bounded test-harness fixes plus a documented, finite Herdr lock-wait adjustment with preserved fallback and refusal semantics.
Testing
Ran the exact seven-script targeted suite; all 7 passed with failed=0 and skipped_gate=0.
Evidence: Targeted test summary
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.
bin/fm-test-run.sh tests/fm-bearings-board.test.sh tests/fm-captain-hold-lifecycle.test.sh tests/fm-chrome-bridge-sweep.test.sh tests/fm-procevent-when.test.sh tests/fm-procevent.test.sh tests/fm-secondmate-reconcile.test.sh tests/fm-wake-queue.test.sh✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Built by: claude/opus at default