the-custodian/docs/changes/netkingdom-target-2026-10-17/platform-current-source-integration-r1/apply_source.py

81 lines
4.3 KiB
Python
Raw Normal View History

"""Apply only independently reviewed owner source, using the normal allocator."""
from pathlib import Path
import hashlib
import json
import re
import subprocess
import sys
HERE = Path(__file__).resolve().parent
ROOT = Path('/home/worsch/railiance-platform')
PACKET = HERE.parent / 'platform-broker-followthrough-r1'
REVIEW = HERE.parent / 'platform-broker-review-r1/review.json'
NEW_PLAN = 'workplans/RPF-WP-0060-browser-case-platform-bindings.md'
BASE = '104ed90f42a9a86bf9fda343b49b65a85c9ee4b9'
def digest(raw):
return hashlib.sha256(raw).hexdigest()
def git(*args):
return subprocess.check_output(['git', '-C', str(ROOT), *args],
stderr=subprocess.PIPE, timeout=40).decode().strip()
assert git('rev-parse', 'HEAD') == BASE
assert git('ls-remote', 'origin', 'refs/heads/main').split()[0] == BASE
assert digest(REVIEW.read_bytes()) == '05d5bf9c2b90a8562ce4675866b8b23c0e12d5d069b43b194948d384b0a553f5'
review = json.loads(REVIEW.read_text())
assert review['source_integration_verdict'] == 'accept'
assert review['t1_complete'] is False
manifest = json.loads((PACKET / 'manifest.json').read_text())
assert digest((PACKET / 'platform-source.patch').read_bytes()) == review['candidate_patch_sha256']
assert {r['path']: r['output_sha256'] for r in manifest['files']} == {
r['path']: r['sha256'] for r in review['reviewed_outputs']}
for row in manifest['files']:
assert digest((ROOT / row['path']).read_bytes()) == row['input_sha256']
assert digest((PACKET / 'candidate' / row['path']).read_bytes()) == row['output_sha256']
assert not (ROOT / NEW_PLAN).exists()
old_plans = {str(p.relative_to(ROOT)): digest(p.read_bytes()) for p in (ROOT / 'workplans').rglob('*.md')}
assert not any(re.search(r'^id:\s*RPF-WP-0060\s*$', (ROOT / p).read_text(), re.M) for p in old_plans)
dirty = git('diff', '--name-only').splitlines()
staged = git('diff', '--cached', '--name-only').splitlines()
assert set(dirty + staged) == {'.custodian-brief.md', 'WORK-RECORDS.md'}
originals = {p: {'worktree': digest((ROOT / p).read_bytes()), 'index': git('ls-files', '--stage', '--', p)}
for p in set(dirty + staged)}
sys.path.insert(0, '/home/worsch/repo-manager/src')
from repo_manager.identifiers import ensure_missing_work_record_identifiers
preview = ensure_missing_work_record_identifiers(ROOT, execute=False)
assert preview['ok'] and not preview['assignments'] and not preview['files_changed']
for row in manifest['files']:
(ROOT / row['path']).write_bytes((PACKET / 'candidate' / row['path']).read_bytes())
(ROOT / NEW_PLAN).write_bytes((HERE / 'workplan.md').read_bytes())
preview = ensure_missing_work_record_identifiers(ROOT, execute=False)
(HERE / 'identifier-preview.json').write_text(json.dumps(preview, indent=2) + '\n')
assert preview['ok'] and preview['files_changed'] == [NEW_PLAN]
assert len(preview['assignments']) == 5
assigned = ensure_missing_work_record_identifiers(ROOT, execute=True)
(HERE / 'identifier-assignment.json').write_text(json.dumps(assigned, indent=2) + '\n')
assert assigned['ok'] and assigned['files_changed'] == [NEW_PLAN]
for p, value in old_plans.items():
assert digest((ROOT / p).read_bytes()) == value
for p, value in originals.items():
assert digest((ROOT / p).read_bytes()) == value['worktree']
assert git('ls-files', '--stage', '--', p) == value['index']
files = [dict(path=row['path'], sha256=row['output_sha256']) for row in manifest['files']]
files.append(dict(path=NEW_PLAN, sha256=digest((ROOT / NEW_PLAN).read_bytes())))
cfg = {'owner': 'railiance-platform', 'base_revision': BASE,
'message': 'Bind mint broker validation to exact reviewed sources and track successor obligations',
'files': files}
(HERE / 'publication-inputs.json').write_text(json.dumps(cfg, indent=2) + '\n')
(HERE / 'source-application.json').write_text(json.dumps({
'base': BASE, 'review_sha256': 'sha256:' + digest(REVIEW.read_bytes()),
'files': files, 'existing_workplans_preserved': len(old_plans),
'unrelated_state': originals, 'native_actions': False,
'tasks': {'RPF-WP-0060-T01': 'progress', 'RPF-WP-0060-T02': 'done',
'RPF-WP-0060-T03': 'todo', 'RPF-WP-0060-T04': 'todo'}}, indent=2) + '\n')
print(json.dumps({'status': 'applied_source_only', 'files': len(files),
'normal_allocator_assignments': len(assigned['assignments']),
'existing_workplans_preserved': len(old_plans)}))