diff --git a/seaweed-block/.github/scripts/ci-evidence.md b/seaweed-block/.github/scripts/ci-evidence.md index 36a1b0336b..ab9f09edd9 100644 --- a/seaweed-block/.github/scripts/ci-evidence.md +++ b/seaweed-block/.github/scripts/ci-evidence.md @@ -4,7 +4,9 @@ Both test suites keep one `ci---` artifact on failure for 14 days. `go-test.json` contains Go's timestamped events and per-test `Elapsed` values; process shards also keep their original JSON, logs and exit receipts. `go-test.stderr` keeps build/tool errors outside Go's JSON event stream. The -console still shows the original test output. Test arguments, scope, timeouts, +console still shows the original test output. Recording/rendering errors are +best effort: they report the missing evidence and keep draining Go, whose own +exit code alone decides the wrapper's result. Test arguments, scope, timeouts, exit-code handling and the required-tests gate are unchanged. `load.tsv` begins immediately after checkout and samples once per second until diff --git a/seaweed-block/.github/scripts/go-test-output.py b/seaweed-block/.github/scripts/go-test-output.py index 888af12ab0..264e316b14 100644 --- a/seaweed-block/.github/scripts/go-test-output.py +++ b/seaweed-block/.github/scripts/go-test-output.py @@ -1,9 +1,58 @@ -"""Render go test -json Output events without changing the test verdict.""" +"""Drain a Go stream even when recording/rendering fails; never judge tests.""" import json +import os import sys +sys.stdin.reconfigure(encoding='utf-8', errors='replace') + + +def warn(error): + try: + print('test evidence unavailable: '+str(error), file=sys.stderr) + except OSError: + pass + + +archive = None +try: + archive = open(sys.argv[1], 'a', encoding='utf-8', buffering=1) +except OSError as error: + warn(error) +raw = len(sys.argv) > 2 and sys.argv[2] == '--raw' +console = True for line in sys.stdin: - event = json.loads(line) - if 'Output' in event: - sys.stdout.write(event['Output']) - sys.stdout.flush() + if archive is not None: + try: + archive.write(line) + except OSError as error: + warn(error) + try: + archive.close() + except OSError: + pass + archive = None + output = line + if not raw: + try: + output = json.loads(line).get('Output', '') + except (ValueError, AttributeError) as error: + # Keep and display unexpected text, but keep draining the producer. + warn(error) + if console: + try: + sys.stdout.write(output) + sys.stdout.flush() + except OSError: + console = False + # Avoid an interpreter-exit BrokenPipe flush; the stream still + # drains Go to EOF so a dead console cannot send SIGPIPE upstream. + try: + with open(os.devnull, 'w') as sink: + os.dup2(sink.fileno(), sys.stdout.fileno()) + except OSError: + pass +if archive is not None: + try: + archive.close() + except OSError as error: + warn(error) diff --git a/seaweed-block/.github/scripts/record-go-test-test.sh b/seaweed-block/.github/scripts/record-go-test-test.sh index 26d0955d27..43fd831f0e 100644 --- a/seaweed-block/.github/scripts/record-go-test-test.sh +++ b/seaweed-block/.github/scripts/record-go-test-test.sh @@ -6,10 +6,14 @@ trap 'rm -rf "$root"' EXIT mkdir -p "$root/bin" cat >"$root/bin/go" <<'EOF' #!/usr/bin/env bash +set -e test "$1" = test && test "$2" = -json || exit 99 printf '%s\n' '{"Time":"2026-12-02T00:00:01Z","Action":"run","Test":"TestX"}' printf '%s\n' '{"Time":"2026-12-02T00:00:02Z","Action":"output","Test":"TestX","Output":"fixture output\n"}' printf '%s\n' '{"Time":"2026-12-02T00:00:02Z","Action":"fail","Test":"TestX","Elapsed":1}' +if [ "${FAKE_GO_LARGE:-0}" = 1 ]; then + for ((i=0; i<10000; i++)); do printf '%s\n' '{"Action":"output","Output":"draining after recorder failure\n"}'; done +fi echo 'fixture stderr' >&2 exit "${FAKE_GO_EXIT:-0}" EOF @@ -23,4 +27,20 @@ grep -q 'fixture stderr' "$root/go-test.stderr" "${PYTHON:-python3}" -c 'import json,sys; events=[json.loads(s) for s in open(sys.argv[1])]; assert len(events)==3; assert events[-1]["Elapsed"]==1; assert events[-1]["Time"]=="2026-12-02T00:00:02Z"' "$root/go-test.json" FAKE_GO_EXIT=0 bash "$here/record-go-test.sh" "$root/go-test.json" -run TestX >"$root/console" 2>"$root/stderr" test "$(wc -l <"$root/go-test.json")" = 6 +# The evidence destination cannot be opened (a file where its parent belongs). +# The original Go success/failure must still be the command's answer. +echo occupied >"$root/not-a-directory" +code=0 +FAKE_GO_EXIT=0 bash "$here/record-go-test.sh" "$root/not-a-directory/go-test.json" >"$root/console" 2>"$root/stderr" || code=$? +test "$code" = 0 +grep -q 'fixture output' "$root/console" +code=0 +FAKE_GO_EXIT=7 bash "$here/record-go-test.sh" "$root/not-a-directory/go-test.json" >"$root/console" 2>"$root/stderr" || code=$? +test "$code" = 7 +if [ "$(uname -s)" = Linux ] && [ -c /dev/full ]; then + ln -s /dev/full "$root/full.json" + FAKE_GO_LARGE=1 FAKE_GO_EXIT=0 bash "$here/record-go-test.sh" "$root/full.json" >"$root/console" 2>"$root/stderr" + grep -q 'draining after recorder failure' "$root/console" + grep -q 'test evidence unavailable' "$root/stderr" +fi echo 'record-go-test: output, timestamp, elapsed, append and exit-status controls PASS' diff --git a/seaweed-block/.github/scripts/record-go-test.sh b/seaweed-block/.github/scripts/record-go-test.sh index f91c05b64c..caebc315d1 100644 --- a/seaweed-block/.github/scripts/record-go-test.sh +++ b/seaweed-block/.github/scripts/record-go-test.sh @@ -4,13 +4,17 @@ set -euo pipefail out=$1 shift -mkdir -p "$(dirname "$out")" -exec 3> >(tee -a "${out%.json}.stderr" >&2) +mkdir -p "$(dirname "$out")" || true +capture="$(dirname "$0")/go-test-output.py" +exec 3> >("${PYTHON:-python3}" -u "$capture" "${out%.json}.stderr" --raw >&2) stderr_pid=$! -status=0 +# Only Go judges the test. The readers keep draining after evidence IO errors, +# so a disk-full recorder cannot turn Go's PASS into a pipeline/SIGPIPE failure. +set +e go test -json "$@" 2>&3 | - tee -a "$out" | - "${PYTHON:-python3}" -u "$(dirname "$0")/go-test-output.py" || status=$? + "${PYTHON:-python3}" -u "$capture" "$out" +status=${PIPESTATUS[0]} +set -e exec 3>&- wait "$stderr_pid" || true exit "$status"