Skip to content

Commit 437f188

Browse files
committed
Fix SIGPIPE flaky test in test-skill-monitor.sh
Replace echo-pipe-grep pattern with here-strings to avoid broken pipe errors under pipefail when grep -q exits early.
1 parent d9e8e73 commit 437f188

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

tests/test-skill-monitor.sh

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ echo "=== Skill Monitor: Directory Checks ==="
111111

112112
setup_test_env
113113
output=$(_humanize_monitor_skill --once 2>&1) && rc=0 || rc=$?
114-
if [[ $rc -ne 0 ]] && echo "$output" | grep -q "directory not found"; then
114+
if [[ $rc -ne 0 ]] && grep -q "directory not found" <<< "$output"; then
115115
pass "Returns error when .humanize/skill does not exist"
116116
else
117117
fail "Should error when skill dir missing" "got: $output"
@@ -126,7 +126,7 @@ echo "=== Skill Monitor: Empty Directory ==="
126126
setup_test_env
127127
mkdir -p .humanize/skill
128128
output=$(_humanize_monitor_skill --once 2>&1) && rc=0 || rc=$?
129-
if [[ $rc -ne 0 ]] && echo "$output" | grep -q "No skill invocations found"; then
129+
if [[ $rc -ne 0 ]] && grep -q "No skill invocations found" <<< "$output"; then
130130
pass "Returns error when no invocations exist"
131131
else
132132
fail "Should error when no invocations" "got: $output"
@@ -149,43 +149,43 @@ else
149149
fail "--once mode should succeed" "exit code: $rc"
150150
fi
151151

152-
if echo "$output" | grep -q "Total Invocations: 1"; then
152+
if grep -q "Total Invocations: 1" <<< "$output"; then
153153
pass "Shows total invocation count"
154154
else
155155
fail "Should show total count" "got: $output"
156156
fi
157157

158-
if echo "$output" | grep -q "Success: 1"; then
158+
if grep -q "Success: 1" <<< "$output"; then
159159
pass "Shows success count"
160160
else
161161
fail "Should show success count" "got: $output"
162162
fi
163163

164-
if echo "$output" | grep -q "success"; then
164+
if grep -q "success" <<< "$output"; then
165165
pass "Shows success status for focused invocation"
166166
else
167167
fail "Should show success status" "got: $output"
168168
fi
169169

170-
if echo "$output" | grep -q "gpt-5.4"; then
170+
if grep -q "gpt-5.4" <<< "$output"; then
171171
pass "Shows model name"
172172
else
173173
fail "Should show model" "got: $output"
174174
fi
175175

176-
if echo "$output" | grep -q "15s"; then
176+
if grep -q "15s" <<< "$output"; then
177177
pass "Shows duration"
178178
else
179179
fail "Should show duration" "got: $output"
180180
fi
181181

182-
if echo "$output" | grep -q "How should I structure the auth module"; then
182+
if grep -q "How should I structure the auth module" <<< "$output"; then
183183
pass "Shows question text"
184184
else
185185
fail "Should show question" "got: $output"
186186
fi
187187

188-
if echo "$output" | grep -q "This is the response"; then
188+
if grep -q "This is the response" <<< "$output"; then
189189
pass "Shows output content"
190190
else
191191
fail "Should show output" "got: $output"
@@ -205,38 +205,38 @@ create_skill_invocation "2026-02-19_21-00-00-333-ccc" "timeout" "gpt-5.4" "high"
205205
create_skill_invocation "2026-02-19_21-30-00-444-ddd" "success" "gpt-5.4" "high" "20s" "Latest question"
206206

207207
output=$(_humanize_monitor_skill --once 2>&1) && rc=0 || rc=$?
208-
if echo "$output" | grep -q "Total Invocations: 4"; then
208+
if grep -q "Total Invocations: 4" <<< "$output"; then
209209
pass "Counts all invocations"
210210
else
211211
fail "Should count all invocations" "got: $(echo "$output" | grep 'Total')"
212212
fi
213213

214-
if echo "$output" | grep -q "Success: 2"; then
214+
if grep -q "Success: 2" <<< "$output"; then
215215
pass "Counts success invocations"
216216
else
217217
fail "Should count 2 successes" "got: $(echo "$output" | grep 'Success')"
218218
fi
219219

220-
if echo "$output" | grep -q "Error: 1"; then
220+
if grep -q "Error: 1" <<< "$output"; then
221221
pass "Counts error invocations"
222222
else
223223
fail "Should count 1 error" "got: $(echo "$output" | grep 'Error')"
224224
fi
225225

226-
if echo "$output" | grep -q "Timeout: 1"; then
226+
if grep -q "Timeout: 1" <<< "$output"; then
227227
pass "Counts timeout invocations"
228228
else
229229
fail "Should count 1 timeout" "got: $(echo "$output" | grep 'Timeout')"
230230
fi
231231

