Skip to content

test(herdr): make real-herdr-gated lane portable across environments - #56

Merged
trillium merged 3 commits into
mainfrom
fm/robots-7jy9-herdr-lane-green
Aug 5, 2026
Merged

trillium merged 3 commits into
mainfrom
fm/robots-7jy9-herdr-lane-green

Conversation

@trillium

@trillium trillium commented Aug 5, 2026 •

Copy link
Copy Markdown
Owner

Intent

The developer wanted to make the real-herdr-gated test lane environment-independent so it could run portably across different environments without breaking. They modified three test files — herdr-test-safety.sh, fm-herdr-session-cleanup-e2e.test.sh, and fm-afk-inject-herdr-e2e.test.sh — to remove environment-specific dependencies. The goal was to improve cross-environment portability for the herdr safety checks, session cleanup, and AFK injection end-to-end tests.

What Changed

  • Replaced fixed sleep waits in fm-afk-inject-herdr-e2e.test.sh with bounded wait_for_log/wait_for_file polls (30–45 s timeout), eliminating timing-dependent flakes in the AFK-inject scenarios (A–D) while adding settle_for_duplicate dwells where negative "no second injection" assertions still need a fixed window.
  • Pinned SHELL=/bin/bash before lab server startup in fm-herdr-session-cleanup-e2e.test.sh so restored panes always come back as a bare bash — preventing a permanently-local-red from a captain box's zsh startup that forks a persistent helper (which the childless-shell proof then rejects).
  • Added unset FM_HOME to herdr-test-safety.sh so an ambient captain-box FM_HOME cannot silently outrank the workspace identity a test intends, matching the behavior of CI where FM_HOME is unset.

Risk Assessment

✅ Low: All three changes are targeted portability fixes — replacing racy fixed sleeps with bounded polling and unsetting environment variables that cause CI/local divergence — with no logic changes to the assertions under test.

Testing

Ran targeted validation of all three changed files. FM_HOME is correctly dropped when herdr-test-safety.sh is sourced. The new polling helpers (wait_for_log, wait_for_file, settle_for_duplicate) behave correctly under async conditions. Both E2E test suites ran to completion with all assertions green on herdr 0.8.0.

Evidence: Full test output transcript

=== FM_HOME unset behavior (herdr-test-safety.sh) === PASS: FM_HOME is unset after sourcing herdr-test-safety.sh === wait_for_log / wait_for_file helper functions === PASS: wait_for_log returns 0 when pattern appears asynchronously PASS: wait_for_log returns 1 on timeout (no spurious match) PASS: wait_for_file returns 0 when file appears asynchronously PASS: wait_for_file correctly ignores empty files === SHELL=/bin/bash pin precondition === PASS: /bin/bash exists and is executable (SHELL pin precondition satisfied) === fm-herdr-session-cleanup-e2e.test.sh === ok - real named lab reproduced the exact restored one-tab one-pane childless no-agent shell shape ok - real named lab cleanup closes only the exact stale pane and preserves exact focus ok - real named lab cleanup is idempotent and leaves the default fleet session to the teardown tripwire evidence: herdr=0.8.0 protocol=19 default-session-tripwire=armed === fm-afk-inject-herdr-e2e.test.sh (Scenarios A-D) === ok - real herdr Scenario A: partial input defers injection; digest arrives clean after idle ok - real herdr Scenario B: swallowed Enter (via the herdr shim) produces exactly one clean digest ok - real herdr Scenario C: a normal captain status injects exactly one clean single-line sentinel digest ok - real herdr Scenario D: a persistently pending composer raises the max-defer wedge alarm, preserves the buffer, and never crashes the daemon all real-herdr afk injection e2e tests passed

=== FM_HOME unset behavior (herdr-test-safety.sh) ===
PASS: FM_HOME is unset after sourcing herdr-test-safety.sh

=== wait_for_log / wait_for_file helper functions ===
PASS: wait_for_log returns 0 when pattern appears asynchronously
PASS: wait_for_log returns 1 on timeout (no spurious match)
PASS: wait_for_file returns 0 when file appears asynchronously
PASS: wait_for_file correctly ignores empty files

