"""Check first, offline and update runs without Docker or production writes.""" from pathlib import Path import os import shutil import subprocess import tempfile source = Path(__file__).resolve().parents[2] / "venue" / "deploy.sh" for name, cold, update in [("first", True, False), ("offline", False, False), ("update", False, True)]: with tempfile.TemporaryDirectory() as directory: root = Path(directory) venue = root / "venue" venue.mkdir() shutil.copy(source, venue / "deploy.sh") log = root / "commands.log" bin_dir = root / "bin" bin_dir.mkdir() for command in ["docker", "make", "npm"]: stub = bin_dir / command stub.write_text( '#!/bin/sh\n' 'echo "$(basename "$0") $*" >> "$TEST_LOG"\n' 'if [ "$1 $2" = "image inspect" ] && [ "$TEST_COLD" = 1 ]; then exit 1; fi\n' ) stub.chmod(0o755) if not cold: (venue / "migrations").mkdir() (venue / ".env").write_text("EXISTING_SECRET=unchanged\n") for artifact in ["backend/evening_detective_server", "backend/goose", "backend/dev-user.sql", "frontend/dist/index.html"]: path = venue / artifact path.parent.mkdir(parents=True, exist_ok=True) path.touch() env = {**os.environ, "PATH": str(bin_dir) + os.pathsep + os.environ["PATH"], "TEST_LOG": str(log), "TEST_COLD": str(int(cold))} subprocess.run(["bash", str(venue / "deploy.sh"), *(["--build"] if update else [])], env=env, check=True, capture_output=True) commands = log.read_text() assert "volume create evening-detective-local_postgres_data" in commands, name assert "volume create evening-detective-local_rustfs_data" in commands, name assert "compose up -d --no-build --pull never" in commands, name assert "compose --profile setup run --rm bootstrap" in commands, name assert ("make -C .. build" in commands) == (cold or update), name assert ("compose pull" in commands) == (cold or update), name assert ("compose build --pull=false" in commands) == (cold or update), name if cold: config = dict(line.split("=", 1) for line in (venue / ".env").read_text().splitlines()) assert len(config["JWT_SECRET"]) == 64 assert len(config["VENUE_USER_PASSWORD"]) == 16 assert (venue / ".env").stat().st_mode & 0o777 == 0o600 else: assert (venue / ".env").read_text() == "EXISTING_SECRET=unchanged\n", name print("PASS: automatic first setup, offline reuse, explicit update and preserved secrets")