#!/usr/bin/env python3 """Run acceptance checks and save real UTF-8 evidence. Requires an already running stand.""" import os from pathlib import Path import subprocess import sys ROOT = Path(__file__).resolve().parents[1] def main(): url = os.environ.get('BASE_URL', 'http://127.0.0.1:8080') hook = 'scripts/restart.cmd' if os.name == 'nt' else 'scripts/restart.sh' checks = [ ('offline.txt', ['scripts/check_contract.py']), ('smoke.txt', ['tests/smoke.py', '--base-url', url]), ('tests.txt', ['-m', 'unittest', 'discover', '-s', 'student-tests', '-v']), ('lab4-checks.txt', ['scripts/lab4_checks.py', '--base-url', url]), ('persistence.txt', ['tests/resilience.py', '--mode', 'persistence', '--action-script', hook, '--base-url', url]), ('stack.txt', ['scripts/stack_evidence.py']), ] for filename, args in checks: result = subprocess.run([sys.executable, '-X', 'utf8', *args], cwd=ROOT, env=dict(os.environ, BASE_URL=url), capture_output=True) content = result.stdout.decode('utf-8', errors='replace') + result.stderr.decode('utf-8', errors='replace') (ROOT / 'evidence' / filename).write_text(content, encoding='utf-8') print(filename + ': ' + ('PASS' if result.returncode == 0 else 'FAIL'), flush=True) if result.returncode: print(content[-6000:], flush=True) return result.returncode return 0 if __name__ == '__main__': sys.exit(main())