"""Synthetic fixture used for the OpenCode retry-warning comparison.
Run with: python3 seed-fixture.py WORKTREE FIXTURE_DIR OPENCODE_BINARY
Set OPENCODE_PASSWORD to the synthetic external OpenCode server password.
The dev server must use T3CODE_DEV_SEED=0 and its own .t3 home.
"""
import json, os, subprocess, sys
from pathlib import Path
worktree, fixture, binary = map(Path, sys.argv[1:])
config = fixture / "config"
config.mkdir(parents=True, exist_ok=True)
(config / "opencode.json").write_text(json.dumps({"providers": {"standin": {
 "name": "Stand-in", "package": "@ai-sdk/openai-compatible",
 "settings": {"baseURL": "http://127.0.0.1:19876/v1", "apiKey": "synthetic"},
 "models": {"limited-model": {"name": "Limited Model", "limit": {"context": 32000, "output": 1024}}}
}}}))
settings_file = worktree / ".t3/userdata/settings.json"
settings = json.loads(settings_file.read_text())
settings.setdefault("providerInstances", {})["opencode"] = {
 "driver": "opencode", "displayName": "OpenCode", "enabled": True,
 "config": {"enabled": True, "binaryPath": str(binary.resolve()),
 "serverUrl": "http://127.0.0.1:19877", "serverPassword": os.environ["OPENCODE_PASSWORD"]}}
settings_file.write_text(json.dumps(settings))
project = fixture / "retry-demo"
project.mkdir(exist_ok=True)
if not (project / ".git").exists():
 subprocess.run(["git", "init", "--initial-branch=main", str(project)], check=True)
 subprocess.run(["git", "-C", str(project), "-c", "user.name=Evidence", "-c", "user.email=evidence@example.invalid", "commit", "--allow-empty", "-m", "Synthetic reproduction workspace"], check=True)
subprocess.run(["node", "apps/server/src/bin.ts", "project", "add", str(project.resolve()), "--title", "Retry warning demo", "--base-dir", ".t3"], cwd=worktree, check=True)
