Open History to see the last commit
1import { EnvironmentId, MessageId, ThreadId } from "@t3tools/contracts";
2import { serializeAssistantCitation } from "@t3tools/shared/assistantCitations";
3import * as DateTime from "effect/DateTime";
4import type { ComponentProps } from "react";
5import { expect, it, vi } from "vite-plus/test";
6import { page } from "vite-plus/test/browser";
7
8const state = vi.hoisted(() => ({
9 projection: null as unknown,
10 workflow: null as unknown,
11}));
12
13vi.mock(import("@t3tools/client-runtime/state/thread-workflows"), async (importOriginal) => ({
14 ...(await importOriginal()),
15 deriveThreadQueueWorkflowState: (() => state.workflow) as never,
16}));
17
18vi.mock(import("../../state/entities"), async (importOriginal) => ({
19 ...(await importOriginal()),
20 useThreadProjection: (() => state.projection) as never,
21 useQuietThreadShell: ((target: unknown) =>
22 target === null ? null : { title: "Release lead" }) as never,
23}));
24
25vi.mock(import("../../state/query"), async (importOriginal) => ({
26 ...(await importOriginal()),
27 useEnvironmentQuery: (() => ({
28 data: { tasks: [{ id: "task:webhook", title: "PR dispatcher" }] },
29 })) as never,
30}));
31
32vi.mock(import("../../state/use-atom-command"), async (importOriginal) => ({
33 ...(await importOriginal()),
34 useAtomCommand: (() => async () => undefined) as never,
35}));
36
37vi.mock(import("../../assets/assetUrls"), async (importOriginal) => ({
38 ...(await importOriginal()),
39 useAssetUrls: ((_environmentId: never, resources: ReadonlyArray<{ attachmentId: string }>) =>
40 resources.map((resource) => `https://assets.test/${resource.attachmentId}`)) as never,
41}));
42
43import "~/index.css";
44import { render as renderUi } from "../../../test/render";
45import { QueuedRunsControl } from "./QueuedRunsControl";
46
47function setup() {
48 state.projection = null;
49 state.workflow = null;
50}
51
52const baseProps = {
53 environmentId: "environment:test" as never,
54 optimisticMessages: [],
55 threadId: "thread:test" as never,
56 editingRunId: null,
57 editBlockedReason: null,
58 onEditQueuedRun: () => undefined,
59 onCancelEdit: () => undefined,
60 timestampFormat: "locale",
61 onOpenThread: () => undefined,
62} satisfies ComponentProps<typeof QueuedRunsControl>;
63
64async function renderQueue(props: Partial<ComponentProps<typeof QueuedRunsControl>> = {}) {
65 return renderUi(<QueuedRunsControl {...baseProps} {...props} />);
66}
67
68it("previews assistant quotes as readable text and preserves the citation when editing", async () => {
69 setup();
70 const quotedText = "Cache the parsed config per worktree.";
71 const quote = serializeAssistantCitation({
72 version: 1,
73 environmentId: EnvironmentId.make("environment:test"),
74 threadId: ThreadId.make("thread:test"),
75 messageId: MessageId.make("message:assistant"),
76 text: quotedText,
77 start: 0,
78 end: quotedText.length,
79 prefix: "",
80 suffix: "",
81 });
82 const quoteAndText = `${quote}\n\nWhy per worktree?`;
83 state.projection = { projection: { messages: [] } };
84 state.workflow = {
85 activeRun: { id: "run:active" },
86 canPromoteToSteer: true,
87 queuedRuns: [
88 {
89 run: { id: "run:quote-only", userMessageId: "message:quote-only" },
90 text: quote,
91 attachments: [],
92 },
93 {
94 run: { id: "run:quote-and-text", userMessageId: "message:quote-and-text" },
95 text: quoteAndText,
96 attachments: [],
97 },
98 ],
99 };
100 const onEditQueuedRun = vi.fn();
101 await using _screen = await renderQueue({ onEditQueuedRun });
102
103 await expect.element(page.getByText(quotedText, { exact: true })).toBeVisible();
104 await expect
105 .element(page.getByText(`${quotedText} Why per worktree?`, { exact: true }))
106 .toBeVisible();
107
108 await page.getByRole("button", { name: "Edit queued message", exact: true }).nth(1).click();
109 expect(onEditQueuedRun).toHaveBeenCalledExactlyOnceWith(
110 expect.objectContaining({ text: quoteAndText }),
111 );
112});
113
114it("shows who sent a queued message and folds automation and agent prompts", async () => {
115 setup();
116 const message = (id: string, fields: Record<string, unknown>) => ({
117 id,
118 role: "user",
119 createdAt: DateTime.makeUnsafe("2026-10-27T12:00:00.000Z"),
120 ...fields,
121 });
122 state.projection = { projection: { messages: [] } };
123 state.workflow = {
124 activeRun: { id: "run:active" },
125 canPromoteToSteer: true,
126 queuedRuns: [
127 [
128 "run:automation",
129 "GitHub labeled a pull request.\nFollow the runbook.",
130 {
131 createdBy: "agent",
132 scheduledTaskId: "task:webhook",
133 },
134 ],
135 [
136 "run:agent",
137 "Review finished.",
138 {
139 createdBy: "agent",
140 creationSource: "provider",
141 senderThreadId: "thread:lead",
142 },
143 ],
144 [
145 "run:server",
146 "Continue where you left off.",
147 {
148 createdBy: "agent",
149 creationSource: "server",
150 },
151 ],
152 ].map(([runId, text, fields]) => ({
153 run: { id: runId, userMessageId: `${runId}:message` },
154 text,
155 attachments: [],
156 message: message(`${runId}:message`, { text, ...(fields as object) }),
157 })),
158 };
159 const onOpenThread = vi.fn();
160 await using _screen = await renderQueue({ onOpenThread });
161
162 const automation = page.getByRole("button", { name: /PR dispatcher/ });
163 await expect.element(automation).toHaveAttribute("aria-expanded", "false");
164 await expect.element(page.getByText(/Follow the runbook/)).not.toBeInTheDocument();
165 await automation.click();
166 await expect.element(page.getByText(/Follow the runbook/)).toBeVisible();
167 await expect.element(page.getByRole("link", { name: "Open automation" })).toBeInTheDocument();
168
169 await expect.element(page.getByRole("button", { name: /Release lead/ })).toBeVisible();
170 await page.getByRole("button", { name: "Open thread" }).click({ force: true });
171 expect(onOpenThread).toHaveBeenCalledExactlyOnceWith("thread:lead");
172
173 await expect.element(page.getByText("Sent by T3 Code")).toBeVisible();
174 await expect.element(page.getByText("Continue where you left off.")).toBeVisible();
175});
176
177it("stays inside the timeline scroller instead of growing the chat column", async () => {
178 setup();
179 state.projection = { projection: { messages: [] } };
180 state.workflow = {
181 activeRun: { id: "run:active" },
182 canPromoteToSteer: true,
183 queuedRuns: [
184 {
185 run: { id: "run:queued", userMessageId: "message:queued" },
186 text: "Later",
187 attachments: [],
188 },
189 ],
190 };
191 // Mirrors ChatView: a scrollable column, a positioned wrapper, then a non-positioned scroller.
192 await using screen = await renderUi(
193 <div data-testid="column" style={{ height: 200, overflowY: "auto" }}>
194 <div style={{ position: "relative", height: "100%" }}>
195 <div style={{ height: "100%", overflowY: "auto" }}>
196 <div style={{ height: 1000 }} />
197 <QueuedRunsControl {...baseProps} />
198 </div>
199 </div>
200 </div>,
201 );
202 await expect.element(page.getByText("Later", { exact: true })).toBeInTheDocument();
203 const column = screen.getByTestId("column").element();
204 expect(column.scrollHeight).toBe(column.clientHeight);
205});