Skip to content

Fix eight tests that fail on dev on a Mac, and a flaky one on Linux - #2870

Merged
AbirAbbas merged 8 commits into
Agent-Field:devfrom
joshbarrington:fix-dev-red-tests
Nov 23, 2026
Merged

AbirAbbas merged 8 commits into
Agent-Field:devfrom
joshbarrington:fix-dev-red-tests

Conversation

@joshbarrington

Copy link
Copy Markdown
Contributor

Eight tests fail on dev on a Mac (macOS 27, bash 3.2 as /bin/bash), and one of them fails on Linux too, about one run in twenty. CI runs only on Ubuntu, so most of these were never seen there. Each fix below is its own commit.

1. A reader that stops early read as a failure on bash older than 4.2

Fixes TestPipefailForgivesOnlyAReaderThatStoppedEarly, TestAnEarlyReaderIsNotAFailureButEveryOtherStageIs, TestACommandLookFailsOnAFailingPipeStage, TestWatchTickFailsOnAFailingPipeStage, TestBashBeltTruncationWritesHeadTailAndPath and TestBashBeltTruncationCapFollowsTheWindow.

This is a product bug on every Mac, not only a test failure: git log | head and every other cmd | head reported exit 141 through the bash tool.

internal/shell/pipefail.go forgives a writer killed by SIGPIPE from an EXIT trap that reads PIPESTATUS. Bash 4.2 and later restore PIPESTATUS after a trap runs; 3.2 and 4.0/4.1 do not. On those shells the EXIT trap read the ERR trap's own assignment (0) instead of the pipeline's 141 0, so every check declined and the 141 stood.

The ERR trap now ends on a function that returns 213, when errexit is off. On a bash older than 4.2, an EXIT trap that sees exactly that one status knows the ERR trap ran last, and judges the statuses the ERR trap recorded by the same rules as before. A newer bash never takes this path.

Checked with the package's own table on bash 3.2 (macOS) and in containers on 4.0, 4.1, 4.2, 4.4, 5.0, 5.1 and 5.2. Before the fix the same table fails on 4.0 and 4.1 and passes on 4.2+, which confirms the cause.

2. The cache-landing test read the machine's git config

Fixes TestLandLeavesOutUntrackedBuildCachesOnly.

A global excludes file that ignores __pycache__ (a common one) made the test's own seed git add refuse the file, and would also change which untracked caches the landing sees. The test now sets GIT_CONFIG_GLOBAL to the null device and GIT_CONFIG_NOSYSTEM=1, as other tests in the repository already do. Test-only change.

3. The prefix budget measured a different machine on each runner

Fixes TestTheFixedPrefixStaysUnderItsBudget.

The gate already swaps in the widest grep and load_capability descriptions, but two other things vary by machine:

  • find's description is longer where fd is installed.
  • The load_capability schema's enum lists media only where ffmpeg is.

So a laptop measured 52,510 bytes and a Linux runner 52,488, against a 52,497 cap: the gate failed where it was run and passed where it was proved. The true widest prefix was 52,528, 31 over.

  • bare.WidestFindDescription mirrors WidestGrepDescription, and the test now also swaps in the widest loader schema, built from the same group list as its sentence.
  • Following the file's rule (pay the bytes back rather than raise the cap), find's and ls's descriptions state the same facts more briefly: what each returns, .gitignore, sorting, the / suffix, dotfiles and the cap all stay. These two descriptions are the one change the model sees.
  • The widest fixed prefix is now 52,458 bytes on both macOS and Linux, 39 under the cap. The lean prefix went from 44,666 to 44,596 bytes. The waivers are unchanged.

4. The late-spend meter test was flaky

Fixes TestConcurrentTurnAndLateSpendStampsKeepTheLatestMeter.

A late bill stamps the spend itself (Agent.bank), and the test stamps again while the older stamp is held. The stamp writer merges what is owed before it starts and performs once more for what is owed while it runs, so the newer figure is written once or twice depending on scheduling. Both keep the latest meter, which is what the test is about, but it demanded exactly two notices and failed about one run in twenty on Linux and macOS.

The test now requires the first notice to be 0.25, every later one 0.375, one or two of them, and the saved meter 0.375. It passed 200 of 200 runs, and 30 of 30 under -race. Test-only change.

