import os, pathlib, subprocess, sys
home, port = sys.argv[1:]
def run(*args):
    return subprocess.run(args, check=True, capture_output=True, text=True, env={**os.environ, 'T3CODE_PORT': port}).stdout
for name in ('alpha', 'beta'):
    p = pathlib.Path(home) / 'workspaces' / name
    p.mkdir(parents=True, exist_ok=True)
    (p / 'README.md').write_text(name + '\n')
    run('git', '-C', str(p), 'init', '-q', '-b', 'main')
    run('git', '-C', str(p), 'add', '.')
    run('git', '-C', str(p), '-c', 'user.name=Scenario', '-c', 'user.email=scenario@example.invalid', 'commit', '-qm', 'Initial commit')
    run('node', 'apps/server/src/bin.ts', 'project', 'add', str(p), '--title', name, '--base-dir', home)
print('Created alpha and beta')
