"""Apply independently reviewed Approval adapter and Access B1 R2 source.""" import integrate_source_wave5 as integration import hashlib import json from pathlib import Path import subprocess from datetime import datetime, timezone integration.TARGETS = ( ('approval-engine', 'approval-go-fact', 'implementation.patch', '096de94db8afff6b429215d951a98b94cd501cc6a7e1c374420e546169df2179', 'eece796b8bbee19551f6aa07ad389cbf83cabcdb', 'manifest.json', 'files'), ('access-engine', 'access-native-source/b1', 'b1-r2-over-native-prep-r2.patch', '8880eb0f693f6793cfa6b3ea6f2466dbe67313e521a7f79c30180ca4880609b9', '919ce25a377300ef9749c85e41b608467bed02ad', 'manifest-r2.json', 'source_files_sha256'), ) def main(): prepared = [] wp = 'workplans/FLEX-WP-0024-decision-envelope-authenticity.md' managed = {'FLEX-WP-0024-T05': 'cfe4d275-9f02-5090-8391-06eea59d45c5', 'FLEX-WP-0024-T06': '7f785b52-bf62-5884-8d34-670d70bc9023'} for repo, part, filename, patch_hash, head, manifest_name, key in integration.TARGETS: owner, folder = Path('/home/worsch') / repo, integration.ROOT / part patch = folder / filename assert not (folder / 'canonical-integration.json').exists() assert integration.digest(patch) == patch_hash assert subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=owner, text=True).strip() == head files = json.loads((folder / manifest_name).read_text())[key] before = {name: integration.digest(owner / name) for name in files} for name in files: tracked = subprocess.run(['git', 'ls-files', '--error-unmatch', name], cwd=owner, capture_output=True).returncode == 0 assert tracked or not (owner / name).exists(), name if tracked: original = subprocess.check_output(['git', 'show', 'HEAD:' + name], cwd=owner) current = (owner / name).read_bytes() if repo == 'access-engine' and name == wp: without_ids = current for value in managed.values(): line = f'state_hub_task_id: "{value}"\n'.encode() assert without_ids.count(line) == 1 without_ids = without_ids.replace(line, b'') assert without_ids == original, 'only verified registrar IDs may differ' source = Path('/tmp/netkingdom-target-root-review/access-b1') / name reviewed = source.read_bytes() assert hashlib.sha256(reviewed).hexdigest() == files[name] for task, value in managed.items(): anchor = ('id: ' + task + '\nstatus: ' + ('done' if task.endswith('T05') else 'progress') + '\npriority: high\n').encode() assert reviewed.count(anchor) == 1 reviewed = reviewed.replace(anchor, anchor + f'state_hub_task_id: "{value}"\n'.encode()) files[name] = hashlib.sha256(reviewed).hexdigest() else: assert current == original, name subprocess.run(['git', 'apply', '--check', str(patch)], cwd=owner, check=True) prepared.append((repo, owner, folder, patch, patch_hash, head, before, files)) for repo, owner, folder, patch, patch_hash, head, before, files in prepared: assert subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=owner, text=True).strip() == head assert all(integration.digest(owner / name) == value for name, value in before.items()) subprocess.run(['git', 'apply', str(patch)], cwd=owner, check=True) assert all(integration.digest(owner / name) == value for name, value in files.items()) receipt = {'repo': repo, 'base_commit': head, 'patch_sha256': 'sha256:' + patch_hash, 'integrated_at': datetime.now(timezone.utc).isoformat(), 'files_sha256': {name: 'sha256:' + value for name, value in files.items()}, 'source_integrated': True, 'committed': False, 'published': False, 'native_accepted': False, 'preserved_registrar_ids': managed if repo == 'access-engine' else {}} (folder / 'canonical-integration.json').write_text(json.dumps(receipt, indent=2) + '\n') print(repo, 'reviewed source integrated; native acceptance unchanged') if __name__ == '__main__': main()