Verification

  • make pr-ready passes on macOS: every selected test passed on its first run.
  • The prefix budget tests give identical numbers in a Linux container.

joshbarrington and others added 8 commits November 22, 2026 18:02
…h included

Bash before 4.2 does not restore PIPESTATUS after a trap, so the EXIT trap read the ERR trap's own assignment and every `cmd | head` reported exit 141. The ERR trap now leaves a sentinel status the EXIT trap recognises on those shells. Checked on bash 3.2 (macOS) and 4.0, 4.1, 4.2, 4.4, 5.0, 5.1 and 5.2.
A global excludes file that ignores __pycache__ refused the test's seed commit and would change which untracked caches the landing sees.
…a, and pay the bytes back

The gate swapped in the widest grep and load_capability sentences but not find's, which is longer where fd is installed, nor the loader schema, whose enum names media only where ffmpeg is. A laptop measured 52,510 bytes and a runner 52,488, so the gate failed where it was run and passed where it was proved; the true widest was 52,528, over its 52,497 cap. find and ls now state the same facts more briefly, and the widest prefix is 52,458 on every machine.
…ther keeps the latest

The late bill stamps itself and the test stamps again while the older stamp is held; the writer merges or repeats that owed write depending on scheduling. The test demanded exactly two notices and failed about one run in twenty on Linux and macOS.
…ad only under the default IFS

On a bash that restores PIPESTATUS after a trap the new ERR helper was
still installed and called, which changed $_ after a failing command and
added commands to a user's trace. The helper and its trap are now chosen
by version when the prefix runs, so a newer bash is handed the trap it had
before. On 4.0/4.1 a digit in IFS joined the recorded statuses so they
could not be split apart again and a real stage failure could read as
success; the mark is now read back only under the default IFS, which
leaves the old 141 in place instead.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…eigh the lean shelf

- land_test: GIT_CONFIG_GLOBAL=/dev/null does not hide
  $XDG_CONFIG_HOME/git/ignore, so a __pycache__/ entry there still failed the
  seed add. XDG_CONFIG_HOME now points at an empty folder.
- spendsaved_test: only the first two captures were read, so a third one's
  stamp-lock flag was never checked. The buffered rest is drained and each
  must be .375 and taken under the lock.
- prefixbudget_test: the widest load_capability schema and sentence read the
  shipped table, which drops the four groups a lean belt also shelves.
  They read the shape's own shelf now, so the lean number is not lighter than
  the belt it weighs (lean 44,596 -> 44,738; fixed prefix unchanged at 52,458).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@AbirAbbas

Copy link
Copy Markdown
Collaborator

Pushed two commits on top (plus a dev merge), so this can land today. The Mac fixes themselves are untouched.

  • pipefail.go: on bash 4.2+ the new ERR helper was still installed and called, so $_ after a failing command read __codeaf_left and a user's set -x trace gained extra lines. The trap is now chosen by version when the prefix runs, so a newer bash gets exactly the trap it had before. Also, on 4.0/4.1 a digit in IFS joined the recorded statuses so they couldn't be split again, and IFS=3; (exit 3) | yes | head -1 exited 0. The mark is now read back only under the default IFS, which leaves the old 141 in place there.
  • tests: XDG_CONFIG_HOME pointed at an empty dir in the land test (GIT_CONFIG_GLOBAL=/dev/null doesn't hide ~/.config/git/ignore); the spend-meter test now drains the buffered captures and checks a third one was taken under the lock; the widest load_capability schema/sentence read the shape's own shelf, because the shipped table drops the four groups a lean belt also shelves (lean 44,596 -> 44,738, fixed prefix unchanged at 52,458).

Checked the shell table and the bash belt tests against bash 3.2.57, 4.0, 4.1, 4.2, 4.4, 5.2 built from source, and an 89-command differential against dev: on 4.2+ the only differences left are extra xtrace/DEBUG lines from the EXIT helper, no status, stdout or stderr changes.

@AbirAbbas
AbirAbbas added this pull request to the merge queue Nov 23, 2026
Merged via the queue into Agent-Field:dev with commit f86f748 Nov 23, 2026
8 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.

2 participants