Open History to see the last commit
1import { EMPTY_V2_ITEM_SUPPORT } from "@t3tools/client-runtime/state/item-support";
2import {
3 CheckpointId,
4 CheckpointScopeId,
5 NodeId,
6 ProviderDriverKind,
7 ProviderInstanceId,
8 RunId,
9 ThreadId,
10 TurnItemId,
11 type OrchestrationV2ProjectedTurnItem,
12 type OrchestrationV2TurnItem,
13} from "@t3tools/contracts";
14import * as DateTime from "effect/DateTime";
15import { describe, expect, it } from "vite-plus/test";
16
17import { buildThreadFeed, type ThreadFeedActivity } from "./threadActivity";
18import { buildThreadActivityInspector } from "./threadActivityInspector";
19
20const threadId = ThreadId.make("thread-1");
21const sourceThreadId = ThreadId.make("thread-source");
22const runId = RunId.make("run-1");
23const nodeId = NodeId.make("node-1");
24const startedAt = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z");
25const completedAt = DateTime.makeUnsafe("2026-06-20T00:00:02.000Z");
26
27function itemBase(id: string) {
28 return {
29 id: TurnItemId.make(id),
30 threadId,
31 runId,
32 nodeId,
33 providerThreadId: null,
34 providerTurnId: null,
35 nativeItemRef: null,
36 parentItemId: null,
37 ordinal: 0,
38 status: "completed" as const,
39 title: null,
40 startedAt,
41 completedAt,
42 updatedAt: completedAt,
43 };
44}
45
46function activityFor(item: OrchestrationV2TurnItem): ThreadFeedActivity {
47 const row: OrchestrationV2ProjectedTurnItem = {
48 position: 0,
49 visibility: "inherited",
50 sourceThreadId,
51 sourceItemId: item.id,
52 item,
53 };
54 const group = buildThreadFeed([row])[0];
55 if (group?.type !== "activity-group" || !group.activities[0]) {
56 throw new Error("Expected an activity group");
57 }
58 return group.activities[0];
59}
60
61describe("buildThreadActivityInspector", () => {
62 it("presents command lifecycle, execution support, output, and exit state", () => {
63 const item: OrchestrationV2TurnItem = {
64 ...itemBase("command"),
65 type: "command_execution",
66 input: "vp check",
67 output: "all checks passed",
68 exitCode: 0,
69 };
70 const support = {
71 ...EMPTY_V2_ITEM_SUPPORT,
72 item,
73 run: { status: "completed" } as never,
74 attempts: [
75 {
76 id: "attempt-1",
77 attemptOrdinal: 1,
78 status: "superseded",
79 reason: "initial",
80 },
81 {
82 id: "attempt-2",
83 attemptOrdinal: 2,
84 status: "completed",
85 reason: "steering_restart",
86 },
87 ] as never,
88 node: { kind: "tool_call", status: "completed" } as never,
89 providerSession: {
90 status: "ready",
91 model: "gpt-5.4",
92 cwd: "/workspace/project",
93 } as never,
94 };
95
96 const model = buildThreadActivityInspector(activityFor(item), support);
97 expect(model.fields).toEqual(
98 expect.arrayContaining([
99 { label: "Duration", value: "2.0s" },
100 { label: "Run", value: "completed" },
101 { label: "Working directory", value: "/workspace/project" },
102 { label: "Visibility", value: "inherited" },
103 ]),
104 );
105 expect(model.blocks).toEqual(
106 expect.arrayContaining([
107 expect.objectContaining({ label: "Command", value: "vp check" }),
108 expect.objectContaining({ label: "Output", value: "all checks passed" }),
109 expect.objectContaining({ label: "Exit", value: "Process exited with code 0" }),
110 expect.objectContaining({ label: "Attempt history" }),
111 ]),
112 );
113 });
114
115 it("exposes file and web result provenance plus dynamic structured data", () => {
116 const fileSearch: OrchestrationV2TurnItem = {
117 ...itemBase("file-search"),
118 type: "file_search",
119 pattern: "resolveSession",
120 results: [{ fileName: "src/session.ts", line: 42, preview: "function resolveSession()" }],
121 };
122 const fileModel = buildThreadActivityInspector(activityFor(fileSearch), EMPTY_V2_ITEM_SUPPORT);
123 expect(fileModel.fileLinks).toEqual([
124 {
125 label: "src/session.ts — function resolveSession()",
126 path: "src/session.ts",
127 line: 42,
128 },
129 ]);
130
131 const webSearch: OrchestrationV2TurnItem = {
132 ...itemBase("web-search"),
133 type: "web_search",
134 patterns: ["Effect Schema docs"],
135 results: [
136 { title: "Schema", url: "https://effect.website/docs/schema", snippet: "Typed schemas" },
137 ],
138 };
139 const webModel = buildThreadActivityInspector(activityFor(webSearch), EMPTY_V2_ITEM_SUPPORT);
140 expect(webModel.webLinks).toEqual([
141 { label: "Schema", url: "https://effect.website/docs/schema" },
142 ]);
143 expect(webModel.blocks).toEqual(
144 expect.arrayContaining([
145 expect.objectContaining({ label: "Schema", value: "Typed schemas" }),
146 ]),
147 );
148
149 const dynamicTool: OrchestrationV2TurnItem = {
150 ...itemBase("dynamic"),
151 type: "dynamic_tool",
152 toolName: "custom",
153 input: { nested: { value: 1 } },
154 output: { ok: true },
155 };
156 const dynamicModel = buildThreadActivityInspector(
157 activityFor(dynamicTool),
158 EMPTY_V2_ITEM_SUPPORT,
159 );
160 expect(dynamicModel.blocks).toEqual(
161 expect.arrayContaining([
162 expect.objectContaining({ label: "Input", value: expect.stringContaining('"nested"') }),
163 expect.objectContaining({ label: "Output", value: expect.stringContaining('"ok"') }),
164 ]),
165 );
166 expect(dynamicModel.structuredDetails).toContain('"type": "dynamic_tool"');
167 });
168
169 it("enables rollback only for the matching ready checkpoint", () => {
170 const checkpointId = CheckpointId.make("checkpoint-1");
171 const scopeId = CheckpointScopeId.make("scope-1");
172 const item: OrchestrationV2TurnItem = {
173 ...itemBase("checkpoint"),
174 type: "checkpoint",
175 checkpointId,
176 scopeId,
177 files: [{ path: "src/main.ts", kind: "modified", additions: 2, deletions: 1 }],
178 };
179 const checkpoint = { id: checkpointId, scopeId, status: "ready" } as never;
180 const model = buildThreadActivityInspector(activityFor(item), {
181 ...EMPTY_V2_ITEM_SUPPORT,
182 item,
183 checkpoint,
184 });
185
186 expect(model.canRollback).toBe(true);
187 expect(model.rollbackTarget).toEqual({
188 threadId: sourceThreadId,
189 checkpointId,
190 scopeId,
191 });
192 });
193
194 it("prefers live subagent progress from supporting state", () => {
195 const item: OrchestrationV2TurnItem = {
196 ...itemBase("subagent"),
197 type: "subagent",
198 subagentId: nodeId,
199 origin: "provider_native",
200 driver: ProviderDriverKind.make("claude"),
201 providerInstanceId: ProviderInstanceId.make("claude"),
202 childThreadId: null,
203 prompt: "Audit the reducer",
204 progress: "Starting",
205 result: null,
206 };
207 const model = buildThreadActivityInspector(activityFor(item), {
208 ...EMPTY_V2_ITEM_SUPPORT,
209 item,
210 subagent: {
211 origin: "provider_native",
212 status: "running",
213 progress: "Reading projection tests",
214 result: null,
215 } as never,
216 });
217
218 expect(model.fields).toContainEqual({
219 label: "Delegated task",
220 value: "provider native · running",
221 });
222 expect(model.blocks).toContainEqual({
223 label: "Progress",
224 value: "Reading projection tests",
225 monospaced: false,
226 });
227 });
228});