import json,pathlib,sys,shutil,tempfile,subprocess
# Usage: python run_local.py family.json spec.json traces.json method.py
family,spec,traces,method=sys.argv[1:5]
work=pathlib.Path(tempfile.mkdtemp(prefix="tfp-dynamics-")); inp=work/'input';out=work/'output';inp.mkdir();out.mkdir()
refs=[]
for key,src in [('family',family),('spec',spec),('traces',traces)]:
 shutil.copy(src,inp/(key+'.json'));refs.append({'key':key,'path':'/input/'+key+'.json'})
shutil.copy(method,inp/'method.py')
(inp/'manifest.json').write_text(json.dumps({'reference':refs,'artifacts':[{'role':'method','path':'/input/method.py'}]}))
image='docker.io/tokensforprogress/tfp-verifiers@sha256:22f9c832d5b6b0a624bf5205de33742786184613fe1e1dab89a0d73a0b6fce25'
subprocess.run(['docker','run','--rm','--platform','linux/amd64','--network','none','--cpus','4','--memory','12g','-v',str(inp)+':/input:ro','-v',str(out)+':/output','--entrypoint','python',image,'/checker/checker.py'],check=True,timeout=600)
print((out/'result.json').read_text());print('Evidence:',out/'evidence/summary.json')
