Skip to content

Commit 16e6ef7

Browse files
sawenzelclaude
andcommitted
Keep the first non-zero exit code instead of summing
Summing can land on a multiple of 256: two phases failing with 128 each summed to 256 and exited 0, reporting success. Keeping the first non-zero code also makes the exit status identify the phase that failed. The static guard in test/tests/ now checks that neither site sums again. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 5b55d7e commit 16e6ef7

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

‎test/tests/exit_code_aggregation.sh‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/bin/bash
2-
# Static guard against the exit-code-aggregation bug in run_workflow_tests.sh:
3-
# the final RET=$(( ... )) line must include every aggregate return-code
4-
# variable the script computes, and each of those variables must actually be
5-
# assigned somewhere in the script.
2+
# Static guard against the exit-code-aggregation bugs in run_workflow_tests.sh.
3+
# Two things must hold:
4+
# 1. the final RET= line must reference every aggregate return-code variable
5+
# the script computes, and each must actually be assigned somewhere;
6+
# 2. no exit code may be produced by *summing* codes. Sums can land on a
7+
# multiple of 256 — two phases failing with 128 each sum to 256, which
8+
# exits 0 — so a real failure would report success.
69

710
set -u
811
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
@@ -25,7 +28,7 @@ check()
2528
# whoever adds it come here and update this list.
2629
REQUIRED_VARS="ret_global_pwg ret_analysis_qc ret_global_anchored"
2730

28-
RET_LINE=$(grep -m1 -E '^RET=\$\(\(' "${SCRIPT}")
31+
RET_LINE=$(grep -m1 -E '^RET=' "${SCRIPT}")
2932

3033
for var in ${REQUIRED_VARS} ; do
3134
present=$(grep -c -- "${var}" <<< "${RET_LINE}")
@@ -37,6 +40,13 @@ for var in ${REQUIRED_VARS} ; do
3740
check "${var} is assigned in the script" 1 "$( [[ "${assigned}" -ge 1 ]] && echo 1 || echo 0 )"
3841
done
3942

43+
# No exit code may be a sum of codes. These are the two sites that had it.
44+
summed_ret=$(grep -c -E '^RET=\$\(\(' "${SCRIPT}")
45+
check "RET is not a sum of codes" 0 "${summed_ret}"
46+
47+
summed_this=$(grep -c -E 'ret_this=\$\(\(ret_this[[:space:]]*\+' "${SCRIPT}")
48+
check "test_single_wf does not sum codes" 0 "${summed_this}"
49+
4050
echo
4151
if [[ "${FAILURES}" == "0" ]] ; then
4252
echo "All exit-code aggregation checks passed"

0 commit comments

Comments
 (0)