#!/usr/bin/env bash set -euo pipefail # Build historical source, not today's implementation with a legacy DTO. # Keep this commit pinned; a moved release tag must not silently change the gate. case "${EVOBGP_LEGACY_VERSION:-2.56.2}" in 2.56.2) legacy_ref=924f111e4871e1d6d47c9916d7da1b9051718f1c ;; 1.0.0) legacy_ref=6ca34b900859665eede22044d734b698059bdf84 ;; *) echo 'Unsupported legacy test version' >&2; exit 2 ;; esac if ! git cat-file -e "$legacy_ref^{commit}" 2>/dev/null; then git fetch --no-tags --depth=1 origin "$legacy_ref" fi legacy_tmp="$(mktemp -d)" trap 'rm -rf -- "$legacy_tmp"' EXIT mkdir "$legacy_tmp/source" archive_paths=(go.mod go.sum cmd/evobgp-node internal migrations) if [ "${EVOBGP_LEGACY_VERSION:-2.56.2}" = 2.56.2 ]; then archive_paths+=(cmd/evobgp-agent) fi git archive "$legacy_ref" "${archive_paths[@]}" | tar -x -C "$legacy_tmp/source" ( cd "$legacy_tmp/source" go build -mod=readonly -o "$legacy_tmp/evobgp-node-legacy" ./cmd/evobgp-node if [ "${EVOBGP_LEGACY_VERSION:-2.56.2}" = 2.56.2 ]; then go build -mod=readonly -o "$legacy_tmp/evobgp-agent-legacy" ./cmd/evobgp-agent fi ) export EVOBGP_TEST_LEGACY_NODE_BIN="$legacy_tmp/evobgp-node-legacy" go test -race -count=1 -json -run '^TestLegacyNodeBinaryCurrentControlPlane$' ./internal/httpapi | tee "$legacy_tmp/result.jsonl" assert_test() { python3 - "$1" "$2" "$3" <<'PY' import json import sys events = [json.loads(line) for line in open(sys.argv[1], encoding="utf-8")] package, expected = sys.argv[2:4] if any(e.get("Package") != package for e in events): raise SystemExit("unexpected legacy compatibility package") if any(e.get("Action") in ("skip", "fail") for e in events): raise SystemExit("legacy compatibility test skipped or failed") if not any(e.get("Test") == expected and e.get("Action") == "pass" for e in events): raise SystemExit("required legacy binary compatibility test did not execute") if not any("Test" not in e and e.get("Action") == "pass" for e in events): raise SystemExit("legacy compatibility package did not pass") print(f"Pinned legacy executable passed {expected}") PY } assert_test "$legacy_tmp/result.jsonl" evobgp/internal/httpapi TestLegacyNodeBinaryCurrentControlPlane if [ "${EVOBGP_LEGACY_VERSION:-2.56.2}" = 2.56.2 ]; then export EVOBGP_TEST_LEGACY_AGENT_BIN="$legacy_tmp/evobgp-agent-legacy" go test -race -count=1 -json -run '^TestLegacyAgentBinaryCurrentDispatch$' ./internal/nodedispatch | tee "$legacy_tmp/agent-result.jsonl" assert_test "$legacy_tmp/agent-result.jsonl" evobgp/internal/nodedispatch TestLegacyAgentBinaryCurrentDispatch fi