Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(ci): executed-test receipts from every bun invocation (X2, B2, B9)

garrytan99f784a74a99
diff --git a/scripts/check-admin-build.sh b/scripts/check-admin-build.sh
index 028faa48ae..512fb1a231 100755
--- a/scripts/check-admin-build.sh
+++ b/scripts/check-admin-build.sh
@@ -15,6 +15,7 @@ set -euo pipefail
if [ "${GBRAIN_SKIP_ADMIN_BUILD:-0}" = "1" ]; then
echo "[check:admin-build] GBRAIN_SKIP_ADMIN_BUILD=1, skipping"
+ echo "GBRAIN_CHECK_SKIPPED: GBRAIN_SKIP_ADMIN_BUILD=1"
exit 0
fi
@@ -22,6 +23,7 @@ cd "$(dirname "$0")/.."
if [ ! -d admin ]; then
echo "[check:admin-build] no admin/ directory, skipping"
+ echo "GBRAIN_CHECK_SKIPPED: no admin/ directory"
exit 0
fi
diff --git a/scripts/check-bootstrap-tag.sh b/scripts/check-bootstrap-tag.sh
index 69465dfebe..24e521609f 100755
--- a/scripts/check-bootstrap-tag.sh
+++ b/scripts/check-bootstrap-tag.sh
@@ -132,6 +132,7 @@ if [ "$fail" -ne 0 ]; then
fi
if [ "$checked" -eq 0 ]; then
echo "check-bootstrap-tag: ok (no bootstrap entry docs present yet — all checks skipped)"
+ echo "GBRAIN_CHECK_SKIPPED: no bootstrap entry docs present"
else
echo "check-bootstrap-tag: ok ($checked doc(s) on the '$SANCTIONED' distribution ref)"
fi
diff --git a/scripts/check-bootstrap-templates.sh b/scripts/check-bootstrap-templates.sh
index 4824afa604..d471a24b7b 100755
--- a/scripts/check-bootstrap-templates.sh
+++ b/scripts/check-bootstrap-templates.sh
@@ -56,6 +56,7 @@ fail=0
if [ ! -d "$TDIR" ]; then
echo "SKIP: templates/bootstrap/ absent — nothing to check yet"
echo "check-bootstrap-templates: ok (skipped)"
+ echo "GBRAIN_CHECK_SKIPPED: templates/bootstrap/ absent"
exit 0
fi
diff --git a/scripts/check-grok-pin.sh b/scripts/check-grok-pin.sh
index 24e0d17f9d..44608c1a7f 100755
--- a/scripts/check-grok-pin.sh
+++ b/scripts/check-grok-pin.sh
@@ -34,10 +34,12 @@ WORKFLOW="$ROOT/.github/workflows/heavy-tests.yml"
if [ ! -f "$WORKFLOW" ]; then
echo "check-grok-pin: SKIP (no $WORKFLOW)"
+ echo "GBRAIN_CHECK_SKIPPED: no heavy-tests.yml"
exit 0
fi
if ! grep -q '^ grok-door:' "$WORKFLOW"; then
echo "check-grok-pin: SKIP (no grok-door job in heavy-tests.yml yet)"
+ echo "GBRAIN_CHECK_SKIPPED: no grok-door job in heavy-tests.yml"
exit 0
fi
# Once the grok-door job EXISTS, a missing pin doc is a FAILURE, not a skip —
diff --git a/scripts/check-opencode-pin.sh b/scripts/check-opencode-pin.sh
index 54dba64532..f76e2ac2f0 100755
--- a/scripts/check-opencode-pin.sh
+++ b/scripts/check-opencode-pin.sh
@@ -34,10 +34,12 @@ WORKFLOW="$ROOT/.github/workflows/heavy-tests.yml"
if [ ! -f "$WORKFLOW" ]; then
echo "check-opencode-pin: SKIP (no $WORKFLOW)"
+ echo "GBRAIN_CHECK_SKIPPED: no heavy-tests.yml"
exit 0
fi
if ! grep -q '^ opencode-door:' "$WORKFLOW"; then
echo "check-opencode-pin: SKIP (no opencode-door job in heavy-tests.yml yet)"
+ echo "GBRAIN_CHECK_SKIPPED: no opencode-door job in heavy-tests.yml"
exit 0
fi
# Once the opencode-door job EXISTS, a missing pin doc is a FAILURE, not a skip —
diff --git a/scripts/check-pagetype-exhaustive.sh b/scripts/check-pagetype-exhaustive.sh
index 85aa7975a4..ebbb0e9d97 100755
--- a/scripts/check-pagetype-exhaustive.sh
+++ b/scripts/check-pagetype-exhaustive.sh
@@ -32,6 +32,7 @@ PAGETYPE_FILES=$(grep -rlE "import.*PageType.*from.*types" src 2>/dev/null || tr
if [ -z "$PAGETYPE_FILES" ]; then
echo "[check-pagetype-exhaustive] No files import PageType. Skipping."
+ echo "GBRAIN_CHECK_SKIPPED: no src file imports PageType"
exit 0
fi
diff --git a/scripts/check-pglite-embedded.sh b/scripts/check-pglite-embedded.sh
index e8d8ab68cd..cff5ee9f4c 100755
--- a/scripts/check-pglite-embedded.sh
+++ b/scripts/check-pglite-embedded.sh
@@ -55,6 +55,7 @@ if ! (cd "$BUILD_DIR" && bun build --compile --no-compile-autoload-bunfig --outf
# e2e — so local dev without compile support isn't blocked. CI has compile.
if grep -qiE 'not (found|available)|permission denied|Could not download|ETIMEDOUT|network' "$BUILD_DIR/compile.log"; then
echo "[check-pglite-embedded] SKIP: bun build --compile unavailable in this sandbox." >&2
+ echo "GBRAIN_CHECK_SKIPPED: bun build --compile unavailable"
sed -n '1,20p' "$BUILD_DIR/compile.log" >&2 || true
exit 0
fi
diff --git a/scripts/check-pin-doc-privacy.sh b/scripts/check-pin-doc-privacy.sh
index 9a887dffba..9a55091564 100755
--- a/scripts/check-pin-doc-privacy.sh
+++ b/scripts/check-pin-doc-privacy.sh
@@ -28,6 +28,7 @@ shopt -u nullglob
if [ "${#PIN_DOCS[@]}" -eq 0 ]; then
echo "check-pin-doc-privacy: SKIP (no docs/mcp/*-CLI-PIN.md yet)"
+ echo "GBRAIN_CHECK_SKIPPED: no docs/mcp/*-CLI-PIN.md"
exit 0
fi
diff --git a/scripts/check-schema-migration-order.ts b/scripts/check-schema-migration-order.ts
index 92352b01d3..5851c35ffa 100644
--- a/scripts/check-schema-migration-order.ts
+++ b/scripts/check-schema-migration-order.ts
@@ -71,6 +71,7 @@ function main(): number {
return 1;
}
console.log(`skip: ${msg}`);
+ console.log(`GBRAIN_CHECK_SKIPPED: base ref ${ref} unavailable`);
return 0;
}
let head;
diff --git a/scripts/check-synthetic-corpus-privacy.sh b/scripts/check-synthetic-corpus-privacy.sh
index 5ef5068175..c349a6a000 100755
--- a/scripts/check-synthetic-corpus-privacy.sh
+++ b/scripts/check-synthetic-corpus-privacy.sh
@@ -37,6 +37,7 @@ PLACEHOLDERS=(
# Skip if directory doesn't exist yet (early-clone state).
if [ ! -d "$CORPUS_DIR" ]; then
echo "OK: $CORPUS_DIR does not exist yet (skipping privacy scan)"
+ echo "GBRAIN_CHECK_SKIPPED: $CORPUS_DIR absent"
exit 0
fi
diff --git a/scripts/lib/test-env.sh b/scripts/lib/test-env.sh
index 08497a57a3..ca796cbb81 100644
--- a/scripts/lib/test-env.sh
+++ b/scripts/lib/test-env.sh
@@ -104,3 +104,88 @@ ensure_default_pglite_snapshot() {
esac
echo "[$label] default PGLite snapshot active: $GBRAIN_TEST_DEFAULT_SNAPSHOT" >&2
}
+
+# ──────────────────────────────────────────────────────────────────────────
+# Executed-test receipts (X2). With GBRAIN_TEST_RECEIPT_DIR set, every bun
+# invocation a runner makes records one receipt in that directory:
+# <id>.receipt key=value lines: lane, kind (primary|rerun|rescue),
+# shard/of, arm, sha, run_id, run_attempt, started, and
+# exit= once the invocation returns
+# <id>.files the test files assigned to the invocation
+# <id>.junit.xml Bun's native JUnit report (--reporter=junit)
+# scripts/ci-executed-counts.ts reads them: an assigned file with no valid
+# JUnit from any attempt is `incomplete`, and a later attempt (rerun/rescue)
+# supersedes an earlier one for the files it re-ran.
+#
+# receipts_init captures the directory and lane, then UNSETS both variables so
+# test processes (and the nested runners some tests start) never inherit
+# them; a runner that starts another runner passes
+# GBRAIN_TEST_RECEIPT_DIR="$TEST_RECEIPT_DIR" explicitly.
+# GBRAIN_TEST_RECEIPT_DIR receipt directory (unset = receipts off)
+# GBRAIN_TEST_RECEIPT_LANE overrides the runner's default lane name
+# ──────────────────────────────────────────────────────────────────────────
+receipts_init() {
+ TEST_RECEIPT_LANE="${GBRAIN_TEST_RECEIPT_LANE:-$1}"
+ TEST_RECEIPT_DIR="${GBRAIN_TEST_RECEIPT_DIR:-}"
+ unset GBRAIN_TEST_RECEIPT_DIR GBRAIN_TEST_RECEIPT_LANE
+ RECEIPT_ID=""
+ RECEIPT_ARGS=()
+ [ -n "$TEST_RECEIPT_DIR" ] || return 0
+ case "$TEST_RECEIPT_DIR" in /*) ;; *) TEST_RECEIPT_DIR="$PWD/$TEST_RECEIPT_DIR" ;; esac
+ mkdir -p "$TEST_RECEIPT_DIR" || {
+ echo "[receipts] cannot create $TEST_RECEIPT_DIR; receipts are required when GBRAIN_TEST_RECEIPT_DIR is set" >&2
+ return 1
+ }
+ TEST_RECEIPT_SHA="${GITHUB_SHA:-$(git rev-parse HEAD 2>/dev/null || echo unknown)}"
+}
+
+# receipt_begin <kind> <tag> <shard> <of> <arm> [file...]
+# Sets RECEIPT_ID and RECEIPT_ARGS (the bun reporter flags; empty when
+# receipts are off). <tag> must be unique per invocation within the lane.
+receipt_begin() {
+ local kind="$1" tag="$2" shard="$3" of="$4" arm="$5" id n=1
+ shift 5
+ RECEIPT_ID=""
+ RECEIPT_ARGS=()
+ [ -n "${TEST_RECEIPT_DIR:-}" ] || return 0
+ id="${TEST_RECEIPT_LANE}--${tag}--${kind}"
+ while [ -e "$TEST_RECEIPT_DIR/$id.receipt" ]; do
+ n=$((n + 1))
+ id="${TEST_RECEIPT_LANE}--${tag}--${kind}-$n"
+ done
+ {
+ echo "version=1"
+ echo "lane=$TEST_RECEIPT_LANE"
+ echo "kind=$kind"
+ echo "tag=$tag"
+ echo "shard=$shard"
+ echo "of=$of"
+ echo "arm=$arm"
+ echo "sha=$TEST_RECEIPT_SHA"
+ echo "root=$PWD"
+ echo "run_id=${GITHUB_RUN_ID:-}"
+ echo "run_attempt=${GITHUB_RUN_ATTEMPT:-}"
+ echo "job=${GITHUB_JOB:-}"
+ echo "started=$(date +%s)"
+ } > "$TEST_RECEIPT_DIR/$id.receipt"
+ if [ "$#" -gt 0 ]; then printf '%s\n' "$@" > "$TEST_RECEIPT_DIR/$id.files"; else : > "$TEST_RECEIPT_DIR/$id.files"; fi
+ RECEIPT_ID="$id"
+ RECEIPT_ARGS=(--reporter=junit "--reporter-outfile=$TEST_RECEIPT_DIR/$id.junit.xml")
+}
+
+# receipt_end <exit-code>: records how the invocation returned. A receipt
+# without exit= was interrupted before its runner saw the result.
+receipt_end() {
+ [ -n "${TEST_RECEIPT_DIR:-}" ] && [ -n "${RECEIPT_ID:-}" ] || return 0
+ echo "exit=$1" >> "$TEST_RECEIPT_DIR/$RECEIPT_ID.receipt"
+}
+
+# receipt_empty <tag> <shard> <of>: this invocation was assigned no files.
+# Keeps an empty shard from reading as a missing one.
+receipt_empty() {
+ receipt_begin primary "$1" "$2" "$3" ""
+ [ -n "${RECEIPT_ID:-}" ] || return 0
+ echo "empty=1" >> "$TEST_RECEIPT_DIR/$RECEIPT_ID.receipt"
+ receipt_end 0
+ RECEIPT_ARGS=()
+}
diff --git a/scripts/run-e2e.sh b/scripts/run-e2e.sh
index 0742151e14..514d87cc99 100755
--- a/scripts/run-e2e.sh
+++ b/scripts/run-e2e.sh
@@ -38,6 +38,12 @@ RUNNER_SHARD="${SHARD:-}"
unset SHARD
cd "$(dirname "$0")/.."
+# Executed-test receipts (X2): captured here, before the GBRAIN_* scrub below,
+# and unset so test processes never inherit them. Each file pass keeps its
+# native JUnit report as a receipt (lane e2e unless GBRAIN_TEST_RECEIPT_LANE
+# says otherwise; backend-matrix passes record their arm).
+. scripts/lib/test-env.sh
+receipts_init e2e || exit 2
# COVERAGE_DIR (opt-in lcov coverage) must be an ABSOLUTE path: this script
# redirects HOME (and E2E tests spawn CLI subprocesses with varying cwd), so
@@ -208,9 +214,19 @@ if [ "$DRY_RUN_LIST" = "1" ]; then
exit 0
fi
+RECEIPT_SHARD=""
+RECEIPT_OF=""
+RECEIPT_TAG="run"
+if [ -n "$RUNNER_SHARD" ]; then
+ RECEIPT_SHARD="$shard_n"
+ RECEIPT_OF="$shard_m"
+ RECEIPT_TAG="s${shard_n}of${shard_m}"
+fi
+
if [ "${#files[@]}" -eq 0 ]; then
# Empty shard (e.g. SHARD=4/4 with only 3 files): nothing to do.
echo "No files for shard ${RUNNER_SHARD:-(unsharded)}; exiting clean."
+ receipt_empty "$RECEIPT_TAG" "$RECEIPT_SHARD" "$RECEIPT_OF"
exit 0
fi
@@ -345,8 +361,41 @@ except (OSError, ET.ParseError, ValueError, TypeError) as error:
PY
}
+# A file's HOME must be removable once its bun process exits. Anything still
+# running with HOME=<file home> is a leaked child of that file (the B2 class:
+# a detached refresh still writing Bun's install cache). Kill those first
+# (Linux /proc scan; elsewhere none can be found), then remove the HOME. A
+# HOME that still cannot be removed fails THIS file by name instead of
+# letting `set -e` abort the rest of the partition. Prints a note on stdout
+# (empty when nothing leaked); returns 1 when the HOME is still there.
+remove_file_home() {
+ local home="$1" leaked="" pid cmd details=""
+ if [ -d /proc/self ]; then
+ leaked=$(grep -lzxF "HOME=$home" /proc/[0-9]*/environ 2>/dev/null | sed 's|^/proc/||; s|/environ$||' || true)
+ fi
+ for pid in $leaked; do
+ [ "$pid" = "$$" ] && continue
+ cmd=$(tr '\0' ' ' < "/proc/$pid/cmdline" 2>/dev/null | cut -c1-200 || true)
+ details="$details
+ pid $pid: ${cmd:-<exited>}"
+ kill -KILL "$pid" 2>/dev/null || true
+ done
+ if rm -rf "$home" 2>/dev/null || { sleep 1; rm -rf "$home" 2>/dev/null; }; then
+ [ -z "$details" ] || echo "WARN: $name left processes running with HOME=$home after its bun process exited (killed):$details"
+ return 0
+ fi
+ echo "FAILED: $name left a process writing to its HOME; cleanup could not remove $home"
+ echo " Why: a test started a child (often detached) that outlived the test file and kept writing under HOME."
+ echo " Fix: make the test wait for or stop its children; reproduce with: bash scripts/run-e2e.sh $f"
+ [ -z "$details" ] || echo " Leaked processes (killed):$details"
+ find "$home" -mindepth 1 -maxdepth 4 2>/dev/null | head -10 | sed 's/^/ Remaining: /'
+ return 1
+}
+
+executed_files=()
for f in "${files[@]}"; do
name=$(basename "$f")
+ executed_files+=("$f")
file_idx=$((file_idx + 1))
# COVERAGE_DIR (opt-in): each E2E file runs in its OWN bun process, so each
# needs its OWN coverage dir — a second bun process reusing a coverage dir
@@ -407,29 +456,41 @@ for f in "${files[@]}"; do
in_backend_matrix=0
case "$backend_matrix" in *" ${f#./} "*) in_backend_matrix=1 ;; esac
run_e2e_pass() {
- # $1 = pass label; remaining args = env assignments for this pass.
- local pass_label="$1"
- shift
+ # $1 = pass label; $2 = receipt arm ("" outside the backend matrix);
+ # remaining args = env assignments for this pass.
+ local pass_label="$1" arm="$2"
+ shift 2
FILE_HOME="$E2E_TMP_HOME/file-$file_idx-$pass_label"
mkdir -p "$FILE_HOME/.gbrain"
rc=0
p=0
rm -f "$E2E_TMP_HOME/current.junit.xml"
+ receipt_begin primary "$RECEIPT_TAG-f$file_idx-$pass_label" "$RECEIPT_SHARD" "$RECEIPT_OF" "$arm" "${f#./}"
env "$@" HOME="$FILE_HOME" GBRAIN_HOME="$FILE_HOME" $TIMEOUT_CMD bun test --timeout=60000 --reporter=junit --reporter-outfile="$E2E_TMP_HOME/current.junit.xml" ${COVERAGE_ARGS[@]+"${COVERAGE_ARGS[@]}"} "$f" > "$E2E_TMP_HOME/current.log" 2>&1 &
ACTIVE_E2E_PID=$!
wait "$ACTIVE_E2E_PID" || rc=$?
ACTIVE_E2E_PID=""
+ if [ -n "$RECEIPT_ID" ] && [ -f "$E2E_TMP_HOME/current.junit.xml" ]; then
+ cp "$E2E_TMP_HOME/current.junit.xml" "$TEST_RECEIPT_DIR/$RECEIPT_ID.junit.xml"
+ fi
+ receipt_end "$rc"
output=$(cat "$E2E_TMP_HOME/current.log")
- rm -rf "$FILE_HOME"
+ if ! cleanup_note=$(remove_file_home "$FILE_HOME"); then
+ output="$output
+$cleanup_note"
+ rc=1
+ return
+ fi
+ [ -z "$cleanup_note" ] || echo "$cleanup_note"
if [ "$rc" -eq 0 ] && ! p=$(completed_e2e_passes "$f"); then
echo "FAILED: $name did not produce a complete native Bun report for the selected file"
rc=1
fi
}
if [ "$in_backend_matrix" = "1" ]; then
- run_e2e_pass direct GBRAIN_TEST_BACKEND=postgres-direct
+ run_e2e_pass direct postgres-direct GBRAIN_TEST_BACKEND=postgres-direct
else
- run_e2e_pass direct
+ run_e2e_pass direct ""
fi
if [ "$rc" -eq 0 ] && [ "$in_backend_matrix" = "1" ] && [ -n "${DATABASE_URL:-}" ]; then
direct_passes="$p"
@@ -455,7 +516,7 @@ for f in "${files[@]}"; do
case "$pooled_timeout" in ''|*[!0-9]*) ;; *) [ -n "$TIMEOUT_CMD" ] && TIMEOUT_CMD="${TIMEOUT_CMD%% *} $pooled_timeout" ;; esac
;;
esac
- run_e2e_pass pgbouncer DATABASE_URL="$PGBOUNCER_E2E_URL" GBRAIN_TEST_BACKEND=pgbouncer
+ run_e2e_pass pgbouncer pgbouncer DATABASE_URL="$PGBOUNCER_E2E_URL" GBRAIN_TEST_BACKEND=pgbouncer
TIMEOUT_CMD="$pooled_timeout_cmd"
if [ "$rc" -eq 0 ] && { [ "$p" -eq 0 ] || [ "$p" -ne "$direct_passes" ]; }; then
echo "$output"
@@ -493,6 +554,13 @@ for f in "${files[@]}"; do
fi
done
+# Execution receipt (B9): which files this lane ran, written pass or fail so a
+# red nightly still records them. lane-manifest.json (complete:true) stays
+# green-only, written at the end.
+if [ -n "${COVERAGE_DIR:-}" ]; then
+ printf '%s\n' "${executed_files[@]}" > "$COVERAGE_DIR/executed-files.txt"
+fi
+
echo ""
echo "========================================"
echo "E2E SUMMARY (sequential execution)"
@@ -555,7 +623,6 @@ if [ -n "${COVERAGE_DIR:-}" ]; then
LANE="e2e"
[ -z "$RUNNER_SHARD" ] || LANE="e2e-$shard_n"
RUN_SHA=$(git rev-parse HEAD)
- printf '%s\n' "${files[@]}" > "$COVERAGE_DIR/executed-files.txt"
printf '{"lane":"%s","sha":"%s","lcovCount":%s,"complete":true}\n' \
"$LANE" "$RUN_SHA" "${LCOV_COUNT:-0}" > "$COVERAGE_DIR/lane-manifest.json"
fi
diff --git a/scripts/run-serial-tests.sh b/scripts/run-serial-tests.sh
index 91bcb131bf..e1fda9e9ba 100755
--- a/scripts/run-serial-tests.sh
+++ b/scripts/run-serial-tests.sh
@@ -73,6 +73,15 @@ case "${1:-}" in
esac
. scripts/lib/test-env.sh
+receipts_init serial
+RECEIPT_SHARD=""
+RECEIPT_OF=""
+RECEIPT_TAG="all"
+if [ -n "$SERIAL_SHARD" ]; then
+ RECEIPT_SHARD="$shard_n"
+ RECEIPT_OF="$shard_m"
+ RECEIPT_TAG="s${shard_n}of${shard_m}"
+fi
# ──────────────────────────────────────────────────────────────────────────
# EXCLUSIVE_FILES: files that must never run concurrently with anything else
@@ -156,7 +165,11 @@ if [ "$DRY_RUN_MODE" = "--dry-run-list-exclusive" ]; then
exit 0
fi
-if [ "${#ordered_files[@]}" -gt 0 ]; then ensure_pglite_snapshot "serial-tests"; fi
+if [ "${#ordered_files[@]}" -gt 0 ]; then
+ ensure_pglite_snapshot "serial-tests"
+else
+ receipt_empty "$RECEIPT_TAG" "$RECEIPT_SHARD" "$RECEIPT_OF"
+fi
# ──────────────────────────────────────────────────────────────────────────
# Pool sizing: min(detect_cpus, 4) — each pooled bun process can hold a
@@ -293,8 +306,9 @@ echo "[serial-tests] ${#ordered_files[@]} file(s): pool=$POOL (${#exclusive_pres
# against in v0.40.10. The literal `bun test --max-concurrency=1` below is
# contract-pinned by test/scripts/serial-files.test.ts.
run_one_file() {
- # $1 file, $2 log path, $3 exit-sentinel path, $4 wrap ("wrap"|"nowrap")
- local f="$1" log="$2" exitf="$3" wrap="$4" rc=0
+ # $1 file, $2 log path, $3 exit-sentinel path, $4 wrap ("wrap"|"nowrap"),
+ # $5 receipt kind (primary|rescue; default primary)
+ local f="$1" log="$2" exitf="$3" wrap="$4" kind="${5:-primary}" rc=0
local key="${log%.log}" started finished
printf '%s\n' "$f" > "$key.file"
started=$(now_ms)
@@ -309,12 +323,14 @@ run_one_file() {
cov_key=$(basename "$log" .log)
cov_args=(--coverage --coverage-reporter=lcov --coverage-dir="$COVERAGE_DIR/serial-$cov_key")
fi
+ receipt_begin "$kind" "$RECEIPT_TAG-$(basename "$log" .log)" "$RECEIPT_SHARD" "$RECEIPT_OF" "" "$f"
if [ "$wrap" = "wrap" ] && [ -n "$TIMEOUT_BIN" ]; then
"$TIMEOUT_BIN" -k 15 "$PER_FILE_TIMEOUT" \
- bun test --max-concurrency=1 --timeout=120000 ${cov_args[@]+"${cov_args[@]}"} "$f" > "$log" 2>&1 || rc=$?
+ bun test --max-concurrency=1 --timeout=120000 ${cov_args[@]+"${cov_args[@]}"} ${RECEIPT_ARGS[@]+"${RECEIPT_ARGS[@]}"} "$f" > "$log" 2>&1 || rc=$?
else
- bun test --max-concurrency=1 --timeout=120000 ${cov_args[@]+"${cov_args[@]}"} "$f" > "$log" 2>&1 || rc=$?
+ bun test --max-concurrency=1 --timeout=120000 ${cov_args[@]+"${cov_args[@]}"} ${RECEIPT_ARGS[@]+"${RECEIPT_ARGS[@]}"} "$f" > "$log" 2>&1 || rc=$?
fi
+ receipt_end "$rc"
echo "$rc" > "$exitf"
finished=$(now_ms)
echo "$((finished - started))" > "$key.duration-ms"
@@ -420,7 +436,7 @@ if [ "${#rescue_files[@]}" -gt 0 ]; then
is_exclusive "$f" && wrap_mode="nowrap"
s=$(date +%s)
[ "$wrap_mode" != "nowrap" ] || running_exclusive=1
- run_one_file "$f" "$LOG_DIR/$i.log" "$LOG_DIR/$i.exit" "$wrap_mode" &
+ run_one_file "$f" "$LOG_DIR/$i.log" "$LOG_DIR/$i.exit" "$wrap_mode" rescue &
wait "$!"
running_exclusive=0
e=$(date +%s)
diff --git a/scripts/run-slow-tests.sh b/scripts/run-slow-tests.sh
index 8c4024006a..0e6f929ee5 100755
--- a/scripts/run-slow-tests.sh
+++ b/scripts/run-slow-tests.sh
@@ -39,11 +39,13 @@ if [ "$DRY_RUN" = "1" ]; then
fi
. scripts/lib/test-env.sh
+receipts_init slow
ensure_pglite_snapshot "run-slow-tests"
ensure_default_pglite_snapshot "run-slow-tests"
if [ "${#slow_files[@]}" -eq 0 ]; then
echo "[run-slow-tests] no *.slow.test.ts files; nothing to do."
+ receipt_empty all "" ""
exit 0
fi
@@ -53,4 +55,8 @@ echo "[run-slow-tests] running ${#slow_files[@]} slow files (CI runs these as pa
# when bun runs slow files in parallel, CPU contention pushes them past
# 60s and individual tests timeout even though they'd pass solo. Slow
# tests are explicit by-name — generous per-test budget is correct.
-exec bun test --timeout=120000 "${slow_files[@]}"
+receipt_begin primary all "" "" "" "${slow_files[@]}"
+rc=0
+bun test --timeout=120000 ${RECEIPT_ARGS[@]+"${RECEIPT_ARGS[@]}"} "${slow_files[@]}" || rc=$?
+receipt_end "$rc"
+exit "$rc"
diff --git a/scripts/run-unit-parallel.sh b/scripts/run-unit-parallel.sh
index 996a058ffa..115df8a1a4 100755
--- a/scripts/run-unit-parallel.sh
+++ b/scripts/run-unit-parallel.sh
@@ -201,6 +201,15 @@ fi
rm -f "$LOG_DIR"/shard-*.log "$LOG_DIR"/shard-*.exit "$LOG_DIR"/shard-*.wedged "$LOG_DIR"/shard-*.lastkb "$LOG_DIR"/shard-*.lastprogress "$LOG_DIR"/shard-*.start "$LOG_DIR"/shard-*.end "$LOG_DIR"/shard-*.watchdog "$LOG_DIR"/shard-*.assigned "$LOG_DIR"/shard-*.hbsum 2>/dev/null
: > "$FAILURES_LOG"
: > "$SUMMARY_FILE"
+# Executed-test receipts (X2): on by default for this loop, under
+# .context/test-receipts (cleared per run) unless GBRAIN_TEST_RECEIPT_DIR names
+# another directory. `bun scripts/ci-executed-counts.ts --head-dir <dir>`
+# reads them; the shard and serial runners each write their own.
+if [ "$DRY_RUN" = "0" ] && [ -z "${GBRAIN_TEST_RECEIPT_DIR:-}" ] && [ "$LOG_DIR" = ".context/test-shards" ]; then
+ rm -rf .context/test-receipts
+ GBRAIN_TEST_RECEIPT_DIR=.context/test-receipts
+fi
+receipts_init unit || exit 2
# ──────────────────────────────────────────────────────────────────────────
# Resolve `timeout` command. macOS without coreutils has neither; we degrade
@@ -294,12 +303,12 @@ for i in $(seq 1 "$N"); do
date +%s > "$LOG_DIR/shard-$i.start"
if [ -n "$TIMEOUT_BIN" ]; then
"$TIMEOUT_BIN" --signal=TERM --kill-after="${SHARD_KILL_AFTER}s" "${SHARD_TIMEOUT}s" \
- env SHARD="$i/$N" \
+ env SHARD="$i/$N" GBRAIN_TEST_RECEIPT_DIR="$TEST_RECEIPT_DIR" \
bash scripts/run-unit-shard.sh --max-concurrency="$INTRA_CONC" \
> "$SHARD_LOG" 2>&1
rc=$?
else
- env SHARD="$i/$N" \
+ env SHARD="$i/$N" GBRAIN_TEST_RECEIPT_DIR="$TEST_RECEIPT_DIR" \
bash scripts/run-unit-shard.sh --max-concurrency="$INTRA_CONC" \
> "$SHARD_LOG" 2>&1 &
pid=$!
@@ -820,7 +829,7 @@ SERIAL_FILES_COUNT=0
SERIAL_FILES_COUNT=$(find test -name '*.serial.test.ts' -not -path 'test/e2e/*' 2>/dev/null | wc -l | tr -d ' ')
if [ "$SERIAL_FILES_COUNT" -gt 0 ]; then
echo "════════════ serial pass ($SERIAL_FILES_COUNT files) ════════════"
- bash scripts/run-serial-tests.sh > "$LOG_DIR/serial.log" 2>&1
+ GBRAIN_TEST_RECEIPT_DIR="$TEST_RECEIPT_DIR" bash scripts/run-serial-tests.sh > "$LOG_DIR/serial.log" 2>&1
SERIAL_RC=$?
cat "$LOG_DIR/serial.log"
if [ "$SERIAL_RC" != "0" ]; then
@@ -895,23 +904,33 @@ if [ "$TOTAL_RC" != "0" ] && [ "${RESCUE_COUNT:-0}" -gt 0 ]; then
grep '\.serial\.test\.ts$' "$OOM_RESCUE_LIST" > "$LOG_DIR/oom-rescue-serial.txt" || true
RESCUE_RC=0
: > "$RESCUE_LOG"
- run_rescue() { # $1 = per-invocation timeout seconds; rest = test-file args
- local t="$1"; shift
+ # Each rescue invocation writes its own receipt (kind=rescue), which
+ # supersedes the killed or failed attempt for the files it re-ran.
+ run_rescue() { # $1 = per-invocation timeout seconds; $2 = receipt lane; $3 = receipt tag; rest = test-file args
+ local t="$1" lane="$2" tag="$3" rc=0 primary_lane="$TEST_RECEIPT_LANE"
+ shift 3
+ TEST_RECEIPT_LANE="$lane"
+ receipt_begin rescue "$tag" "" "" "" "$@"
+ TEST_RECEIPT_LANE="$primary_lane"
if [ -n "$TIMEOUT_BIN" ]; then
"$TIMEOUT_BIN" --signal=TERM --kill-after="${SHARD_KILL_AFTER}s" "${t}s" \
- bun test --max-concurrency 1 --timeout=60000 "$@" >> "$RESCUE_LOG" 2>&1
+ bun test --max-concurrency 1 --timeout=60000 ${RECEIPT_ARGS[@]+"${RECEIPT_ARGS[@]}"} "$@" >> "$RESCUE_LOG" 2>&1 || rc=$?
else
- bun test --max-concurrency 1 --timeout=60000 "$@" >> "$RESCUE_LOG" 2>&1
+ bun test --max-concurrency 1 --timeout=60000 ${RECEIPT_ARGS[@]+"${RECEIPT_ARGS[@]}"} "$@" >> "$RESCUE_LOG" 2>&1 || rc=$?
fi
+ receipt_end "$rc"
+ return "$rc"
}
if [ -s "$LOG_DIR/oom-rescue-batch.txt" ]; then
# shellcheck disable=SC2046
- run_rescue "$RESCUE_TIMEOUT" $(cat "$LOG_DIR/oom-rescue-batch.txt") || RESCUE_RC=1
+ run_rescue "$RESCUE_TIMEOUT" unit batch $(cat "$LOG_DIR/oom-rescue-batch.txt") || RESCUE_RC=1
fi
if [ -s "$LOG_DIR/oom-rescue-serial.txt" ]; then
+ rescue_idx=0
while IFS= read -r serial_file; do
[ -n "$serial_file" ] || continue
- run_rescue 300 "$serial_file" || RESCUE_RC=1
+ rescue_idx=$((rescue_idx + 1))
+ run_rescue 300 serial "file$rescue_idx" "$serial_file" || RESCUE_RC=1
done < "$LOG_DIR/oom-rescue-serial.txt"
fi
cat "$RESCUE_LOG"
diff --git a/scripts/run-unit-shard.sh b/scripts/run-unit-shard.sh
index 33054ec5d2..f1f9f5fa41 100755
--- a/scripts/run-unit-shard.sh
+++ b/scripts/run-unit-shard.sh
@@ -28,6 +28,8 @@ unset DATABASE_URL GBRAIN_DATABASE_URL
unset GBRAIN_HOME
cd "$(dirname "$0")/.."
+. scripts/lib/test-env.sh
+receipts_init unit
# --max-concurrency=N is forwarded to `bun test`. v0.26.4: invoked by
# run-unit-parallel.sh; safe to call without (defaults to bun's default cap).
@@ -79,13 +81,23 @@ else
files=("${all_files[@]}")
fi
-if [ "${#files[@]}" -eq 0 ]; then
- echo "[unit-shard ${RUNNER_SHARD:-(unsharded)}] no files; exiting clean."
+if [ "$DRY_RUN" = "1" ]; then
+ [ "${#files[@]}" -eq 0 ] || printf '%s\n' "${files[@]}"
exit 0
fi
-if [ "$DRY_RUN" = "1" ]; then
- printf '%s\n' "${files[@]}"
+RECEIPT_SHARD=""
+RECEIPT_OF=""
+RECEIPT_TAG="all"
+if [ -n "$RUNNER_SHARD" ]; then
+ RECEIPT_SHARD="$shard_n"
+ RECEIPT_OF="$shard_m"
+ RECEIPT_TAG="s${shard_n}of${shard_m}"
+fi
+
+if [ "${#files[@]}" -eq 0 ]; then
+ echo "[unit-shard ${RUNNER_SHARD:-(unsharded)}] no files; exiting clean."
+ receipt_empty "$RECEIPT_TAG" "$RECEIPT_SHARD" "$RECEIPT_OF"
exit 0
fi
@@ -121,12 +133,14 @@ for ((offset=0, group=1; offset<${#files[@]}; offset+=GROUP_SIZE, group++)); do
log="$GROUP_LOG_DIR/$group.log"
printf '%s\n' "${group_files[@]}" > "$GROUP_LOG_DIR/$group.assigned"
echo "__gbrain_unit_group_start__ group=$group/$GROUPS_TOTAL files=${#group_files[@]}"
+ receipt_begin primary "$RECEIPT_TAG-g$group" "$RECEIPT_SHARD" "$RECEIPT_OF" "" "${group_files[@]}"
set +e
- bun "${TEST_ARGS[@]}" "${group_files[@]}" 2>&1 | tee "$log"
+ bun "${TEST_ARGS[@]}" ${RECEIPT_ARGS[@]+"${RECEIPT_ARGS[@]}"} "${group_files[@]}" 2>&1 | tee "$log"
statuses=("${PIPESTATUS[@]}")
set -e
bun_rc=${statuses[0]}
tee_rc=${statuses[1]}
+ receipt_end "$bun_rc"
sed "s/${ESC}\\[[0-9;]*[a-zA-Z]//g" "$log" > "$GROUP_LOG_DIR/$group.clean"
# Child tests can print their own Bun summaries. Use the final block, require
# its exact selected-file count, and independently check every file header.
diff --git a/scripts/run-verify-parallel.sh b/scripts/run-verify-parallel.sh
index ef451d1f6d..23cfd042a2 100755
--- a/scripts/run-verify-parallel.sh
+++ b/scripts/run-verify-parallel.sh
@@ -16,7 +16,16 @@
#
# Env overrides:
# GBRAIN_VERIFY_TIMEOUT per-check wallclock cap, seconds (default 120)
-# GBRAIN_VERIFY_LOG_DIR where to write per-check logs (default tempdir)
+# GBRAIN_VERIFY_LOG_DIR where to write per-check logs (default tempdir,
+# removed on success and kept on failure)
+# GBRAIN_TEST_RECEIPT_DIR also write the verify receipt (X2): one JUnit
+# testcase per check with its real outcome
+#
+# Outcomes: every check is recorded as pass, fail, timeout or skip in
+# <log dir>/outcomes.tsv and in the receipt. A check that exits 0 without
+# checking anything (its subject is absent) must print a line starting with
+# `GBRAIN_CHECK_SKIPPED: <reason>`; the recorder reads that marker, so a
+# self-skip is never counted as a pass.
#
# Exit codes:
# 0 all checks passed
@@ -30,6 +39,7 @@ cd "$(dirname "$0")/.."
# detect_cpus + ensure_pglite_snapshot (the PGLite-booting eval checks use
# the snapshot fast-path when the shape matches).
. scripts/lib/test-env.sh
+receipts_init verify || exit 2
# ──────────────────────────────────────────────────────────────────────────
# Checks to run. Each entry is a bun-script name (the `package.json`
@@ -188,7 +198,8 @@ if [ -n "${GBRAIN_VERIFY_LOG_DIR:-}" ]; then
mkdir -p "$LOG_DIR" || { echo "ERROR: cannot create $LOG_DIR" >&2; exit 2; }
else
LOG_DIR="$(mktemp -d /tmp/gbrain-verify-XXXXXX)"
- trap 'rm -rf "$LOG_DIR"' EXIT
+ KEEP_LOGS=0
+ trap '[ "$KEEP_LOGS" = "1" ] || rm -rf "$LOG_DIR"' EXIT
fi
# Resolve `timeout` for per-check wallclock cap. macOS doesn't ship one;
@@ -279,8 +290,14 @@ ELAPSED=$((END_TS - START_TS))
# ──────────────────────────────────────────────────────────────────────────
PASS=0
FAIL=0
+SKIP=0
FAIL_NAMES=()
+SKIP_REPORT=""
FAIL_REPORT=""
+OUTCOMES="$LOG_DIR/outcomes.tsv"
+printf 'check\toutcome\trc\tdetail\n' > "$OUTCOMES"
+xml_escape() { sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g' -e 's/"/\&quot;/g'; }
+JUNIT_CASES=""
for i in "${!CHECKS[@]}"; do
c="${CHECKS[$i]}"
@@ -290,10 +307,26 @@ for i in "${!CHECKS[@]}"; do
rc=1
[ -f "$EXIT_FILE" ] && rc=$(cat "$EXIT_FILE" 2>/dev/null || echo 1)
+ skip_reason=""
+ if [ "$rc" = "0" ] && [ -f "$LOG_FILE" ]; then
+ skip_reason=$(sed -n 's/^GBRAIN_CHECK_SKIPPED:[[:space:]]*//p' "$LOG_FILE" | head -1 | tr '\t' ' ')
+ [ -n "$skip_reason" ] || ! grep -q '^GBRAIN_CHECK_SKIPPED:' "$LOG_FILE" || skip_reason="(no reason given)"
+ fi
- if [ "$rc" = "0" ]; then
+ if [ "$rc" = "0" ] && [ -n "$skip_reason" ]; then
+ SKIP=$((SKIP + 1))
+ SKIP_REPORT+=" $c: $skip_reason"$'\n'
+ printf '%s\tskip\t0\t%s\n' "$c" "$skip_reason" >> "$OUTCOMES"
+ JUNIT_CASES+=" <testcase name=\"$c\" classname=\"verify\" file=\"verify\"><skipped message=\"$(printf '%s' "$skip_reason" | xml_escape)\" /></testcase>"$'\n'
+ elif [ "$rc" = "0" ]; then
PASS=$((PASS + 1))
+ printf '%s\tpass\t0\t\n' "$c" >> "$OUTCOMES"
+ JUNIT_CASES+=" <testcase name=\"$c\" classname=\"verify\" file=\"verify\" />"$'\n'
else
+ outcome=fail
+ [ "$rc" = "124" ] && outcome=timeout
+ printf '%s\t%s\t%s\t%s\n' "$c" "$outcome" "$rc" "$LOG_FILE" >> "$OUTCOMES"
+ JUNIT_CASES+=" <testcase name=\"$c\" classname=\"verify\" file=\"verify\"><failure message=\"$outcome rc=$rc\" /></testcase>"$'\n'
FAIL=$((FAIL + 1))
FAIL_NAMES+=("$c")
if [ "$rc" = "124" ]; then
@@ -308,7 +341,28 @@ for i in "${!CHECKS[@]}"; do
fi
done
+if [ -n "$SKIP_REPORT" ]; then
+ {
+ echo "[verify-parallel] $SKIP check(s) self-skipped (recorded as skip, not pass):"
+ printf '%s' "$SKIP_REPORT"
+ } >&2
+fi
+
+receipt_begin primary all "" "" "" verify
+if [ -n "$RECEIPT_ID" ]; then
+ {
+ echo '<?xml version="1.0" encoding="UTF-8"?>'
+ echo "<testsuites name=\"verify\" tests=\"${#CHECKS[@]}\" failures=\"$FAIL\" skipped=\"$SKIP\">"
+ echo " <testsuite name=\"verify\" file=\"verify\" tests=\"${#CHECKS[@]}\" failures=\"$FAIL\" skipped=\"$SKIP\">"
+ printf '%s' "$JUNIT_CASES"
+ echo " </testsuite>"
+ echo "</testsuites>"
+ } > "$TEST_RECEIPT_DIR/$RECEIPT_ID.junit.xml"
+ receipt_end "$([ "$FAIL" -eq 0 ] && echo 0 || echo 1)"
+fi
+
if [ "$FAIL" -gt 0 ]; then
+ KEEP_LOGS=1
{
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
@@ -317,10 +371,11 @@ if [ "$FAIL" -gt 0 ]; then
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
printf '%s' "$FAIL_REPORT"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
- echo "[verify-parallel] elapsed=${ELAPSED}s | pass=$PASS fail=$FAIL"
+ echo "[verify-parallel] elapsed=${ELAPSED}s | pass=$PASS fail=$FAIL skip=$SKIP"
+ echo "[verify-parallel] per-check logs kept in $LOG_DIR (outcomes.tsv lists every check)"
} >&2
exit 1
fi
-echo "[verify-parallel] elapsed=${ELAPSED}s | pass=$PASS fail=0 | all checks green" >&2
+echo "[verify-parallel] elapsed=${ELAPSED}s | pass=$PASS fail=0 skip=$SKIP | all checks green" >&2
exit 0
diff --git a/scripts/run-with-receipt.sh b/scripts/run-with-receipt.sh
new file mode 100755
index 0000000000..075e42548e
--- /dev/null
+++ b/scripts/run-with-receipt.sh
@@ -0,0 +1,55 @@
+#!/usr/bin/env bash
+# scripts/run-with-receipt.sh — run one named `bun test` invocation and record
+# its executed-test receipt (X2) when GBRAIN_TEST_RECEIPT_DIR is set.
+#
+# CI jobs that call `bun test` directly (the slow lanes, Tier 1, Tier 2, the
+# JSONB parity guard) go through this wrapper so every bun invocation leaves a
+# receipt like the runner scripts do. Receipt format and consumers:
+# scripts/lib/test-env.sh (receipts_init) and scripts/ci-executed-counts.ts.
+#
+# Usage:
+# bash scripts/run-with-receipt.sh <lane> <tag> -- bun test --timeout=N [args] <files...>
+#
+# <lane> names the identity lane (unit, slow, tier1, ...); <tag> must be unique
+# per invocation inside that lane. Test files are the *.test.ts arguments.
+# Without GBRAIN_TEST_RECEIPT_DIR the command runs unchanged. Exit code: the
+# command's.
+
+set -euo pipefail
+
+if [ "$#" -lt 5 ] || [ "$3" != "--" ] || [ "$4" != "bun" ] || [ "$5" != "test" ]; then
+ echo "usage: bash scripts/run-with-receipt.sh <lane> <tag> -- bun test --timeout=N [args] <files...>" >&2
+ exit 2
+fi
+lane="$1"
+tag="$2"
+shift 4
+
+cd "$(dirname "$0")/.."
+GBRAIN_TEST_RECEIPT_LANE="$lane"
+. scripts/lib/test-env.sh
+receipts_init "$lane" || exit 2
+
+shift
+files=()
+has_timeout=0
+for arg in "$@"; do
+ case "$arg" in
+ *.test.ts) files+=("${arg#./}") ;;
+ --timeout|--timeout=*) has_timeout=1 ;;
+ esac
+done
+if [ "$has_timeout" = "0" ]; then
+ echo "run-with-receipt: pass an explicit --timeout (scripts/check-bun-test-timeout.sh explains why)" >&2
+ exit 2
+fi
+if [ "${#files[@]}" -eq 0 ]; then
+ echo "run-with-receipt: no *.test.ts file arguments; a receipt needs the files the invocation runs" >&2
+ exit 2
+fi
+
+receipt_begin primary "$tag" "" "" "" "${files[@]}"
+rc=0
+bun test ${RECEIPT_ARGS[@]+"${RECEIPT_ARGS[@]}"} "$@" || rc=$? # "$@" carries --timeout (refused above otherwise)
+receipt_end "$rc"
+exit "$rc"
diff --git a/scripts/test-shard.sh b/scripts/test-shard.sh
index 21d29dbb94..10d21c7c04 100755
--- a/scripts/test-shard.sh
+++ b/scripts/test-shard.sh
@@ -58,6 +58,7 @@ fi
cd "$(dirname "$0")/.."
. scripts/lib/test-env.sh
+receipts_init unit
# Collect non-E2E, non-serial unit test files. Slow files INCLUDED — see
# header comment. Local run-unit-shard.sh excludes slow files (different
@@ -130,6 +131,7 @@ echo "shard $SHARD_INDEX/$TOTAL_SHARDS: ${SHARD_COUNT}/${ALL_COUNT} files (LPT-b
if [ "$SHARD_COUNT" -eq 0 ]; then
echo "warning: shard $SHARD_INDEX has no files (total shards may exceed file count)" >&2
+ receipt_empty "s${SHARD_INDEX}of${TOTAL_SHARDS}" "$SHARD_INDEX" "$TOTAL_SHARDS"
exit 0
fi
@@ -153,11 +155,19 @@ if [ -n "${COVERAGE_DIR:-}" ]; then
COVERAGE_ARGS=(--coverage --coverage-reporter=lcov --coverage-dir="$COVERAGE_DIR/shard")
XARGS_FLAGS=(-n 100000 -x)
fi
+# Receipts (X2): one JUnit report per bun process. A second xargs batch would
+# overwrite it the same way it overwrites lcov.info, so receipts also force
+# the single-invocation -x tripwire.
+shard_file_args=()
+while IFS= read -r f; do [ -n "$f" ] && shard_file_args+=("$f"); done <<< "$SHARD_FILES"
+receipt_begin primary "s${SHARD_INDEX}of${TOTAL_SHARDS}" "$SHARD_INDEX" "$TOTAL_SHARDS" "" "${shard_file_args[@]}"
+[ "${#RECEIPT_ARGS[@]}" -eq 0 ] || XARGS_FLAGS=(-n 100000 -x)
# --max-concurrency mirrors the local runner: unbounded intra-process
# concurrency under parallel PGLite boots produced real shard deaths (the
# 22-minute matrix timeout in test.yml records 13 of them).
rc=0
-printf '%s\n' "$SHARD_FILES" | xargs ${XARGS_FLAGS[@]+"${XARGS_FLAGS[@]}"} bun test --timeout=60000 --max-concurrency="${GBRAIN_TEST_MAX_CONCURRENCY:-4}" ${COVERAGE_ARGS[@]+"${COVERAGE_ARGS[@]}"} || rc=$?
+printf '%s\n' "$SHARD_FILES" | xargs ${XARGS_FLAGS[@]+"${XARGS_FLAGS[@]}"} bun test --timeout=60000 --max-concurrency="${GBRAIN_TEST_MAX_CONCURRENCY:-4}" ${COVERAGE_ARGS[@]+"${COVERAGE_ARGS[@]}"} ${RECEIPT_ARGS[@]+"${RECEIPT_ARGS[@]}"} || rc=$?
+receipt_end "$rc"
# Lane manifest: written ONLY on a fully green run (complete:true means the
# lcov data represents the whole shard). The real exit code is preserved
diff --git a/test/scripts/e2e-runner.test.ts b/test/scripts/e2e-runner.test.ts
index 8a99a456e4..d1815bda6e 100644
--- a/test/scripts/e2e-runner.test.ts
+++ b/test/scripts/e2e-runner.test.ts
@@ -1,5 +1,5 @@
import { describe, test, expect } from 'bun:test';
-import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, copyFileSync, chmodSync, existsSync } from 'node:fs';
+import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, readdirSync, rmSync, copyFileSync, chmodSync, existsSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { spawnSync } from 'node:child_process';
@@ -87,8 +87,10 @@ test('fresh process',()=>{
const failedCoverage = join(root, 'failed-coverage');
const bad = spawnSync('bash', ['scripts/run-e2e.sh', ...files], { cwd: root, env: { ...coverageEnv, COVERAGE_DIR: failedCoverage }, encoding: 'utf8' });
expect(bad.status).toBe(1);
+ // B9: a red lane still records which files it ran; only the
+ // complete:true manifest stays green-only.
expect(existsSync(join(failedCoverage, 'lane-manifest.json'))).toBe(false);
- expect(existsSync(join(failedCoverage, 'executed-files.txt'))).toBe(false);
+ expect(readFileSync(join(failedCoverage, 'executed-files.txt'), 'utf8').trim().split('\n').sort()).toEqual(files);
} finally { rmSync(root, { recursive: true, force: true }); }
});
test.each(['empty', 'populated'])('refuses an existing %s coverage destination without changing its files', kind => {
@@ -167,7 +169,7 @@ test('parent',()=>{
const complete = kind === 'nested summary with parent';
expect(result.status, result.stdout + result.stderr).toBe(complete ? 0 : 1);
expect(existsSync(join(root, 'coverage/lane-manifest.json'))).toBe(complete);
- expect(existsSync(join(root, 'coverage/executed-files.txt'))).toBe(complete);
+ expect(readFileSync(join(root, 'coverage/executed-files.txt'), 'utf8')).toBe('test/e2e/a.test.ts\n');
if (!complete) expect(result.stdout).toContain('did not produce a complete native Bun report');
} finally { rmSync(root, { recursive: true, force: true }); }
});
@@ -195,7 +197,7 @@ printf '%s' '${output}'
expect(result.status, result.stdout + result.stderr).toBe(1);
expect(result.stdout).toContain('did not produce a complete native Bun report');
expect(existsSync(join(root, 'coverage/lane-manifest.json'))).toBe(false);
- expect(existsSync(join(root, 'coverage/executed-files.txt'))).toBe(false);
+ expect(readFileSync(join(root, 'coverage/executed-files.txt'), 'utf8')).toBe(`${selected}\n`);
} finally { rmSync(root, { recursive: true, force: true }); }
});
for (const firstFails of [false, true]) test(`each file has a fresh home after a ${firstFails ? 'failing' : 'passing'} config writer`, () => {
@@ -276,3 +278,72 @@ printf '%s' '${output}'
}
}, 10000);
});
+
+describe('per-file HOME cleanup and receipts', () => {
+ const env = { ...process.env, GBRAIN_NO_SNAPSHOT: '1', DATABASE_URL: '', GBRAIN_DATABASE_URL: '', SHARD: '', COVERAGE_DIR: '' };
+ const files = ['test/e2e/a.test.ts', 'test/e2e/b.test.ts'];
+
+ test('a HOME that cannot be removed fails that file by name and the partition continues (B2)', () => {
+ const root = setup();
+ const tmp = join(root, 'tmp');
+ mkdirSync(tmp);
+ try {
+ writeFileSync(join(root, files[0]), `import {test} from 'bun:test';
+import {mkdirSync,writeFileSync,chmodSync} from 'node:fs';
+test('leaves an unremovable HOME entry',()=>{
+ const dir = process.env.HOME + '/locked';
+ mkdirSync(dir + '/inner', { recursive: true });
+ writeFileSync(dir + '/inner/x', 'x');
+ chmodSync(dir, 0o500);
+});`);
+ const r = spawnSync('bash', ['scripts/run-e2e.sh', ...files], { cwd: root, encoding: 'utf8', env: { ...env, TMPDIR: tmp } });
+ expect(r.status, r.stdout + r.stderr).toBe(1);
+ expect(r.stdout).toMatch(/FAILED: a\.test\.ts left a process writing to its HOME; cleanup could not remove \S+file-1-direct/);
+ expect(r.stdout).toContain('Fix: make the test wait for or stop its children; reproduce with: bash scripts/run-e2e.sh test/e2e/a.test.ts');
+ expect(r.stdout).toContain('=== b.test.ts ===');
+ expect(r.stdout).toContain('Files: 2 total, 1 passed, 1 failed');
+ } finally {
+ spawnSync('chmod', ['-R', 'u+rwx', tmp]);
+ rmSync(root, { recursive: true, force: true });
+ }
+ });
+
+ test.skipIf(process.platform !== 'linux')('a child left running with the file HOME is killed before cleanup and named', () => {
+ const root = setup();
+ try {
+ writeFileSync(join(root, files[0]), `import {test} from 'bun:test';
+import {spawn} from 'node:child_process';
+import {writeFileSync} from 'node:fs';
+test('leaks a detached child',()=>{
+ const child = spawn('sleep', ['60'], { detached: true, stdio: 'ignore', env: process.env });
+ child.unref();
+ writeFileSync(${JSON.stringify(join(root, 'leak.pid'))}, String(child.pid));
+});`);
+ const r = spawnSync('bash', ['scripts/run-e2e.sh', files[0]], { cwd: root, encoding: 'utf8', env });
+ expect(r.status, r.stdout + r.stderr).toBe(0);
+ expect(r.stdout).toContain('WARN: a.test.ts left processes running with HOME=');
+ const pid = Number(readFileSync(join(root, 'leak.pid'), 'utf8'));
+ let alive = true;
+ for (let i = 0; i < 50 && alive; i++) {
+ try { process.kill(pid, 0); alive = !/\) Z /.test(readFileSync(`/proc/${pid}/stat`, 'utf8')); } catch { alive = false; }
+ if (alive) Bun.sleepSync(20);
+ }
+ expect(alive).toBe(false);
+ } finally { rmSync(root, { recursive: true, force: true }); }
+ });
+
+ test('each file pass leaves a receipt with its native JUnit report, failures included', () => {
+ const root = setup();
+ try {
+ writeFileSync(join(root, files[1]), "import {test,expect} from 'bun:test';test('breaks',()=>expect(1).toBe(2));");
+ const receipts = join(root, 'receipts');
+ const r = spawnSync('bash', ['scripts/run-e2e.sh', ...files], { cwd: root, encoding: 'utf8', env: { ...env, GBRAIN_TEST_RECEIPT_DIR: receipts, GBRAIN_TEST_RECEIPT_LANE: 'tier9' } });
+ expect(r.status).toBe(1);
+ const ids = readdirSync(receipts).filter(n => n.endsWith('.receipt')).sort();
+ expect(ids).toEqual(['tier9--run-f1-direct--primary.receipt', 'tier9--run-f2-direct--primary.receipt']);
+ expect(readFileSync(join(receipts, ids[1]), 'utf8')).toContain('exit=1');
+ expect(readFileSync(join(receipts, 'tier9--run-f2-direct--primary.junit.xml'), 'utf8')).toContain('<failure');
+ expect(readFileSync(join(receipts, 'tier9--run-f2-direct--primary.files'), 'utf8')).toBe('test/e2e/b.test.ts\n');
+ } finally { rmSync(root, { recursive: true, force: true }); }
+ });
+});
diff --git a/test/scripts/run-unit-shard.test.ts b/test/scripts/run-unit-shard.test.ts
index 7e3c014f52..69e4440184 100644
--- a/test/scripts/run-unit-shard.test.ts
+++ b/test/scripts/run-unit-shard.test.ts
@@ -17,7 +17,7 @@ import { describe, it, expect } from 'bun:test';
import { execFileSync, spawnSync } from 'child_process';
import { chmodSync, copyFileSync, mkdtempSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'fs';
import { tmpdir } from 'os';
-import { join, resolve } from 'path';
+import { dirname, join, resolve } from 'path';
const REPO_ROOT = resolve(import.meta.dir, '..', '..');
const SHARD_SH = resolve(REPO_ROOT, 'scripts/run-unit-shard.sh');
@@ -87,8 +87,10 @@ describe('run-unit-shard.sh timeout multiplier reach', () => {
function runGroupedFixture(count: number, mode = 'pass', shard = '') {
const root = mkdtempSync(join(tmpdir(), 'gbrain-unit-groups-test-'));
try {
- for (const dir of ['scripts', 'test', 'bin', 'calls']) mkdirSync(join(root, dir));
+ for (const dir of ['scripts', 'scripts/lib', 'test', 'bin', 'calls']) mkdirSync(join(root, dir));
copyFileSync(SHARD_SH, join(root, 'scripts/run-unit-shard.sh'));
+ // The runner sources the shared lib (receipt helpers) — stage it too.
+ copyFileSync(join(dirname(SHARD_SH), 'lib/test-env.sh'), join(root, 'scripts/lib/test-env.sh'));
const files = Array.from({ length: count }, (_, i) => `test/case-${String(i).padStart(4, '0')}.test.ts`);
for (const file of files) writeFileSync(join(root, file), '');
for (const file of ['ignored.slow.test.ts', 'ignored.serial.test.ts']) writeFileSync(join(root, 'test', file), '');
diff --git a/test/scripts/run-verify-parallel.test.ts b/test/scripts/run-verify-parallel.test.ts
index e5a445e49b..def298307b 100644
--- a/test/scripts/run-verify-parallel.test.ts
+++ b/test/scripts/run-verify-parallel.test.ts
@@ -272,6 +272,9 @@ describe("run-verify-parallel.sh — no-timeout-binary fallback rc capture (regr
`#!/usr/bin/env bash
name="\${2:-}"
echo "stub check OK: $name"
+if [ -n "\${STUB_SKIP_CHECK:-}" ] && [ "$name" = "\${STUB_SKIP_CHECK}" ]; then
+ echo "GBRAIN_CHECK_SKIPPED: subject absent in this checkout"
+fi
if [ -n "\${STUB_FAIL_CHECK:-}" ] && [ "$name" = "\${STUB_FAIL_CHECK}" ]; then
echo "stub check failing: $name" >&2
exit 7
@@ -309,6 +312,48 @@ exit 0
}
});
+ it("records every check's real outcome: a self-skip is a skip (not a pass) in outcomes.tsv and the receipt", () => {
+ const { root, env } = makeFallbackHarness();
+ try {
+ const receipts = join(root, "receipts");
+ const r = spawnSync("bash", [join(root, "scripts", "run-verify-parallel.sh")], {
+ encoding: "utf8",
+ env: { ...env, STUB_SKIP_CHECK: "check:grok-pin", STUB_FAIL_CHECK: "check:jsonb", GBRAIN_TEST_RECEIPT_DIR: receipts },
+ });
+ expect(r.status).toBe(1);
+ expect(r.stderr).toMatch(/fail=1 skip=1\b/);
+ expect(r.stderr).toContain("check:grok-pin: subject absent in this checkout");
+ const outcomes = readFileSync(join(root, "logs", "outcomes.tsv"), "utf8");
+ expect(outcomes).toContain("check:grok-pin\tskip\t0\tsubject absent in this checkout");
+ expect(outcomes).toContain("check:jsonb\tfail\t7\t");
+ expect(outcomes).toContain("check:privacy\tpass\t0\t");
+ const junit = readFileSync(join(receipts, "verify--all--primary.junit.xml"), "utf8");
+ expect(junit).toContain('<testcase name="check:grok-pin" classname="verify" file="verify"><skipped message="subject absent in this checkout" /></testcase>');
+ expect(junit).toContain('<testcase name="check:jsonb" classname="verify" file="verify"><failure message="fail rc=7" /></testcase>');
+ expect(readFileSync(join(receipts, "verify--all--primary.receipt"), "utf8")).toContain("exit=1");
+ } finally {
+ rmSync(root, { recursive: true, force: true });
+ }
+ });
+
+ it("keeps its default temp log directory when a check fails and names it", () => {
+ const { root, env } = makeFallbackHarness();
+ const { GBRAIN_VERIFY_LOG_DIR: _unused, ...defaults } = env;
+ try {
+ const r = spawnSync("bash", [join(root, "scripts", "run-verify-parallel.sh")], {
+ encoding: "utf8",
+ env: { ...defaults, STUB_FAIL_CHECK: "check:jsonb" },
+ });
+ expect(r.status).toBe(1);
+ const kept = /per-check logs kept in (\S+)/.exec(r.stderr)?.[1];
+ expect(kept).toBeDefined();
+ expect(readFileSync(join(kept!, "check_jsonb.log"), "utf8")).toContain("stub check failing: check:jsonb");
+ rmSync(kept!, { recursive: true, force: true });
+ } finally {
+ rmSync(root, { recursive: true, force: true });
+ }
+ });
+
it("one check failing → exit 1, sentinel records the check's own rc (7), not 143", () => {
const { root, env } = makeFallbackHarness();
try {
diff --git a/test/scripts/run-with-receipt.test.ts b/test/scripts/run-with-receipt.test.ts
new file mode 100644
index 0000000000..2724c68d62
--- /dev/null
+++ b/test/scripts/run-with-receipt.test.ts
@@ -0,0 +1,59 @@
+import { describe, test, expect } from 'bun:test';
+import { copyFileSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { spawnSync } from 'node:child_process';
+import { buildSide, loadReceiptDir } from '../../scripts/ci-executed-counts.ts';
+
+const REPO = join(import.meta.dir, '../..');
+
+function sandbox() {
+ const root = mkdtempSync(join(tmpdir(), 'gbrain-with-receipt-'));
+ mkdirSync(join(root, 'scripts/lib'), { recursive: true });
+ mkdirSync(join(root, 'test'));
+ copyFileSync(join(REPO, 'scripts/run-with-receipt.sh'), join(root, 'scripts/run-with-receipt.sh'));
+ copyFileSync(join(REPO, 'scripts/lib/test-env.sh'), join(root, 'scripts/lib/test-env.sh'));
+ // Receipt variables are consumed by the wrapper; the test process must never see them.
+ writeFileSync(join(root, 'test/a.test.ts'), `import { describe, test, expect } from 'bun:test';
+describe('wrapped', () => {
+ test('hides receipt routing', () => {
+ expect(process.env.GBRAIN_TEST_RECEIPT_DIR).toBeUndefined();
+ expect(process.env.GBRAIN_TEST_RECEIPT_LANE).toBeUndefined();
+ });
+ test.skip('optional', () => {});
+});`);
+ return root;
+}
+const run = (root: string, args: string[], env: Record<string, string> = {}) =>
+ spawnSync('bash', ['scripts/run-with-receipt.sh', ...args], { cwd: root, encoding: 'utf8', env: { ...process.env, GBRAIN_NO_SNAPSHOT: '1', ...env } });
+
+describe('run-with-receipt.sh', () => {
+ test('records lane, files, exit and the native JUnit report for one bun invocation', () => {
+ const root = sandbox();
+ try {
+ const receipts = join(root, 'receipts');
+ const r = run(root, ['slow', 'perf-a', '--', 'bun', 'test', 'test/a.test.ts', '--timeout=60000'], { GBRAIN_TEST_RECEIPT_DIR: receipts });
+ expect(r.status, r.stdout + r.stderr).toBe(0);
+ expect(readdirSync(receipts).sort()).toEqual(['slow--perf-a--primary.files', 'slow--perf-a--primary.junit.xml', 'slow--perf-a--primary.receipt']);
+ const meta = readFileSync(join(receipts, 'slow--perf-a--primary.receipt'), 'utf8');
+ expect(meta).toContain('lane=slow\n');
+ expect(meta).toContain('exit=0\n');
+ const side = buildSide('local', loadReceiptDir(receipts));
+ expect(side.issues).toEqual([]);
+ expect([...side.identities.values()].map(i => [i.test, i.status])).toEqual([['wrapped > hides receipt routing', 'pass'], ['wrapped > optional', 'skip']]);
+ } finally { rmSync(root, { recursive: true, force: true }); }
+ });
+
+ test('runs the command unchanged without a receipt directory and refuses a missing --timeout', () => {
+ const root = sandbox();
+ try {
+ const plain = run(root, ['slow', 'perf-a', '--', 'bun', 'test', '--timeout=60000', 'test/a.test.ts']);
+ expect(plain.status, plain.stdout + plain.stderr).toBe(0);
+ expect(readdirSync(root).includes('receipts')).toBe(false);
+ const bare = run(root, ['slow', 'perf-a', '--', 'bun', 'test', 'test/a.test.ts']);
+ expect(bare.status).toBe(2);
+ expect(bare.stderr).toContain('pass an explicit --timeout');
+ expect(run(root, ['slow', '--', 'bun', 'test']).status).toBe(2);
+ } finally { rmSync(root, { recursive: true, force: true }); }
+ });
+});