Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 EventId,
5 ProjectId,
6 ProviderInstanceId,
7 ThreadId,
8 TurnId,
9 type OrchestrationThread,
10 type OrchestrationThreadActivity,
11} from "@t3tools/contracts";
12
13import { buildThreadFeed } from "./threadActivity";
14
15function makeActivity(
16 input: Partial<OrchestrationThreadActivity> &
17 Pick<OrchestrationThreadActivity, "id" | "kind" | "summary" | "createdAt">,
18): OrchestrationThreadActivity {
19 return {
20 tone: "info",
21 payload: {},
22 turnId: null,
23 ...input,
24 };
25}
26
27function makeThread(
28 input: Partial<OrchestrationThread> & Pick<OrchestrationThread, "id" | "projectId" | "title">,
29): OrchestrationThread {
30 return {
31 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
32 runtimeMode: "full-access",
33 interactionMode: "default",
34 branch: null,
35 worktreePath: null,
36 latestTurn: null,
37 createdAt: "2026-04-01T00:00:00.000Z",
38 updatedAt: "2026-04-01T00:00:00.000Z",
39 archivedAt: null,
40 deletedAt: null,
41 messages: [],
42 proposedPlans: [],
43 activities: [],
44 checkpoints: [],
45 session: null,
46 ...input,
47 };
48}
49
50describe("buildThreadFeed", () => {
51 it("includes runtime warnings from the latest turn", () => {
52 const thread = makeThread({
53 id: ThreadId.make("thread-1"),
54 projectId: ProjectId.make("project-1"),
55 title: "Runtime warning thread",
56 latestTurn: {
57 turnId: TurnId.make("turn-latest"),
58 state: "running",
59 requestedAt: "2026-04-01T00:00:00.000Z",
60 startedAt: "2026-04-01T00:00:01.000Z",
61 completedAt: null,
62 assistantMessageId: null,
63 },
64 activities: [
65 makeActivity({
66 id: EventId.make("activity-old"),
67 kind: "runtime.warning",
68 summary: "Runtime warning",
69 createdAt: "2026-04-01T00:00:02.000Z",
70 turnId: TurnId.make("turn-old"),
71 payload: {
72 message: "Old warning",
73 },
74 }),
75 makeActivity({
76 id: EventId.make("activity-latest"),
77 kind: "runtime.warning",
78 summary: "Runtime warning",
79 createdAt: "2026-04-01T00:00:03.000Z",
80 turnId: TurnId.make("turn-latest"),
81 payload: {
82 message: "Latest warning",
83 },
84 }),
85 ],
86 });
87
88 const feed = buildThreadFeed(thread, [], null);
89 const group = feed[0];
90
91 expect(group).toMatchObject({
92 type: "activity-group",
93 });
94 if (!group || group.type !== "activity-group") {
95 return;
96 }
97
98 expect(group.activities).toEqual([
99 {
100 id: "activity-latest",
101 createdAt: "2026-04-01T00:00:03.000Z",
102 summary: "Runtime warning",
103 detail: null,
104 status: null,
105 },
106 ]);
107 });
108
109 it("collapses matching tool lifecycle rows like desktop", () => {
110 const thread = makeThread({
111 id: ThreadId.make("thread-2"),
112 projectId: ProjectId.make("project-1"),
113 title: "Collapsed tools",
114 latestTurn: {
115 turnId: TurnId.make("turn-1"),
116 state: "completed",
117 requestedAt: "2026-04-01T00:00:00.000Z",
118 startedAt: "2026-04-01T00:00:01.000Z",
119 completedAt: "2026-04-01T00:00:03.000Z",
120 assistantMessageId: null,
121 },
122 activities: [
123 makeActivity({
124 id: EventId.make("tool-updated"),
125 kind: "tool.updated",
126 tone: "tool",
127 summary: "Run tests",
128 createdAt: "2026-04-01T00:00:01.000Z",
129 turnId: TurnId.make("turn-1"),
130 payload: {
131 title: "Run tests",
132 itemType: "command_execution",
133 detail: "/bin/zsh -lc 'bun run test'",
134 },
135 }),
136 makeActivity({
137 id: EventId.make("tool-completed"),
138 kind: "tool.completed",
139 tone: "tool",
140 summary: "Run tests completed",
141 createdAt: "2026-04-01T00:00:02.000Z",
142 turnId: TurnId.make("turn-1"),
143 payload: {
144 title: "Run tests",
145 itemType: "command_execution",
146 detail: "/bin/zsh -lc 'bun run test'",
147 },
148 }),
149 ],
150 });
151
152 const feed = buildThreadFeed(thread, [], null);
153 const group = feed[0];
154
155 expect(group).toMatchObject({
156 type: "activity-group",
157 });
158 if (!group || group.type !== "activity-group") {
159 return;
160 }
161
162 expect(group.activities).toEqual([
163 {
164 id: "tool-completed",
165 createdAt: "2026-04-01T00:00:02.000Z",
166 summary: "Run tests",
167 detail: "bun run test",
168 status: null,
169 },
170 ]);
171 });
172});