"""Usage: python3 run-comparison.py BASE_CHECKOUT HEAD_CHECKOUT OUTPUT_DIR.
Copy shell-count-scaling.mjs into apps/server of both installed checkouts first.
Runs sequentially with alternating side order to limit drift; output never contains checkout paths.
"""
import sys,subprocess,pathlib,datetime
base,head,out=sys.argv[1:]
out=pathlib.Path(out)/datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%SZ')
out.mkdir(parents=True)
for round in range(1,8):
    sides=[('base',base),('head',head)]
    if round%2==0: sides.reverse()
    for side,checkout in sides:
        sha=subprocess.check_output(['git','rev-parse','HEAD'],cwd=checkout,text=True).strip()
        with (out/f'{side}-{round}.log').open('w') as f:
            subprocess.run(['node','shell-count-scaling.mjs',str(round),sha],cwd=pathlib.Path(checkout)/'apps/server',stdout=f,stderr=subprocess.STDOUT,check=True)
        print(f'{side} round {round} complete',flush=True)
print(out.name)
