import pathlib,subprocess,json,urllib.request,uuid,sys
root=pathlib.Path(sys.argv[1]); port=sys.argv[2]; tokenfile=sys.argv[3]
token=pathlib.Path(tokenfile).read_text().strip()
for n in range(100):
 p=root/'.t3'/'synthetic'/f'repo-{n}'; p.mkdir(parents=True,exist_ok=True)
 subprocess.run(['git','init','-q','-b','main',str(p)],check=True)
 subprocess.run(['git','-C',str(p),'remote','add','origin',f'https://github.com/perf-example/repo-{n}.git'],check=True)
 payload={'type':'project.create','commandId':str(uuid.uuid4()),'projectId':f'perf-project-{n}','title':f'Benchmark {n}','workspaceRoot':str(p)}
 req=urllib.request.Request(f'http://127.0.0.1:{port}/api/projects/mutate',data=json.dumps(payload).encode(),headers={'Authorization':f'Bearer {token}','Content-Type':'application/json'})
 try:
  with urllib.request.urlopen(req) as res: data=json.load(res)
 except urllib.error.HTTPError as e: print(e.read().decode()); raise
 if n in [0,99]: print(n,json.dumps(data)[:1000])
