#!/usr/bin/env bash # Keep timestamped Go events, while preserving the existing human output and # nonzero pipeline status. One caller at a time appends to a job's event file. set -euo pipefail out=$1 shift mkdir -p "$(dirname "$out")" || true capture="$(dirname "$0")/go-test-output.py" # A recorder that dies (or cannot start) hands the rest of its stream to cat, # so Go never writes into a closed pipe. exec 3> >({ "${PYTHON:-python3}" -u "$capture" "${out%.json}.stderr" --raw || cat; } >&2) stderr_pid=$! # 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 | { "${PYTHON:-python3}" -u "$capture" "$out" || { echo "test evidence unavailable: the recorder exited" >&2; cat; }; } status=${PIPESTATUS[0]} set -e exec 3>&- wait "$stderr_pid" || true exit "$status"