Skip to content

Commit 383f5aa

Browse files
feat: detect stale RED markers in test gate (4d88-671b) (merge worktree-20260325-153135)
2 parents df617d4 + 1b30910 commit 383f5aa

File tree

2 files changed

+456
-2
lines changed

2 files changed

+456
-2
lines changed

plugins/dso/hooks/record-test-status.sh

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,35 @@ parse_failing_tests_from_output() {
187187
|| true
188188
}
189189

190+
# parse_passing_tests_from_output: extract passing test names from test runner output.
191+
# Mirrors parse_failing_tests_from_output for the pass case.
192+
# Supports:
193+
# - Bash-style: "test_name ... PASS" or "test_name: PASS"
194+
# - Pytest PASSED lines: "PASSED path/to/test.py::test_name"
195+
# Returns one test name per line on stdout.
196+
parse_passing_tests_from_output() {
197+
local output_file="$1"
198+
199+
if [[ ! -f "$output_file" ]]; then
200+
return 0
201+
fi
202+
203+
# Bash-style: "test_name ... PASS" (with optional whitespace/dots between)
204+
grep -oE '^[a-zA-Z_][a-zA-Z0-9_-]*[[:space:]]*\.\.\..*PASS' "$output_file" \
205+
| sed 's/[[:space:]]*\.\.\..*PASS//' \
206+
|| true
207+
208+
# Bash-style: "test_name: PASS"
209+
grep -oE '^[a-zA-Z_][a-zA-Z0-9_-]*[[:space:]]*:[[:space:]]*PASS' "$output_file" \
210+
| sed 's/[[:space:]]*:[[:space:]]*PASS//' \
211+
|| true
212+
213+
# Pytest-style: "PASSED path/to/test.py::test_name"
214+
grep -oE '^PASSED [^[:space:]]+::[a-zA-Z_][a-zA-Z0-9_]*' "$output_file" \
215+
| sed 's/^PASSED [^:]*:://' \
216+
|| true
217+
}
218+
190219
# get_test_line_number: find the line number of a test function in a test file.
191220
# For Python: 'def test_name('
192221
# For Bash: 'test_name()' or any line containing test_name as a word
@@ -478,7 +507,28 @@ for test_file in "${ASSOCIATED_TESTS[@]}"; do
478507
done
479508

480509
if [[ "$all_in_red_zone" == true ]]; then
481-
# All failures are in the RED zone — tolerate
510+
# All failures are in the RED zone — check for passing RED-zone tests
511+
# before tolerating. A passing RED-zone test means the marker is stale.
512+
mapfile -t passing_tests < <(parse_passing_tests_from_output "$test_output_file")
513+
_has_stale_pass=false
514+
for passing_test in "${passing_tests[@]}"; do
515+
[[ -z "$passing_test" ]] && continue
516+
_pass_line=$(get_test_line_number "$test_file" "$passing_test")
517+
if [[ "$_pass_line" -ne -1 ]] && [[ "$_pass_line" -ge "$red_zone_line" ]]; then
518+
echo "STALE RED MARKER: ${test_file} — RED-zone test '${passing_test}' passed (line ${_pass_line}, RED zone starts line ${red_zone_line}); remove or update the [${red_marker}] marker" >&2
519+
_has_stale_pass=true
520+
fi
521+
done
522+
523+
if [[ "$_has_stale_pass" == true ]]; then
524+
rm -f "$test_output_file"
525+
if [[ "$STATUS" != "timeout" ]]; then
526+
STATUS="failed"
527+
fi
528+
continue
529+
fi
530+
531+
# No stale passing tests — tolerate RED zone failures as normal
482532
echo "INFO: RED zone failures tolerated for ${test_file} (marker: ${red_marker}, zone starts line ${red_zone_line})" >&2
483533
rm -f "$test_output_file"
484534
# Do NOT downgrade STATUS — this test is non-blocking
@@ -496,7 +546,19 @@ for test_file in "${ASSOCIATED_TESTS[@]}"; do
496546
fi
497547
fi
498548

499-
# No RED marker (or test passed) — standard behavior
549+
# ── Stale RED marker detection: exit 0 + RED marker ───────────────────
550+
# If the test file passed (exit 0) but has a RED marker, the marker is
551+
# stale — all RED-zone tests are now passing. Block and report.
552+
if [[ $exit_code -eq 0 ]] && [[ -n "$red_marker" ]]; then
553+
echo "STALE RED MARKER: ${test_file} (marker: ${red_marker}) — all RED-zone tests passed; remove the [${red_marker}] marker from .test-index" >&2
554+
rm -f "$test_output_file"
555+
if [[ "$STATUS" != "timeout" ]]; then
556+
STATUS="failed"
557+
fi
558+
continue
559+
fi
560+
561+
# No RED marker (or test passed without marker) — standard behavior
500562
if [[ $exit_code -ne 0 ]]; then
501563
echo "--- Test output for $test_file (exit $exit_code) ---" >&2
502564
cat "$test_output_file" >&2

0 commit comments

Comments
 (0)