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

threadShell.test.ts

632 lines24.0 KB

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 };
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 } = {},
185 ) =>
186 registry.set(snapshotAtom(environmentId), {
187 ...v2ShellSnapshot,
188 threads: [
189 root,
190 {
191 ...sideChat,
192 pendingRuntimeRequest: {
193 ...request,
194 kind,
195 ...(options.blocking === undefined ? {} : { blocking: options.blocking }),
196 },
197 },
198 ],
199 });
200​
201 withRequest("user_input");
202 expect(registry.get(parent)?.pendingSubagentRequest).toBe("user_input");
203 expect(childThreadInputsTitle(registry.get(inputs))).toBe("Side chat needs input");
204 expect(registry.get(threads.navigationThreadShellsAtom).map((thread) => thread.id)).toEqual([
205 root.id,
206 ]);
207​
208 withRequest("user_input", { blocking: false });
209 expect(registry.get(parent)?.pendingSubagentRequest).toBe("user_input");
210​
211 withRequest("command");
212 expect(registry.get(parent)?.pendingSubagentRequest).toBe("approval");
213 expect(childThreadInputsTitle(registry.get(inputs))).toBe("Side chat needs approval");
214​
215 const helper = {
216 ...sideChat,
217 id: ThreadId.make("side-chat-helper"),
218 creationSource: "mcp" as const,
219 lineage: {
220 ...sideChat.lineage,
221 parentThreadId: sideChat.id,
222 relationshipToParent: "subagent" as const,
223 sideChat: false,
224 },
225 pendingRuntimeRequest: { ...request, kind: "command" as const },
226 };
227 const sideChats = threads.sideChatsAtom(parentRef);
228 const disposeSideChats = registry.mount(sideChats);
229 registry.set(snapshotAtom(environmentId), {
230 ...v2ShellSnapshot,
231 threads: [root, sideChat, helper],
232 });
233 expect(registry.get(parent)?.pendingSubagentRequest).toBe("approval");
234 expect(
235 registry.get(sideChats).map((thread) => [thread.id, thread.pendingSubagentRequest]),
236 ).toEqual([[sideChat.id, "approval"]]);
237​
238 registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [root, sideChat] });
239 expect(registry.get(parent)?.pendingSubagentRequest).toBeNull();
240 expect(registry.get(sideChats).map((thread) => thread.pendingSubagentRequest)).toEqual([null]);
241 expect(registry.get(inputs)).toEqual([]);
242 disposeSideChats();
243 disposeNavigation();
244 disposeInputs();
245 disposeParent();
246 registry.dispose();
247 });
248​
249 it("brings a parent back from Working while a nested subagent waits for approval", () => {
250 const { registry, threads, snapshotAtom } = makeHarness();
251 const child = {
252 ...v2ThreadShell,
253 id: ThreadId.make("review"),
254 creationSource: "mcp" as const,
255 status: "running" as const,
256 activityRunStatus: "running" as const,
257 lineage: {
258 ...v2ThreadShell.lineage,
259 parentThreadId: v2ThreadShell.id,
260 relationshipToParent: "subagent" as const,
261 },
262 };
263 const grandchild = {
264 ...child,
265 id: ThreadId.make("review-helper"),
266 lineage: { ...child.lineage, parentThreadId: child.id },
267 };
268 const root = {
269 ...v2ThreadShell,
270 latestRunId: RunId.make("root-run"),
271 status: "completed" as const,
272 pendingBackgroundTasks: [
273 { taskId: "review", kind: "subagent" as const, childThreadId: child.id },
274 ],
275 };
276 const approval = {
277 id: RuntimeRequestId.make("cat-file"),
278 kind: "command" as const,
279 createdAt: v2Now,
280 };
281 const parent = threads.threadShellAtom({ environmentId, threadId: root.id });
282 const inputs = threads.childThreadInputsAtom({ environmentId, threadId: root.id });
283 const disposeParent = registry.mount(parent);
284 const disposeInputs = registry.mount(inputs);
285 registry.set(snapshotAtom(environmentId), {
286 ...v2ShellSnapshot,
287 threads: [root, child, grandchild],
288 });
289 expect(isThreadWorking(registry.get(parent)!)).toBe(true);
290​
291 registry.set(snapshotAtom(environmentId), {
292 ...v2ShellSnapshot,
293 threads: [root, child, { ...grandchild, pendingRuntimeRequest: approval }],
294 });
295 expect(registry.get(parent)?.pendingSubagentRequest).toBe("approval");
296 expect(isThreadWorking(registry.get(parent)!)).toBe(false);
297 const asking = registry.get(inputs);
298 expect(asking.map((thread) => thread.id)).toEqual([grandchild.id]);
299 expect(childThreadInputsTitle(asking)).toBe("Subagent needs approval");
300​
301 registry.set(snapshotAtom(environmentId), {
302 ...v2ShellSnapshot,
303 threads: [root, child, grandchild],
304 });
305 expect(registry.get(parent)?.pendingSubagentRequest).toBeNull();
306 expect(isThreadWorking(registry.get(parent)!)).toBe(true);
307 disposeInputs();
308 disposeParent();
309 registry.dispose();
310 });
311​
312 it("lists a task a linked environment runs for a listed thread under that thread", () => {
313 const { registry, threads, snapshotAtom, catalogValueAtom } = makeHarness([
314 environmentId,
315 remoteEnvironmentId,
316 ]);
317 const parent = v2ThreadShell;
318 const task = {
319 ...v2ThreadShell,
320 id: ThreadId.make("remote-task"),
321 creationSource: "mcp" as const,
322 status: "running" as const,
323 activityRunStatus: "running" as const,
324 delegatedFrom: { environmentId, threadId: parent.id, title: parent.title },
325 };
326 const helper = {
327 ...task,
328 id: ThreadId.make("remote-helper"),
329 delegatedFrom: undefined,
330 lineage: {
331 ...task.lineage,
332 parentThreadId: task.id,
333 relationshipToParent: "subagent" as const,
334 },
335 };
336 const approval = {
337 id: RuntimeRequestId.make("cat-file"),
338 kind: "command" as const,
339 createdAt: v2Now,
340 };
341 registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [parent] });
342 registry.set(snapshotAtom(remoteEnvironmentId), {
343 ...v2ShellSnapshot,
344 threads: [task, helper],
345 });
346 const parentRef = { environmentId, threadId: parent.id };
347 const inputs = threads.childThreadInputsAtom(parentRef);
348 const disposeNavigation = registry.mount(threads.navigationThreadShellsAtom);
349 const disposeParent = registry.mount(threads.threadShellAtom(parentRef));
350 const disposeInputs = registry.mount(inputs);
351 const listed = () =>
352 registry
353 .get(threads.navigationThreadShellsAtom)
354 .map((thread) => `${thread.environmentId}/${thread.id}`);
355 expect(listed()).toEqual([`${environmentId}/${parent.id}`]);
356​
357 // The helper the task started there asks for approval: the parent here hears of it.
358 registry.set(snapshotAtom(remoteEnvironmentId), {
359 ...v2ShellSnapshot,
360 threads: [task, { ...helper, pendingRuntimeRequest: approval }],
361 });
362 expect(registry.get(threads.threadShellAtom(parentRef))?.pendingSubagentRequest).toBe(
363 "approval",
364 );
365 expect(registry.get(inputs).map((thread) => `${thread.environmentId}/${thread.id}`)).toEqual([
366 `${remoteEnvironmentId}/${helper.id}`,
367 ]);
368​
369 registry.set(snapshotAtom(remoteEnvironmentId), {
370 ...v2ShellSnapshot,
371 threads: [
372 task,
373 { ...helper, pendingRuntimeRequest: { ...approval, kind: "user_input" as const } },
374 ],
375 });
376 expect(registry.get(threads.threadShellAtom(parentRef))?.pendingSubagentRequest).toBeNull();
377 expect(registry.get(inputs).map((thread) => thread.id)).toEqual([helper.id]);
378​
379 // A task whose parent is gone there is listed on its own, as is one whose
380 // parent's environment is switched off.
381 registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [] });
382 expect(listed()).toEqual([`${remoteEnvironmentId}/${task.id}`]);
383 // Archiving the parent here leaves the task there unarchived, so it is listed on its own.
384 registry.set(snapshotAtom(environmentId), {
385 ...v2ShellSnapshot,
386 threads: [{ ...parent, archivedAt: v2Now }],
387 });
388 expect(listed()).toEqual([`${remoteEnvironmentId}/${task.id}`]);
389 registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [parent] });
390 expect(listed()).toEqual([`${environmentId}/${parent.id}`]);
391 const catalog = registry.get(catalogValueAtom);
392 const entries = new Map(catalog.entries);
393 entries.set(environmentId, { ...entries.get(environmentId)!, enabled: false });
394 registry.set(catalogValueAtom, { ...catalog, entries });
395 expect(listed()).toEqual([`${remoteEnvironmentId}/${task.id}`]);
396 disposeInputs();
397 disposeParent();
398 disposeNavigation();
399 registry.dispose();
400 });
401​
402 it("brings an approval up a chain of tasks across three environments to its root", () => {
403 const thirdEnvironmentId = EnvironmentId.make("third-environment-v2");
404 const { registry, threads, snapshotAtom } = makeHarness([
405 environmentId,
406 remoteEnvironmentId,
407 thirdEnvironmentId,
408 ]);
409 const root = v2ThreadShell;
410 const running = {
411 creationSource: "mcp" as const,
412 status: "running" as const,
413 activityRunStatus: "running" as const,
414 };
415 const task = {
416 ...v2ThreadShell,
417 ...running,
418 id: ThreadId.make("remote-task"),
419 delegatedFrom: { environmentId, threadId: root.id, title: root.title },
420 };
421 const nestedTask = {
422 ...v2ThreadShell,
423 ...running,
424 id: ThreadId.make("third-task"),
425 delegatedFrom: { environmentId: remoteEnvironmentId, threadId: task.id, title: task.title },
426 };
427 // A task the middle one delegates back to the root's own environment.
428 const returningTask = {
429 ...nestedTask,
430 id: ThreadId.make("returning-task"),
431 };
432 const approval = {
433 id: RuntimeRequestId.make("cat-file"),
434 kind: "command" as const,
435 createdAt: v2Now,
436 };
437 registry.set(snapshotAtom(environmentId), { ...v2ShellSnapshot, threads: [root] });
438 registry.set(snapshotAtom(remoteEnvironmentId), { ...v2ShellSnapshot, threads: [task] });
439 registry.set(snapshotAtom(thirdEnvironmentId), {
440 ...v2ShellSnapshot,
441 threads: [{ ...nestedTask, pendingRuntimeRequest: approval }],
442 });
443 const rootRef = { environmentId, threadId: root.id };
444 const taskRef = { environmentId: remoteEnvironmentId, threadId: task.id };
445 const disposeRoot = registry.mount(threads.threadShellAtom(rootRef));
446 const disposeTask = registry.mount(threads.threadShellAtom(taskRef));
447 expect(registry.get(threads.threadShellAtom(taskRef))?.pendingSubagentRequest).toBe("approval");
448 expect(registry.get(threads.threadShellAtom(rootRef))?.pendingSubagentRequest).toBe("approval");
449​
450 // Once it is answered, neither stays flagged.
451 registry.set(snapshotAtom(thirdEnvironmentId), {
452 ...v2ShellSnapshot,
453 threads: [nestedTask],
454 });
455 expect(registry.get(threads.threadShellAtom(rootRef))?.pendingSubagentRequest).toBeNull();
456​
457 // Environments that delegate to each other still settle on the root's flag.
458 registry.set(snapshotAtom(environmentId), {
459 ...v2ShellSnapshot,
460 threads: [root, { ...returningTask, pendingRuntimeRequest: approval }],
461 });
462 expect(registry.get(threads.threadShellAtom(rootRef))?.pendingSubagentRequest).toBe("approval");
463 disposeTask();
464 disposeRoot();
465 registry.dispose();
466 });
467​
468 it.each([
469 { reason: "switched-off", state: { enabled: false } },
470 {
471 reason: "unsupported",
472 state: { enabled: true, unsupportedReason: "Use a compatible client." },
473 },
474 ])("leaves $reason environments out of navigation until restored", ({ state }) => {
475 const { registry, threads, catalogValueAtom } = makeHarness([
476 environmentId,
477 remoteEnvironmentId,
478 ]);
479 const dispose = registry.mount(threads.navigationThreadShellsAtom);
480 const environmentsOf = () =>
481 new Set(registry.get(threads.navigationThreadShellsAtom).map((t) => t.environmentId));
482 expect(environmentsOf()).toEqual(new Set([environmentId, remoteEnvironmentId]));
483​
484 const setRemotePaused = (paused: boolean) => {
485 const catalog = registry.get(catalogValueAtom);
486 const entries = new Map(catalog.entries);
487 entries.set(remoteEnvironmentId, {
488 ...entries.get(remoteEnvironmentId)!,
489 ...(paused ? state : { enabled: true, unsupportedReason: undefined }),
490 });
491 registry.set(catalogValueAtom, { ...catalog, entries });
492 };
493 setRemotePaused(true);
494 expect(environmentsOf()).toEqual(new Set([environmentId]));
495 setRemotePaused(false);
496 expect(environmentsOf()).toEqual(new Set([environmentId, remoteEnvironmentId]));
497 dispose();
498 registry.dispose();
499 });
500​
501 it("preserves project memberships on updates and keeps the same thread separate per environment", () => {
502 const harness = makeHarness([environmentId, remoteEnvironmentId]);
503 const otherThread = {
504 ...v2ThreadShell,
505 id: ThreadId.make("other-thread"),
506 projectId: otherProjectId,
507 };
508 const snapshot = { ...v2ShellSnapshot, threads: [v2ThreadShell, otherThread] };
509 harness.registry.set(harness.snapshotAtom(environmentId), snapshot);
510 const membershipAtom = harness.threads.environmentThreadRefsByProjectAtom(environmentId);
511 const listAtom = harness.threads.threadShellsForProjectRefsAtom([
512 { environmentId: remoteEnvironmentId, projectId: v2ThreadShell.projectId },
513 { environmentId, projectId: v2ThreadShell.projectId },
514 ]);
515 const disposeList = harness.registry.mount(listAtom);
516 try {
517 const membership = harness.registry.get(membershipAtom);
518 const before = harness.registry.get(listAtom);
519 expect(before).toHaveLength(2);
520 expect(before[0]).not.toBe(before[1]);
521 expect(before.map((thread) => thread.environmentId)).toEqual([
522 remoteEnvironmentId,
523 environmentId,
524 ]);
525​
526 harness.registry.set(harness.snapshotAtom(environmentId), {
527 ...snapshot,
528 threads: [v2ThreadShell, { ...otherThread, title: "Changed elsewhere" }],
529 });
530 expect(harness.registry.get(membershipAtom)).toBe(membership);
531 expect(harness.registry.get(listAtom)).toBe(before);
532​
533 harness.registry.set(harness.snapshotAtom(environmentId), {
534 ...snapshot,
535 threads: [{ ...v2ThreadShell, projectId: otherProjectId }, otherThread],
536 });
537 expect(harness.registry.get(listAtom)).toEqual([before[0]]);
538 harness.registry.set(harness.snapshotAtom(remoteEnvironmentId), {
539 ...v2ShellSnapshot,
540 threads: [],
541 });
542 expect(harness.registry.get(listAtom)).toEqual([]);
543 } finally {
544 disposeList();
545 harness.registry.dispose();
546 }
547 });
548​
549 it("keeps the quiet shell through streaming ticks and follows every change once the run stops", () => {
550 const harness = makeHarness();
551 const runId = RunId.make("streaming-run");
552 const running: OrchestrationV2ThreadShell = {
553 ...v2ThreadShell,
554 latestRunId: runId,
555 activeRunId: runId,
556 status: "running",
557 itemCount: 1,
558 visibleItemCount: 1,
559 };
560 const setThread = (thread: OrchestrationV2ThreadShell, sequence: number) =>
561 harness.registry.set(harness.snapshotAtom(environmentId), {
562 ...v2ShellSnapshot,
563 snapshotSequence: sequence,
564 threads: [thread],
565 });
566 const at = (seconds: number) => DateTime.add(v2Now, { seconds });
567 setThread(running, 1);
568 const ref = { environmentId, threadId: v2ThreadShell.id };
569 const quietAtom = harness.threads.quietThreadShellAtom(ref);
570 const dispose = harness.registry.mount(quietAtom);
571 try {
572 const first = harness.registry.get(quietAtom);
573 setThread({ ...running, updatedAt: at(1), itemCount: 4, visibleItemCount: 3 }, 2);
574 expect(harness.registry.get(quietAtom)).toBe(first);
575 expect(harness.registry.get(harness.threads.threadShellAtom(ref))?.itemCount).toBe(4);
576​
577 setThread({ ...running, updatedAt: at(2), itemCount: 5, title: "Renamed" }, 3);
578 const renamed = harness.registry.get(quietAtom);
579 expect(renamed?.title).toBe("Renamed");
580​
581 const stopped: OrchestrationV2ThreadShell = {
582 ...running,
583 activeRunId: null,
584 status: "completed",
585 };
586 setThread({ ...stopped, title: "Renamed", updatedAt: at(3) }, 4);
587 const completed = harness.registry.get(quietAtom);
588 expect(completed).not.toBe(renamed);
589 setThread({ ...stopped, title: "Renamed", updatedAt: at(4) }, 5);
590 expect(harness.registry.get(quietAtom)?.updatedAt).toBe(DateTime.formatIso(at(4)));
591 expect(harness.registry.get(quietAtom)).not.toBe(completed);
592 } finally {
593 dispose();
594 harness.registry.dispose();
595 }
596 });
597​
598 it("keeps the quiet shell list through streaming ticks", () => {
599 const harness = makeHarness();
600 const runId = RunId.make("streaming-list-run");
601 const running: OrchestrationV2ThreadShell = {
602 ...v2ThreadShell,
603 latestRunId: runId,
604 activeRunId: runId,
605 status: "running",
606 itemCount: 1,
607 visibleItemCount: 1,
608 };
609 const setThread = (thread: OrchestrationV2ThreadShell, sequence: number) =>
610 harness.registry.set(harness.snapshotAtom(environmentId), {
611 ...v2ShellSnapshot,
612 snapshotSequence: sequence,
613 threads: [thread],
614 });
615 setThread(running, 1);
616 const listAtom = harness.threads.quietThreadShellsAtom;
617 const dispose = harness.registry.mount(listAtom);
618 try {
619 const first = harness.registry.get(listAtom);
620 expect(first).toHaveLength(1);
621 setThread({ ...running, updatedAt: DateTime.add(v2Now, { seconds: 1 }), itemCount: 4 }, 2);
622 expect(harness.registry.get(listAtom)).toBe(first);
623​
624 setThread({ ...running, title: "Renamed" }, 3);
625 expect(harness.registry.get(listAtom)).not.toBe(first);
626 expect(harness.registry.get(listAtom)[0]?.title).toBe("Renamed");
627 } finally {
628 dispose();
629 harness.registry.dispose();
630 }
631 });
632});