Open History to see the last commit
1import {
2 EnvironmentId,
3 MessageId,
4 ProjectId,
5 ProviderInstanceId,
6 ThreadId,
7 TurnId,
8} from "@t3tools/contracts";
9import { afterEach, describe, expect, it, vi } from "vite-plus/test";
10
11import type { Thread, ThreadShell } from "../types";
12import {
13 MAX_HIDDEN_MOUNTED_PREVIEW_THREADS,
14 MAX_HIDDEN_MOUNTED_TERMINAL_THREADS,
15 branchMismatchKey,
16 buildExpiredTerminalContextToastCopy,
17 buildLoadingThreadFromShell,
18 buildThreadTurnInterruptInput,
19 createLocalDispatchSnapshot,
20 deriveComposerSendState,
21 dismissBranchMismatchForSession,
22 ENVIRONMENT_RECONNECT_WARNING_GRACE_MS,
23 getStartedThreadModelChangeBlockReason,
24 hasEnvironmentReconnectWarningGraceElapsed,
25 hasServerAcknowledgedLocalDispatch,
26 isBranchMismatchDismissedForSession,
27 reconcileMountedTerminalThreadIds,
28 reconcileRetainedMountedThreadIds,
29 resolveBackgroundDraftWorkspaceOptions,
30 resolveDraftPromotionNavigationTarget,
31 resolveThreadMetadataUpdateForNextTurn,
32 resolveSendEnvMode,
33 resolveDraftHeroState,
34 scheduleEnvironmentReconnectWarning,
35 startNewThreadForProject,
36 shouldDockDraftHeroForSubmission,
37 shouldShowBranchMismatchBanner,
38 shouldWriteThreadErrorToCurrentServerThread,
39} from "./ChatView.logic";
40
41const environmentId = EnvironmentId.make("environment-local");
42const projectId = ProjectId.make("project-1");
43const threadId = ThreadId.make("thread-1");
44const now = "2026-03-29T00:00:00.000Z";
45
46describe("draft hero submission transition", () => {
47 it("does not dock the composer before a background submission", () => {
48 expect(
49 shouldDockDraftHeroForSubmission({
50 isDraftHeroState: true,
51 activeThreadKey: "environment-local:thread-1",
52 submissionIntent: "background",
53 }),
54 ).toBe(false);
55 });
56
57 it("keeps the composer in the hero layout until navigation after server promotion", () => {
58 expect(
59 resolveDraftHeroState({
60 isLocalDraftThread: false,
61 hasTimelineEntries: true,
62 isWorking: true,
63 draftHeroDockRequested: false,
64 backgroundSubmissionPending: true,
65 }),
66 ).toBe(true);
67 });
68
69 it("does not auto-navigate a background submission after server promotion", () => {
70 expect(
71 resolveDraftPromotionNavigationTarget({
72 serverThreadRef: { environmentId, threadId },
73 serverThreadStarted: true,
74 backgroundSubmissionPending: true,
75 }),
76 ).toBeNull();
77 });
78});
79
80describe("environment reconnect warning grace", () => {
81 afterEach(() => vi.useRealTimers());
82
83 it("shows a persistent reconnect after the grace period", () => {
84 vi.useFakeTimers();
85 const showWarning = vi.fn();
86
87 scheduleEnvironmentReconnectWarning(showWarning);
88 vi.advanceTimersByTime(ENVIRONMENT_RECONNECT_WARNING_GRACE_MS - 1);
89 expect(showWarning).not.toHaveBeenCalled();
90
91 vi.advanceTimersByTime(1);
92 expect(showWarning).toHaveBeenCalledOnce();
93 });
94
95 it("cancels the warning when the connection recovers during the grace period", () => {
96 vi.useFakeTimers();
97 const showWarning = vi.fn();
98
99 const cancel = scheduleEnvironmentReconnectWarning(showWarning);
100 cancel();
101 vi.advanceTimersByTime(ENVIRONMENT_RECONNECT_WARNING_GRACE_MS);
102
103 expect(showWarning).not.toHaveBeenCalled();
104 });
105
106 it("does not reuse elapsed grace from another environment", () => {
107 const anotherEnvironmentId = EnvironmentId.make("environment-remote");
108
109 expect(hasEnvironmentReconnectWarningGraceElapsed(environmentId, environmentId)).toBe(true);
110 expect(hasEnvironmentReconnectWarningGraceElapsed(anotherEnvironmentId, environmentId)).toBe(
111 false,
112 );
113 });
114});
115
116function makeThread(overrides: Partial<Thread> = {}): Thread {
117 return {
118 id: threadId,
119 environmentId,
120 projectId,
121 title: "Thread",
122 modelSelection: {
123 instanceId: ProviderInstanceId.make("codex"),
124 model: "gpt-5.4",
125 },
126 runtimeMode: "full-access",
127 interactionMode: "default",
128 session: null,
129 messages: [],
130 proposedPlans: [],
131 activities: [],
132 checkpoints: [],
133 createdAt: now,
134 updatedAt: now,
135 archivedAt: null,
136 settledOverride: null,
137 settledAt: null,
138 deletedAt: null,
139 latestTurn: null,
140 branch: null,
141 worktreePath: null,
142 ...overrides,
143 };
144}
145
146const completedTurn = {
147 turnId: TurnId.make("turn-1"),
148 state: "completed" as const,
149 requestedAt: now,
150 startedAt: "2026-03-29T00:00:01.000Z",
151 completedAt: "2026-03-29T00:00:10.000Z",
152 assistantMessageId: null,
153};
154
155const readySession = {
156 threadId,
157 status: "ready" as const,
158 providerName: "codex",
159 providerInstanceId: ProviderInstanceId.make("codex"),
160 runtimeMode: "full-access" as const,
161 activeTurnId: null,
162 lastError: null,
163 updatedAt: "2026-03-29T00:00:10.000Z",
164};
165
166describe("buildLoadingThreadFromShell", () => {
167 it("preserves shell metadata and supplies empty detail collections", () => {
168 const shell = {
169 environmentId,
170 id: threadId,
171 projectId,
172 title: "Loading thread",
173 modelSelection: {
174 instanceId: ProviderInstanceId.make("codex"),
175 model: "gpt-5.4",
176 },
177 runtimeMode: "full-access",
178 interactionMode: "default",
179 branch: "main",
180 worktreePath: null,
181 latestTurn: null,
182 createdAt: now,
183 updatedAt: now,
184 archivedAt: null,
185 settledOverride: null,
186 settledAt: null,
187 snoozedUntil: null,
188 snoozedAt: null,
189 session: null,
190 latestUserMessageAt: now,
191 hasPendingApprovals: false,
192 hasPendingUserInput: false,
193 hasActionableProposedPlan: false,
194 } satisfies ThreadShell;
195
196 expect(buildLoadingThreadFromShell(shell)).toMatchObject({
197 environmentId,
198 id: threadId,
199 projectId,
200 title: "Loading thread",
201 branch: "main",
202 deletedAt: null,
203 messages: [],
204 proposedPlans: [],
205 activities: [],
206 checkpoints: [],
207 });
208 });
209});
210
211describe("resolveThreadMetadataUpdateForNextTurn", () => {
212 const modelSelection = {
213 instanceId: ProviderInstanceId.make("codex"),
214 model: "gpt-5.4",
215 };
216
217 it("updates a stale local thread branch to the active checkout", () => {
218 expect(
219 resolveThreadMetadataUpdateForNextTurn({
220 currentModelSelection: modelSelection,
221 currentBranch: "feature/thread",
222 nextBranch: "feature/checkout",
223 }),
224 ).toEqual({ branch: "feature/checkout", worktreePath: null });
225 });
226
227 it("does not write metadata when the model and branch are unchanged", () => {
228 expect(
229 resolveThreadMetadataUpdateForNextTurn({
230 currentModelSelection: modelSelection,
231 nextModelSelection: modelSelection,
232 currentBranch: "feature/current",
233 nextBranch: "feature/current",
234 }),
235 ).toBeNull();
236 });
237});
238
239describe("buildThreadTurnInterruptInput", () => {
240 it("targets the session's active running turn", () => {
241 const activeTurnId = TurnId.make("turn-running");
242
243 expect(
244 buildThreadTurnInterruptInput(
245 makeThread({
246 session: {
247 ...readySession,
248 status: "running",
249 activeTurnId,
250 },
251 }),
252 ),
253 ).toEqual({ threadId, turnId: activeTurnId });
254 });
255
256 it("omits a turn id when the session is not running", () => {
257 expect(buildThreadTurnInterruptInput(makeThread({ session: readySession }))).toEqual({
258 threadId,
259 });
260 });
261});
262
263describe("deriveComposerSendState", () => {
264 it("treats expired terminal pills as non-sendable content", () => {
265 const state = deriveComposerSendState({
266 prompt: "\uFFFC",
267 imageCount: 0,
268 terminalContexts: [
269 {
270 id: "ctx-expired",
271 threadId,
272 terminalId: "default",
273 terminalLabel: "Terminal 1",
274 lineStart: 4,
275 lineEnd: 4,
276 text: "",
277 createdAt: now,
278 },
279 ],
280 });
281
282 expect(state.trimmedPrompt).toBe("");
283 expect(state.sendableTerminalContexts).toEqual([]);
284 expect(state.expiredTerminalContextCount).toBe(1);
285 expect(state.hasSendableContent).toBe(false);
286 });
287
288 it("keeps text sendable while excluding expired terminal pills", () => {
289 const state = deriveComposerSendState({
290 prompt: `yoo \uFFFC waddup`,
291 imageCount: 0,
292 terminalContexts: [
293 {
294 id: "ctx-expired",
295 threadId,
296 terminalId: "default",
297 terminalLabel: "Terminal 1",
298 lineStart: 4,
299 lineEnd: 4,
300 text: "",
301 createdAt: now,
302 },
303 ],
304 });
305
306 expect(state.trimmedPrompt).toBe("yoo waddup");
307 expect(state.expiredTerminalContextCount).toBe(1);
308 expect(state.hasSendableContent).toBe(true);
309 });
310
311 it("treats element contexts as sendable content (no text, no images, no terminals)", () => {
312 const state = deriveComposerSendState({
313 prompt: "",
314 imageCount: 0,
315 terminalContexts: [],
316 elementContextCount: 1,
317 });
318
319 expect(state.trimmedPrompt).toBe("");
320 expect(state.expiredTerminalContextCount).toBe(0);
321 expect(state.hasSendableContent).toBe(true);
322 });
323
324 it("does NOT treat zero element contexts as sendable", () => {
325 expect(
326 deriveComposerSendState({
327 prompt: "",
328 imageCount: 0,
329 terminalContexts: [],
330 elementContextCount: 0,
331 }).hasSendableContent,
332 ).toBe(false);
333 });
334});
335
336describe("buildExpiredTerminalContextToastCopy", () => {
337 it("formats empty and omission guidance", () => {
338 expect(buildExpiredTerminalContextToastCopy(1, "empty")).toEqual({
339 title: "Expired terminal context won't be sent",
340 description: "Remove it or re-add it to include terminal output.",
341 });
342 expect(buildExpiredTerminalContextToastCopy(2, "omitted")).toEqual({
343 title: "Expired terminal contexts omitted from message",
344 description: "Re-add it if you want that terminal output included.",
345 });
346 });
347});
348
349describe("getStartedThreadModelChangeBlockReason", () => {
350 const providers = [
351 {
352 instanceId: ProviderInstanceId.make("codex"),
353 },
354 {
355 instanceId: ProviderInstanceId.make("grok"),
356 requiresNewThreadForModelChange: true,
357 },
358 ];
359
360 it("allows model changes before a provider session has started", () => {
361 expect(
362 getStartedThreadModelChangeBlockReason({
363 providers,
364 hasStartedSession: false,
365 currentModelSelection: {
366 instanceId: ProviderInstanceId.make("grok"),
367 model: "grok-build",
368 },
369 nextModelSelection: {
370 instanceId: ProviderInstanceId.make("grok"),
371 model: "grok-other",
372 },
373 }),
374 ).toBeNull();
375 });
376
377 it("allows unchanged model selections for restricted providers", () => {
378 expect(
379 getStartedThreadModelChangeBlockReason({
380 providers,
381 hasStartedSession: true,
382 currentModelSelection: {
383 instanceId: ProviderInstanceId.make("grok"),
384 model: "grok-build",
385 },
386 nextModelSelection: {
387 instanceId: ProviderInstanceId.make("grok"),
388 model: "grok-build",
389 },
390 }),
391 ).toBeNull();
392 });
393
394 it("blocks started-session model changes when either provider requires a new thread", () => {
395 expect(
396 getStartedThreadModelChangeBlockReason({
397 providers,
398 hasStartedSession: true,
399 currentModelSelection: {
400 instanceId: ProviderInstanceId.make("codex"),
401 model: "gpt-5.4",
402 },
403 nextModelSelection: {
404 instanceId: ProviderInstanceId.make("grok"),
405 model: "grok-build",
406 },
407 }),
408 ).toEqual({
409 title: "Start a new chat to change models",
410 description:
411 "This provider does not allow switching models after a conversation has started.",
412 });
413 });
414});
415
416describe("resolveSendEnvMode", () => {
417 it("keeps worktree mode only for git repositories", () => {
418 expect(resolveSendEnvMode({ requestedEnvMode: "worktree", isGitRepo: true })).toBe("worktree");
419 expect(resolveSendEnvMode({ requestedEnvMode: "worktree", isGitRepo: false })).toBe("local");
420 });
421});
422
423describe("resolveBackgroundDraftWorkspaceOptions", () => {
424 it("keeps New worktree selected without reusing the launched worktree", () => {
425 expect(
426 resolveBackgroundDraftWorkspaceOptions({
427 envMode: "worktree",
428 branch: "main",
429 startFromOrigin: true,
430 }),
431 ).toEqual({
432 envMode: "worktree",
433 branch: "main",
434 worktreePath: null,
435 startFromOrigin: true,
436 });
437 });
438});
439
440describe("branchMismatchKey", () => {
441 it("builds a key from thread id and both branches", () => {
442 expect(branchMismatchKey("thread-1", { threadBranch: "feat/a", currentBranch: "feat/b" })).toBe(
443 "thread-1:feat/a:feat/b",
444 );
445 });
446
447 it("returns null without a thread or mismatch", () => {
448 expect(branchMismatchKey(null, { threadBranch: "a", currentBranch: "b" })).toBeNull();
449 expect(branchMismatchKey("thread-1", null)).toBeNull();
450 });
451});
452
453describe("shouldShowBranchMismatchBanner", () => {
454 const base = {
455 hasMismatch: true,
456 isDismissed: false,
457 composerHasContent: false,
458 wasShownForCurrentMismatch: false,
459 };
460
461 it("stays hidden during passive browsing (even though the composer autofocuses)", () => {
462 expect(shouldShowBranchMismatchBanner(base)).toBe(false);
463 });
464
465 it("shows once the composer has draft content", () => {
466 expect(shouldShowBranchMismatchBanner({ ...base, composerHasContent: true })).toBe(true);
467 });
468
469 it("stays mounted after the draft clears once shown for the current mismatch", () => {
470 expect(shouldShowBranchMismatchBanner({ ...base, wasShownForCurrentMismatch: true })).toBe(
471 true,
472 );
473 });
474
475 it("never shows when dismissed or without a mismatch", () => {
476 expect(
477 shouldShowBranchMismatchBanner({ ...base, composerHasContent: true, isDismissed: true }),
478 ).toBe(false);
479 expect(
480 shouldShowBranchMismatchBanner({ ...base, composerHasContent: true, hasMismatch: false }),
481 ).toBe(false);
482 });
483});
484
485describe("session branch mismatch dismissal", () => {
486 it("tracks dismissed keys and treats other keys as active", () => {
487 expect(isBranchMismatchDismissedForSession("t1:a:b")).toBe(false);
488 dismissBranchMismatchForSession("t1:a:b");
489 expect(isBranchMismatchDismissedForSession("t1:a:b")).toBe(true);
490 expect(isBranchMismatchDismissedForSession("t1:a:c")).toBe(false);
491 expect(isBranchMismatchDismissedForSession(null)).toBe(false);
492 });
493});
494
495describe("reconcileMountedTerminalThreadIds", () => {
496 it("keeps open threads and makes the active thread most recent", () => {
497 expect(
498 reconcileMountedTerminalThreadIds({
499 currentThreadIds: ["thread-a", "thread-b", "thread-c"],
500 openThreadIds: ["thread-a", "thread-b", "thread-c"],
501 activeThreadId: "thread-a",
502 activeThreadTerminalOpen: true,
503 maxHiddenThreadCount: 2,
504 }),
505 ).toEqual(["thread-b", "thread-c", "thread-a"]);
506 });
507
508 it("drops closed threads and enforces the hidden mounted cap", () => {
509 const ids = Array.from(
510 { length: MAX_HIDDEN_MOUNTED_TERMINAL_THREADS + 2 },
511 (_, index) => `thread-${index}`,
512 );
513 expect(
514 reconcileMountedTerminalThreadIds({
515 currentThreadIds: ids,
516 openThreadIds: ids.slice(1),
517 activeThreadId: null,
518 activeThreadTerminalOpen: false,
519 }),
520 ).toEqual(ids.slice(-MAX_HIDDEN_MOUNTED_TERMINAL_THREADS));
521 });
522});
523
524describe("reconcileRetainedMountedThreadIds", () => {
525 it("retains hidden open threads and adds the active open thread", () => {
526 expect(
527 reconcileRetainedMountedThreadIds({
528 currentThreadIds: [ThreadId.make("thread-hidden")],
529 openThreadIds: [ThreadId.make("thread-hidden")],
530 activeThreadId: ThreadId.make("thread-active"),
531 activeThreadOpen: true,
532 maxHiddenThreadCount: MAX_HIDDEN_MOUNTED_PREVIEW_THREADS,
533 }),
534 ).toEqual([ThreadId.make("thread-hidden"), ThreadId.make("thread-active")]);
535 });
536
537 it("can retain the active thread as hidden when it is inactive", () => {
538 expect(
539 reconcileRetainedMountedThreadIds({
540 currentThreadIds: [ThreadId.make("thread-active")],
541 openThreadIds: [ThreadId.make("thread-active")],
542 activeThreadId: ThreadId.make("thread-active"),
543 activeThreadOpen: false,
544 maxHiddenThreadCount: MAX_HIDDEN_MOUNTED_PREVIEW_THREADS,
545 retainInactiveActiveThread: true,
546 }),
547 ).toEqual([ThreadId.make("thread-active")]);
548 });
549
550 it("evicts the oldest hidden threads beyond the configured cap", () => {
551 const currentThreadIds = Array.from(
552 { length: MAX_HIDDEN_MOUNTED_PREVIEW_THREADS + 2 },
553 (_, index) => ThreadId.make(`thread-${index + 1}`),
554 );
555
556 expect(
557 reconcileRetainedMountedThreadIds({
558 currentThreadIds,
559 openThreadIds: currentThreadIds,
560 activeThreadId: null,
561 activeThreadOpen: false,
562 maxHiddenThreadCount: MAX_HIDDEN_MOUNTED_PREVIEW_THREADS,
563 }),
564 ).toEqual(currentThreadIds.slice(-MAX_HIDDEN_MOUNTED_PREVIEW_THREADS));
565 });
566});
567
568describe("shouldWriteThreadErrorToCurrentServerThread", () => {
569 it("writes errors for a shell-derived active server thread", () => {
570 const routeThreadRef = { environmentId, threadId };
571
572 expect(
573 shouldWriteThreadErrorToCurrentServerThread({
574 activeServerThread: { environmentId, id: threadId },
575 routeThreadRef,
576 targetThreadId: threadId,
577 }),
578 ).toBe(true);
579 });
580
581 it("requires an active server thread matching the environment, route, and target", () => {
582 const routeThreadRef = { environmentId, threadId };
583
584 expect(
585 shouldWriteThreadErrorToCurrentServerThread({
586 activeServerThread: null,
587 routeThreadRef,
588 targetThreadId: threadId,
589 }),
590 ).toBe(false);
591 });
592});
593
594describe("startNewThreadForProject", () => {
595 it("starts a thread through the supplied shared handler for the active project", () => {
596 const calls: Array<{ environmentId: EnvironmentId; projectId: ProjectId }> = [];
597 const projectRef = { environmentId, projectId };
598
599 expect(
600 startNewThreadForProject(projectRef, (nextProjectRef) => {
601 calls.push(nextProjectRef);
602 return Promise.resolve();
603 }),
604 ).toBe(true);
605 expect(calls).toEqual([projectRef]);
606 });
607
608 it("does nothing when the active project is unavailable", () => {
609 let called = false;
610
611 expect(
612 startNewThreadForProject(null, () => {
613 called = true;
614 return Promise.resolve();
615 }),
616 ).toBe(false);
617 expect(called).toBe(false);
618 });
619});
620
621describe("hasServerAcknowledgedLocalDispatch", () => {
622 it("does not acknowledge unchanged server state", () => {
623 const localDispatch = createLocalDispatchSnapshot(
624 makeThread({ latestTurn: completedTurn, session: readySession }),
625 );
626
627 expect(
628 hasServerAcknowledgedLocalDispatch({
629 localDispatch,
630 phase: "ready",
631 latestTurn: completedTurn,
632 latestUserMessageId: localDispatch.latestUserMessageId,
633 session: readySession,
634 hasPendingApproval: false,
635 hasPendingUserInput: false,
636 threadError: null,
637 }),
638 ).toBe(false);
639 });
640
641 it("acknowledges a settled newer turn", () => {
642 const localDispatch = createLocalDispatchSnapshot(
643 makeThread({ latestTurn: completedTurn, session: readySession }),
644 );
645 const newerTurn = {
646 ...completedTurn,
647 turnId: TurnId.make("turn-2"),
648 requestedAt: "2026-03-29T00:01:00.000Z",
649 startedAt: "2026-03-29T00:01:01.000Z",
650 completedAt: "2026-03-29T00:01:30.000Z",
651 };
652
653 expect(
654 hasServerAcknowledgedLocalDispatch({
655 localDispatch,
656 phase: "ready",
657 latestTurn: newerTurn,
658 latestUserMessageId: localDispatch.latestUserMessageId,
659 session: { ...readySession, updatedAt: newerTurn.completedAt },
660 hasPendingApproval: false,
661 hasPendingUserInput: false,
662 threadError: null,
663 }),
664 ).toBe(true);
665 });
666
667 it("waits for the matching running turn before acknowledging", () => {
668 const localDispatch = createLocalDispatchSnapshot(
669 makeThread({ latestTurn: completedTurn, session: readySession }),
670 );
671 const runningTurn = {
672 ...completedTurn,
673 turnId: TurnId.make("turn-2"),
674 state: "running" as const,
675 requestedAt: "2026-03-29T00:01:00.000Z",
676 startedAt: "2026-03-29T00:01:01.000Z",
677 completedAt: null,
678 };
679
680 expect(
681 hasServerAcknowledgedLocalDispatch({
682 localDispatch,
683 phase: "running",
684 latestTurn: runningTurn,
685 latestUserMessageId: localDispatch.latestUserMessageId,
686 session: {
687 ...readySession,
688 status: "running",
689 activeTurnId: TurnId.make("turn-other"),
690 },
691 hasPendingApproval: false,
692 hasPendingUserInput: false,
693 threadError: null,
694 }),
695 ).toBe(false);
696 expect(
697 hasServerAcknowledgedLocalDispatch({
698 localDispatch,
699 phase: "running",
700 latestTurn: runningTurn,
701 latestUserMessageId: localDispatch.latestUserMessageId,
702 session: {
703 ...readySession,
704 status: "running",
705 activeTurnId: runningTurn.turnId,
706 },
707 hasPendingApproval: false,
708 hasPendingUserInput: false,
709 threadError: null,
710 }),
711 ).toBe(true);
712 });
713
714 it("acknowledges a steering message projected onto the current running turn", () => {
715 const runningTurn = {
716 ...completedTurn,
717 state: "running" as const,
718 completedAt: null,
719 };
720 const runningSession = {
721 ...readySession,
722 status: "running" as const,
723 activeTurnId: runningTurn.turnId,
724 };
725 const localDispatch = createLocalDispatchSnapshot(
726 makeThread({
727 latestTurn: runningTurn,
728 session: runningSession,
729 messages: [
730 {
731 id: MessageId.make("message-before-steer"),
732 role: "user",
733 text: "Initial prompt",
734 turnId: runningTurn.turnId,
735 createdAt: runningTurn.requestedAt,
736 updatedAt: runningTurn.requestedAt,
737 streaming: false,
738 },
739 ],
740 }),
741 );
742
743 expect(
744 hasServerAcknowledgedLocalDispatch({
745 localDispatch,
746 phase: "running",
747 latestTurn: runningTurn,
748 latestUserMessageId: MessageId.make("message-steer"),
749 session: runningSession,
750 hasPendingApproval: false,
751 hasPendingUserInput: false,
752 threadError: null,
753 }),
754 ).toBe(true);
755 });
756
757 it("acknowledges pending user interaction and errors immediately", () => {
758 const localDispatch = createLocalDispatchSnapshot(makeThread());
759 const common = {
760 localDispatch,
761 phase: "ready" as const,
762 latestTurn: null,
763 latestUserMessageId: localDispatch.latestUserMessageId,
764 session: null,
765 hasPendingApproval: false,
766 hasPendingUserInput: false,
767 threadError: null,
768 };
769
770 expect(hasServerAcknowledgedLocalDispatch({ ...common, hasPendingApproval: true })).toBe(true);
771 expect(hasServerAcknowledgedLocalDispatch({ ...common, hasPendingUserInput: true })).toBe(true);
772 expect(hasServerAcknowledgedLocalDispatch({ ...common, threadError: "failed" })).toBe(true);
773 });
774});