import os, pathlib, subprocess, json, sys
checkout, output, port = sys.argv[1:]
workspace = pathlib.Path(output) / 'blank-line-review'
workspace.mkdir(parents=True)
source = 'function one() {\n  return 1;\n}\n\nfunction two() {\n  return 2;\n}\n'
(workspace / 'app.ts').write_text(source)
def git(*args): subprocess.run(['git', '-C', str(workspace), *args], check=True, capture_output=True)
git('init', '--quiet', '--initial-branch=main')
git('add', 'app.ts')
git('-c', 'user.name=Scenario', '-c', 'user.email=scenario@example.invalid', 'commit', '-qm', 'Initial commit')
env = dict(os.environ, T3CODE_PORT=port)
def cli(*args):
    return subprocess.check_output(['node', 'apps/server/src/bin.ts', *args, '--base-dir', checkout+'/.t3/proof'], cwd=checkout, env=env, text=True)
cli('project', 'add', str(workspace), '--title', 'Blank line review')
thread = json.loads(cli('thread', 'start', str(workspace), 'hello', '--title', 'Review blank lines', '--provider', 'devReplay', '--model', 'multi-turn', '--wait', '--json'))
(workspace / 'app.ts').write_text(source.replace('return 1;', 'return 11;  '))
(pathlib.Path(output) / 'thread.json').write_text(json.dumps(thread))
print(json.dumps(thread))
