Skip to content

fix: harden test fixtures and Herdr recovery - #24

Merged
TastyTom13 merged 2 commits into
mainfrom
fm/fm-firstmate-main-test-failures
Sep 7, 2026
Merged

TastyTom13 merged 2 commits into
mainfrom
fm/fm-firstmate-main-test-failures

Conversation

@TastyTom13

@TastyTom13 TastyTom13 commented Sep 7, 2026 •

Copy link
Copy Markdown
Owner

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 --all before 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:

  • Run the repository's test suite first to confirm the current failing list on main, then fix each root cause.
  • The 10 named scripts: fm-bearings-board, fm-captain-hold-lifecycle, fm-backend-herdr-presentation-e2e, fm-remote-secondmate-trace-context, fm-secondmate-reconcile, fm-wake-queue, fm-watch-triage, fm-chrome-bridge-sweep, fm-procevent-when, fm-procevent.
  • If a failure is environmental (a tool version, a macOS-only path, a missing fixture), make the test hermetic rather than skipping it, and say so in the PR body per test.
  • Do not delete or weaken assertions.
  • Keep the change under about 500 lines; stack two ordered PRs only if the fixes clearly split into unrelated areas.
  • Later instruction accepted mid-task: never run artificial load generators on this shared machine.

Deliberate decisions a reviewer reading only the diff would not know:

  1. Four distinct root causes were found, and each was fixed at its own owner rather than by relaxing a test.

  2. 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 -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 (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 in fm_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.

  3. fm-wake-queue asserts that a 20 KB status line survives a drain whole, using grep -Fx with that whole line as the pattern. macOS /usr/bin/grep aborts 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 shared assert_exact_line helper 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 to grep -Fx was checked empirically for backslashes, leading and trailing whitespace, a file with no trailing newline, and partial matches.

  4. fm-procevent's shell-injection probe passed second; rm -rf /tmp/nope as 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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.yml already runs tests/fm-backend-herdr-presentation-e2e.test.sh in a required real-Herdr lane that hard-fails on a skip.

  9. 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 touch that 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 --all reports 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) and bin/fm-doc-audience-check.sh both 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.yml runs both in required lanes. .no-mistakes.yaml in 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 --all was 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) and bin/fm-doc-audience-check.sh both 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

  • Extended Herdr presentation-journal recovery waits to 60 seconds while retaining the shorter budget for degrading callers, and updated backend documentation.
  • Canonicalized macOS temporary roots for fm-bearings-board, fm-captain-hold-lifecycle, fm-watch-triage, fm-chrome-bridge-sweep, fm-procevent-when, and fm-procevent; replaced the wake-queue long-line grep assertion with a shared exact-line helper.
  • Made fm-procevent's injection check use a fixture-owned surviving sentinel, and changed fm-secondmate-reconcile's busy-lock check from fixed sleeping to polling while the lock remains held.

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
FM_TEST_SUMMARY total=7 failed=0 skipped_gate=0

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

`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
TastyTom13 force-pushed the fm/fm-firstmate-main-test-failures branch from bb3aa95 to 09b86dc Compare September 7, 2026 17:57
@TastyTom13 TastyTom13 changed the title fix: restore green test suite and bound Herdr recovery contention fix: harden test fixtures and Herdr recovery Sep 7, 2026
@TastyTom13
TastyTom13 merged commit 8903a65 into main Sep 7, 2026
16 of 17 checks passed
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