=== SHELL=/bin/bash pin precondition ===
PASS: /bin/bash exists and is executable (SHELL pin precondition satisfied)

=== fm-herdr-session-cleanup-e2e.test.sh ===
ok - real named lab reproduced the exact restored one-tab one-pane childless no-agent shell shape
ok - real named lab cleanup closes only the exact stale pane and preserves exact focus
ok - real named lab cleanup is idempotent and leaves the default fleet session to the teardown tripwire
evidence: herdr=0.8.0 protocol=19 default-session-tripwire=armed

=== fm-afk-inject-herdr-e2e.test.sh (Scenarios A-D) ===
ok - real herdr Scenario A: partial input defers injection; digest arrives clean after idle
ok - real herdr Scenario B: swallowed Enter (via the herdr shim) produces exactly one clean digest
ok - real herdr Scenario C: a normal captain status injects exactly one clean single-line sentinel digest
ok - real herdr Scenario D: a persistently pending composer raises the max-defer wedge alarm, preserves the buffer, and never crashes the daemon
all real-herdr afk injection e2e tests passed

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.

  • FM_HOME=/some/captain/home bash -c '. tests/herdr-test-safety.sh; check FM_HOME unset' — verifies the new unset FM_HOME takes effect when herdr-test-safety.sh is sourced
  • Direct exercise of wait_for_log and wait_for_file helpers with async writers and timeout cases — confirms 0 on match, 1 on timeout, -s empty-file rejection
  • bash tests/fm-herdr-session-cleanup-e2e.test.sh — all 3 restored-shell session cleanup assertions pass with SHELL=/bin/bash pin
  • bash tests/fm-afk-inject-herdr-e2e.test.sh — Scenarios A, B, C, D all pass with new event-driven wait_for_log/wait_for_file replacing fixed sleeps
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

fmtest and others added 2 commits August 5, 2026 05:03
Three suites in the real-herdr-gated family failed permanently on a captain
box while the required Herdr CI lane stayed green, which is exactly the
"permanently red trains everyone to ignore the suite" shape. All three were
the suite reading the operator's environment instead of its own fixture.

tests/herdr-test-safety.sh: unset an inherited FM_HOME, the same fix
tests/lib.sh already carries, which these suites never got because they do
not source it. For the Herdr backend this is a workspace-IDENTITY leak, not
just a config-path one: fm_backend_herdr_workspace_label reads
"$FM_HOME/.fm-secondmate-home", so an exported FM_HOME pointing at a
SECONDMATE home labels the suite's primary workspace 2M-<scope> instead of
1M-FIRSTMATE. That broke fm-backend-herdr-smoke's restart-stability check
(before=w1 after=) and fm-backend-herdr-prune-safety-e2e's adoption check
(adopted :w2 instead of the pre-created w1).

tests/fm-herdr-session-cleanup-e2e.test.sh: pin SHELL=/bin/bash before the
lab server starts. That server hands its own login shell to every pane it
RESTORES, and a per-create --env SHELL does not survive the stop/restore
cycle this case exercises. Inheriting the operator's interactive shell means
a zsh startup that forks a persistent helper leaves the restored pane with a
child forever, so the childless bare idle-shell proof can never converge.

tests/fm-afk-inject-herdr-e2e.test.sh: replace two fixed dwells that wait
for a daemon-produced result with bounded polls (wait_for_log,
wait_for_file). Scenario A's post-Enter digest wait and Scenario D's
max-defer alarm wait were both races against the daemon's next poll under
a serially-loaded box - the reported flake, plus the one it produced on a
full-family run here. The negative dwell that proves the daemon does NOT
inject while input is pending stays a fixed wait.

Fixes robots-7jy9.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@trillium, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 32 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2b9482be-5367-43bb-9024-a960ae886e1c

📥 Commits

Reviewing files that changed from the base of the PR and between 3673dbd and 037b23c.

📒 Files selected for processing (3)
  • tests/fm-afk-inject-herdr-e2e.test.sh
  • tests/fm-herdr-session-cleanup-e2e.test.sh
  • tests/herdr-test-safety.sh

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

