Skip to content

Commit 7d5f2d4

Browse files
JohnMcLearclaude
andcommitted
fix(snap-tests): assert_grep — use here-string to dodge pipefail SIGPIPE
`assert_grep` ran `printf '%s' "$out" | grep -q -F -- "$needle"` under `set -o pipefail`. When grep matched early it closed its stdin, printf got SIGPIPE on its next write (exit 141), and pipefail propagated the broken-pipe failure to the pipeline — making `if` see non-zero and falling into the FAIL branch even though grep itself succeeded. Failure was timing-dependent: it only fired when `$out` was large enough that printf hadn't flushed before grep exited. CI ubuntu-latest tipped into the racy path on PR #7698 once `settings.json.template` grew by 11 lines (the new `enablePluginPadOptions` flag); the symptom was the `Wrapper unit tests` step reporting `dbType rewritten to sqlite ✗` with "got: /*…" output even though the seeded file did contain the needle. Replace the pipe with a here-string so grep gets its input in one shot with no pipe between processes — no SIGPIPE possible. The fail-message `head -3` is converted to a here-string for the same reason. Repro on a runner whose pipe-buffer flush is slower than grep's first match would have hit the same flake on any PR; the bug isn't about this particular template change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 92b27dd commit 7d5f2d4

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

snap/tests/lib.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,23 @@ assert_exit() {
5757
}
5858

5959
# assert_grep cmd needle name — fail if cmd's combined output doesn't match
60+
#
61+
# Uses a here-string instead of `printf | grep -q` because `set -o pipefail`
62+
# (declared at the top of this file) propagates SIGPIPE failures: when grep
63+
# -q matches early it closes its stdin, printf gets SIGPIPE on its next
64+
# write, and pipefail makes the whole pipeline exit non-zero — even though
65+
# the grep itself succeeded. The failure mode is timing-dependent, only
66+
# tripping when the captured output is large enough that printf hasn't
67+
# flushed before grep matches and exits. A here-string feeds grep its input
68+
# in one shot with no pipe in between.
6069
assert_grep() {
6170
local needle="$1" name="$2"; shift 2
6271
local out
6372
out=$("$@" 2>&1 || true)
64-
if printf '%s' "$out" | grep -q -F -- "$needle"; then
73+
if grep -q -F -- "$needle" <<<"$out"; then
6574
pass "$name"
6675
else
67-
fail "$name" "expected output to contain: $needle; got: $(printf '%s' "$out" | head -3)"
76+
fail "$name" "expected output to contain: $needle; got: $(head -3 <<<"$out")"
6877
fi
6978
}
7079

0 commit comments

Comments
 (0)