Open History to see the last commit
1import {
2 EnvironmentId,
3 ProjectId,
4 RunId,
5 RuntimeRequestId,
6 ThreadId,
7 type OrchestrationV2ShellSnapshot,
8 type OrchestrationV2ThreadShell,
9} from "@t3tools/contracts";
10import * as DateTime from "effect/DateTime";
11import * as Option from "effect/Option";
12import { Atom, AtomRegistry } from "effect/reactivity";
13import { describe, expect, it } from "vite-plus/test";
14
15import { PrimaryConnectionTarget } from "../connection/model.ts";
16import { v2Now, v2ShellSnapshot, v2ThreadShell } from "./orchestrationV2TestFixtures.ts";
17import { applyShellStreamEvent } from "./shellReducer.ts";
18import { isThreadWorking } from "./threadInbox.ts";
19import { childThreadInputsTitle, createEnvironmentThreadShellAtoms } from "./threadShell.ts";
20
21const environmentId = EnvironmentId.make("environment-v2");
22const remoteEnvironmentId = EnvironmentId.make("remote-environment-v2");
23const otherProjectId = ProjectId.make("other-project");
24
25function makeHarness(environmentIds: ReadonlyArray<EnvironmentId> = [environmentId]) {
26 const snapshotAtom = Atom.family((_environmentId: EnvironmentId) =>
27 Atom.make<OrchestrationV2ShellSnapshot | null>(v2ShellSnapshot),
28 );
29 const catalogValueAtom = Atom.make({
30 isReady: true,
31 entries: new Map(
32 environmentIds.map((id) => [
33 id,
34 {
35 target: new PrimaryConnectionTarget({
36 environmentId: id,
37 label: "Environment",
38 httpBaseUrl: "https://example.test",
39 wsBaseUrl: "wss://example.test",
40 }),
41 profile: Option.none(),
42 enabled: true,
43 },
44 ]),
45 ),
46 });
47 return {
48 registry: AtomRegistry.make(),
49 snapshotAtom,
50 catalogValueAtom,
51 threads: createEnvironmentThreadShellAtoms({ catalogValueAtom, snapshotAtom }),
52 };
53}
54
55describe("v2 thread shell lists", () => {
56 it("preserves ordered reference arrays when a middle thread changes", () => {
57 const { registry, threads, snapshotAtom } = makeHarness();
58 const snapshot = {
59 ...v2ShellSnapshot,
60 threads: ["a", "b", "c"].map((id) => ({ ...v2ThreadShell, id: ThreadId.make(id) })),
61 };
62 registry.set(snapshotAtom(environmentId), snapshot);
63 const dispose = registry.mount(threads.threadRefsAtom);
64 const before = registry.get(threads.threadRefsAtom);
65 registry.set(
66 snapshotAtom(environmentId),
67 applyShellStreamEvent(snapshot, {
68 kind: "thread.updated",
69 location: "active",
70 sequence: 1,
71 thread: { ...snapshot.threads[1]!, title: "Updated" },
72 }),
73 );
74 expect(registry.get(threads.threadRefsAtom)).toBe(before);
75 dispose();
76 registry.dispose();
77 });
78
79 it("keeps navigation stable on hidden subagent updates and retains user forks", () => {
80 const { registry, threads, snapshotAtom } = makeHarness();
81 const root = v2ThreadShell;
82 const child = {
83 ...root,
84 id: ThreadId.make("child"),
85 lineage: {
86 ...root.lineage,
87 parentThreadId: root.id,
88 relationshipToParent: "subagent" as const,
89 },
90 };
91 const fork = {
92 ...child,
93 id: ThreadId.make("fork"),
94 lineage: { ...child.lineage, relationshipToParent: "fork" as const },
95 };
96 const snapshot = { ...v2ShellSnapshot, threads: [root, child, fork] };
97 registry.set(snapshotAtom(environmentId), snapshot);
98 const dispose = registry.mount(threads.navigationThreadShellsAtom);
99 const before = registry.get(threads.navigationThreadShellsAtom);
100 expect(before.map((thread) => thread.id)).toEqual([root.id, fork.id]);
101 registry.set(snapshotAtom(environmentId), {
102 ...snapshot,
103 threads: [root, { ...child, title: "Child streaming" }, fork],
104 });
105 expect(registry.get(threads.navigationThreadShellsAtom)).toBe(before);
106 expect(registry.get(threads.threadShellsAtom)).toHaveLength(3);
107 dispose();
108 registry.dispose();
109 });
110
111 it("keeps a live subagent question inside the parent without flagging its thread", () => {
112 const { registry, threads, snapshotAtom } = makeHarness();
113 const root = v2ThreadShell;
114 const child = {
115 ...root,
116 id: ThreadId.make("child"),
117 creationSource: "mcp" as const,
118 status: "running" as const,
119 activityRunStatus: "running" as const,
120 lineage: {
121 ...root.lineage,
122 parentThreadId: root.id,
123 relationshipToParent: "subagent" as const,
124 },
125 pendingRuntimeRequest: {
126 id: RuntimeRequestId.make("question"),
127 kind: "user_input" as const,
128 createdAt: v2Now,
129 },
130 };
131 const inputs = threads.childThreadInputsAtom({ environmentId, threadId: root.id });
132 const dispose = registry.mount(inputs);
133 registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [root, child] });
134 expect(registry.get(inputs).map((thread) => thread.id)).toEqual([child.id]);
135 expect(
136 registry.get(threads.threadShellAtom({ environmentId, threadId: root.id }))
137 ?.pendingSubagentRequest,
138 ).toBeNull();
139 registry.set(snapshotAtom(environmentId), {
140 ...v2ShellSnapshot,
141 threads: [root, { ...child, status: "queued" as const }],
142 });
143 expect(registry.get(inputs).map((thread) => thread.id)).toEqual([child.id]);
144 registry.set(snapshotAtom(environmentId), {
145 ...v2ShellSnapshot,
146 threads: [root, { ...child, status: "completed" as const, activityRunStatus: null }],
147 });
148 expect(registry.get(inputs)).toEqual([]);
149 const { activityRunStatus: _omitted, ...legacyChild } = child;
150 registry.set(snapshotAtom(environmentId), {
151 ...v2ShellSnapshot,
152 threads: [root, { ...legacyChild, status: "completed" as const }],
153 });
154 expect(registry.get(inputs)).toEqual([]);
155 dispose();
156 registry.dispose();
157 });
158
159 it("rolls a side chat's questions and approvals up to its parent row", () => {
160 const { registry, threads, snapshotAtom } = makeHarness();
161 const root = v2ThreadShell;
162 const sideChat = {
163 ...root,
164 id: ThreadId.make("side-chat"),
165 status: "running" as const,
166 activityRunStatus: "running" as const,
167 latestRunId: RunId.make("side-chat-run"),
168 lineage: {
169 ...root.lineage,
170 parentThreadId: root.id,
171 relationshipToParent: "fork" as const,
172 sideChat: true,
173 },
174 };
175 const request = { id: RuntimeRequestId.make("ask"), createdAt: v2Now };
176 const parentRef = { environmentId, threadId: root.id };
177 const parent = threads.threadShellAtom(parentRef);
178 const inputs = threads.childThreadInputsAtom(parentRef);
179 const disposeParent = registry.mount(parent);
180 const disposeInputs = registry.mount(inputs);
181 const disposeNavigation = registry.mount(threads.navigationThreadShellsAtom);
182 const withRequest = (
183 kind: "user_input" | "command",
184 options: { readonly blocking?: boolean; readonly settled?: boolean } = {},
185 ) =>
186 registry.set(snapshotAtom(environmentId), {
187 ...v2ShellSnapshot,
188 threads: [
189 root,
190 {
191 ...sideChat,
192 ...(options.settled ? { status: "completed" as const, activityRunStatus: null } : {}),
193 pendingRuntimeRequest: {
194 ...request,
195 kind,
196 ...(options.blocking === undefined ? {} : { blocking: options.blocking }),
197 },
198 },
199 ],
200 });
201
202 withRequest("user_input");
203 expect(registry.get(parent)?.pendingSubagentRequest).toBe("user_input");
204 expect(childThreadInputsTitle(registry.get(inputs))).toBe("Side chat needs input");
205 expect(registry.get(threads.navigationThreadShellsAtom).map((thread) => thread.id)).toEqual([
206 root.id,
207 ]);
208
209 // An async question waits while the side chat works, like its own row's indicator.
210 withRequest("user_input", { blocking: false });
211 expect(registry.get(parent)?.pendingSubagentRequest).toBeNull();
212 expect(registry.get(inputs)).toEqual([]);
213 withRequest("user_input", { blocking: false, settled: true });
214 expect(registry.get(parent)?.pendingSubagentRequest).toBe("user_input");
215
216 withRequest("command");
217 expect(registry.get(parent)?.pendingSubagentRequest).toBe("approval");
218 expect(childThreadInputsTitle(registry.get(inputs))).toBe("Side chat needs approval");
219
220 const helper = {
221 ...sideChat,
222 id: ThreadId.make("side-chat-helper"),
223 creationSource: "mcp" as const,
224 lineage: {
225 ...sideChat.lineage,
226 parentThreadId: sideChat.id,
227 relationshipToParent: "subagent" as const,
228 sideChat: false,
229 },
230 pendingRuntimeRequest: { ...request, kind: "command" as const },
231 };
232 const sideChats = threads.sideChatsAtom(parentRef);
233 const disposeSideChats = registry.mount(sideChats);
234 registry.set(snapshotAtom(environmentId), {
235 ...v2ShellSnapshot,
236 threads: [root, sideChat, helper],
237 });
238 expect(registry.get(parent)?.pendingSubagentRequest).toBe("approval");
239 expect(
240 registry.get(sideChats).map((thread) => [thread.id, thread.pendingSubagentRequest]),
241 ).toEqual([[sideChat.id, "approval"]]);
242
243 registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [root, sideChat] });
244 expect(registry.get(parent)?.pendingSubagentRequest).toBeNull();
245 expect(registry.get(sideChats).map((thread) => thread.pendingSubagentRequest)).toEqual([null]);
246 expect(registry.get(inputs)).toEqual([]);
247 disposeSideChats();
248 disposeNavigation();
249 disposeInputs();
250 disposeParent();
251 registry.dispose();
252 });
253
254 it("brings a parent back from Working while a nested subagent waits for approval", () => {
255 const { registry, threads, snapshotAtom } = makeHarness();
256 const child = {
257 ...v2ThreadShell,
258 id: ThreadId.make("review"),
259 creationSource: "mcp" as const,
260 status: "running" as const,
261 activityRunStatus: "running" as const,
262 lineage: {
263 ...v2ThreadShell.lineage,
264 parentThreadId: v2ThreadShell.id,
265 relationshipToParent: "subagent" as const,
266 },
267 };
268 const grandchild = {
269 ...child,
270 id: ThreadId.make("review-helper"),
271 lineage: { ...child.lineage, parentThreadId: child.id },
272 };
273 const root = {
274 ...v2ThreadShell,
275 latestRunId: RunId.make("root-run"),
276 status: "completed" as const,
277 pendingBackgroundTasks: [
278 { taskId: "review", kind: "subagent" as const, childThreadId: child.id },
279 ],
280 };
281 const approval = {
282 id: RuntimeRequestId.make("cat-file"),
283 kind: "command" as const,
284 createdAt: v2Now,
285 };
286 const parent = threads.threadShellAtom({ environmentId, threadId: root.id });
287 const inputs = threads.childThreadInputsAtom({ environmentId, threadId: root.id });
288 const disposeParent = registry.mount(parent);
289 const disposeInputs = registry.mount(inputs);
290 registry.set(snapshotAtom(environmentId), {
291 ...v2ShellSnapshot,
292 threads: [root, child, grandchild],
293 });
294 expect(isThreadWorking(registry.get(parent)!)).toBe(true);
295
296 registry.set(snapshotAtom(environmentId), {
297 ...v2ShellSnapshot,
298 threads: [root, child, { ...grandchild, pendingRuntimeRequest: approval }],
299 });
300 expect(registry.get(parent)?.pendingSubagentRequest).toBe("approval");
301 expect(isThreadWorking(registry.get(parent)!)).toBe(false);
302 const asking = registry.get(inputs);
303 expect(asking.map((thread) => thread.id)).toEqual([grandchild.id]);
304 expect(childThreadInputsTitle(asking)).toBe("Subagent needs approval");
305
306 registry.set(snapshotAtom(environmentId), {
307 ...v2ShellSnapshot,
308 threads: [root, child, grandchild],
309 });
310 expect(registry.get(parent)?.pendingSubagentRequest).toBeNull();
311 expect(isThreadWorking(registry.get(parent)!)).toBe(true);
312 disposeInputs();
313 disposeParent();
314 registry.dispose();
315 });
316
317 it("lists a task a linked environment runs for a listed thread under that thread", () => {
318 const { registry, threads, snapshotAtom, catalogValueAtom } = makeHarness([
319 environmentId,
320 remoteEnvironmentId,
321 ]);
322 const parent = v2ThreadShell;
323 const task = {
324 ...v2ThreadShell,
325 id: ThreadId.make("remote-task"),
326 creationSource: "mcp" as const,
327 status: "running" as const,
328 activityRunStatus: "running" as const,
329 delegatedFrom: { environmentId, threadId: parent.id, title: parent.title },
330 };
331 const helper = {
332 ...task,
333 id: ThreadId.make("remote-helper"),
334 delegatedFrom: undefined,
335 lineage: {
336 ...task.lineage,
337 parentThreadId: task.id,
338 relationshipToParent: "subagent" as const,
339 },
340 };
341 const approval = {
342 id: RuntimeRequestId.make("cat-file"),
343 kind: "command" as const,
344 createdAt: v2Now,
345 };
346 registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [parent] });
347 registry.set(snapshotAtom(remoteEnvironmentId), {
348 ...v2ShellSnapshot,
349 threads: [task, helper],
350 });
351 const parentRef = { environmentId, threadId: parent.id };
352 const inputs = threads.childThreadInputsAtom(parentRef);
353 const disposeNavigation = registry.mount(threads.navigationThreadShellsAtom);
354 const disposeParent = registry.mount(threads.threadShellAtom(parentRef));
355 const disposeInputs = registry.mount(inputs);
356 const listed = () =>
357 registry
358 .get(threads.navigationThreadShellsAtom)
359 .map((thread) => `${thread.environmentId}/${thread.id}`);
360 expect(listed()).toEqual([`${environmentId}/${parent.id}`]);
361
362 // The helper the task started there asks for approval: the parent here hears of it.
363 registry.set(snapshotAtom(remoteEnvironmentId), {
364 ...v2ShellSnapshot,
365 threads: [task, { ...helper, pendingRuntimeRequest: approval }],
366 });
367 expect(registry.get(threads.threadShellAtom(parentRef))?.pendingSubagentRequest).toBe(
368 "approval",
369 );
370 expect(registry.get(inputs).map((thread) => `${thread.environmentId}/${thread.id}`)).toEqual([
371 `${remoteEnvironmentId}/${helper.id}`,
372 ]);
373
374 registry.set(snapshotAtom(remoteEnvironmentId), {
375 ...v2ShellSnapshot,
376 threads: [
377 task,
378 { ...helper, pendingRuntimeRequest: { ...approval, kind: "user_input" as const } },
379 ],
380 });
381 expect(registry.get(threads.threadShellAtom(parentRef))?.pendingSubagentRequest).toBeNull();
382 expect(registry.get(inputs).map((thread) => thread.id)).toEqual([helper.id]);
383
384 // A task whose parent is gone there is listed on its own, as is one whose
385 // parent's environment is switched off.
386 registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [] });
387 expect(listed()).toEqual([`${remoteEnvironmentId}/${task.id}`]);
388 // Archiving the parent here leaves the task there unarchived, so it is listed on its own.
389 registry.set(snapshotAtom(environmentId), {
390 ...v2ShellSnapshot,
391 threads: [{ ...parent, archivedAt: v2Now }],
392 });
393 expect(listed()).toEqual([`${remoteEnvironmentId}/${task.id}`]);
394 registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [parent] });
395 expect(listed()).toEqual([`${environmentId}/${parent.id}`]);
396 const catalog = registry.get(catalogValueAtom);
397 const entries = new Map(catalog.entries);
398 entries.set(environmentId, { ...entries.get(environmentId)!, enabled: false });
399 registry.set(catalogValueAtom, { ...catalog, entries });
400 expect(listed()).toEqual([`${remoteEnvironmentId}/${task.id}`]);
401 disposeInputs();
402 disposeParent();
403 disposeNavigation();
404 registry.dispose();
405 });
406
407 it("brings an approval up a chain of tasks across three environments to its root", () => {
408 const thirdEnvironmentId = EnvironmentId.make("third-environment-v2");
409 const { registry, threads, snapshotAtom } = makeHarness([
410 environmentId,
411 remoteEnvironmentId,
412 thirdEnvironmentId,
413 ]);
414 const root = v2ThreadShell;
415 const running = {
416 creationSource: "mcp" as const,
417 status: "running" as const,
418 activityRunStatus: "running" as const,
419 };
420 const task = {
421 ...v2ThreadShell,
422 ...running,
423 id: ThreadId.make("remote-task"),
424 delegatedFrom: { environmentId, threadId: root.id, title: root.title },
425 };
426 const nestedTask = {
427 ...v2ThreadShell,
428 ...running,
429 id: ThreadId.make("third-task"),
430 delegatedFrom: { environmentId: remoteEnvironmentId, threadId: task.id, title: task.title },
431 };
432 // A task the middle one delegates back to the root's own environment.
433 const returningTask = {
434 ...nestedTask,
435 id: ThreadId.make("returning-task"),
436 };
437 const approval = {
438 id: RuntimeRequestId.make("cat-file"),
439 kind: "command" as const,
440 createdAt: v2Now,
441 };
442 registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [root] });
443 registry.set(snapshotAtom(remoteEnvironmentId), { ...v2ShellSnapshot, threads: [task] });
444 registry.set(snapshotAtom(thirdEnvironmentId), {
445 ...v2ShellSnapshot,
446 threads: [{ ...nestedTask, pendingRuntimeRequest: approval }],
447 });
448 const rootRef = { environmentId, threadId: root.id };
449 const taskRef = { environmentId: remoteEnvironmentId, threadId: task.id };
450 const disposeRoot = registry.mount(threads.threadShellAtom(rootRef));
451 const disposeTask = registry.mount(threads.threadShellAtom(taskRef));
452 expect(registry.get(threads.threadShellAtom(taskRef))?.pendingSubagentRequest).toBe("approval");
453 expect(registry.get(threads.threadShellAtom(rootRef))?.pendingSubagentRequest).toBe("approval");
454
455 // Once it is answered, neither stays flagged.
456 registry.set(snapshotAtom(thirdEnvironmentId), {
457 ...v2ShellSnapshot,
458 threads: [nestedTask],
459 });
460 expect(registry.get(threads.threadShellAtom(rootRef))?.pendingSubagentRequest).toBeNull();
461
462 // Environments that delegate to each other still settle on the root's flag.
463 registry.set(snapshotAtom(environmentId), {
464 ...v2ShellSnapshot,
465 threads: [root, { ...returningTask, pendingRuntimeRequest: approval }],
466 });
467 expect(registry.get(threads.threadShellAtom(rootRef))?.pendingSubagentRequest).toBe("approval");
468 disposeTask();
469 disposeRoot();
470 registry.dispose();
471 });
472
473 it.each([
474 { reason: "switched-off", state: { enabled: false } },
475 {
476 reason: "unsupported",
477 state: { enabled: true, unsupportedReason: "Use a compatible client." },
478 },
479 ])("leaves $reason environments out of navigation until restored", ({ state }) => {
480 const { registry, threads, catalogValueAtom } = makeHarness([
481 environmentId,
482 remoteEnvironmentId,
483 ]);
484 const dispose = registry.mount(threads.navigationThreadShellsAtom);
485 const environmentsOf = () =>
486 new Set(registry.get(threads.navigationThreadShellsAtom).map((t) => t.environmentId));
487 expect(environmentsOf()).toEqual(new Set([environmentId, remoteEnvironmentId]));
488
489 const setRemotePaused = (paused: boolean) => {
490 const catalog = registry.get(catalogValueAtom);
491 const entries = new Map(catalog.entries);
492 entries.set(remoteEnvironmentId, {
493 ...entries.get(remoteEnvironmentId)!,
494 ...(paused ? state : { enabled: true, unsupportedReason: undefined }),
495 });
496 registry.set(catalogValueAtom, { ...catalog, entries });
497 };
498 setRemotePaused(true);
499 expect(environmentsOf()).toEqual(new Set([environmentId]));
500 setRemotePaused(false);
501 expect(environmentsOf()).toEqual(new Set([environmentId, remoteEnvironmentId]));
502 dispose();
503 registry.dispose();
504 });
505
506 it("preserves project memberships on updates and keeps the same thread separate per environment", () => {
507 const harness = makeHarness([environmentId, remoteEnvironmentId]);
508 const otherThread = {
509 ...v2ThreadShell,
510 id: ThreadId.make("other-thread"),
511 projectId: otherProjectId,
512 };
513 const snapshot = { ...v2ShellSnapshot, threads: [v2ThreadShell, otherThread] };
514 harness.registry.set(harness.snapshotAtom(environmentId), snapshot);
515 const membershipAtom = harness.threads.environmentThreadRefsByProjectAtom(environmentId);
516 const listAtom = harness.threads.threadShellsForProjectRefsAtom([
517 { environmentId: remoteEnvironmentId, projectId: v2ThreadShell.projectId },
518 { environmentId, projectId: v2ThreadShell.projectId },
519 ]);
520 const disposeList = harness.registry.mount(listAtom);
521 try {
522 const membership = harness.registry.get(membershipAtom);
523 const before = harness.registry.get(listAtom);
524 expect(before).toHaveLength(2);
525 expect(before[0]).not.toBe(before[1]);
526 expect(before.map((thread) => thread.environmentId)).toEqual([
527 remoteEnvironmentId,
528 environmentId,
529 ]);
530
531 harness.registry.set(harness.snapshotAtom(environmentId), {
532 ...snapshot,
533 threads: [v2ThreadShell, { ...otherThread, title: "Changed elsewhere" }],
534 });
535 expect(harness.registry.get(membershipAtom)).toBe(membership);
536 expect(harness.registry.get(listAtom)).toBe(before);
537
538 harness.registry.set(harness.snapshotAtom(environmentId), {
539 ...snapshot,
540 threads: [{ ...v2ThreadShell, projectId: otherProjectId }, otherThread],
541 });
542 expect(harness.registry.get(listAtom)).toEqual([before[0]]);
543 harness.registry.set(harness.snapshotAtom(remoteEnvironmentId), {
544 ...v2ShellSnapshot,
545 threads: [],
546 });
547 expect(harness.registry.get(listAtom)).toEqual([]);
548 } finally {
549 disposeList();
550 harness.registry.dispose();
551 }
552 });
553
554 it("keeps the quiet shell through streaming ticks and follows every change once the run stops", () => {
555 const harness = makeHarness();
556 const runId = RunId.make("streaming-run");
557 const running: OrchestrationV2ThreadShell = {
558 ...v2ThreadShell,
559 latestRunId: runId,
560 activeRunId: runId,
561 status: "running",
562 itemCount: 1,
563 visibleItemCount: 1,
564 };
565 const setThread = (thread: OrchestrationV2ThreadShell, sequence: number) =>
566 harness.registry.set(harness.snapshotAtom(environmentId), {
567 ...v2ShellSnapshot,
568 snapshotSequence: sequence,
569 threads: [thread],
570 });
571 const at = (seconds: number) => DateTime.add(v2Now, { seconds });
572 setThread(running, 1);
573 const ref = { environmentId, threadId: v2ThreadShell.id };
574 const quietAtom = harness.threads.quietThreadShellAtom(ref);
575 const dispose = harness.registry.mount(quietAtom);
576 try {
577 const first = harness.registry.get(quietAtom);
578 setThread({ ...running, updatedAt: at(1), itemCount: 4, visibleItemCount: 3 }, 2);
579 expect(harness.registry.get(quietAtom)).toBe(first);
580 expect(harness.registry.get(harness.threads.threadShellAtom(ref))?.itemCount).toBe(4);
581
582 setThread({ ...running, updatedAt: at(2), itemCount: 5, title: "Renamed" }, 3);
583 const renamed = harness.registry.get(quietAtom);
584 expect(renamed?.title).toBe("Renamed");
585
586 const stopped: OrchestrationV2ThreadShell = {
587 ...running,
588 activeRunId: null,
589 status: "completed",
590 };
591 setThread({ ...stopped, title: "Renamed", updatedAt: at(3) }, 4);
592 const completed = harness.registry.get(quietAtom);
593 expect(completed).not.toBe(renamed);
594 setThread({ ...stopped, title: "Renamed", updatedAt: at(4) }, 5);
595 expect(harness.registry.get(quietAtom)?.updatedAt).toBe(DateTime.formatIso(at(4)));
596 expect(harness.registry.get(quietAtom)).not.toBe(completed);
597 } finally {
598 dispose();
599 harness.registry.dispose();
600 }
601 });
602
603 it("keeps the quiet shell list through streaming ticks", () => {
604 const harness = makeHarness();
605 const runId = RunId.make("streaming-list-run");
606 const running: OrchestrationV2ThreadShell = {
607 ...v2ThreadShell,
608 latestRunId: runId,
609 activeRunId: runId,
610 status: "running",
611 itemCount: 1,
612 visibleItemCount: 1,
613 };
614 const setThread = (thread: OrchestrationV2ThreadShell, sequence: number) =>
615 harness.registry.set(harness.snapshotAtom(environmentId), {
616 ...v2ShellSnapshot,
617 snapshotSequence: sequence,
618 threads: [thread],
619 });
620 setThread(running, 1);
621 const listAtom = harness.threads.quietThreadShellsAtom;
622 const dispose = harness.registry.mount(listAtom);
623 try {
624 const first = harness.registry.get(listAtom);
625 expect(first).toHaveLength(1);
626 setThread({ ...running, updatedAt: DateTime.add(v2Now, { seconds: 1 }), itemCount: 4 }, 2);
627 expect(harness.registry.get(listAtom)).toBe(first);
628
629 setThread({ ...running, title: "Renamed" }, 3);
630 expect(harness.registry.get(listAtom)).not.toBe(first);
631 expect(harness.registry.get(listAtom)[0]?.title).toBe("Renamed");
632 } finally {
633 dispose();
634 harness.registry.dispose();
635 }
636 });
637});