The previous commit replaced the fixed sleeps in Scenarios B and C with
wait_for_log, which fixed a real flake but silently weakened what those
two cases actually test.

Each of them carries two assertions, not one:

  - positive: the daemon eventually injects a digest
  - negative: marker_count == 1, i.e. it does NOT inject a SECOND one

wait_for_log returns on the FIRST match. Counting markers immediately
after it therefore samples the log at the earliest possible instant, so
a duplicate digest injected on the daemon's next poll would arrive after
the count and never be seen. The old sleep 10 / sleep 8 happened to
cover that window; the bounded poll does not. Both cases stayed green
while losing the ability to fail on exactly the bug they were written
for - "swallowed Enter produces exactly ONE clean digest".

Add a short explicit dwell between the positive wait and the count. A
negative assertion has nothing to poll for, because the correct outcome
is that nothing further happens, so it needs a dwell for the same reason
Scenario A's pending-input wait does. The daemon runs at FM_POLL=1 here,
so three seconds covers several poll cycles while remaining far shorter
than the sleeps the positive waits replaced.

Scenarios A and D need no equivalent: neither performs an "exactly one"
count after its positive wait.

Refs robots-7jy9.
@trillium trillium changed the title test(herdr): fix real-herdr-gated lane for cross-environment portability test(herdr): make real-herdr-gated lane portable across environments Aug 5, 2026
@trillium
trillium merged commit 598b6f3 into main Aug 5, 2026
11 checks passed
@trillium
trillium deleted the fm/robots-7jy9-herdr-lane-green branch August 5, 2026 15:59
trillium added a commit that referenced this pull request Aug 6, 2026
…56)

* tests: make the real-herdr-gated lane environment-independent

Three suites in the real-herdr-gated family failed permanently on a captain
box while the required Herdr CI lane stayed green, which is exactly the
"permanently red trains everyone to ignore the suite" shape. All three were
the suite reading the operator's environment instead of its own fixture.

tests/herdr-test-safety.sh: unset an inherited FM_HOME, the same fix
tests/lib.sh already carries, which these suites never got because they do
not source it. For the Herdr backend this is a workspace-IDENTITY leak, not
just a config-path one: fm_backend_herdr_workspace_label reads
"$FM_HOME/.fm-secondmate-home", so an exported FM_HOME pointing at a
SECONDMATE home labels the suite's primary workspace 2M-<scope> instead of
1M-FIRSTMATE. That broke fm-backend-herdr-smoke's restart-stability check
(before=w1 after=) and fm-backend-herdr-prune-safety-e2e's adoption check
(adopted :w2 instead of the pre-created w1).

tests/fm-herdr-session-cleanup-e2e.test.sh: pin SHELL=/bin/bash before the
lab server starts. That server hands its own login shell to every pane it
RESTORES, and a per-create --env SHELL does not survive the stop/restore
cycle this case exercises. Inheriting the operator's interactive shell means
a zsh startup that forks a persistent helper leaves the restored pane with a
child forever, so the childless bare idle-shell proof can never converge.

tests/fm-afk-inject-herdr-e2e.test.sh: replace two fixed dwells that wait
for a daemon-produced result with bounded polls (wait_for_log,
wait_for_file). Scenario A's post-Enter digest wait and Scenario D's
max-defer alarm wait were both races against the daemon's next poll under
a serially-loaded box - the reported flake, plus the one it produced on a
full-family run here. The negative dwell that proves the daemon does NOT
inject while input is pending stays a fixed wait.

Fixes robots-7jy9.

* no-mistakes(review): replace fixed sleeps in Scenarios B and C with wait_for_log

* tests: restore duplicate detection in afk-inject Scenarios B and C

The previous commit replaced the fixed sleeps in Scenarios B and C with
wait_for_log, which fixed a real flake but silently weakened what those
two cases actually test.

Each of them carries two assertions, not one:

  - positive: the daemon eventually injects a digest
  - negative: marker_count == 1, i.e. it does NOT inject a SECOND one

