Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

pending-thread-creation.test.ts

140 lines3.7 KB

1import {
2 CommandId,
3 EnvironmentId,
4 MessageId,
5 ProjectId,
6 ProviderInstanceId,
7 ThreadId,
8} from "@t3tools/contracts";
9import { describe, expect, it } from "vite-plus/test";
10​
11import {
12 resolvePendingThreadCreation,
13 type PendingThreadCreation,
14} from "./pending-thread-creation";
15import type { QueuedThreadMessage } from "./thread-outbox-model";
16​
17const creation: QueuedThreadMessage = {
18 environmentId: EnvironmentId.make("environment-1"),
19 threadId: ThreadId.make("thread-1"),
20 messageId: MessageId.make("message-1"),
21 commandId: CommandId.make("command-1"),
22 text: "Fix the flaky login test",
23 attachments: [
24 {
25 id: "draft-image",
26 type: "image",
27 name: "screen.png",
28 mimeType: "image/png",
29 sizeBytes: 10,
30 previewUri: "data:image/png;base64,AAAA",
31 },
32 ],
33 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol" },
34 runtimeMode: "full-access",
35 creation: {
36 projectId: ProjectId.make("project-1"),
37 workspaceMode: "worktree",
38 branch: "main",
39 worktreePath: null,
40 },
41 createdAt: "2026-08-24T12:00:00.000Z",
42};
43​
44describe("resolvePendingThreadCreation", () => {
45 const threadKey = `${creation.environmentId}:${creation.threadId}`;
46 const pending: PendingThreadCreation = { message: creation, outcome: null };
47 const prompt = { id: creation.messageId };
48​
49 it("keeps setup visible through the prompt echo and shell cleanup until detail has a turn", () => {
50 let previous = resolvePendingThreadCreation({
51 threadKey,
52 pending,
53 previous: null,
54 detail: null,
55 });
56 expect(previous).toBe(pending);
57​
58 previous = resolvePendingThreadCreation({
59 threadKey,
60 pending,
61 previous,
62 detail: { messages: [], latestTurn: null, session: null },
63 });
64 expect(previous).toBe(pending);
65​
66 previous = resolvePendingThreadCreation({
67 threadKey,
68 pending,
69 previous,
70 detail: { messages: [prompt], latestTurn: null, session: { status: "starting" } },
71 });
72 expect(previous).toBe(pending);
73​
74 previous = resolvePendingThreadCreation({
75 threadKey,
76 pending: null,
77 previous,
78 detail: { messages: [prompt], latestTurn: null, session: { status: "starting" } },
79 });
80 expect(previous).toBe(pending);
81​
82 expect(
83 resolvePendingThreadCreation({
84 threadKey,
85 pending: null,
86 previous,
87 detail: {
88 messages: [prompt],
89 latestTurn: { turnId: "turn-1" },
90 session: { status: "running" },
91 },
92 }),
93 ).toBeNull();
94 });
95​
96 it("keeps the prompt until both the turn and its message have arrived", () => {
97 expect(
98 resolvePendingThreadCreation({
99 threadKey,
100 pending,
101 previous: null,
102 detail: { messages: [], latestTurn: { turnId: "turn-1" }, session: { status: "running" } },
103 }),
104 ).toBe(pending);
105 });
106​
107 it("preserves rejected task recovery", () => {
108 const failed: PendingThreadCreation = {
109 message: creation,
110 outcome: { kind: "failed", message: creation, reason: "Checkout failed" },
111 };
112 expect(
113 resolvePendingThreadCreation({
114 threadKey,
115 pending: failed,
116 previous: pending,
117 detail: { messages: [], latestTurn: null, session: { status: "error" } },
118 }),
119 ).toBe(failed);
120 });
121​
122 it("does not carry setup into another thread or invent it for existing threads", () => {
123 expect(
124 resolvePendingThreadCreation({
125 threadKey: "another-thread",
126 pending: null,
127 previous: pending,
128 detail: null,
129 }),
130 ).toBeNull();
131 expect(
132 resolvePendingThreadCreation({
133 threadKey,
134 pending: null,
135 previous: null,
136 detail: null,
137 }),
138 ).toBeNull();
139 });
140});