Repository navigation
test(bin): isolate directly invoked suites from the ambient fleet environment - #3098
AgardnerAU wants to merge 16 commits into
Conversation
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the previously reported indirect-suite selection issue is resolved because the emitted watcher family expands to include both affected suites. Reviews (7): Last reviewed commit: "Revert "no-mistakes: apply CI fixes"" | Re-trigger Greptile |
bin/fm-test-run.sh isolated the environment only in its --jobs worker subshell, so the default serial path ran every test script with FM_HOME and the FM_*_OVERRIDE pointers inherited verbatim. Firstmate exports FM_HOME into a worker, so a suite run the default way read and wrote the real locks, wake queue, and task records, and produced false failures. Move the contract to bin/fm-test-env-lib.sh and clear the pointers once in each runner process, before any script starts. Every selected script is a child of that process, so serial runs, --jobs workers, and isolation-proof workers all inherit the cleared environment and no caller has to pass a flag. Both runners drop their own copy of the list, which is how the two paths drifted apart in the first place. The list also gains the pointers the old copy missed: FM_ROOT, the durable record paths, and the primary-home pointer a worker carries. The helper refuses if any pointer survives, so a runner that cannot isolate stops instead of running against the live home.
A worker's environment carries FM_SESSION_START_STAGE_FILE as well as the home pointers, left there by the session start the worker was launched from. bin/fm-session-start.sh treats that variable's presence as "I am already the bounded child" and skips its own runtime bound, so a test that inherits one loses the bound it is asserting: tests/fm-session-start installs a git that ignores SIGTERM and sleeps 600 seconds, and the suite sits on that fixture instead of failing. Verified directly: with a hanging git on PATH and a 3 second budget, a clean environment truncates and exits 0 in 3 seconds, while the same run with the variable set was still going after 25 seconds. Add it to the shared list, which now covers both classes: the pointers a Firstmate script uses to find a home, and the control variables a live session start creates.
…rs, drive helper test from list
5a9c530 to
efcbb99
Compare
|
@greptileai Re-review requested. The The experimentScratch clone at ResultBoth suites named in the finding are selected. The selection is the complete suite, so nothing is omitted. Why the needle never had to match themSelection here is family-expanded, not needle-expanded, which is the step the finding's reasoning skips:
So the family is selected on their match, and both watch suites come in with it — whether or not the scan ever looks at On the removed helper closureAn earlier round of this PR did add a transitive needle closure over If a future family ever contains only indirect reachers, that changes and the closure becomes necessary. That case does not exist today, and the fix then would be small and would arrive with a real reproducer. If this is wrongIf you have a concrete case at |
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
faca4c9 to
910b96a
Compare
Workflow runs are held, not failingAll three workflow runs at head
To be explicit about what that means: nothing has run, and nothing here has passed. I am not claiming CI is green — I am saying no job ever started, so there is no result either way. Could a maintainer release the runs for this PR? The What this fixes
There is a second, louder symptom: the direct path also leaves Independent confirmation, which I did not have to construct: the Greptile review on the dependency PR #3026 raised Local evidence at
|
| check | result |
|---|---|
tests/fm-pending-reply.test.sh |
exit 0 (previously refused at the first send) |
tests/fm-session-start.test.sh |
exit 0 in 204s (previously still running when killed at a 420s bound) |
tests/fm-test-run.test.sh |
exit 0 |
tests/fm-send-inbox.test.sh |
exit 0 |
tests/fm-send-strict.test.sh |
exit 0 |
tests/fm-send-resolve-key.test.sh |
exit 0 |
tests/fm-send-secondmate-marker.test.sh |
exit 0 |
bin/fm-lint.sh |
exit 0 |
bin/fm-doc-audience-check.sh |
exit 0 |
Disconfirming checks, so the suite is not green by weakening:
- Removing the fix turns both the originally reported case and the new regression test red again.
- The reported case still fails when the behaviour it protects is removed — dropping the
kind=secondmatecondition that keeps crewmate steers unmarked.
Merge order
#3026 should merge first. It introduces bin/fm-test-env-lib.sh, the owner this change calls, so that file does not exist on main until it lands. This branch carries #3026's commits for that reason; once #3026 merges they drop out of this diff and only the isolation-caller change and its regression coverage remain.
…vironment tests/fm-pending-reply.test.sh's unmarked-crewmate-send case fails whenever the suite is invoked directly from a firstmate worker, independent of locale. A worker's environment carries the live home's pointers, and FM_STATE_OVERRIDE outranks FM_HOME/state in every script that reads it. The fixture sets its own FM_HOME but inherits the rest, so bin/fm-send.sh resolved state/<id>.meta under the live fleet home, could not find the fixture's target, and refused with exit 1 - the correct refusal for the environment it was actually given. Four sibling fm-send suites fail the same way for the same reason. bin/fm-test-run.sh already isolates every suite it starts, so a run through the runner is green and only a direct `bash tests/<file>.test.sh` sees this. Call the same owner from tests/lib.sh so the direct path is isolated too. This is a second caller of bin/fm-test-env-lib.sh, not a second copy of its list - which matters here, because an incomplete copy is exactly what this defect looks like from the other side: the same gap leaves FM_SESSION_START_STAGE_FILE in place on the direct path, and bin/fm-session-start.sh reads its presence as "the runtime bound is already applied", so tests/fm-session-start.test.sh loses the bound it asserts and hangs on its fixture. The send path is unchanged: its precedence is the documented one, and the case still fails when the guarantee it protects is removed (dropping the kind=secondmate condition that keeps crewmate steers unmarked turns it red). Verified locally with the live environment still present: - tests/fm-pending-reply.test.sh and the sibling fm-send suites pass; before this change they refused at the first send. - tests/fm-session-start.test.sh completes in 188s; before this change it was still running when killed at a 420s bound. - bin/fm-lint.sh and bin/fm-doc-audience-check.sh pass.
…lper The changed-selection fixture writes a literal source line into a generated tests/wake-helpers.sh. The single quotes are required: the fixture helper, not this test shell, expands $(dirname ...). ShellCheck read it as an accidental non-expansion and failed the Lint job. Add the repo's targeted disable with its reason, matching the existing SC2016 suppressions in tests/fm-opencode-primary-live-e2e.test.sh. No assertion, fixture content, or production path changes.
This reverts commit faca4c934ce4be0b73626c1f5927a484922830cf, which reinstated the expand_test_reference_needles closure and its fixture. The closure was removed earlier in this branch on measurement, not on style: with it neutralised and everything else identical, the selection is byte-for-byte the same - 165 of 165 suites, with tests/fm-watch-arm.test.sh and tests/fm-watch-recovery-loop.test.sh selected either way. Selection here is family-expanded, so a needle-level refinement is inert; the two watch suites arrive with family watcher-wake-lock, which contains suites that source tests/lib.sh directly. The reinstating commit was made by an automated round chasing a review failure that had already reversed to pass, so it fixed nothing, and it also deleted the comment recording the family-expansion fact. Both are restored here.
910b96a to
d179372
Compare
|
Flagging a discrepancy in this PR rather than leaving it to be discovered. The attestation in the description is stale. It binds Why the head moved. The branch was rebuilt so it shares #3026's exact commits rather than pipeline-rebased copies of them. It previously carried rewritten duplicates, which would not have shed cleanly once #3026 landed; sharing the same commits removes that merge-order friction. Why we have not simply refreshed it. Our pipeline rebases onto the default branch before it emits an attestation. While #3026's commits are not yet on the default branch, that rebase rewrites them back into copies, undoing the very thing the rebuild fixed. Refreshing now would trade one problem for the other. We expect this to resolve itself. Once #3026 merges, its commits are on the default branch, the rebase becomes harmless, and a normal run should produce a valid attestation while keeping the exact sharing. We will refresh it then. To be explicit: we are not asking for the attestation requirement to be waived, relaxed, or overlooked, and we understand this PR is not merge-ready while the attestation is stale. The earlier request on this PR still stands: the workflow runs on this head are held at |
|
Superseded by #3706. |
Intent
Diagnose and fix the failing unmarked-crewmate-send case in tests/fm-pending-reply.test.sh.
Evidence given at intake: that case fails on the clean default branch, independent of locale, reproduced on a clean tree on 2026-08-25. It is not an environment problem and not caused by an unrelated away-mode change landed the same day. Keep it distinct from two findings reported at the same time that are NOT defects: tests/fm-afk-inject-e2e.test.sh and tests/fm-composer-lib.test.sh fail only under LC_ALL=C on multi-byte fixture comparisons and pass under UTF-8; that is locale sensitivity in the fixtures, already recorded as environment sensitivity rather than a defect, and must be left alone.
Required approach: reproduce it first on a clean base and confirm independently that it fails regardless of locale; do not take the reported evidence on trust. Establish whether the TEST is wrong or the SEND PATH is wrong before fixing, because these have opposite correct fixes. Fix the actual cause.
Absolute constraint: do not weaken, skip, relax, delete or mark-flaky the test to get green. If the test is genuinely wrong, prove it before changing it, ideally with a disconfirming experiment showing the assertion still fails when the behaviour it claims to protect is removed. A suite made green by weakening it is worse than a red one.
Scope: fix this one case. If the diagnosis showed a larger defect in the pending-reply machinery, stop and report it with evidence rather than building the larger change.
What the diagnosis established. The test's fixture is wrong, not its assertion and not the send path. A firstmate worker's environment carries the live home's pointers. FM_STATE_OVERRIDE outranks FM_HOME/state in every script that reads it (docs/configuration.md "FM_HOME"). The fixture sets its own FM_HOME but inherits the rest, so bin/fm-send.sh resolved state/.meta under the live fleet home, could not find the fixture's target, and refused with exit 1 - the correct refusal for the environment it was actually given. Four sibling fm-send suites fail the same way for the same reason. With the inherited pointers cleared, the whole suite passes untouched.
The chosen fix and why it is placed where it is. bin/fm-test-run.sh already isolates every suite it starts, so a run through the runner is green and only a direct
bash tests/<file>.test.shsees this. tests/lib.sh now sources bin/fm-test-env-lib.sh and calls fm_test_env_isolate, so the direct-invocation path is isolated too. This is deliberately a second CALLER of that single owner, never a second copy of its pointer list: bin/fm-test-env-lib.sh states that no runner keeps its own copy because two copies drift. That rule is load-bearing here rather than stylistic. An earlier attempt on this task did duplicate the list, on a branch cut below the landed owner, and that copy was already missing FM_SESSION_START_STAGE_FILE - which is exactly the drift the rule predicts, and it left a real symptom in place: bin/fm-session-start.sh treats that variable's presence as "the runtime bound is already applied", so tests/fm-session-start.test.sh lost the bound it asserts and hung on its fixture instead of being truncated. That earlier commit was rebuilt from scratch on top of the landed owner rather than carried forward.Accepted requirement from supervision: the unbounded session-start suite is NOT a separate defect to track. It is the same missing isolation on the direct-invocation path, and this change closes it.
The send path is deliberately unchanged. Its precedence is the documented one, and the failing case still catches a real regression: removing the kind=secondmate condition that keeps crewmate steers unmarked turns it red again.
Regression coverage added to tests/fm-test-run.test.sh, which already owns the runner-path and helper-level isolation cases; the direct-invocation path was the gap. The new case is driven from the library's own published pointer list so no second copy is introduced, and it asserts the sentinel genuinely reaches an unisolated child so it cannot pass vacuously.
Verified locally with the live worker environment still present: tests/fm-pending-reply.test.sh and the sibling fm-send suites pass where they previously refused at the first send; tests/fm-session-start.test.sh completes in 188s where it previously ran past a 420s kill; the portable-parallel-1 lane is 11 suites with 0 failures; the proven-isolated set is 24 suites with only the known composer-lib locale case, which is present on pristine main too; bin/fm-lint.sh and bin/fm-doc-audience-check.sh pass. Removing the fix turns both the reported case and the new regression test red again.
Delivery constraints for this run: the push step targets an upstream repository where this account has no write access, so an HTTP 403 there is correct behaviour rather than a credential fault; pushing to the fork remote https://github.com/AgardnerAU/firstmate is pre-authorised, naming the remote on the push itself. Do not change the pipeline's push target, do not edit remotes in the primary checkout, do not touch credentials, and never force. The pull request must be opened against kunchenguid/firstmate with base main, head AgardnerAU: into base kunchenguid:main; a fork-internal pull request reaches nobody. CI will not run on the fork pull request because it waits on an upstream maintainer to release workflow runs, so it must never be called green. This worker does not merge.
RUN PURPOSE, accepted after the previous run: take this pipeline to COMPLETION so the pull request body carries a parseable no-mistakes v1 attestation bound to its FINAL head. The upstream repository's "Require no-mistakes" check requires that attestation to bind to the current head and report review, test and document completed; the previous run was cancelled at CI attempt 2 of 3, before it was emitted, which is why the check cannot pass as things stand. Do not cancel early this time. Once the attestation is verified bound to the head, waiting further on CI is pointless: this is a fork pull request on a repository that holds contributor workflow runs, so those checks are held rather than red and no amount of waiting produces them.
BRANCH REBUILD, done deliberately before this run: the branch was rebuilt on top of the CURRENT head of its dependency pull request #3026 (038da15), by replaying this change's own five commits onto it. Verified afterwards that 038da15 is an ancestor of this branch, so the two pull requests now share the SAME dependency commits rather than this one carrying rewritten copies of them. That is the honest improvement available; fully unstacking is NOT possible yet, because bin/fm-test-env-lib.sh does not exist on upstream main and GitHub compares a pull request from its merge base, so any branch carrying this fix must also carry the dependency until #3026 merges. Do not attempt to remove the dependency commits, and never invent history to make the diff look smaller. Never merge - the upstream maintainer merges. Never force-push to work around a guard; if the push step refuses, stop and report the exact refusal rather than working around it.
RUN PURPOSE: emit a no-mistakes v1 attestation bound to this branch's FINAL head. The previous attestation went stale because an automated CI round pushed a commit after the pr step had already emitted it. This run must reach the emitting step against the current head. The attestation must never be hand-written.
STANDING DECISION, already made and NOT open for re-debate: expand_test_reference_needles must NOT exist on this branch. It was removed on measurement - neutralising it leaves the --changed selection byte-for-byte identical, 165 of 165 suites with tests/fm-watch-arm.test.sh and tests/fm-watch-recovery-loop.test.sh selected either way - because selection here is family-expanded, so a needle-level refinement is inert and those suites arrive with family watcher-wake-lock, which contains direct tests/lib.sh sourcers. An automated round reinstated it while chasing a review verdict that had already reversed to pass; that commit has been reverted. Do NOT reinstate the closure, its fixture, or its assertion. If review raises it again, the answer is this measurement, not a fresh debate. Keep the bin/fm-test-env-lib.sh map routing, which is the part that genuinely changed behaviour from 32 of 162 to full selection, and keep the comment recording that selection expands each emitted family to all of its suites.
What Changed
bin/fm-test-env-lib.shas the single owner of the ambient fleet pointer list (FM_HOME, theFM_*_OVERRIDEset, wake-queue pointers, and the runtime control variablesFM_SESSION_START_STAGE_FILE,FM_SUPERVISION_MODEL,FM_TRACE_CONTEXT). Itsfm_test_env_isolateclears them in the calling process and returns non-zero if any survives.bin/fm-test-run.sh,bin/fm-test-isolation-proof.sh, andtests/lib.shall call that one owner once per process and refuse with exit 2 if isolation fails; the two runners drop their own inlineunsetlists, andtests/lib.shlatchesFM_TEST_LIB_SOURCEDonly after a successful isolate. This closes the directbash tests/<file>.test.shpath, which previously inherited a live worker's pointers.bin/fm-test-env-lib.shthrough the same reference scantests/lib.shgets (pluspure-contract-unit), and adds three cases totests/fm-test-run.test.shcovering the runner path, the helper itself, and direct invocation - each driven from the library's published pointer list, with a sentinel check so the direct-invocation case cannot pass vacuously.CONTRIBUTING.mdanddocs/scripts.mdrecord the new owner and its callers.Risk Assessment
✅ Low: The change is a well-bounded test-harness fix that introduces a single shared owner for the fleet-pointer list with three consistent callers, all fixture copy sites were updated, no suite exports a pointer before sourcing tests/lib.sh, and every intent constraint (no needle closure, byte-identical proof record, narrowed CONTRIBUTING claim) is satisfied; the only issue found is a stale invariant comment.
Testing
I drove the change through the exact end-user command that was reported broken -
bash tests/fm-pending-reply.test.shfrom a firstmate-worker-shaped environment - against a scratch export of the base commit and against this worktree. The unmarked-crewmate-send case fails on base under both C and UTF-8 locales and passes on target with the test file untouched, and a disconfirming mutation that strips thekind=secondmateguard from bin/fm-send.sh turns it red again, so the suite was fixed rather than weakened. Four sibling fm-send suites and tests/fm-session-start.test.sh show the same base-fails / target-passes transition on the direct path, and the new regression case in tests/fm-test-run.test.sh fails when the tests/lib.sh fix is reverted, so it is not vacuous. I also confirmed the standing decisions hold: the needle closure is gone, the dated proof record is byte-identical to base, and the env-lib changed-map routing still selects the full 165-suite set. No UI surface is involved, so the evidence is a CLI transcript rather than a screenshot. Everything ran green and no findings are actionable; the only caveat is that my scratch trees under /tmp could not be deleted because the sandbox declined everyrm -rf, and the worktree itself is clean including untracked files.Evidence: Direct-invocation isolation CLI transcript (base vs target, disconfirming mutation, sibling suites, selection)
Source: Direct-invocation isolation CLI transcript (base vs target, disconfirming mutation, sibling suites, selection)
--- 1. BASE 5953e9b: bash tests/fm-pending-reply.test.sh --- not ok - unmarked crewmate send should succeed: expected exit 0, got 1 exit status: 1 --- 2. BASE, locale independence --- [LC_ALL=C] not ok - unmarked crewmate send should succeed: expected exit 0, got 1 [LC_ALL=en_AU.UTF-8] not ok - unmarked crewmate send should succeed: expected exit 0, got 1 --- 3. TARGET 910b96a: same command, same ambient environment --- ok - all pending-reply tests passed exit status: 0 --- 4. Disconfirming experiment: remove the kind=secondmate guard in bin/fm-send.sh --- not ok - crewmate steer should be recorded unmarked exit status: 1 -- the case still protects the behaviour it claims to --- 7. New regression coverage --- target tree: ok - sourcing tests/lib.sh isolates a directly invoked suite with the fix removed: not ok - fleet pointers survived a direct suite invocation: FM_PROJECTS_OVERRIDE=/live-sentinelPipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-test-run.sh:911- The map's contract comment (# Conservative path → family map. Over-selects rather than under-selects. / # Never expands to the complete suite., line 911, restated at line 70 as "never expands to the complete suite unless --all") is contradicted by the newbin/fm-test-env-lib.shentry added at line 928. That entry callsfamilies_for_test_reference lib.sh, whosegrep -Fq "lib.sh"matches essentially every suite in the repository (almost all of them reference some*-lib.sh), so by the intent's own measurement a one-line edit tobin/fm-test-env-lib.shselects 165 of 165 suites - the complete suite, without--all. The full expansion is deliberate and correct here; the defect is the stale absolute claim two lines above it, which now tells a maintainer the opposite of what the code does. Nothing fails as a result:test_changed_file_selection_is_conservative(tests/fm-test-run.test.sh:80) only assertslisted_count -le all_count, so the assertion still passes at exactly full selection. Narrow both sentences to what still holds - the map over-selects related families rather than under-selecting, and a path may legitimately expand to every family when its blast radius is that wide.✅ **Test** - passed
✅ No issues found.
bash tests/fm-pending-reply.test.shon a scratch export of base 5953e9b with FM_HOME/FM_STATE_OVERRIDE/FM_DATA_OVERRIDE/FM_ROOT aimed at a fake live home - reproducednot ok - unmarked crewmate send should succeed: expected exit 0, got 1Same base command underLC_ALL=CandLC_ALL=en_AU.UTF-8- identical failure, so it is not locale sensitivitybash tests/fm-pending-reply.test.shin this worktree with the same ambient environment - exit 0, whole suite greenDisconfirming mutation: removed thekind=secondmatecondition at bin/fm-send.sh:500 in a scratch copy of the target tree and re-ran the suite -not ok - crewmate steer should be recorded unmarkedbash tests/fm-send-inbox.test.sh,bash tests/fm-send-strict.test.sh,bash tests/fm-send-resolve-key.test.sh,bash tests/fm-send-secondmate-marker.test.shon base vs target with the same ambient pointers - one failure each on base, zero on targetbash tests/fm-session-start.test.shwith a leakedFM_SESSION_START_STAGE_FILE- base exits 1 at 10s, target passes in 228sbash tests/fm-test-run.test.shon the target tree - the three isolation cases pass, includingsourcing tests/lib.sh isolates a directly invoked suiteSame suite withtests/lib.shreverted to the base version -not ok - fleet pointers survived a direct suite invocation: FM_PROJECTS_OVERRIDE=/live-sentinel, confirming fail-before/pass-afterbin/fm-test-run.sh --list --changed --base HEAD~1in a scratch clone after appending a line to bin/fm-test-env-lib.sh - 165 of 165 suites selected, including tests/fm-watch-arm.test.sh and tests/fm-watch-recovery-loop.test.shgrep -rn 'expand_test_reference_needles|tests_helper_scripts' bin tests- no matches;git diff 5953e9b 910b96a -- docs/fm-test-isolation-proof.md- empty✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.