wait_for_log returns on the FIRST match. Counting markers immediately
after it therefore samples the log at the earliest possible instant, so
a duplicate digest injected on the daemon's next poll would arrive after
the count and never be seen. The old sleep 10 / sleep 8 happened to
cover that window; the bounded poll does not. Both cases stayed green
while losing the ability to fail on exactly the bug they were written
for - "swallowed Enter produces exactly ONE clean digest".

Add a short explicit dwell between the positive wait and the count. A
negative assertion has nothing to poll for, because the correct outcome
is that nothing further happens, so it needs a dwell for the same reason
Scenario A's pending-input wait does. The daemon runs at FM_POLL=1 here,
so three seconds covers several poll cycles while remaining far shorter
than the sleeps the positive waits replaced.

Scenarios A and D need no equivalent: neither performs an "exactly one"
count after its positive wait.

Refs robots-7jy9.

---------

Co-authored-by: fmtest <[email protected]>
trillium added a commit that referenced this pull request Aug 6, 2026
…56)

* tests: make the real-herdr-gated lane environment-independent

Three suites in the real-herdr-gated family failed permanently on a captain
box while the required Herdr CI lane stayed green, which is exactly the
"permanently red trains everyone to ignore the suite" shape. All three were
the suite reading the operator's environment instead of its own fixture.

tests/herdr-test-safety.sh: unset an inherited FM_HOME, the same fix
tests/lib.sh already carries, which these suites never got because they do
not source it. For the Herdr backend this is a workspace-IDENTITY leak, not
just a config-path one: fm_backend_herdr_workspace_label reads
"$FM_HOME/.fm-secondmate-home", so an exported FM_HOME pointing at a
SECONDMATE home labels the suite's primary workspace 2M-<scope> instead of
1M-FIRSTMATE. That broke fm-backend-herdr-smoke's restart-stability check
(before=w1 after=) and fm-backend-herdr-prune-safety-e2e's adoption check
(adopted :w2 instead of the pre-created w1).

tests/fm-herdr-session-cleanup-e2e.test.sh: pin SHELL=/bin/bash before the
lab server starts. That server hands its own login shell to every pane it
RESTORES, and a per-create --env SHELL does not survive the stop/restore
cycle this case exercises. Inheriting the operator's interactive shell means
a zsh startup that forks a persistent helper leaves the restored pane with a
child forever, so the childless bare idle-shell proof can never converge.

tests/fm-afk-inject-herdr-e2e.test.sh: replace two fixed dwells that wait
for a daemon-produced result with bounded polls (wait_for_log,
wait_for_file). Scenario A's post-Enter digest wait and Scenario D's
max-defer alarm wait were both races against the daemon's next poll under
a serially-loaded box - the reported flake, plus the one it produced on a
full-family run here. The negative dwell that proves the daemon does NOT
inject while input is pending stays a fixed wait.

Fixes robots-7jy9.

* no-mistakes(review): replace fixed sleeps in Scenarios B and C with wait_for_log

* tests: restore duplicate detection in afk-inject Scenarios B and C

The previous commit replaced the fixed sleeps in Scenarios B and C with
wait_for_log, which fixed a real flake but silently weakened what those
two cases actually test.

Each of them carries two assertions, not one:

  - positive: the daemon eventually injects a digest
  - negative: marker_count == 1, i.e. it does NOT inject a SECOND one

wait_for_log returns on the FIRST match. Counting markers immediately
after it therefore samples the log at the earliest possible instant, so
a duplicate digest injected on the daemon's next poll would arrive after
the count and never be seen. The old sleep 10 / sleep 8 happened to
cover that window; the bounded poll does not. Both cases stayed green
while losing the ability to fail on exactly the bug they were written
for - "swallowed Enter produces exactly ONE clean digest".

Add a short explicit dwell between the positive wait and the count. A
negative assertion has nothing to poll for, because the correct outcome
is that nothing further happens, so it needs a dwell for the same reason
Scenario A's pending-input wait does. The daemon runs at FM_POLL=1 here,
so three seconds covers several poll cycles while remaining far shorter
than the sleeps the positive waits replaced.

Scenarios A and D need no equivalent: neither performs an "exactly one"
count after its positive wait.

Refs robots-7jy9.

---------

Co-authored-by: fmtest <[email protected]>
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