#!/usr/bin/env bash # The gate before a commit. ./test.sh runs every check but only the e2e tests # the change touches (test/e2e/e2e_select.py picks them, and Go e2e only for a # cli/ change); ./test.sh --full runs everything, as CI does on every push. # # test/quick.sh runs first, then the other quick checks. Then the daemon is # compiled once and every suite runs at the same time, each into its own log, # which is printed only if that suite fails. The e2e suites boot their daemons # from that one snapshot (ALBEDO_TEST_DAEMON) instead of through gleam, so none # of them waits on the build lock `gleam test` holds for its whole run. # test/manual is opt-in and not run here; those harnesses need a provider, a # PTY, or artifacts from an earlier benchmark run. set -euo pipefail cd "$(dirname "$0")" full=false case "${1:-}" in --full) full=true ;; "") ;; *) echo "usage: $0 [--full]" >&2 exit 2 ;; esac export ALBEDO_NO_BROWSER=1 # a detached kernel a suite left behind ends soon after, not in an hour export ALBEDO_KERNEL_GRACE_SECONDS=20 test/quick.sh cargo test --quiet --release --locked --manifest-path native/render/Cargo.toml native/render/install.sh npm --prefix web test # the Python e2e suite drives the CLI through this binary go -C cli build -o bin/albedo ./cmd/albedo scratch="${ALBEDO_TEST_TMP:-/tmp/albedo-tests}/gate-$$" mkdir -p "$scratch" trap 'rm -rf "$scratch"' EXIT ALBEDO_TEST_DAEMON="$(test/snapshot-daemon.sh "$scratch/daemon")" export ALBEDO_TEST_DAEMON names=() pids=() log() { echo "$scratch/${1//[\/ ]/-}.log" } suite() { local name="$1" shift "$@" >"$(log "$name")" 2>&1 & names+=("$name") pids+=("$!") } failed=0 # Names the suites still running every 30 s, so a long quiet stretch (CI's log # shows nothing until a suite ends) reads as progress rather than a stall. ticker() { while sleep 30; do local running=() for i in "${!pids[@]}"; do if kill -0 "${pids[$i]}" 2>/dev/null; then running+=("${names[$i]}") fi done echo "... ${SECONDS}s, still running: ${running[*]}" done } # Waits for every suite started so far, printing each one's log if it failed. settle() { ticker & local ticking=$! for i in "${!pids[@]}"; do if wait "${pids[$i]}"; then echo "ok ${names[$i]}" else failed=1 echo "FAILED ${names[$i]}" cat "$(log "${names[$i]}")" fi done kill "$ticking" wait "$ticking" 2>/dev/null || true names=() pids=() } suite "gleam test" gleam test for test in test/harness/*_test.py; do suite "$test" python3 test/python_test_runner.py "$test" done suite "go test" go -C cli test ./internal/... ./cmd/... # the Go e2e suite builds its own CLI and boots a hermetic daemon, so it must # never reuse a cached run. Bound parallel scenarios while the other suites run. go_parallel="$(python3 -c 'import os; print(max(1, min(4, (os.cpu_count() or 1) // 4)))')" if $full; then # On a machine with fewer cores (CI's VM) the e2e suites' daemon boots starve # the unit suites' startup timeouts, so they run after them. settle suite "go e2e" go -C cli test -count=1 -parallel="$go_parallel" ./test/e2e suite "python e2e" python3 test/e2e/run.py else if { git diff --name-only origin/main...HEAD git diff --name-only HEAD git ls-files --others --exclude-standard } | grep '^cli/' >/dev/null; then suite "go e2e" go -C cli test -count=1 -parallel="$go_parallel" ./test/e2e fi mapfile -t selected < <(python3 test/e2e/e2e_select.py --print-reasons) suite "python e2e" python3 test/e2e/run.py "${selected[@]}" fi settle exit "$failed"