the-custodian/docs/changes/netkingdom-target-2026-10-18/forgejo-postgres-source-r1/owner-integration/apply_source.py

49 lines
2.7 KiB
Python
Raw Normal View History

"""Apply the tested build candidate, preserving every unrelated owner file."""
from pathlib import Path
import hashlib
import json
import re
import subprocess
HERE = Path(__file__).resolve().parent
ROOT = Path('/home/worsch/railiance-apps')
cfg = json.loads((HERE / 'source-manifest.json').read_text())
sha = lambda data: hashlib.sha256(data).hexdigest()
def git(*args):
return subprocess.check_output(['git', '-C', str(ROOT), *args], text=True).strip()
assert git('rev-parse', 'HEAD') == cfg['base_revision']
assert git('ls-remote', 'origin', 'refs/heads/main').split()[0] == cfg['base_revision']
assert set(git('diff', '--name-only', 'HEAD').splitlines()) <= {'.custodian-brief.md', 'WORK-RECORDS.md'}
tracked = git('ls-files').splitlines()
protected = {name: sha((ROOT / name).read_bytes()) for name in tracked
if (ROOT / name).is_file() and name not in {row['path'] for row in cfg['files']}}
index = git('ls-files', '--stage', '--', '.custodian-brief.md', 'WORK-RECORDS.md')
plan = 'workplans/RAPPS-WP-0016-forgejo-netkingdom-login.md'
before = re.findall(r'```task\n.*?```', (ROOT / plan).read_text(), re.S)
assert len(before) == 9
for row in cfg['files']:
current = ROOT / row['path']
if row['before_sha256'] is None:
assert not current.exists(), row['path']
else:
assert sha(current.read_bytes()) == row['before_sha256'], row['path']
assert sha(Path(row['source']).read_bytes()) == row['sha256'], row['path']
for row in cfg['files']:
target = ROOT / row['path']
target.parent.mkdir(parents=True, exist_ok=True)
target.write_bytes(Path(row['source']).read_bytes())
after = re.findall(r'```task\n.*?```', (ROOT / plan).read_text(), re.S)
assert before == after
assert all(sha((ROOT / name).read_bytes()) == value for name, value in protected.items())
assert git('ls-files', '--stage', '--', '.custodian-brief.md', 'WORK-RECORDS.md') == index
receipt = dict(owner=cfg['owner'], base_revision='git:' + cfg['base_revision'],
files=cfg['files'], preserved_other_tracked_files=len(protected),
original_task_uuids_preserved=9, status_change=None,
native_actions=False, independent_owner_review=False, operational_admission=False)
(HERE / 'source-application.json').write_text(json.dumps(receipt, indent=2) + '\n')
publication = dict(owner=cfg['owner'], base_revision=cfg['base_revision'],
message='Verify Forgejo PostgreSQL operations and preserve tracing hook context',
files=[dict(path=row['path'], sha256=row['sha256']) for row in cfg['files']])
(HERE / 'publication-inputs.json').write_text(json.dumps(publication, indent=2) + '\n')
print(json.dumps(dict(status='source_applied', files=len(cfg['files']), native_actions=False)))