"""Run against an already started local Compose stack; save sanitized evidence.""" from pathlib import Path import json import subprocess import sys ROOT = Path(__file__).resolve().parents[1] def run(name, args): p = subprocess.run(args, cwd=ROOT, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (ROOT / "evidence" / name).write_text(p.stdout) print(p.stdout, end="", flush=True) p.check_returncode() def states(): ids = subprocess.check_output(["docker", "compose", "ps", "-q"], cwd=ROOT, text=True).split() data = json.loads(subprocess.check_output(["docker", "inspect", *ids], text=True)) return [{"Name": d["Name"], "Id": d["Id"], "StartedAt": d["State"]["StartedAt"]} for d in data] run("check.txt", ["make", "check"]) run("smoke.txt", ["make", "test"]) before = states() run("persistence.txt", ["make", "test-persistence", "ACTION_SCRIPT=scripts/restart.sh"]) after = states() for name in ("api", "postgres", "valkey"): b = next(x for x in before if x["Name"] == "/mtusi-lab2-" + name + "-1") a = next(x for x in after if x["Name"] == b["Name"]) assert a["StartedAt"] != b["StartedAt"], name + " did not restart" (ROOT / "evidence/restart-containers.json").write_text(json.dumps({"before":before,"after":after},indent=2)+"\n") run("student-tests.txt", [sys.executable, "student-tests/verify.py"]) run("explain.txt", [sys.executable, "student-tests/explain.py"])