Files
Pulse/scripts/tests/run.sh
pulse-triage[bot] 8f37d1f682 Retain active script-suite results when validation is interrupted
Forward catchable cancellation to each suite's owned process group, bound its stop and reap observation, and preserve returned exits separately from the runner signal. Never admit a later suite or a passing verdict after interruption; SIGKILL and detached-child cleanup remain unknown. Keep all suite selection and test deadlines unchanged.

Contract-Neutral: Product test-runner observation and cancellation only; no application, installed-runtime or release contract change.
Change-source: pulse-maintainer
2026-11-16 21:29:28 +00:00

168 lines
5.3 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Simple harness to execute smoke tests under scripts/tests/.
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
TEST_DIR="${ROOT_DIR}/scripts/tests"
usage() {
cat <<'EOF'
Usage: scripts/tests/run.sh [test-script ...]
scripts/tests/run.sh --smoke-shard <0|1>
scripts/tests/run.sh --docs-shard <0|1|2|3>
Run all scripts/tests/test-*.sh and scripts/tests/test_*.py tests or a subset
when specified. Documentation and smoke CI balance their complete discovered
inventories across four and two isolated, sorted shards respectively, using
measured suite durations. Hints never define coverage or change test deadlines;
new suites receive a default scheduling weight.
Failed runs finish with the selected suite names and their observed exit codes.
CI can retain atomic, output-free suite observations with PULSE_SCRIPT_TEST_RECEIPT
and PULSE_SCRIPT_TEST_SOURCE_SHA. Incomplete collection never establishes a pass.
SIGINT/SIGTERM stop the active suite's owned process group with bounded grace,
retain observed child results separately from the runner's signal, and admit no
later suite. Detached descendants and uncatchable signals remain unverified.
EOF
}
discover_tests() {
local -n ref=$1
local mode="${2:-all}"
local inventory
local -a patterns=(-name 'test-*.sh' -o -name 'test_*.py')
if [[ "${mode}" == docs ]]; then
# Keep the established safety helpers whose names predate the docs suffix.
patterns=(-name 'test_*docs*.py' -o -name 'test_vm_disk_diagnostics.py'
-o -name 'test_troubleshooting_logs.py'
-o -name 'test-retired-trial-acquisition-docs.sh')
fi
# Process substitution hides producer failures from mapfile. Admit the
# complete discovery pipeline before running any tests, never a partial list.
if ! inventory="$(
find "${TEST_DIR}" -maxdepth 1 -type f \
\( "${patterns[@]}" \) | LC_ALL=C sort
)"; then
echo "Failed to discover the complete smoke test inventory under ${TEST_DIR}" >&2
return 1
fi
ref=()
if [[ -n "${inventory}" ]]; then
mapfile -t ref <<< "${inventory}"
fi
}
resolve_test_path() {
local input="$1"
if [[ "${input}" == /* ]]; then
printf '%s\n' "${input}"
return 0
fi
if [[ -f "${TEST_DIR}/${input}" ]]; then
printf '%s\n' "${TEST_DIR}/${input}"
return 0
fi
if [[ -f "${input}" ]]; then
printf '%s\n' "${input}"
return 0
fi
return 1
}
run_tests() {
# One sequencer preserves selection/order and streams original child output.
# Returned observations are saved before a later suite can block the summary.
exec python3 "${ROOT_DIR}/scripts/run-script-tests.py" "$@"
}
main() {
if [[ $# -gt 0 ]]; then
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
usage
exit 0
fi
fi
local -a tests=()
if [[ "${1:-}" == --docs-shard ]]; then
if [[ $# -ne 2 || ! "${2:-}" =~ ^[0-3]$ ]]; then
echo "Usage: scripts/tests/run.sh --docs-shard <0|1|2|3>" >&2
return 1
fi
local -a doc_tests=()
if ! discover_tests doc_tests docs; then
return 1
fi
local doc_selection
if (( ${#doc_tests[@]} > 0 )); then
# Reuse smoke's whole-suite partitioner, with docs-only measurements.
# Discovery remains the inventory; admit no partial selector output.
if ! doc_selection="$(
printf '%s\n' "${doc_tests[@]}" | python3 \
"${ROOT_DIR}/scripts/select-smoke-test-shard.py" \
"${ROOT_DIR}/.github/scripts/docs-test-seconds.txt" 4 "$2"
)"; then
echo "Failed to partition the complete documentation test inventory" >&2
return 1
fi
if [[ -n "${doc_selection}" ]]; then
mapfile -t tests <<< "${doc_selection}"
fi
fi
printf 'Documentation shard %s/4: %s of %s suites\n' "$2" "${#tests[@]}" "${#doc_tests[@]}"
elif [[ "${1:-}" == --smoke-shard ]]; then
if [[ $# -ne 2 || ! "${2:-}" =~ ^[0-1]$ ]]; then
echo "Usage: scripts/tests/run.sh --smoke-shard <0|1>" >&2
return 1
fi
local -a smoke_tests=()
if ! discover_tests smoke_tests; then
return 1
fi
local selection
if (( ${#smoke_tests[@]} > 0 )); then
# Capture the entire successful selector before admitting any suite. A
# partial output from a failed selector is not a complete shard. Timing
# hints only place discovered suites; they cannot add or omit coverage.
if ! selection="$(
printf '%s\n' "${smoke_tests[@]}" | python3 \
"${ROOT_DIR}/scripts/select-smoke-test-shard.py" \
"${ROOT_DIR}/.github/scripts/smoke-test-seconds.txt" 2 "$2"
)"; then
echo "Failed to partition the complete smoke test inventory" >&2
return 1
fi
if [[ -n "${selection}" ]]; then
mapfile -t tests <<< "${selection}"
fi
fi
printf 'Smoke shard %s/2: %s of %s suites\n' "$2" "${#tests[@]}" "${#smoke_tests[@]}"
elif [[ $# -gt 0 ]]; then
local arg resolved
for arg in "$@"; do
if ! resolved="$(resolve_test_path "${arg}")"; then
echo "Unknown test: ${arg}" >&2
exit 1
fi
tests+=("${resolved}")
done
else
if ! discover_tests tests; then
return 1
fi
fi
if [[ ${#tests[@]} -eq 0 ]]; then
echo "No tests found under ${TEST_DIR}" >&2
exit 1
fi
run_tests "${tests[@]}"
}
main "$@"