Open History to see the last commit
1import "~/index.css";
2import {
3 EnvironmentId,
4 NodeId,
5 ProviderDriverKind,
6 ProviderInstanceId,
7 ThreadId,
8 TurnItemId,
9} from "@t3tools/contracts";
10import * as DateTime from "effect/DateTime";
11import { expect, it, vi } from "vite-plus/test";
12import { page } from "vite-plus/test/browser";
13vi.mock(import("./CommandOutputPanel"), () => ({
14 useCommandOutputStreaming: () => true,
15 CommandOutputPanel: () => <div>Command output stream</div>,
16}));
17
18import { render } from "../../../test/render";
19import { backgroundWorkNowItem } from "./ThreadActivityBanners";
20import { ThreadNow } from "./ThreadNow";
21
22it("opens full command details for short labels and keeps pending tasks current", async () => {
23 const command = "python3 audit.py -j 6\n> scratch/audit.log 2>&1";
24 const commandItem = (status: "running" | "completed") => ({
25 id: TurnItemId.make("bash-1"),
26 threadId: ThreadId.make("thread"),
27 runId: null,
28 nodeId: null,
29 providerThreadId: null,
30 providerTurnId: null,
31 nativeItemRef: null,
32 parentItemId: null,
33 ordinal: 1,
34 status,
35 title: null,
36 startedAt: null,
37 completedAt: null,
38 updatedAt: DateTime.makeUnsafe("2026-11-09T00:00:00Z"),
39 type: "command_execution" as const,
40 input: command,
41 output: "Command running in background with ID: native-task",
42 });
43 const view = (
44 description?: string,
45 status: "running" | "completed" = "completed",
46 explicitItem = true,
47 ) => (
48 <ThreadNow
49 attention={null}
50 goal={null}
51 work={backgroundWorkNowItem({
52 environmentId: EnvironmentId.make("test"),
53 threadId: ThreadId.make("thread"),
54 tasks: [
55 {
56 taskId: "native-task",
57 itemId: explicitItem ? TurnItemId.make("bash-1") : undefined,
58 kind: "command",
59 description,
60 command,
61 awaited: true,
62 },
63 ],
64 turnItems: [
65 commandItem(status),
66 {
67 ...commandItem("running"),
68 id: TurnItemId.make("native-match"),
69 nativeItemRef: {
70 driver: ProviderDriverKind.make("codex"),
71 nativeId: "native-task",
72 strength: "strong",
73 },
74 ordinal: 2,
75 },
76 ],
77 stopDisabled: false,
78 stopping: false,
79 onStop: async () => undefined,
80 onOpenThread: () => undefined,
81 })}
82 />
83 );
84 await using screen = await render(view("Audit"));
85 await screen.getByRole("button", { name: "Details", exact: true }).click();
86 await vi.waitFor(() => expect(page.getByRole("dialog").element().textContent).toContain(command));
87 await expect.element(page.getByText("Command output stream")).not.toBeInTheDocument();
88
89 await screen.rerender(view(command));
90 await expect.element(page.getByRole("heading", { name: "Command", exact: true })).toBeVisible();
91 await screen.rerender(view());
92 await expect.element(page.getByRole("heading", { name: "Command", exact: true })).toBeVisible();
93
94 await screen.rerender(view("Check remaining modules", "running"));
95 await expect
96 .element(page.getByRole("heading", { name: "Check remaining modules" }))
97 .toBeVisible();
98 await expect.element(page.getByText("Command output stream")).toBeVisible();
99 await screen.rerender(view("Native fallback", "completed", false));
100 await expect.element(page.getByText("Command output stream")).toBeVisible();
101 await page.getByRole("button", { name: "Close", exact: true }).click();
102 await expect.element(page.getByRole("dialog")).not.toBeInTheDocument();
103});
104
105it("gives a subagent the same status as the background work line", async () => {
106 await using screen = await render(
107 <ThreadNow
108 attention={null}
109 goal={null}
110 work={backgroundWorkNowItem({
111 environmentId: EnvironmentId.make("test"),
112 threadId: ThreadId.make("thread"),
113 tasks: [
114 {
115 taskId: "subagent-task",
116 kind: "subagent",
117 description: "Review refactor diffs",
118 childThreadId: ThreadId.make("child"),
119 },
120 ],
121 turnItems: [],
122 stopDisabled: false,
123 stopping: false,
124 onStop: async () => undefined,
125 onOpenThread: () => undefined,
126 })}
127 />,
128 );
129 await expect.element(page.getByText("Waiting · Review refactor diffs")).toBeVisible();
130 await screen.getByRole("button", { name: "Details", exact: true }).click();
131 await expect
132 .element(page.getByRole("dialog").getByText("Waiting", { exact: true }))
133 .toBeVisible();
134});
135
136it("offers to open a subagent running in a linked environment", async () => {
137 const remoteItemId = TurnItemId.make("subagent-item-1");
138 await using screen = await render(
139 <ThreadNow
140 attention={null}
141 goal={null}
142 work={backgroundWorkNowItem({
143 environmentId: EnvironmentId.make("mac"),
144 threadId: ThreadId.make("parent"),
145 tasks: [
146 {
147 taskId: "remote-task",
148 itemId: remoteItemId,
149 kind: "subagent",
150 description: "Implement Anzen",
151 },
152 ],
153 turnItems: [
154 {
155 id: remoteItemId,
156 threadId: ThreadId.make("parent"),
157 runId: null,
158 nodeId: null,
159 providerThreadId: null,
160 providerTurnId: null,
161 nativeItemRef: null,
162 parentItemId: null,
163 ordinal: 1,
164 status: "running",
165 title: "Implement Anzen",
166 startedAt: null,
167 completedAt: null,
168 updatedAt: DateTime.makeUnsafe("2026-11-09T00:00:00Z"),
169 type: "subagent",
170 subagentId: NodeId.make("subagent-1"),
171 origin: "app_owned",
172 driver: ProviderDriverKind.make("remote"),
173 providerInstanceId: ProviderInstanceId.make("remote"),
174 childThreadId: null,
175 remoteChild: {
176 environmentId: EnvironmentId.make("boat"),
177 threadId: ThreadId.make("remote-child"),
178 label: "Boat",
179 },
180 prompt: "",
181 result: null,
182 },
183 ],
184 stopDisabled: false,
185 stopping: false,
186 onStop: async () => undefined,
187 onOpenThread: () => undefined,
188 })}
189 />,
190 );
191 await screen.getByRole("button", { name: "Details", exact: true }).click();
192 await expect
193 .element(page.getByRole("dialog").getByRole("button", { name: "Open subagent" }))
194 .toBeVisible();
195});