import os, pathlib, subprocess, sys, time
head, base, scratch = map(pathlib.Path, sys.argv[1:4])
stamp = time.strftime('%Y%m%d-%H%M%S')
for launcher in (sys.argv[4:] or ('absent', 'apple')):
    for side, checkout in (('base', base), ('head', head)):
        name = f'{stamp}-{side}-{launcher}'
        env = dict(os.environ, T3CODE_DEV_SEED='0', T3_SCENARIO_APP_DIR=str(checkout), EVIDENCE_LAUNCHER=launcher)
        env.pop('TERM_PROGRAM', None)
        env.pop('TERM_PROGRAM_VERSION', None)
        with open(scratch / f'{name}.log', 'w') as log:
            result = subprocess.run(['vp', 'exec', 'e2e', 'run', 'scenarios/terminal-identity.e2e.ts', '--target', 'web', '--output', f'.e2e/{name}'], cwd=head / 'scripts', env=env, stdout=log, stderr=subprocess.STDOUT)
        print(name, result.returncode, flush=True)
