#!/usr/bin/env python3
"""Synthetic fixture used for both commits. Start T3 with T3CODE_DEV_SEED=0 vp run dev first.
Usage: python3 reproduce.py CHECKOUT PROJECT_DIR
Requires cc, git, and the checkout's installed dependencies.
"""
FORGE_SOURCE = '#include <stdio.h>\n#include <time.h>\nint main(){ long start=0; FILE*f=fopen(".ci-start","r"); if(f){fscanf(f,"%ld",&start);fclose(f);}else{start=time(NULL); f=fopen(".ci-start","w");fprintf(f,"%ld",start);fclose(f);}puts(time(NULL)-start<40?"checks running":"all checks passed");return 0;}\n'
PROMPT = "I pushed this branch and opened PR https://forge.acme.internal/acme/app/pull/7 on our self-hosted forge. Monitor its CI and continue development once checks finish: our forge's CLI for CI status is ./ci-status.sh. When checks pass, run ./next-step.sh."
from pathlib import Path
import subprocess, sys, time
checkout=Path(sys.argv[1]).resolve()
project=Path(sys.argv[2]).resolve()
project.mkdir(parents=True)
source=project.parent / (project.name + "-forge.c")
source.write_text(FORGE_SOURCE)
subprocess.run(["cc",str(source),"-o",str(project/"forge")],check=True)
(project/"ci-status.sh").write_text('#!/bin/sh\ncd "$(dirname "$0")"\nexec ./forge pr checks 7\n')
(project/"next-step.sh").write_text('#!/bin/sh\necho continued > workflow-completed\necho "Development continued: workflow-completed written"\n')
(project/".gitignore").write_text('.ci-start\nworkflow-completed\n')
for name in ["ci-status.sh","next-step.sh"]:(project/name).chmod(0o755)
subprocess.run(["git","init","-q","-b","feature/ci-workflow",str(project)],check=True)
subprocess.run(["git","-C",str(project),"remote","add","origin","https://forge.acme.internal/acme/app.git"],check=True)
subprocess.run(["git","-C",str(project),"add","."],check=True)
subprocess.run(["git","-C",str(project),"-c","user.name=Fixture","-c","user.email=fixture@example.com","commit","-qm","Add CI workflow helpers"],check=True)
def cli(args):
 return subprocess.run(["node","src/bin.ts",*args,"--base-dir",str(checkout/".t3")],cwd=checkout/"apps/server",text=True,check=True,capture_output=True)
print(cli(["project","add","--title","Acme application",str(project)]).stdout)
result=cli(["thread","start","--provider","claudeAgent","--model","claude-haiku-5-5","--title","Monitor custom forge CI","--wait",str(project),PROMPT])
print(result.stdout)
# Background shell completion wakes the agent after the initial turn ends.
time.sleep(90)
print("workflow-completed exists:", (project/"workflow-completed").exists())
