* test(init): make gateway credential fixture portable (#5715) Replace shell-specific fixture commands with an opt-in test helper, exercise exact credential semantics under a restricted shell PATH without copied Windows PE fixtures, and require the focused suite in native Windows PR CI. Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell * test(init): keep the original shell across native credential fixtures Use a symlink to the original Unix shell so macOS AMFI does not reject a copied system executable. Keep Windows cmd.exe and the test image in place, internalize helper environment names and assert the typed helper exit code. Run the six fixture cases through one Bash3.2-compatible driver in the existing required three-host preflight matrix. Preserve the liveness check name and optional macOS suite policy; reject missing or skipped execution. Review: https://github.com/gastownhall/beads/pull/5725#pullrequestreview-5096996756 Bead: saa-cgh.47 Agent-Signature: unknown-model/unknown-reasoning * test(ci): sync-check the native fixture list and stop forcing a second build graph Maintainer review fixes for PR #5725, adoption iteration 1. The synthesis is `approve` with no required changes; all findings are minor or nit. The rebase lane had to repair this branch (`repaired_clean`, and the original head still conflicts with main), so there is no accepted-as-is path and finalize owes a push either way — these cost nothing extra. Test evidence (minor): the `expected` array is, by its own comment, the single list owning both test selection and required execution evidence -- but nothing tied it back to the source file. A seventh TestApplyInitGatewayCredential* fixture added later would fall out of the `-run` selector, lose native macOS/Windows execution entirely, and still leave the driver exiting 0 with the required gate green: precisely the "green because nothing ran" mode the per-name PASS counting exists to prevent. The driver now compares the array against `grep -Eo '^func TestApplyInitGatewayCredential[A-Za-z0-9_]*'` on cmd/bd/init_gateway_test.go, by name and by count, before running anything, and exits non-zero naming the offending fixture. That file is the whole population -- no same-prefix fixture lives in any other cmd/bd test file. Release safety (minor): the driver sourced .buildflags and then forced CGO_ENABLED=0, compiling a package graph disjoint from the ./cmd/bd build the same job performs two steps earlier under the default. Re-measured under the tags the steps use: `go list -deps -tags=gms_pure_go ./cmd/bd` is 1505 packages with cgo and 742 without, and the differing cgo users include `net` and `os/user`, whose build IDs propagate upward -- so nothing was reused and this blocking, `cache: false` lane paid a second cold compile on macOS and Windows. The export is dropped. Two consequences beyond the time: the step becomes incremental, and the natively executed fixtures now exercise the same build of cmd/bd that actually ships on those platforms rather than a nocgo one. The comment now explains the build configuration, which is what the old one did not do -- it explained why no database is needed, a separate question. Debuggability (nit): the base comment above test-windows-liveness carried three checkable mechanism clauses (the test is //go:build windows; the Ubuntu job selects it by name but compiles it out; main.yml's Windows job runs only on pushes to main). The replacement stated a conclusion a future maintainer cannot verify, which is how a redundant-looking CI job gets deleted. The mechanisms are restored and the new pr-preflight-platforms pointer is appended rather than substituted. The remaining nit asked for no change in this PR (the credential cache is keyed by command string, which is harmless as shipped since neither the marker nor the failure arm populates the cache) and none was made. Validation: the driver runs green on Linux under the inherited default CGO -- 6 of 6 fixtures PASS, exit 0 -- and the sync check was proved by appending an unwired seventh fixture, which reds it with exit 1 naming that fixture, before any test runs. `bash -n` clean, no shellcheck SC2086, and ./scripts/ stays green. --------- Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
84 lines
3.9 KiB
Bash
Executable file
84 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.
|
|
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=(
|
|
TestApplyInitGatewayCredentialHelperProtocol
|
|
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 seventh
|
|
# 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
|