232232
# Latest should be the newest (2026-02-19_21-30-00)
233-
if echo "$output" | grep "Focused:" | grep -q "2026-02-19_21-30-00"; then
233+
if grep "Focused:" <<< "$output" | grep -q "2026-02-19_21-30-00"; then
234234
pass "Shows the most recent invocation with content as focused"
235235
else
236236
fail "Should show newest with content as focused" "got: $(echo "$output" | grep 'Focused:')"
237237
fi
238238

239-
if echo "$output" | grep -q "Latest question"; then
239+
if grep -q "Latest question" <<< "$output"; then
240240
pass "Shows question from latest invocation"
241241
else
242242
fail "Should show latest question" "got: $output"
@@ -254,13 +254,13 @@ create_skill_invocation "2026-02-19_21-00-00-111-aaa" "success" "gpt-5.4" "high"
254254
create_skill_invocation "2026-02-19_21-30-00-222-bbb" "running" "gpt-5.4" "high" "" "Running question"
255255

256256
output=$(_humanize_monitor_skill --once 2>&1) && rc=0 || rc=$?
257-
if echo "$output" | grep -q "Running: 1"; then
257+
if grep -q "Running: 1" <<< "$output"; then
258258
pass "Counts running invocations"
259259
else
260260
fail "Should count 1 running" "got: $(echo "$output" | grep 'Running')"
261261
fi
262262

263-
if echo "$output" | grep -q "running"; then
263+
if grep -q "running" <<< "$output"; then
264264
pass "Shows running status for focused invocation"
265265
else
266266
fail "Should show running status" "got: $output"
@@ -279,14 +279,14 @@ create_skill_invocation "2026-02-19_20-30-00-222-bbb" "error" "gpt-5.4" "high" "
279279
create_skill_invocation "2026-02-19_21-00-00-333-ccc" "success" "gpt-5.4" "high" "20s" "Question three"
280280

281281
output=$(_humanize_monitor_skill --once 2>&1) && rc=0 || rc=$?
282-
if echo "$output" | grep -q "Recent Invocations"; then
282+
if grep -q "Recent Invocations" <<< "$output"; then
283283
pass "Shows recent invocations section"
284284
else
285285
fail "Should show recent section" "got: $output"
286286
fi
287287

288288
# Check that invocations appear in the output
289-
if echo "$output" | grep -q "2026-02-19_21-00-00-333-ccc"; then
289+
if grep -q "2026-02-19_21-00-00-333-ccc" <<< "$output"; then
290290
pass "Lists invocations in recent section"
291291
else
292292
fail "Should list invocations" "got: $(echo "$output" | grep '2026-02-19')"
@@ -332,14 +332,14 @@ EOF
332332
echo "Performance analysis result" > "$local_dir/output.md"
333333

334334
output=$(_humanize_monitor_skill --once 2>&1) && rc=0 || rc=$?
335-
if echo "$output" | grep -q "What are the performance bottlenecks"; then
335+
if grep -q "What are the performance bottlenecks" <<< "$output"; then
336336
pass "Extracts first line of question"
337337
else
338338
fail "Should extract question first line" "got: $output"
339339
fi
340340

341341
# Should NOT contain the second line
342-
if ! echo "$output" | grep -q "Additional context"; then
342+
if ! grep -q "Additional context" <<< "$output"; then
343343
pass "Does not include subsequent lines from question"
344344
else
345345
fail "Should only show first line" "got: $output"
@@ -356,13 +356,13 @@ mkdir -p .humanize/skill
356356
create_skill_invocation "2026-02-19_21-00-00-111-aaa" "empty_response" "gpt-5.4" "high" "30s" "Why is the sky blue?"
357357

358358
output=$(_humanize_monitor_skill --once 2>&1) && rc=0 || rc=$?
359-
if echo "$output" | grep -q "Empty: 1"; then
359+
if grep -q "Empty: 1" <<< "$output"; then
360360
pass "Counts empty response invocations"
361361
else
362362
fail "Should count 1 empty" "got: $(echo "$output" | grep 'Empty')"
363363
fi
364364

365-
if echo "$output" | grep -q "No output available"; then
365+
if grep -q "No output available" <<< "$output"; then
366366
pass "Shows no output message for empty response"
367367
else
368368
fail "Should show no output message" "got: $output"
@@ -382,7 +382,7 @@ mkdir -p ".humanize/skill/not-a-skill-dir"
382382
echo "junk" > ".humanize/skill/not-a-skill-dir/input.md"
383383

384384
output=$(_humanize_monitor_skill --once 2>&1) && rc=0 || rc=$?
385-
if echo "$output" | grep -q "Total Invocations: 1"; then
385+
if grep -q "Total Invocations: 1" <<< "$output"; then
386386
pass "Ignores non-timestamp directories"
387387
else
388388
fail "Should only count valid skill dirs" "got: $(echo "$output" | grep 'Total')"

0 commit comments

Comments
 (0)