#!/usr/bin/env bash # Runs live TTL validation for Attestor dedupe stores against local MongoDB/Redis. set -euo pipefail if ! command -v docker >/dev/null 2>&1; then echo "docker CLI is required. Install Docker Desktop or ensure docker is on PATH." >&2 exit 1 fi if ! docker compose version >/dev/null 2>&1; then if command -v docker-compose >/dev/null 2>&1; then compose_cmd="docker-compose" else echo "docker compose plugin (or docker-compose) is required." >&2 exit 1 fi else compose_cmd="docker compose" fi repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" compose_file="$(mktemp -t attestor-ttl-compose-XXXXXX.yaml)" cleanup() { $compose_cmd -f "$compose_file" down -v >/dev/null 2>&1 || true rm -f "$compose_file" } trap cleanup EXIT cat >"$compose_file" <<'YAML' services: mongo: image: mongo:7.0 ports: - "27017:27017" healthcheck: test: ["CMD", "mongosh", "--quiet", "localhost/test", "--eval", "db.runCommand({ ping: 1 })"] interval: 5s timeout: 3s retries: 20 redis: image: redis:7.2 command: ["redis-server", "--save", "", "--appendonly", "no"] ports: - "6379:6379" healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 3s retries: 20 YAML echo "Starting MongoDB and Redis containers..." $compose_cmd -f "$compose_file" up -d wait_for_port() { local host=$1 local port=$2 local name=$3 for attempt in {1..60}; do if (echo > /dev/tcp/"$host"/"$port") >/dev/null 2>&1; then echo "$name is accepting connections." return 0 fi sleep 1 done echo "Timeout waiting for $name on $host:$port" >&2 return 1 } wait_for_port 127.0.0.1 27017 "MongoDB" wait_for_port 127.0.0.1 6379 "Redis" export ATTESTOR_LIVE_MONGO_URI="${ATTESTOR_LIVE_MONGO_URI:-mongodb://127.0.0.1:27017}" export ATTESTOR_LIVE_REDIS_URI="${ATTESTOR_LIVE_REDIS_URI:-127.0.0.1:6379}" echo "Running live TTL validation tests..." dotnet test "$repo_root/src/Attestor/StellaOps.Attestor.sln" --no-build --filter "Category=LiveTTL" "$@" echo "Live TTL validation complete. Shutting down containers."