Skip to content

Commit 060ffe0

Browse files
test(server): add isolated PR handoff reproduction fixture
1 parent 89ae33f commit 060ffe0

3 files changed

Lines changed: 138 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"root": "/tmp/issue-16455-fixture",
3+
"projects": [
4+
{
5+
"id": "triage-16455-unrelated",
6+
"title": "unrelated",
7+
"directory": "unrelated",
8+
"origin": "https://github.com/octocat/Hello-World.git"
9+
},
10+
{
11+
"id": "triage-16455-app",
12+
"title": "app",
13+
"directory": "app",
14+
"origin": "https://github.com/octocat/Spoon-Knife.git"
15+
}
16+
],
17+
"thread": {
18+
"id": "triage-16455-app-thread",
19+
"projectId": "triage-16455-app",
20+
"title": "PR handoff reproduction",
21+
"branch": "master"
22+
},
23+
"pullRequest": {
24+
"host": "github.com",
25+
"repository": "pingdotgg/t3code",
26+
"number": 23184,
27+
"url": "https://github.com/pingdotgg/t3code/pull/23184"
28+
}
29+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Run in an authenticated isolated app tab; pass fixture.json and a live model selection.
2+
globalThis.seedIssue16455 = async function (fixture, modelSelection) {
3+
if (!modelSelection?.instanceId || !modelSelection?.model) {
4+
throw new Error(
5+
"Pass a valid model selection from this environment. No provider turn is started.",
6+
);
7+
}
8+
const response = await fetch("/api/orchestration/shell", {
9+
headers: { "x-t3-orchestration-protocol": "2" },
10+
});
11+
if (!response.ok) throw new Error(`Shell snapshot: HTTP ${response.status}`);
12+
const snapshot = await response.json();
13+
const socket = new WebSocket(
14+
`${location.origin.replace(/^http/, "ws")}/ws?orchestrationProtocol=2`,
15+
);
16+
await new Promise((resolve, reject) => {
17+
socket.addEventListener("open", resolve, { once: true });
18+
socket.addEventListener(
19+
"error",
20+
() => reject(new Error("Could not connect to the authenticated app socket")),
21+
{ once: true },
22+
);
23+
});
24+
let nextId = 1;
25+
const pending = new Map();
26+
socket.addEventListener("message", (event) => {
27+
const message = JSON.parse(event.data);
28+
if (message._tag === "Ping") {
29+
socket.send(JSON.stringify({ _tag: "Pong" }));
30+
return;
31+
}
32+
const entry = pending.get(String(message.requestId));
33+
if (!entry || message._tag !== "Exit") return;
34+
pending.delete(String(message.requestId));
35+
clearTimeout(entry.timeout);
36+
if (message.exit._tag === "Success") entry.resolve(message.exit.value);
37+
else entry.reject(new Error(JSON.stringify(message.exit)));
38+
});
39+
const rpc = (tag, payload) =>
40+
new Promise((resolve, reject) => {
41+
const id = String(nextId++);
42+
const timeout = setTimeout(() => {
43+
pending.delete(id);
44+
reject(new Error(`${tag} timed out`));
45+
}, 30000);
46+
pending.set(id, { resolve, reject, timeout });
47+
socket.send(JSON.stringify({ _tag: "Request", id, tag, payload, headers: [] }));
48+
});
49+
try {
50+
for (const project of fixture.projects) {
51+
if (!snapshot.projects.some((item) => item.id === project.id))
52+
await rpc("projects.mutate", {
53+
type: "project.create",
54+
commandId: crypto.randomUUID(),
55+
projectId: project.id,
56+
title: project.title,
57+
workspaceRoot: `${fixture.root}/${project.directory}`,
58+
});
59+
}
60+
if (!snapshot.threads.some((item) => item.id === fixture.thread.id))
61+
await rpc("orchestration.dispatchCommand", {
62+
type: "thread.create",
63+
commandId: crypto.randomUUID(),
64+
threadId: fixture.thread.id,
65+
projectId: fixture.thread.projectId,
66+
title: fixture.thread.title,
67+
modelSelection,
68+
runtimeMode: "full-access",
69+
interactionMode: "default",
70+
branch: fixture.thread.branch,
71+
worktreePath: null,
72+
createdBy: "user",
73+
creationSource: "web",
74+
});
75+
await rpc("orchestration.dispatchCommand", {
76+
type: "thread.pull-request.link",
77+
commandId: crypto.randomUUID(),
78+
threadId: fixture.thread.id,
79+
...fixture.pullRequest,
80+
source: "manual",
81+
});
82+
return { threadId: fixture.thread.id, pullRequest: fixture.pullRequest.url };
83+
} finally {
84+
socket.close();
85+
}
86+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
"""Create isolated repositories; refuse to overwrite an existing fixture."""
3+
import json, os, pathlib, subprocess, sys
4+
fixture = json.loads(pathlib.Path(__file__).with_name('fixture.json').read_text())
5+
root = pathlib.Path(sys.argv[1] if len(sys.argv) > 1 else fixture['root']).resolve()
6+
if not str(root).startswith('/tmp/'):
7+
raise SystemExit('Choose an isolated fixture root below /tmp.')
8+
paths = [root / project['directory'] for project in fixture['projects']]
9+
if any(path.exists() for path in paths):
10+
raise SystemExit('Fixture exists; refusing to overwrite it. Use a fresh root or restore a stopped snapshot.')
11+
for project, path in zip(fixture['projects'], paths):
12+
path.mkdir(parents=True)
13+
def git(*args):
14+
subprocess.run(['git', '-C', str(path), *args], check=True, stdout=subprocess.DEVNULL)
15+
git('init', '-b', 'master')
16+
git('config', 'user.name', 'T3 fixture')
17+
git('config', 'user.email', '[email protected]')
18+
(path / 'README.md').write_text('Isolated pull request checkout fixture.\n')
19+
git('add', 'README.md')
20+
subprocess.run(['git', '-C', str(path), 'commit', '-m', 'fixture'], check=True,
21+
stdout=subprocess.DEVNULL, env={**os.environ, 'GIT_AUTHOR_DATE':'2026-10-22T00:00:00Z', 'GIT_COMMITTER_DATE':'2026-10-22T00:00:00Z'})
22+
git('remote', 'add', 'origin', project['origin'])
23+
print(root)

0 commit comments

Comments
 (0)