beads/scripts/ci/test-init-gateway-credential.sh
Julian Knutsen 630eae9b0c
ci(pr): share restored GOCACHE with the native init credential step (#7227)
pr-preflight-platforms' "Exercise native init gateway credential shell"
step had no GOCACHE env, so it fell back to the runner's empty default
cache and cold-compiled all of ./cmd/bd's test binary on every PR, right
after the hook-timeout step had compiled the identical binary (same tags,
same platform-default CGO) into the restored non-race cache. Job logs:
213s of a ~350s macos-latest leg, ~117s on Windows; on Linux the rerun
with a shared cache is a relink only (~8s).

- pr.yml: point that step, and the three Windows-only Go steps, at the
  restored non-race GOCACHE.
- main.yml: the macOS test leg (the only macOS non-race seeder) now runs
  warm-non-race-cache.sh, so the PR macOS legs restore the test packages
  and test-only deps they compile, not just the non-test ./cmd/bd graph.
- Policy tests: every run step in pr-preflight-platforms and
  check-doc-freshness-platforms must use the restored GOCACHE, and the
  macOS seeder must warm before it saves.

No test selection, matrix, or gate wiring changes.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 01:01:23 -07:00

85 lines
3.9 KiB
Bash
Executable file

#!/usr/bin/env bash
# Run the init credential shell boundary on one declared native host.
# Direct invocation: bash scripts/ci/test-init-gateway-credential.sh Linux|macOS|Windows
# Keep this compatible with macOS Bash 3.2.
set -euo pipefail
case "${1:-}" in
Linux) expected_os=linux ;;
macOS) expected_os=darwin ;;
Windows) expected_os=windows ;;
*) echo 'Expected one native host: Linux, macOS, or Windows' >&2; exit 1 ;;
esac
[[ $# -eq 1 ]] || { echo 'Expected exactly one native host' >&2; exit 1; }
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
cd "$repo_root"
# shellcheck source=../../.buildflags
source "$repo_root/.buildflags"
# These fixtures exercise the production shell without opening a database, so
# no database build configuration is needed either way — and the build config is
# deliberately left at whatever .buildflags defaults to rather than forced.
#
# Forcing CGO_ENABLED=0 here used to compile a package graph disjoint from the
# ./cmd/bd build the same job performs a couple of steps earlier under the
# default: 742 packages versus 1505 for `go list -deps -tags=gms_pure_go
# ./cmd/bd`, with `net` and `os/user` among the cgo-using differences, whose
# build IDs propagate upward. Nothing was reused, so this blocking lane paid a
# second cold compile on macOS and Windows. Inheriting the default makes this
# step incremental, and it also means the natively executed fixtures exercise
# the same build of cmd/bd that actually ships on those platforms.
# Incremental only if the caller also shares GOCACHE with that earlier step:
# pr.yml points both at the restored non-race cache.
go_executable="$(command -v go)"
[[ "$go_executable" = /* && -x "$go_executable" ]] || {
echo 'Go must resolve to an absolute executable' >&2; exit 1;
}
host_info="$("$go_executable" env GOHOSTOS GOOS)"
[[ "$host_info" = "$expected_os"$'\n'"$expected_os" ]] || {
echo "Expected native $expected_os Go host and target" >&2; exit 1;
}
# This single list owns both test selection and required execution evidence.
expected=(
TestApplyInitGatewayCredentialAdoptsToken
TestApplyInitGatewayCredentialSkipsEmbeddedMode
TestApplyInitGatewayCredentialNoopWithoutCommand
TestApplyInitGatewayCredentialFailsClosed
TestApplyInitGatewayCredentialPresetWins
)
# ...which makes the array the only wiring between a fixture and native
# execution, with nothing tying it back to the source file. A new
# TestApplyInitGatewayCredential* fixture added later would fall out of the
# selector, lose macOS/Windows execution entirely, and still leave this driver
# exiting 0 with the required gate green — the exact "green because nothing ran"
# mode the per-name PASS counting below exists to prevent. Compare the list
# against the source of truth by name and by count, before running anything.
declared_fixtures="$(grep -Eo '^func TestApplyInitGatewayCredential[A-Za-z0-9_]*' cmd/bd/init_gateway_test.go | sed 's/^func //' | sort)"
wired_fixtures="$(printf '%s\n' "${expected[@]}" | sort)"
if [[ "$declared_fixtures" != "$wired_fixtures" ]]; then
echo 'Init credential fixture list is out of sync with cmd/bd/init_gateway_test.go.' >&2
echo 'Declared in the test file:' >&2
printf '%s\n' "$declared_fixtures" | sed 's/^/ /' >&2
echo 'Wired into this native lane:' >&2
printf '%s\n' "$wired_fixtures" | sed 's/^/ /' >&2
exit 1
fi
selector="$(IFS='|'; echo "${expected[*]}")"
log="$(mktemp)"
trap 'rm -f "$log"' EXIT
status=0
"$go_executable" test -v -count=1 -timeout 5m -run "^($selector)$" ./cmd/bd >"$log" 2>&1 || status=$?
cat "$log"
[[ $status -eq 0 ]] || exit "$status"
if grep -Eq -- '^[[:space:]]*--- (FAIL|SKIP):' "$log"; then
echo 'Init credential fixtures must pass without skips' >&2
exit 1
fi
for test_name in "${expected[@]}"; do
passes="$(grep -Ec -- "^--- PASS: $test_name( |$)" "$log" || true)"
[[ "$passes" = 1 ]] || {
echo "Expected exactly one PASS for $test_name, got $passes" >&2
exit 1
}
done