Open History to see the last commit
1import {
2 EnvironmentId,
3 MessageId,
4 NodeId,
5 ProviderDriverKind,
6 ProviderInstanceId,
7 ProviderSessionId,
8 ProviderThreadId,
9 RunId,
10 RuntimeRequestId,
11 TurnItemId,
12} from "@t3tools/contracts";
13import * as DateTime from "effect/DateTime";
14import { describe, expect, it } from "vite-plus/test";
15
16import {
17 InvalidScopedProjectRefCollectionKeyError,
18 InvalidScopedThreadKeyError,
19 parseProjectRefCollectionKey,
20 parseThreadKey,
21} from "./entities.ts";
22import {
23 presentThreadShell,
24 resolveThreadProviderStack,
25 resolveThreadWorkingStartedAt,
26} from "./models.ts";
27import { v2Projection, v2ThreadShell } from "./orchestrationV2TestFixtures.ts";
28import { deriveLatestThreadRun, deriveThreadRuntime } from "./threadExecution.ts";
29import { derivePendingThreadRequests } from "./threadRequests.ts";
30
31const environmentId = EnvironmentId.make("environment-v2");
32
33describe("scoped entity keys", () => {
34 it("preserves an invalid thread key as structured error data", () => {
35 const key = "missing-thread-key-separator";
36 let error: unknown;
37
38 try {
39 parseThreadKey(key);
40 } catch (cause) {
41 error = cause;
42 }
43
44 expect(error).toEqual(new InvalidScopedThreadKeyError({ key }));
45 });
46
47 it("preserves malformed project reference collection input and its cause", () => {
48 const key = "not-json";
49 let error: unknown;
50
51 try {
52 parseProjectRefCollectionKey(key);
53 } catch (cause) {
54 error = cause;
55 }
56
57 expect(error).toBeInstanceOf(InvalidScopedProjectRefCollectionKeyError);
58 expect(error).toMatchObject({ key, cause: expect.anything() });
59 });
60
61 it("rejects invalid project reference collection shapes", () => {
62 const key = JSON.stringify([["environment-1"]]);
63
64 expect(() => parseProjectRefCollectionKey(key)).toThrowError(
65 InvalidScopedProjectRefCollectionKeyError,
66 );
67 });
68});
69
70describe("V2 client presentation", () => {
71 it("presents shell timestamps and status without constructing V1 state", () => {
72 const shell = presentThreadShell(environmentId, v2ThreadShell);
73 expect(shell.environmentId).toBe(environmentId);
74 expect(shell.createdAt).toBe("2026-06-20T00:00:00.000Z");
75 expect(shell.runtime).toBeNull();
76 expect(shell.source).toBe(v2ThreadShell);
77 });
78
79 it("preserves active ordering and both pull-request sources", () => {
80 const linkedPullRequest = {
81 projectId: v2ThreadShell.projectId,
82 repository: "pingdotgg/t3code",
83 number: 42,
84 url: "https://github.com/pingdotgg/t3code/pull/42",
85 };
86 const branchPullRequest = { ...linkedPullRequest, number: 43 };
87 const shell = presentThreadShell(environmentId, {
88 ...v2ThreadShell,
89 activeOrderKey: "m",
90 linkedPullRequest,
91 branchPullRequest,
92 });
93
94 expect(shell.activeOrderKey).toBe("m");
95 expect(shell.linkedPullRequest).toEqual(linkedPullRequest);
96 expect(shell.branchPullRequest).toEqual(branchPullRequest);
97 });
98
99 it("presents provider errors carried by failed thread shells", () => {
100 const runId = RunId.make("run-failed");
101 const shell = presentThreadShell(environmentId, {
102 ...v2ThreadShell,
103 latestRunId: runId,
104 status: "failed",
105 lastError: "provider process exited",
106 });
107
108 expect(shell.runtime).toMatchObject({
109 status: "failed",
110 lastError: "provider process exited",
111 });
112 });
113
114 it("preserves shell run timestamps for sidebar activity clocks", () => {
115 const runId = RunId.make("run-working-clock");
116 const requestedAt = DateTime.makeUnsafe("2026-06-20T01:00:00.000Z");
117 const startedAt = DateTime.makeUnsafe("2026-06-20T01:00:02.000Z");
118 const shell = presentThreadShell(environmentId, {
119 ...v2ThreadShell,
120 latestRunId: runId,
121 latestRunRequestedAt: requestedAt,
122 latestRunStartedAt: startedAt,
123 latestRunCompletedAt: null,
124 activeRunId: runId,
125 status: "running",
126 updatedAt: DateTime.makeUnsafe("2026-06-20T01:04:45.000Z"),
127 });
128
129 expect(shell.latestRun).toMatchObject({
130 runId,
131 status: "running",
132 requestedAt: "2026-06-20T01:00:00.000Z",
133 startedAt: "2026-06-20T01:00:02.000Z",
134 completedAt: null,
135 });
136 });
137
138 it("parks presented runtime at idle when a settled shell has pending background tasks", () => {
139 const runId = RunId.make("run-completed");
140 const shell = presentThreadShell(environmentId, {
141 ...v2ThreadShell,
142 latestRunId: runId,
143 activeRunId: null,
144 status: "completed",
145 pendingBackgroundTasks: [{ taskId: "bg-1", description: "Watch build", kind: "monitor" }],
146 });
147
148 expect(shell.latestRun).toMatchObject({ runId, status: "completed" });
149 expect(shell.runtime).toMatchObject({
150 status: "idle",
151 activeRunId: null,
152 });
153 expect(shell.pendingBackgroundTasks).toEqual([
154 { taskId: "bg-1", description: "Watch build", kind: "monitor" },
155 ]);
156 });
157
158 it("parks a thread that never ran at idle while a pull request watch holds it", () => {
159 const watch = { taskId: "pull-request-watch:github.com/acme/app#1", kind: "monitor" as const };
160 const watched = presentThreadShell(environmentId, {
161 ...v2ThreadShell,
162 latestRunId: null,
163 activeProviderThreadId: null,
164 activeRunId: null,
165 status: "idle",
166 pendingBackgroundTasks: [watch],
167 });
168 expect(watched.runtime).toMatchObject({ status: "idle", activeRunId: null });
169 expect(
170 presentThreadShell(environmentId, {
171 ...v2ThreadShell,
172 latestRunId: null,
173 activeProviderThreadId: null,
174 status: "idle",
175 pendingBackgroundTasks: [],
176 }).runtime,
177 ).toBeNull();
178 });
179
180 it.each([
181 { kinds: ["command"], expected: "completed" },
182 { kinds: ["command", "subagent"], expected: "idle" },
183 { kinds: ["background_task"], expected: "idle" },
184 ] as const)("presents a completed shell with $kinds as $expected", ({ kinds, expected }) => {
185 const pendingBackgroundTasks = kinds.map((kind, index) => ({
186 taskId: `bg-${index}`,
187 kind,
188 }));
189 const shell = presentThreadShell(environmentId, {
190 ...v2ThreadShell,
191 latestRunId: RunId.make("run-completed"),
192 activeRunId: null,
193 status: "completed",
194 pendingBackgroundTasks,
195 });
196
197 expect(shell.latestRun?.status).toBe("completed");
198 expect(shell.runtime).toMatchObject({ status: expected, activeRunId: null });
199 expect(shell.pendingBackgroundTasks).toEqual(pendingBackgroundTasks);
200 });
201
202 it.each(["running", "waiting"] as const)(
203 "preserves shell %s while only commands remain in the roster",
204 (status) => {
205 const runId = RunId.make("run-command");
206 const shell = presentThreadShell(environmentId, {
207 ...v2ThreadShell,
208 latestRunId: runId,
209 activeRunId: runId,
210 status,
211 pendingBackgroundTasks: [{ taskId: "dev-server", kind: "command" }],
212 });
213
214 expect(shell.latestRun?.status).toBe(status);
215 expect(shell.runtime).toMatchObject({ status, activeRunId: runId });
216 expect(shell.pendingBackgroundTasks).toEqual([{ taskId: "dev-server", kind: "command" }]);
217 },
218 );
219
220 it("keeps a failed latest run failed while background tasks are still pending", () => {
221 const shell = presentThreadShell(environmentId, {
222 ...v2ThreadShell,
223 latestRunId: RunId.make("run-failed"),
224 activeRunId: null,
225 status: "failed",
226 lastError: "Provider turn failed",
227 pendingBackgroundTasks: [{ taskId: "bg-1", description: "Watch build", kind: "monitor" }],
228 });
229
230 expect(shell.runtime).toMatchObject({ status: "failed", lastError: "Provider turn failed" });
231 expect(shell.pendingBackgroundTasks).toHaveLength(1);
232 });
233
234 it("stacks earlier provider owners behind the current one, newest history first to go", () => {
235 const codex = ProviderInstanceId.make("codex");
236 const claude = ProviderInstanceId.make("claude");
237 const cursor = ProviderInstanceId.make("cursor");
238 const grok = ProviderInstanceId.make("grok");
239 const shell = presentThreadShell(environmentId, {
240 ...v2ThreadShell,
241 providerInstanceId: grok,
242 modelSelection: { instanceId: grok, model: "grok-4" },
243 providerInstanceHistory: [codex, claude, cursor, grok],
244 });
245
246 expect(resolveThreadProviderStack(shell)).toEqual([claude, cursor, grok]);
247 expect(
248 resolveThreadProviderStack({ ...shell, providerInstanceHistory: [codex, grok] }),
249 ).toEqual([codex, grok]);
250 expect(resolveThreadProviderStack({ ...shell, providerInstanceHistory: [] })).toEqual([grok]);
251 expect(
252 presentThreadShell(environmentId, { ...v2ThreadShell, providerInstanceHistory: undefined })
253 .providerInstanceHistory,
254 ).toEqual([]);
255 });
256
257 it("keeps terminal runtime completed when there are no pending background tasks", () => {
258 const runId = RunId.make("run-completed");
259 const shell = presentThreadShell(environmentId, {
260 ...v2ThreadShell,
261 latestRunId: runId,
262 activeRunId: null,
263 status: "completed",
264 pendingBackgroundTasks: [],
265 });
266
267 expect(shell.latestRun).toMatchObject({ runId, status: "completed" });
268 expect(shell.runtime).toMatchObject({
269 status: "completed",
270 activeRunId: null,
271 });
272 });
273
274 it("keeps runtime running when there is no background roster", () => {
275 const runId = RunId.make("run-running");
276 const shell = presentThreadShell(environmentId, {
277 ...v2ThreadShell,
278 latestRunId: runId,
279 activeRunId: runId,
280 status: "running",
281 pendingBackgroundTasks: [],
282 });
283
284 expect(shell.latestRun).toMatchObject({ runId, status: "running" });
285 expect(shell.runtime).toMatchObject({
286 status: "running",
287 activeRunId: runId,
288 });
289 });
290
291 it("keeps an older active run visible over a newer cancelled run", () => {
292 const activeRunId = RunId.make("run-active");
293 const cancelledRunId = RunId.make("run-cancelled");
294 const shell = presentThreadShell(environmentId, {
295 ...v2ThreadShell,
296 latestRunId: cancelledRunId,
297 latestRunStartedAt: null,
298 latestRunCompletedAt: DateTime.makeUnsafe("2026-06-20T01:05:00.000Z"),
299 activeRunId,
300 activityRunStatus: "running",
301 status: "cancelled",
302 pendingBackgroundTasks: [],
303 });
304
305 expect(shell.latestRun).toMatchObject({ runId: cancelledRunId, status: "cancelled" });
306 expect(shell.runtime).toMatchObject({
307 status: "running",
308 activeRunId,
309 });
310 });
311
312 it("keeps an older waiting run visible over a newer cancelled run", () => {
313 const shell = presentThreadShell(environmentId, {
314 ...v2ThreadShell,
315 latestRunId: RunId.make("run-cancelled"),
316 activeRunId: null,
317 activityRunStatus: "waiting",
318 status: "cancelled",
319 pendingBackgroundTasks: [],
320 });
321
322 expect(shell.runtime).toMatchObject({ status: "waiting", activeRunId: null });
323 });
324
325 it("keeps a post-settlement background roster ahead of activity status", () => {
326 const activeRunId = RunId.make("run-active");
327 const shell = presentThreadShell(environmentId, {
328 ...v2ThreadShell,
329 latestRunId: RunId.make("run-cancelled"),
330 activeRunId,
331 activityRunStatus: "running",
332 status: "cancelled",
333 pendingBackgroundTasks: [
334 { taskId: "bg-activity", description: "background work", kind: "background_task" },
335 ],
336 });
337
338 expect(shell.runtime).toMatchObject({ status: "idle", activeRunId });
339 });
340
341 it("parks runtime idle over stale shell running when the roster is nonempty", () => {
342 const runId = RunId.make("run-stale-running");
343 const shell = presentThreadShell(environmentId, {
344 ...v2ThreadShell,
345 latestRunId: runId,
346 activeRunId: runId,
347 status: "running",
348 pendingBackgroundTasks: [{ taskId: "bg-1", description: "Watch build", kind: "monitor" }],
349 });
350
351 expect(shell.latestRun).toMatchObject({ runId, status: "running" });
352 expect(shell.runtime).toMatchObject({
353 status: "idle",
354 activeRunId: runId,
355 });
356 expect(shell.pendingBackgroundTasks).toEqual([
357 { taskId: "bg-1", description: "Watch build", kind: "monitor" },
358 ]);
359 });
360
361 it("parks runtime idle over stale checkpoint waiting when the roster is nonempty", () => {
362 const runId = RunId.make("run-stale-waiting");
363 const shell = presentThreadShell(environmentId, {
364 ...v2ThreadShell,
365 latestRunId: runId,
366 activeRunId: runId,
367 status: "waiting",
368 pendingBackgroundTasks: [{ taskId: "bg-2", description: "Watch build", kind: "monitor" }],
369 });
370
371 expect(shell.latestRun).toMatchObject({ runId, status: "waiting" });
372 expect(shell.runtime).toMatchObject({
373 status: "idle",
374 activeRunId: runId,
375 });
376 expect(shell.pendingBackgroundTasks).toEqual([
377 { taskId: "bg-2", description: "Watch build", kind: "monitor" },
378 ]);
379 });
380
381 it("derives execution summaries without wrapping or copying the projection", () => {
382 const runId = RunId.make("run-1");
383 const now = DateTime.makeUnsafe("2026-06-20T01:00:00.000Z");
384 const projection = {
385 ...v2Projection,
386 runs: [
387 {
388 id: runId,
389 threadId: v2Projection.thread.id,
390 ordinal: 1,
391 providerInstanceId: v2Projection.thread.providerInstanceId,
392 modelSelection: v2Projection.thread.modelSelection,
393 providerThreadId: null,
394 userMessageId: MessageId.make("message-user"),
395 rootNodeId: null,
396 activeAttemptId: null,
397 status: "running" as const,
398 requestedAt: now,
399 startedAt: now,
400 completedAt: null,
401 checkpointId: null,
402 contextHandoffId: null,
403 },
404 ],
405 messages: [
406 {
407 id: MessageId.make("message-user"),
408 threadId: v2Projection.thread.id,
409 runId,
410 nodeId: null,
411 role: "user" as const,
412 text: "Hello",
413 attachments: [],
414 streaming: false,
415 createdBy: "user" as const,
416 creationSource: "web" as const,
417 createdAt: now,
418 updatedAt: now,
419 },
420 ],
421 updatedAt: now,
422 };
423
424 expect(deriveLatestThreadRun(projection)).toMatchObject({
425 runId,
426 status: "running",
427 requestedAt: "2026-06-20T01:00:00.000Z",
428 assistantMessageId: null,
429 });
430 expect(deriveThreadRuntime(projection)).toMatchObject({
431 status: "running",
432 activeRunId: runId,
433 providerInstanceId: projection.thread.providerInstanceId,
434 });
435 for (const status of ["queued", "cancelled"] as const) {
436 const later = DateTime.add(now, { hours: 1 });
437 const latest = {
438 ...projection.runs[0]!,
439 id: RunId.make("newer-run"),
440 ordinal: 2,
441 status,
442 requestedAt: later,
443 startedAt: null,
444 completedAt: status === "cancelled" ? later : null,
445 };
446 const detail = { ...projection, runs: [...projection.runs, latest], updatedAt: later };
447 const shell = presentThreadShell(environmentId, {
448 ...v2ThreadShell,
449 latestRunId: latest.id,
450 latestRunStartedAt: null,
451 latestRunRequestedAt: later,
452 latestRunCompletedAt: latest.completedAt,
453 status,
454 activeRunId: runId,
455 activityRunStatus: "running",
456 activityRunStartedAt: now,
457 updatedAt: later,
458 });
459 expect(resolveThreadWorkingStartedAt(shell)).toBe(DateTime.formatIso(now));
460 expect(
461 resolveThreadWorkingStartedAt({
462 latestRun: deriveLatestThreadRun(detail),
463 runtime: deriveThreadRuntime(detail),
464 }),
465 ).toBe(resolveThreadWorkingStartedAt(shell));
466 const stopped = {
467 ...detail,
468 runs: detail.runs.map((run) => ({
469 ...run,
470 status: "completed" as const,
471 completedAt: later,
472 })),
473 };
474 expect(
475 resolveThreadWorkingStartedAt({
476 latestRun: deriveLatestThreadRun(stopped),
477 runtime: deriveThreadRuntime(stopped),
478 }),
479 ).toBeNull();
480 }
481 });
482
483 it("parks waiting runtime for a post-settlement roster without hiding active running work", () => {
484 const runId = RunId.make("run-background-presentation");
485 const now = DateTime.makeUnsafe("2026-06-20T01:00:00.000Z");
486 const run = {
487 id: runId,
488 threadId: v2Projection.thread.id,
489 ordinal: 1,
490 providerInstanceId: v2Projection.thread.providerInstanceId,
491 modelSelection: v2Projection.thread.modelSelection,
492 providerThreadId: null,
493 userMessageId: MessageId.make("message-background-presentation"),
494 rootNodeId: null,
495 activeAttemptId: null,
496 status: "waiting" as const,
497 requestedAt: now,
498 startedAt: now,
499 completedAt: null,
500 checkpointId: null,
501 contextHandoffId: null,
502 };
503 const backgroundItem = {
504 id: TurnItemId.make("item-background-subagent"),
505 threadId: v2Projection.thread.id,
506 runId,
507 nodeId: null,
508 providerThreadId: null,
509 providerTurnId: null,
510 nativeItemRef: null,
511 parentItemId: null,
512 ordinal: 0,
513 status: "running" as const,
514 title: "Background review",
515 startedAt: now,
516 completedAt: null,
517 updatedAt: now,
518 type: "subagent" as const,
519 subagentId: NodeId.make("subagent-review"),
520 origin: "provider_native" as const,
521 driver: ProviderDriverKind.make("codex"),
522 providerInstanceId: v2Projection.thread.providerInstanceId,
523 childThreadId: null,
524 prompt: "Review the changes",
525 result: null,
526 };
527
528 expect(
529 deriveThreadRuntime({
530 ...v2Projection,
531 runs: [run],
532 turnItems: [backgroundItem],
533 }),
534 ).toMatchObject({
535 status: "idle",
536 activeRunId: null,
537 });
538 expect(
539 deriveThreadRuntime({
540 ...v2Projection,
541 runs: [{ ...run, status: "running" as const }],
542 turnItems: [backgroundItem],
543 }),
544 ).toMatchObject({
545 status: "running",
546 activeRunId: runId,
547 });
548 expect(
549 deriveThreadRuntime({
550 ...v2Projection,
551 runs: [{ ...run, status: "failed" as const, completedAt: now }],
552 turnItems: [backgroundItem],
553 }),
554 ).toMatchObject({ status: "failed", activeRunId: null });
555 const commandItem = {
556 ...backgroundItem,
557 id: TurnItemId.make("item-background-command"),
558 type: "command_execution" as const,
559 input: "npm run dev",
560 };
561 expect(
562 deriveThreadRuntime({ ...v2Projection, runs: [run], turnItems: [commandItem] }),
563 ).toMatchObject({ status: "waiting", activeRunId: null });
564
565 for (const [turnItems, status] of [
566 [[commandItem], "completed"],
567 [[backgroundItem], "idle"],
568 [[commandItem, backgroundItem], "idle"],
569 ] as const) {
570 expect(
571 deriveThreadRuntime({
572 ...v2Projection,
573 runs: [{ ...run, status: "completed", completedAt: now }],
574 turnItems,
575 }),
576 ).toMatchObject({ status, activeRunId: null });
577 }
578
579 for (const kind of ["monitor", "background_task"] as const) {
580 const providerThread = {
581 id: ProviderThreadId.make("provider-thread-background"),
582 driver: ProviderDriverKind.make("claudeCode"),
583 providerInstanceId: v2Projection.thread.providerInstanceId,
584 providerSessionId: null,
585 appThreadId: v2Projection.thread.id,
586 ownerNodeId: null,
587 nativeThreadRef: null,
588 nativeConversationHeadRef: null,
589 status: "idle" as const,
590 firstRunOrdinal: 1,
591 lastRunOrdinal: 1,
592 handoffIds: [],
593 forkedFrom: null,
594 pendingBackgroundTasks: [{ taskId: "background-task", kind }],
595 createdAt: now,
596 updatedAt: now,
597 };
598 for (const status of ["completed", "failed"] as const) {
599 expect(
600 deriveThreadRuntime({
601 ...v2Projection,
602 runs: [{ ...run, status, completedAt: now }],
603 providerThreads: [providerThread],
604 }),
605 ).toMatchObject({ status: status === "failed" ? "failed" : "idle", activeRunId: null });
606 }
607 }
608 });
609
610 it("joins pending request entities to their native turn-item display data", () => {
611 const now = DateTime.makeUnsafe("2026-06-20T01:00:00.000Z");
612 const requestId = RuntimeRequestId.make("request-approval");
613 const item = {
614 id: TurnItemId.make("item-approval"),
615 threadId: v2Projection.thread.id,
616 runId: null,
617 nodeId: NodeId.make("node-root"),
618 providerThreadId: null,
619 providerTurnId: null,
620 nativeItemRef: null,
621 parentItemId: null,
622 ordinal: 0,
623 status: "completed" as const,
624 title: null,
625 startedAt: now,
626 completedAt: now,
627 updatedAt: now,
628 type: "approval_request" as const,
629 requestId,
630 requestKind: "command" as const,
631 prompt: "Allow command?",
632 };
633 const projection = {
634 ...v2Projection,
635 runtimeRequests: [
636 {
637 id: requestId,
638 nodeId: NodeId.make("node-root"),
639 providerTurnId: null,
640 nativeRequestRef: null,
641 kind: "command" as const,
642 status: "pending" as const,
643 responseCapability: {
644 type: "not_resumable" as const,
645 reason: "provider disconnected",
646 },
647 createdAt: now,
648 resolvedAt: null,
649 },
650 ],
651 turnItems: [item],
652 updatedAt: now,
653 };
654
655 expect(derivePendingThreadRequests(projection).approvals).toEqual([
656 {
657 requestId,
658 requestKind: "command",
659 createdAt: "2026-06-20T01:00:00.000Z",
660 detail: "Allow command?",
661 responseCapability: "not_resumable",
662 },
663 ]);
664 expect(derivePendingThreadRequests(projection).userInputs).toEqual([]);
665 });
666
667 it("preserves structured-question selection mode and defaults legacy payloads", () => {
668 const now = DateTime.makeUnsafe("2026-06-20T01:00:00.000Z");
669 const multiRequestId = RuntimeRequestId.make("request-multi-select");
670 const legacyRequestId = RuntimeRequestId.make("request-legacy-single-select");
671 const runtimeRequests = [multiRequestId, legacyRequestId].map((id) => ({
672 id,
673 nodeId: NodeId.make(`node-${id}`),
674 providerTurnId: null,
675 nativeRequestRef: null,
676 kind: "user_input" as const,
677 status: "pending" as const,
678 responseCapability: {
679 type: "live" as const,
680 providerSessionId: ProviderSessionId.make("provider-session-questions"),
681 },
682 createdAt: now,
683 resolvedAt: null,
684 }));
685 const common = {
686 threadId: v2Projection.thread.id,
687 runId: null,
688 providerThreadId: null,
689 providerTurnId: null,
690 nativeItemRef: null,
691 parentItemId: null,
692 ordinal: 0,
693 status: "completed" as const,
694 title: null,
695 startedAt: now,
696 completedAt: now,
697 updatedAt: now,
698 type: "user_input_request" as const,
699 };
700 const projection = {
701 ...v2Projection,
702 runtimeRequests,
703 turnItems: [
704 {
705 ...common,
706 id: TurnItemId.make("item-multi-select"),
707 nodeId: NodeId.make("node-request-multi-select"),
708 requestId: multiRequestId,
709 questions: [
710 {
711 id: "regions",
712 header: "Regions",
713 question: "Which regions?",
714 options: [
715 { label: "US", description: "United States" },
716 { label: "EU", description: "European Union" },
717 ],
718 multiSelect: true,
719 },
720 ],
721 },
722 {
723 ...common,
724 id: TurnItemId.make("item-legacy-single-select"),
725 nodeId: NodeId.make("node-request-legacy-single-select"),
726 requestId: legacyRequestId,
727 questions: [
728 {
729 id: "target",
730 header: "Target",
731 question: "Which target?",
732 options: [{ label: "Staging", description: "Staging environment" }],
733 },
734 ],
735 },
736 ],
737 updatedAt: now,
738 };
739
740 expect(
741 derivePendingThreadRequests(projection).userInputs.map((input) => ({
742 requestId: input.requestId,
743 multiSelect: input.questions[0]?.multiSelect,
744 })),
745 ).toEqual([
746 { requestId: multiRequestId, multiSelect: true },
747 { requestId: legacyRequestId, multiSelect: false },
748 ]);
749 });
750});