#!/usr/bin/env python3 """Portable materializer for the unchanged adopted SQLC native runner. The exact original source/metadata inventories remain server evidence. This entry creates them from the immutable agent snapshot, verifies pinned base commits and declared fixture/gold hashes, and executes the original driver. It does not download, change test assertions, or copy generated answers. """ import argparse import hashlib import json import os from pathlib import Path import shutil import subprocess def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest() def main(): cli=argparse.ArgumentParser();cli.add_argument('--world',choices=['all_buggy','all_fixed'],required=True);cli.add_argument('--output',required=True);args=cli.parse_args() package=Path(__file__).resolve().parent;profile=json.loads((package/'native-profile.json').read_text()) output=Path(args.output);assert not output.exists();output.mkdir() proposal=Path('/proposal');assert not proposal.exists();proposal.mkdir() for name in ['run_world.py','parse_native_events.py']: assert sha(package/name)==profile['files'][name]['sha256'];shutil.copy2(package/name,proposal/name) shutil.copytree(package/'fixtures',proposal/'fixtures') for rel,item in profile['files'].items(): if rel.startswith('fixtures/'):assert sha(proposal/rel)==item['sha256'] inp=Path('/frozen-instance');task=json.loads((inp/'task.json').read_text());assert sha(inp/'task.json')==profile['task_sha256'] patches=proposal/'public-production-patches';patches.mkdir();baselines={} for repo in task['repositories']: root=Path(repo['container_path']);assert subprocess.check_output(['git','-C',str(root),'rev-parse','HEAD'],text=True).strip()==repo['base_commit'] assert not subprocess.check_output(['git','-C',str(root),'status','--porcelain=v1','--untracked-files=all']) source=proposal/'public-base-source'/repo['key'];source.parent.mkdir(exist_ok=True) shutil.copytree(root,source,symlinks=True,ignore=shutil.ignore_patterns('.git')) baselines[repo['key']]={'base':repo['base_commit'],'files':{str(p.relative_to(source)):sha(p)for p in sorted(source.rglob('*'))if p.is_file()},'symlinks':{str(p.relative_to(source)):os.readlink(p)for p in sorted(source.rglob('*'))if p.is_symlink()}} gold=inp/repo['gold_patch']['path'];assert sha(gold)==repo['gold_patch']['sha256'] # The declared native protocol retains exact production blocks from full gold. import re chunks=re.split(r'(?=^diff --git )',gold.read_text(),flags=re.M) kept=[] for chunk in chunks: if not chunk.startswith('diff --git '):continue path=re.search(r'^diff --git a/(.*?) b/',chunk,re.M)[1] if not(path.endswith('_test.go')or'/testdata/'in path):kept.append(chunk) p=patches/(repo['key']+'.patch');p.write_text(''.join(kept));assert sha(p)==profile['production_projection_hashes'][repo['key']] public=proposal/'public-inputs';public.mkdir();(public/'baseline-source-manifest.json').write_text(json.dumps(baselines,sort_keys=True)+'\n') # The unchanged runner checks ordinary dependencies against this accepted # snapshot. No host dependency mount or candidate module substitution occurs. (proposal/'required-module-source').symlink_to('/go/pkg/mod',target_is_directory=True) metadata={str(p.relative_to('/go/pkg/mod')):p.read_text()for p in Path('/go/pkg/mod').rglob('*.mod')if p.is_file()} index=proposal/'module-cache-source-index-r1';index.mkdir();(index/'module-source-index.json').write_text(json.dumps({'module_metadata':metadata})+'\n') command=['python3',str(proposal/'run_world.py'),'--world','all_buggy'if args.world=='all_buggy'else'all_public_gold','--output-root',str(output/'native')] subprocess.run(command,check=True) report=json.loads((output/'native/evidence/report.json').read_text());assert report['status']=='EVIDENCE_COMPLETE_ROOT_CLASSIFICATION_REQUIRED' print(json.dumps({'state':'NATIVE_EVIDENCE_COLLECTED_REVIEW_ORIGINAL_RUNTIME_CASES','world':args.world,'output':str(output),'immutable_snapshot_dependency_materialization':True,'test_assertions_changed':False}),flush=True) if __name__=='__main__':main()