#!/usr/bin/env bash
set -euo pipefail
# Run from the app checkout with a fresh T3CODE_DEV_SEED=0 dev server.
# Arguments: synthetic workspace parent, isolated T3 home, model selection.
workspace=$(realpath "$1")
t3_home=$(realpath "$2")
selection=$3
mkdir -p "$workspace/projA" "$workspace/projB"
for project in projA projB; do
  git -C "$workspace/$project" init -q
  git -C "$workspace/$project" -c user.name=Example -c user.email=example@example.invalid commit --allow-empty -qm initial
  node apps/server/src/bin.ts project add "$workspace/$project" --base-dir "$t3_home"
done
node apps/server/src/bin.ts thread start "$workspace/projA" 'Reply with the word ok.' --title 'Session setup' --provider codex --model "$selection" --wait --base-dir "$t3_home" --json
node apps/server/src/bin.ts thread start "$workspace/projB" 'Run the shell command sleep 240 and when it finishes reply with the word done.' --title 'Worktree running turn' --provider codex --model "$selection" --worktree HEAD --branch b2 --base-dir "$t3_home" --json
# In the paired web client, open Worktree running turn while Running sleep is visible.
# Open the model picker and click Standard (Fast is initially selected).
# Base: Run interrupted / Stopped by the provider. Head: keeps running.
# On head, also click Fast again; the turn still runs and eventually replies done.
