"""Setup used for the real GitLab reproduction, parameterized for reruns.
Requires a real authenticated glab account and git HTTPS credentials.
Arguments: a unique temporary project name and an unused checkout directory.
After both runs, delete the temporary project through the GitLab API.
"""
import json
import pathlib
import subprocess
import sys

name, checkout = sys.argv[1:]
p = json.loads(subprocess.check_output([
    'glab', 'api', '--method', 'POST', 'projects', '-f', f'name={name}',
    '-f', 'visibility=private', '-f', 'initialize_with_readme=true'
]))
subprocess.run(['git', 'clone', p['http_url_to_repo'], checkout], check=True)
subprocess.run(['git', 'switch', '-c', 'feature/subtract'], cwd=checkout, check=True)
pathlib.Path(checkout, 'math.ts').write_text('export function subtract(a: number, b: number) {\n  return a - b;\n}\n')
for args in [
    ['git', 'add', 'math.ts'],
    ['git', '-c', 'user.name=Proof', '-c', 'user.email=proof@example.com', 'commit', '-m', 'Add subtract helper'],
    ['git', 'push', '-u', 'origin', 'feature/subtract'],
]:
    subprocess.run(args, cwd=checkout, check=True)
print(p['id'])
# For each app checkout, start T3CODE_DEV_SEED=0 vp run dev.
# Add the sample through: node apps/server/src/bin.ts project add <checkout>
#   --title 'Subtract helper' --base-dir .t3
# Seed one thread with: node apps/server/src/bin.ts thread start <checkout>
#   'Ready for merge request creation.' --title 'Subtract helper'
#   --provider devReplay --model command-output --base-dir .t3 --json
# Replay only establishes a thread. The MR writer remains default Codex gpt-6-luna.
# Pair the web client and follow browser-driver.js. Close the first MR before the
# second side so that the same source branch can create a new MR.
