Skip to content

test: gate real-Herdr tests on a provisionable lab and assert resolver contracts, not host identity - #1

Merged
mattadams-dev merged 8 commits into
mainfrom
fm/fm-test-suite-environmental-failures
Jul 30, 2026
Merged

mattadams-dev merged 8 commits into
mainfrom
fm/fm-test-suite-environmental-failures

Conversation

@mattadams-dev

Copy link
Copy Markdown
Owner

Intent

Make firstmate's own test suite green on an ordinary developer machine by fixing how 12 tests gate on their preconditions. These tests were red for environmental reasons, not because any production code was broken, and a suite that is red by default trains everyone to ignore red - which is exactly when a real regression slips through.

Two distinct causes

1. Eleven tests: an installed-but-not-running dependency hard-failed instead of skipping.

The real-Herdr tests gated on command -v herdr, which passes whenever the binary is on PATH but proves nothing about session state. They then required a running default Herdr session and hard-failed when there wasn't one. The bug was the gate, not the environment.

Fix: gate on whether an isolated lab can actually be provisioned, via a new gate subcommand on bin/fm-herdr-lab.sh. Its verdict derives from the same fm_herdr_lab_fleet_state call that prepare/provision use, so the gate and the provisioning tripwire can never disagree. Tests now skip with a reason naming the missing precondition instead of failing on something they cannot create.

2. One test asserted a specific harness name.

fm-secondmate-harness expected pi and got claude, because resolution reads the actual process ancestry of whatever harness runs the suite. An earlier partial fix stubbed ancestry with a fake ps, but that was insufficient: bin/fm-harness.sh consults its env markers first, so CLAUDECODE=1 decided the result before the ancestry stub was ever reached, and an ambient PI_CODING_AGENT would have satisfied the "no Pi marker" case for the wrong reason.

Fix: drop every ambient marker per call and set only the ones each case is about, so the test asserts the resolver's contract rather than the host runtime's identity. tests/fm-session-start.test.sh had the same class of ambient coupling (a named herdr session overriding its pinned fake fixture) and is corrected the same way.

Both directions are proven

A gate that always skipped would hide the same regressions a red suite does, so the pass direction is proven too:

  • Locally, with a fake-Herdr fixture - deterministic, and it never touches the live default session (a hard safety constraint; the lab helper's tripwire requires that session to stay byte-identical).
  • In CI, for real: the required Herdr lane starts a default session and fails on the gate-skip token, so the gate cannot turn that lane green by skipping the work.

The lane derives its token from bin/fm-herdr-lab.sh gate-token rather than repeating a string literal, so renaming the token cannot leave the lane guarding a string the gate no longer prints. bin/fm-test-run.sh also refuses an empty --fail-on-gate-skip token, since an empty token matches nothing and would silently disable the guard the caller asked for.

No coverage was weakened

No test is disabled or deleted. The branch's test diff removes exactly one line - a fixture conditional in the fake-herdr stub - and no assertions.

Verification

Full suite on an ordinary machine (Herdr installed, no running default session): 95 total, 0 failed.

Before/after on the same machine, --family real-herdr-gated:

base HEAD
total=10 failed=10 skipped_gate=0 total=10 failed=0 skipped_gate=9

Cause 2 reproduced and confirmed fixed under deliberately hostile ambient env (CLAUDECODE=1, HERDR_SESSION=co-captain).

The CI guarantee was exercised by running the lane's exact command shape on a session-less machine: it failed with all ten flagged required gate skip token seen.

Follow-up filed separately

The gate, the runner's token guard, and the CI lane remain coupled. That structural redesign is deliberately not attempted here and is filed as its own task, starting from this improved state.

command -v herdr proves a binary is on PATH and proves nothing about session
state, so every real-Herdr test hard-failed on an ordinary machine where herdr
is installed but no default session runs - the lab helper's fleet-state tripwire
needs one. Add a gate command to bin/fm-herdr-lab.sh, the owner of that tripwire,
so the gate and provisioning can never disagree, and route all ten gated tests
through it.
Two tests read the identity of whatever harness and runtime session happened to
launch the suite:

fm-secondmate-harness stubbed process ancestry but left bin/fm-harness.sh's env
markers ambient, and those are consulted FIRST - so CLAUDECODE=1 decided the
result under claude, and an ambient PI_CODING_AGENT would have satisfied the
no-Pi-marker case for the wrong reason.

fm-session-start pins herdr_session=default in its fake-herdr fixtures, but a
firstmate running inside a NAMED herdr session resolved that operator session
instead, because ambient selection is the documented backend contract
(fm_backend_herdr_session).

Both now drop the ambient inputs on each call, the idiom run_session_start
already used for harness markers.
…rage guard

Adds the gate's own coverage: with a running default session it passes silently
and provisioning really succeeds; with the session stopped, absent, unlistable,
or herdr/jq missing it refuses with one reason line naming the cause. Each case
also asserts the gate agrees with what provisioning would do, so the two cannot
drift.

A gate can also fail by skipping too much, which would look green. The required
CI Herdr lane is what forbids that - it starts a default session and must run
the real bodies - so --fail-on-gate-skip becomes repeatable, the lane lists the
new token too, and a test binds that token to the lane.
Upstream kunchenguid#1282 forbids asserting implementation-source bytes, so the ci.yml grep
is gone. The guarantee it protected - a renamed gate cause or token slipping past
the required Herdr lane's over-skip guard - now runs through executables instead:
the real bin/fm-herdr-lab.sh gate produces a real refusal reason, and the real
runner must fail on it under the token.
@mattadams-dev
mattadams-dev merged commit 8c36fed into main Jul 30, 2026
9 of 10 checks passed
mattadams-dev added a commit that referenced this pull request Jul 31, 2026
…mmits)

Conflicts: 8 test files, one uniform pattern - fork PR #1's provisionable-lab
gate vs upstream's new inherited-pane hygiene at the same insertion point.
Resolved as the union everywhere (gate first, then pane hygiene): the two
changes are complementary, not competing. fm-secondmate-harness kept the
fork side whole - upstream's seven assertions all exist there and the
file's tail references the fork's nomarkers array.
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