# Usage: python3 reproduce.py OUTPUT_DIRECTORY BASE_CHECKOUT HEAD_CHECKOUT
import subprocess,pathlib,datetime,sys
root=pathlib.Path(sys.argv[1])
out=root/datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%SZ');out.mkdir()
for side in ['head','base']:
    cwd=pathlib.Path(sys.argv[2] if side=='base' else sys.argv[3]).resolve()
    lines=['Environment: Linux, Node '+subprocess.check_output(['node','--version'],text=True).strip()+', authenticated GitHub, real network reads; no seeded database.']
    for flags in [[],['--repeats=1'],['--repeats=3'],['--repeats=2'],['--repeats=0']]:
        cmd=['node','packages/source-control-github/scripts/measure-pr-preview.ts','pingdotgg/t3code','39660']+flags
        lines.append('\n$ '+' '.join(cmd))
        run=subprocess.run(cmd,cwd=cwd,text=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,timeout=180)
        output=run.stdout.replace(str(cwd),'<checkout>').replace(str(pathlib.Path.home()),'<home>')
        lines.extend([output,'Exit: '+str(run.returncode)])
        print(side,flags,'exit',run.returncode,flush=True)
    (out/(side+'.txt')).write_text('\n'.join(lines))
print(out)
