"""Full Docker checks, Python stdlib only; works on Windows and Linux. Stops/restarts ONLY services belonging to this Compose project. Keeps volumes. Run against an idle disposable teaching stand, not during other tests. """ import os from pathlib import Path import subprocess import sys import time ROOT=Path(__file__).resolve().parents[1] sys.path.insert(0,str(ROOT/'tests')) from client import Client,Failure,check from resilience import history def compose(*args, capture=False): result=subprocess.run(['docker','compose',*args],cwd=ROOT,text=True,capture_output=capture) if result.returncode: raise RuntimeError('Compose failed: '+args[0]) return result.stdout if capture else None def wait(c): deadline=time.monotonic()+60 while time.monotonic() SQL fallback; unknown token rejected') finally: compose('start','cache') try: compose('stop','db') start=time.monotonic() c.call('GET','/api/v1/users/me',503,actor=alice) check(time.monotonic()-start<8,'DB failure too slow') c.call('GET','/health/ready',503) c.call('GET','/health/live',schema='Health') print('PASS: DB down -> bounded 503; live remains 200') finally: compose('start','db') wait(c) expiry_id=None try: expiry_id=compose('run','-d','--no-deps','-p','127.0.0.1:18082:8080','-e','SESSION_TTL_SECONDS=2','api',capture=True).strip().splitlines()[-1] short=Client('http://localhost:18082') wait(short) env=dict(os.environ,BASE_URL='http://localhost:18082') subprocess.run([sys.executable,'student-tests/expiry.py'],env=env,check=True) finally: if expiry_id: subprocess.run(['docker','rm','-f',expiry_id],check=True) c.call('DELETE','/api/v1/auth/sessions/current',204,actor=alice) c.call('GET','/api/v1/users/me',401,actor=alice) print('PASS: complete Compose verification; volumes retained') if __name__=='__main__': main()