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

BackgroundWorkDetails.browser.test.tsx

97 lines3.5 KB

1import "~/index.css";
2import { EnvironmentId, ProviderDriverKind, ThreadId, TurnItemId } from "@t3tools/contracts";
3import * as DateTime from "effect/DateTime";
4import { expect, it, vi } from "vite-plus/test";
5import { page } from "vite-plus/test/browser";
6vi.mock(import("./CommandOutputPanel"), () => ({
7 useCommandOutputStreaming: () => true,
8 CommandOutputPanel: () => <div>Command output stream</div>,
9}));
10​
11import { render } from "../../../test/render";
12import { backgroundWorkNowItem } from "./ThreadActivityBanners";
13import { ThreadNow } from "./ThreadNow";
14​
15it("opens full command details for short labels and keeps pending tasks current", async () => {
16 const command = "python3 audit.py -j 6\n> scratch/audit.log 2>&1";
17 const commandItem = (status: "running" | "completed") => ({
18 id: TurnItemId.make("bash-1"),
19 threadId: ThreadId.make("thread"),
20 runId: null,
21 nodeId: null,
22 providerThreadId: null,
23 providerTurnId: null,
24 nativeItemRef: null,
25 parentItemId: null,
26 ordinal: 1,
27 status,
28 title: null,
29 startedAt: null,
30 completedAt: null,
31 updatedAt: DateTime.makeUnsafe("2026-11-09T00:00:00Z"),
32 type: "command_execution" as const,
33 input: command,
34 output: "Command running in background with ID: native-task",
35 });
36 const view = (
37 description?: string,
38 status: "running" | "completed" = "completed",
39 explicitItem = true,
40 ) => (
41 <ThreadNow
42 attention={null}
43 syncPhase={null}
44 goal={null}
45 work={backgroundWorkNowItem({
46 environmentId: EnvironmentId.make("test"),
47 threadId: ThreadId.make("thread"),
48 tasks: [
49 {
50 taskId: "native-task",
51 itemId: explicitItem ? TurnItemId.make("bash-1") : undefined,
52 kind: "command",
53 description,
54 command,
55 awaited: true,
56 },
57 ],
58 turnItems: [
59 commandItem(status),
60 {
61 ...commandItem("running"),
62 id: TurnItemId.make("native-match"),
63 nativeItemRef: {
64 driver: ProviderDriverKind.make("codex"),
65 nativeId: "native-task",
66 strength: "strong",
67 },
68 ordinal: 2,
69 },
70 ],
71 stopDisabled: false,
72 stopping: false,
73 onStop: async () => undefined,
74 onOpenThread: () => undefined,
75 })}
76 />
77 );
78 await using screen = await render(view("Audit"));
79 await screen.getByRole("button", { name: "Details", exact: true }).click();
80 await vi.waitFor(() => expect(page.getByRole("dialog").element().textContent).toContain(command));
81 await expect.element(page.getByText("Command output stream")).not.toBeInTheDocument();
82​
83 await screen.rerender(view(command));
84 await expect.element(page.getByRole("heading", { name: "Command", exact: true })).toBeVisible();
85 await screen.rerender(view());
86 await expect.element(page.getByRole("heading", { name: "Command", exact: true })).toBeVisible();
87​
88 await screen.rerender(view("Check remaining modules", "running"));
89 await expect
90 .element(page.getByRole("heading", { name: "Check remaining modules" }))
91 .toBeVisible();
92 await expect.element(page.getByText("Command output stream")).toBeVisible();
93 await screen.rerender(view("Native fallback", "completed", false));
94 await expect.element(page.getByText("Command output stream")).toBeVisible();
95 await page.getByRole("button", { name: "Close", exact: true }).click();
96 await expect.element(page.getByRole("dialog")).not.toBeInTheDocument();
97});