What happens
tests/fm-secondmate-harness.test.sh fails for anyone running the suite from inside a Claude Code session:
not ok - unmarked shared signed-wrapper ancestry resolved 'claude', expected pi
Nothing is wrong with the harness resolution. The test reads an ambient environment variable it never neutralises.
Cause
The assertion at tests/fm-secondmate-harness.test.sh:162-163 builds a fake ps ancestry and expects bin/fm-harness.sh to resolve pi:
got=$(PATH="$fakebin:$BASE_PATH" PI_CODING_AGENT=true "$ROOT/bin/fm-harness.sh")
[ "$got" = pi ] || fail "unmarked shared signed-wrapper ancestry resolved '$got', expected pi"
But bin/fm-harness.sh:38 short-circuits on the Claude marker before any ancestry walk:
[ "${CLAUDECODE:-}" = "1" ] && { echo claude; return; }
A Claude Code session exports CLAUDECODE=1, so it outranks the test's PI_CODING_AGENT=true pin and the fake ancestry is never consulted. The whole detect_own block of this file is affected, not just the one assertion that trips first.
Reproduce
At 99533c5 on any host, from inside a Claude Code session (or with CLAUDECODE=1 exported):
CLAUDECODE=1 bin/fm-test-run.sh tests/fm-secondmate-harness.test.sh
| Invocation |
Runs |
Result |
CLAUDECODE=1 bin/fm-test-run.sh tests/fm-secondmate-harness.test.sh |
2 |
exit=1, resolved 'claude', expected pi |
env -u CLAUDECODE bin/fm-test-run.sh tests/fm-secondmate-harness.test.sh |
1 |
exit=0 (duration_ms=114185 gate_skip=false) |
Expected: the suite is hermetic and passes regardless of which harness the contributor happens to be running it from.
Actual: it fails whenever the surrounding session exports CLAUDECODE=1.
Test-only counterfactual
Single variable, nothing under bin/ touched: env -u CLAUDECODE turns the file green. That isolates ambient environment as the sole cause — it is not host sensitivity and not a regression in the pi-signed adapter.
Proposed minimal fix
Scrub the harness markers at the top of the file, the same way tests/fm-session-start.test.sh already does. That file's prior art is at :408-420:
# Markers today: CLAUDECODE (claude), PI_CODING_AGENT plus FM_PI_HARNESS
# (Pi family), GROK_AGENT (grok).
env -u CLAUDECODE -u PI_CODING_AGENT -u FM_PI_HARNESS -u GROK_AGENT \
So either an unset CLAUDECODE PI_CODING_AGENT FM_PI_HARNESS GROK_AGENT near the top of tests/fm-secondmate-harness.test.sh (every assertion in the file already pins its harness explicitly, so nothing depends on the inherited values), or env -u on each detect_own invocation.
This is the same class PR #432 ("test: isolate session-start suite from ambient harness markers", merged as 3e3dff6) already fixed for the session-start suite; tests/fm-secondmate-harness.test.sh was missed.
Existing work
Open, unmerged PR #1200 ("fix(bin): keep firstmate parsing under stock macOS Bash 3.2") adds exactly this unset line to this file as one piece of a broad sweep. Filing separately so the defect is tracked independently of whether that sweep lands; if #1200 merges as-is, this closes with it. No existing issue reports it — searched CLAUDECODE, fm-secondmate-harness, ambient environment test, test fails macOS.
Environment
- firstmate
99533c5d7d3702050e6084429dddff6ea4fe1aa0
- macOS 15.7.7, Darwin 24.6.0, arm64
- Bash 5.3.9 (Homebrew), stock
/bin/bash 3.2.57
- Reproduced from inside Claude Code (ambient
CLAUDECODE=1); platform-independent
What happens
tests/fm-secondmate-harness.test.shfails for anyone running the suite from inside a Claude Code session:Nothing is wrong with the harness resolution. The test reads an ambient environment variable it never neutralises.
Cause
The assertion at
tests/fm-secondmate-harness.test.sh:162-163builds a fakepsancestry and expectsbin/fm-harness.shto resolvepi:But
bin/fm-harness.sh:38short-circuits on the Claude marker before any ancestry walk:A Claude Code session exports
CLAUDECODE=1, so it outranks the test'sPI_CODING_AGENT=truepin and the fake ancestry is never consulted. The wholedetect_ownblock of this file is affected, not just the one assertion that trips first.Reproduce
At
99533c5on any host, from inside a Claude Code session (or withCLAUDECODE=1exported):CLAUDECODE=1 bin/fm-test-run.sh tests/fm-secondmate-harness.test.shresolved 'claude', expected pienv -u CLAUDECODE bin/fm-test-run.sh tests/fm-secondmate-harness.test.shduration_ms=114185 gate_skip=false)Expected: the suite is hermetic and passes regardless of which harness the contributor happens to be running it from.
Actual: it fails whenever the surrounding session exports
CLAUDECODE=1.Test-only counterfactual
Single variable, nothing under
bin/touched:env -u CLAUDECODEturns the file green. That isolates ambient environment as the sole cause — it is not host sensitivity and not a regression in thepi-signedadapter.Proposed minimal fix
Scrub the harness markers at the top of the file, the same way
tests/fm-session-start.test.shalready does. That file's prior art is at:408-420:So either an
unset CLAUDECODE PI_CODING_AGENT FM_PI_HARNESS GROK_AGENTnear the top oftests/fm-secondmate-harness.test.sh(every assertion in the file already pins its harness explicitly, so nothing depends on the inherited values), orenv -uon eachdetect_owninvocation.This is the same class PR #432 ("test: isolate session-start suite from ambient harness markers", merged as
3e3dff6) already fixed for the session-start suite;tests/fm-secondmate-harness.test.shwas missed.Existing work
Open, unmerged PR #1200 ("fix(bin): keep firstmate parsing under stock macOS Bash 3.2") adds exactly this
unsetline to this file as one piece of a broad sweep. Filing separately so the defect is tracked independently of whether that sweep lands; if #1200 merges as-is, this closes with it. No existing issue reports it — searchedCLAUDECODE,fm-secondmate-harness,ambient environment test,test fails macOS.Environment
99533c5d7d3702050e6084429dddff6ea4fe1aa0/bin/bash3.2.57CLAUDECODE=1); platform-independent