|
1 | 1 | import { AudioPreview } from "../files/AudioPreview"; |
2 | | -import { onTestFinished } from "vite-plus/test"; |
3 | 2 | import { page } from "vite-plus/test/browser"; |
4 | | -import { stubGlobal } from "../../../test/render"; |
5 | 3 | import { |
6 | 4 | ComposerContextId, |
7 | 5 | EnvironmentId, |
8 | 6 | MessageId, |
| 7 | + NodeId, |
| 8 | + ProviderDriverKind, |
| 9 | + ProviderInstanceId, |
9 | 10 | RunAttemptId, |
10 | 11 | RunId, |
11 | 12 | RuntimeRequestId, |
12 | 13 | TurnItemId, |
13 | 14 | ScheduledTaskId, |
14 | 15 | ThreadId, |
| 16 | + type OrchestrationV2Subagent, |
15 | 17 | } from "@t3tools/contracts"; |
16 | 18 | import type { LegendListRef } from "@legendapp/list/react"; |
17 | 19 | import { createRef, Profiler, StrictMode, type ComponentProps, type ReactElement } from "react"; |
18 | | -import { describe, expect, it, vi } from "vite-plus/test"; |
| 20 | +import * as DateTime from "effect/DateTime"; |
| 21 | +import { Atom } from "effect/reactivity"; |
| 22 | +import { describe, expect, it, onTestFinished, vi } from "vite-plus/test"; |
19 | 23 |
|
20 | 24 | import "~/index.css"; |
21 | 25 |
|
22 | | -import { act, fakeTimers, render } from "../../../test/render"; |
| 26 | +import { environmentThreadDetails } from "../../state/threads"; |
| 27 | +import { act, fakeTimers, render, stubGlobal } from "../../../test/render"; |
23 | 28 | import { MessagesTimeline } from "./MessagesTimeline"; |
24 | 29 | import { makeStreamingTimelineFixture } from "../../test-fixtures"; |
25 | 30 | import { |
@@ -128,6 +133,43 @@ function message( |
128 | 133 | }; |
129 | 134 | } |
130 | 135 |
|
| 136 | +function work(id: string, entry: Record<string, unknown>): Entry { |
| 137 | + return { |
| 138 | + id, |
| 139 | + kind: "work", |
| 140 | + createdAt: CREATED_AT, |
| 141 | + entry: { id, createdAt: CREATED_AT, ...entry }, |
| 142 | + } as Entry; |
| 143 | +} |
| 144 | + |
| 145 | +function v2Item(type: string, fields: Record<string, unknown>) { |
| 146 | + const id = (fields.id as string | undefined) ?? type; |
| 147 | + return { |
| 148 | + position: 0, |
| 149 | + visibility: "local", |
| 150 | + sourceThreadId: "thread-1", |
| 151 | + sourceItemId: id, |
| 152 | + item: { |
| 153 | + id, |
| 154 | + threadId: "thread-1", |
| 155 | + runId: "run-1", |
| 156 | + nodeId: null, |
| 157 | + providerThreadId: null, |
| 158 | + providerTurnId: null, |
| 159 | + nativeItemRef: null, |
| 160 | + parentItemId: null, |
| 161 | + ordinal: 0, |
| 162 | + status: "completed", |
| 163 | + title: null, |
| 164 | + startedAt: null, |
| 165 | + completedAt: null, |
| 166 | + updatedAt: {}, |
| 167 | + type, |
| 168 | + ...fields, |
| 169 | + }, |
| 170 | + } as never; |
| 171 | +} |
| 172 | + |
131 | 173 | async function renderElement(element: ReactElement, options: { router?: false } = {}) { |
132 | 174 | const container = document.createElement("div"); |
133 | 175 | container.style.cssText = "height: 1200px; width: 900px; display: flex; flex-direction: column;"; |
@@ -165,6 +207,84 @@ function setup({ scheduledTasks = [] as ReadonlyArray<{ id: string; title: strin |
165 | 207 | const TASK_ID = ScheduledTaskId.make("task-1"); |
166 | 208 | const AUTOMATION_PROMPT = "Triage the inbox\n\nLabel every new issue and close duplicates."; |
167 | 209 |
|
| 210 | +describe("MessagesTimeline work rows", () => { |
| 211 | + it.each(["delegated", "legacy", "missing"] as const)( |
| 212 | + "uses the reported task for %s completion notifications", |
| 213 | + async (source) => { |
| 214 | + setup(); |
| 215 | + const now = DateTime.makeUnsafe(CREATED_AT); |
| 216 | + const childThreadId = ThreadId.make("shared-child"); |
| 217 | + const task = ( |
| 218 | + id: string, |
| 219 | + status: OrchestrationV2Subagent["status"], |
| 220 | + result: string, |
| 221 | + ): OrchestrationV2Subagent => ({ |
| 222 | + id: NodeId.make(id), |
| 223 | + threadId: ThreadId.make("thread-1"), |
| 224 | + runId: null, |
| 225 | + parentNodeId: NodeId.make("parent-root"), |
| 226 | + origin: "app_owned", |
| 227 | + createdBy: "agent", |
| 228 | + driver: ProviderDriverKind.make("claudeAgent"), |
| 229 | + providerInstanceId: ProviderInstanceId.make("claudeAgent"), |
| 230 | + providerThreadId: null, |
| 231 | + childThreadId, |
| 232 | + nativeTaskRef: null, |
| 233 | + prompt: "Simplify delivery", |
| 234 | + title: "Simplify delivery", |
| 235 | + model: null, |
| 236 | + status, |
| 237 | + result, |
| 238 | + startedAt: now, |
| 239 | + completedAt: now, |
| 240 | + updatedAt: now, |
| 241 | + }); |
| 242 | + const tasks = [ |
| 243 | + task("original", "interrupted", "Old interrupted progress"), |
| 244 | + task("continued", "completed", "Final implementation report"), |
| 245 | + task("follow-up", "completed", "Follow-up explanation"), |
| 246 | + ]; |
| 247 | + using _threadAtom = vi.spyOn(environmentThreadDetails, "threadAtom").mockReturnValue( |
| 248 | + Atom.make({ |
| 249 | + projection: { subagents: tasks, turnItems: [], visibleTurnItems: [] }, |
| 250 | + }) as never, |
| 251 | + ); |
| 252 | + const onOpenThread = vi.fn(); |
| 253 | + await using screen = await renderTimeline( |
| 254 | + (source === "delegated" ? ["continued", "follow-up"] : [source]).map((id) => |
| 255 | + work(`notification-${id}`, { |
| 256 | + label: "Notification fallback", |
| 257 | + tone: "info", |
| 258 | + itemType: "notification", |
| 259 | + projectedItem: v2Item("notification", { |
| 260 | + id: `notification-${id}`, |
| 261 | + source: |
| 262 | + source === "legacy" |
| 263 | + ? { kind: "subagent", childThreadId } |
| 264 | + : { kind: "delegated_task", childThreadId, taskIds: [NodeId.make(id)] }, |
| 265 | + outcome: "completed", |
| 266 | + summary: "Notification fallback", |
| 267 | + }), |
| 268 | + }), |
| 269 | + ), |
| 270 | + { onOpenThread }, |
| 271 | + ); |
| 272 | + if (source === "delegated") { |
| 273 | + expect(screen.text()).toContain("Final implementation report"); |
| 274 | + expect(screen.text()).toContain("Follow-up explanation"); |
| 275 | + expect(screen.text()).not.toContain("Old interrupted progress"); |
| 276 | + await click(screen.buttons("Open Simplify delivery")[0]!); |
| 277 | + expect(onOpenThread).toHaveBeenCalledWith(childThreadId); |
| 278 | + } else if (source === "legacy") { |
| 279 | + expect(screen.text()).toContain("Old interrupted progress"); |
| 280 | + } else { |
| 281 | + expect(screen.text()).toContain("Notification fallback"); |
| 282 | + expect(screen.text()).not.toContain("Old interrupted progress"); |
| 283 | + } |
| 284 | + }, |
| 285 | + ); |
| 286 | +}); |
| 287 | + |
168 | 288 | describe("MessagesTimeline messages", () => { |
169 | 289 | it("settles when equally long messages have very different rendered heights", async () => { |
170 | 290 | const props = baseProps(); |
|
0 commit comments