"""Required owner projection; retain the sandbox failure and unrelated state.""" from pathlib import Path import hashlib import json import subprocess BASE = Path(__file__).resolve().parent ROOT = Path('/home/worsch/state-hub') def git(*argv): return subprocess.check_output(['git', '-C', str(ROOT), *argv], stderr=subprocess.PIPE) names = ['.custodian-brief.md', 'WORK-RECORDS.md', 'docs/evidence/legacy-meter-weekly-review-20261014.json'] before = {name: hashlib.sha256((ROOT / name).read_bytes()).hexdigest() for name in names} index = git('ls-files', '--stage', '-z') head = git('rev-parse', 'HEAD').decode().strip() assert head in {'51bc70d1ff8f25450a8650d8e50caf053093a02e', '086d79a2736e34b916bd7de3c8a65e2ea38a3d64'} label = 'state-hub-source-projection' if head.startswith('51bc70d') else 'state-hub-readiness-projection' for name in [label + '.json', label + '.stderr.txt']: old = BASE / name saved = BASE / ('sandbox-failed-' + name) if old.exists() and not saved.exists(): saved.write_bytes(old.read_bytes()) r = subprocess.run(['/home/worsch/repo-manager/.venv/bin/rmgr', 'sync', '--path', str(ROOT), '--push'], cwd=ROOT, capture_output=True, text=True, timeout=180) (BASE / (label + '.json')).write_text(r.stdout) (BASE / (label + '.stderr.txt')).write_text(r.stderr) assert all(hashlib.sha256((ROOT / name).read_bytes()).hexdigest() == pin for name, pin in before.items()) assert git('ls-files', '--stage', '-z') == index assert r.returncode == 0, 'projection failed; retained receipt' value = json.loads(r.stdout) assert value['status'] == 'applied' and value['commit'] == head print(json.dumps({'status': value['status'], 'commit': value['commit'], 'preserved_other_changes': True, 'counts': value['receipt']['outcome']['counts']}))