the-custodian/docs/changes/netkingdom-target-2026-10-17/sync_rollout_custodian.py

33 lines
1.7 KiB
Python

"""Required consistency/projection with exact restoration of unrelated work."""
from pathlib import Path
import hashlib
import json
import subprocess
ROOT = Path('/home/worsch/the-custodian')
BASE = Path(__file__).resolve().parent
BACKUP = BASE / 'custodian-publication-backup'
originals = json.loads((BACKUP / 'originals.json').read_text())
other = json.loads((BACKUP / 'other-dirty-hashes.json').read_text())
def git(*argv):
return subprocess.check_output(['git', '-C', str(ROOT), *argv], stderr=subprocess.PIPE)
try:
for label, argv, timeout in [
('consistency', ['statehub', 'fix-consistency', '--repo', 'the-custodian', '--json'], 300),
('projection', ['/home/worsch/repo-manager/.venv/bin/rmgr', 'sync', '--path', str(ROOT), '--push'], 180),
]:
result = subprocess.run(argv, cwd=ROOT, capture_output=True, text=True, timeout=timeout)
(BASE / ('rollout-custodian-' + label + '.json')).write_text(result.stdout)
(BASE / ('rollout-custodian-' + label + '.stderr.txt')).write_text(result.stderr)
assert result.returncode == 0, label + ' failed; receipt retained'
finally:
for name, entry in originals.items():
(ROOT / name).write_bytes((BACKUP / (name + '.worktree')).read_bytes())
mode, oid, stage, path = entry.split()
assert stage == '0'
git('update-index', '--cacheinfo', mode, oid, path)
assert git('ls-files', '--stage', '--', name).decode() == entry
assert all(hashlib.sha256((ROOT / name).read_bytes()).hexdigest() == pin for name, pin in other.items())
receipt = json.loads((BASE / 'rollout-custodian-projection.json').read_text())
assert receipt['status'] == 'applied'
print(json.dumps({'status': 'applied', 'commit': receipt['commit'], 'other_work_preserved': True}))