Files
minerops/scripts/test-legacy-agent-production-contract.sh
T

68 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "${repo_root}"
project_name="${MINEROPS_LEGACY_PRODUCTION_PROJECT:-minerops-legacy-production-$$}"
compose=(docker compose --project-name "${project_name}" --env-file .env.dev -f compose.dev.yaml)
cleanup() {
status=$?
if (( status != 0 )); then
"${compose[@]}" logs --no-color --tail 160 postgres || true
fi
"${compose[@]}" down --volumes --remove-orphans >/dev/null 2>&1 || true
exit "${status}"
}
trap cleanup EXIT
[[ -f .env.dev ]] || { echo "Missing .env.dev" >&2; exit 1; }
"${compose[@]}" up --detach postgres
for attempt in $(seq 1 60); do
"${compose[@]}" exec -T postgres sh -ec \
'pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB"' >/dev/null 2>&1 && break
(( attempt < 60 )) || { echo "PostgreSQL did not become ready" >&2; exit 1; }
sleep 1
done
"${compose[@]}" build backend
echo "Building the production-shaped database from the 0014 baseline..."
"${compose[@]}" run --rm --no-deps backend \
alembic upgrade 0014_repair_parts_tracking
"${compose[@]}" exec -T postgres sh -ec \
'exec psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB"' <<'SQL'
INSERT INTO sites (id, name) VALUES
('00000000-0000-4000-8000-000000001901', 'Plexus'),
('00000000-0000-4000-8000-000000001902', 'Contract Site B');
INSERT INTO miners (
id, site_id, asset_tag, current_ip, current_mac, status,
first_seen_at, last_seen_at
) VALUES
(
'00000000-0000-4000-8000-000000001911',
'00000000-0000-4000-8000-000000001901',
'LEGACY-CONTRACT-A', '192.0.2.191', '02:00:00:00:19:11',
'online', NULL, NULL
),
(
'00000000-0000-4000-8000-000000001912',
'00000000-0000-4000-8000-000000001902',
'LEGACY-CONTRACT-B', '192.0.2.192', '02:00:00:00:19:12',
'online', NULL, NULL
);
INSERT INTO minerops_site_agents (agent_id, site_name)
VALUES ('legacy-plexus-production', ' plexus ');
SQL
"${compose[@]}" run --rm --no-deps backend alembic upgrade head
echo "Running legacy authentication, routing, and inert telemetry contract..."
"${compose[@]}" run --rm --no-deps \
--volume "${repo_root}/backend/tests:/app/tests:ro" \
--env MINEROPS_LEGACY_PRODUCTION_DISPOSABLE=1 \
--env MINEROPS_AGENT_ID=legacy-plexus-production \
--env MINEROPS_AGENT_SHARED_SECRET=legacy-production-contract-secret \
backend python -m unittest -v \
tests.test_legacy_agent_production_postgres
echo "Legacy production compatibility contract passed."