"""Capture one focused regression run; do not treat expected failure as acceptance.""" from pathlib import Path from datetime import datetime, timezone import hashlib import json import os import re import subprocess import sys import time import zipfile root = Path(__file__).resolve().parents[2] label = sys.argv[1] assert re.fullmatch(r'focus-(?:red|green)-[0-9]+', label) assert os.environ.get('CARGO_BUILD_JOBS') == '1' dest = Path(__file__).resolve().parent / label dest.mkdir() scopes = ['Cargo.toml', 'Cargo.lock', 'crates', 'build', '.cargo', 'docs', 'examples', 'harness/fixtures'] def names(): raw = subprocess.check_output(['git', 'ls-files', '-z', '--cached', '--others', '--exclude-standard', '--', *scopes], cwd=root) return sorted(set(s.decode() for s in raw.split(b'\0') if s)) def identity(path): raw = path.read_bytes() return {'bytes': len(raw), 'sha256': hashlib.sha256(raw).hexdigest()} inputs = {name: identity(root / name) for name in names()} with zipfile.ZipFile(dest / 'inputs.zip', 'x', zipfile.ZIP_DEFLATED) as archive: for name in inputs: archive.write(root / name, name) def save(name, value): with (dest / name).open('x', encoding='utf-8', newline='\n') as stream: json.dump(value, stream, indent=2) stream.write('\n') save('inputs.json', {'baseCommit': subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=root).decode().strip(), 'files': inputs, 'archive': identity(dest / 'inputs.zip')}) command = ['cargo', 'test', '--locked', '--offline', '-p', 'oa-desktop', '--bin', 'arcadia-studio', 'text_workspace::focus_selection_tests', '--', '--nocapture', '--test-threads=1'] start = datetime.now(timezone.utc).isoformat() timer = time.perf_counter() print(json.dumps({'command': command, 'started': start, 'label': label}), flush=True) with (dest / 'stdout.log').open('xb') as out, (dest / 'stderr.log').open('xb') as err: code = subprocess.run(command, cwd=root, stdout=out, stderr=err).returncode unchanged = names() == list(inputs) and all(identity(root / name) == data for name, data in inputs.items()) receipt = {'command': command, 'started': start, 'finished': datetime.now(timezone.utc).isoformat(), 'seconds': time.perf_counter()-timer, 'exitCode': code, 'inputsUnchanged': unchanged, 'stdout': identity(dest / 'stdout.log'), 'stderr': identity(dest / 'stderr.log'), 'scope': 'Focused evaluator run only; red label describes intended old-production run, not proof of the expected failure cause.'} save('result.json', receipt) print(json.dumps(receipt), flush=True) print((dest / 'stdout.log').read_text(encoding='utf-8', errors='replace')[-6000:], flush=True) print((dest / 'stderr.log').read_text(encoding='utf-8', errors='replace')[-6000:], flush=True) sys.exit(code or (0 if unchanged else 1))