Elffuss BraidHub

kikocis/continue public

f0ea2b85847c · 28.9 KiBRawPermalink
1import { JSONContent } from "@tiptap/core";
2import { InputModifiers } from "core";
3import { describe, expect, it, vi } from "vitest";
4import { createMockStore } from "../../util/test/mockStore";
5import { streamResponseThunk } from "./streamResponse";
6
7// Mock external dependencies only - let selectors run naturally
8// Removed: modelSupportsNativeTools - let it run naturally
9
10// Removed: addSystemMessageToolsToSystemMessage - let it run naturally
11
12// Mock system message construction to keep test readable
13vi.mock("../util/getBaseSystemMessage", () => ({
14 getBaseSystemMessage: vi.fn(),
15}));
16
17import { getBaseSystemMessage } from "../util/getBaseSystemMessage";
18
19// Removed: shouldAutoEnableSystemMessageTools - let it run naturally
20
21// Additional mocks for streamResponseThunk
22vi.mock("posthog-js", () => ({
23 default: {
24 capture: vi.fn(),
25 },
26}));
27
28vi.mock("uuid", () => ({
29 v4: vi.fn(() => "mock-uuid-123"),
30}));
31
32vi.mock(
33 "../../components/mainInput/TipTapEditor/utils/resolveEditorContent",
34 () => ({
35 resolveEditorContent: vi.fn(),
36 }),
37);
38
39import { ModelDescription } from "core";
40import posthog from "posthog-js";
41import { resolveEditorContent } from "../../components/mainInput/TipTapEditor/utils/resolveEditorContent";
42
43const mockGetBaseSystemMessage = vi.mocked(getBaseSystemMessage);
44
45const mockPosthog = vi.mocked(posthog);
46const mockResolveEditorContent = vi.mocked(resolveEditorContent);
47
48const mockClaudeModel: ModelDescription = {
49 title: "Claude 3.5 Sonnet",
50 model: "claude-3-5-sonnet-20241022",
51 provider: "anthropic",
52 underlyingProviderName: "anthropic",
53 completionOptions: { reasoningBudgetTokens: 2048 },
54};
55
56// Mock editor state (what user types in the input)
57const mockEditorState: JSONContent = {
58 type: "doc",
59 content: [
60 {
61 type: "paragraph",
62 content: [{ type: "text", text: "Hello, please help me with this code" }],
63 },
64 ],
65};
66
67// Mock input modifiers (codebase context, etc.)
68const mockModifiers: InputModifiers = {
69 useCodebase: true,
70 noContext: false,
71};
72
73function setupTest() {
74 vi.clearAllMocks();
75
76 // Default mock implementations for external functions
77
78 // Default mock for resolveEditorContent (can be overridden in individual tests)
79 mockResolveEditorContent.mockResolvedValue({
80 selectedContextItems: [],
81 selectedCode: [],
82 content: "Hello, please help me with this code",
83 legacyCommandWithInput: undefined,
84 });
85
86 // Mock getBaseSystemMessage to return simple system message for readable tests
87 mockGetBaseSystemMessage.mockReturnValue("You are a helpful assistant.");
88
89 // Create store with realistic state that selectors can work with
90 const mockStore = createMockStore({
91 session: {
92 history: [
93 {
94 message: { id: "1", role: "user", content: "Hello" },
95 contextItems: [],
96 },
97 ],
98 hasReasoningEnabled: false,
99 isStreaming: true,
100 id: "session-123",
101 mode: "chat",
102 streamAborter: new AbortController(),
103 contextPercentage: 0,
104 isPruned: false,
105 isInEdit: false,
106 title: "",
107 lastSessionId: undefined,
108 isSessionMetadataLoading: false,
109 allSessionMetadata: [],
110 symbols: {},
111 codeBlockApplyStates: {
112 states: [],
113 curIndex: 0,
114 },
115 newestToolbarPreviewForInput: {},
116 compactionLoading: {},
117 inlineErrorMessage: undefined,
118 },
119 config: {
120 config: {
121 tools: [],
122 rules: [],
123 tabAutocompleteModel: undefined,
124 selectedModelByRole: {
125 chat: mockClaudeModel,
126 apply: null,
127 edit: null,
128 summarize: null,
129 autocomplete: null,
130 rerank: null,
131 embed: null,
132 },
133 experimental: {
134 onlyUseSystemMessageTools: false,
135 },
136 } as any,
137 lastSelectedModelByRole: {
138 chat: mockClaudeModel.title,
139 },
140 } as any,
141 ui: {
142 toolSettings: {},
143 ruleSettings: {},
144 showDialog: false,
145 dialogMessage: undefined,
146 } as any,
147 });
148
149 const mockIdeMessenger = mockStore.mockIdeMessenger;
150
151 return { mockStore, mockIdeMessenger };
152}
153
154describe("streamResponseThunk", () => {
155 it("should throw error when no chat model is selected", async () => {
156 const { mockStore, mockIdeMessenger } = setupTest();
157
158 // Create store with no selected chat model
159 const mockStoreNoModel = createMockStore({
160 session: {
161 history: [
162 {
163 message: { id: "1", role: "user", content: "Hello" },
164 contextItems: [],
165 },
166 ],
167 hasReasoningEnabled: false,
168 isStreaming: true,
169 id: "session-123",
170 mode: "chat",
171 streamAborter: new AbortController(),
172 contextPercentage: 0,
173 isPruned: false,
174 isInEdit: false,
175 title: "",
176 lastSessionId: undefined,
177 isSessionMetadataLoading: false,
178 allSessionMetadata: [],
179 symbols: {},
180 codeBlockApplyStates: {
181 states: [],
182 curIndex: 0,
183 },
184 newestToolbarPreviewForInput: {},
185 compactionLoading: {},
186 inlineErrorMessage: undefined,
187 },
188 config: {
189 config: {
190 tools: [],
191 rules: [],
192 tabAutocompleteModel: undefined,
193 selectedModelByRole: {
194 chat: null, // No model selected
195 apply: null,
196 edit: null,
197 summarize: null,
198 autocomplete: null,
199 rerank: null,
200 embed: null,
201 },
202 experimental: {
203 onlyUseSystemMessageTools: false,
204 },
205 } as any,
206 lastSelectedModelByRole: {},
207 } as any,
208 ui: {
209 toolSettings: {},
210 ruleSettings: {},
211 showDialog: false,
212 dialogMessage: undefined,
213 } as any,
214 });
215
216 // Execute thunk and expect it to be rejected
217 const result = await mockStoreNoModel.dispatch(
218 streamResponseThunk({
219 editorState: mockEditorState,
220 modifiers: mockModifiers,
221 }) as any,
222 );
223
224 // Verify the thunk completed successfully but shows error dialog
225 expect(result.type).toBe("chat/streamResponse/fulfilled");
226
227 // Verify the complete error handling flow
228 const dispatchedActions = (mockStoreNoModel as any).getActions();
229 expect(dispatchedActions).toEqual([
230 {
231 type: "chat/streamResponse/pending",
232 meta: {
233 arg: {
234 editorState: mockEditorState,
235 modifiers: mockModifiers,
236 },
237 requestId: expect.any(String),
238 requestStatus: "pending",
239 },
240 payload: undefined,
241 },
242 {
243 type: "chat/streamWrapper/pending",
244 meta: {
245 arg: expect.any(Function),
246 requestId: expect.any(String),
247 requestStatus: "pending",
248 },
249 payload: undefined,
250 },
251 {
252 type: "chat/cancelStream/pending",
253 meta: {
254 arg: undefined,
255 requestId: expect.any(String),
256 requestStatus: "pending",
257 },
258 payload: undefined,
259 },
260 {
261 type: "session/setInactive",
262 payload: undefined,
263 },
264 {
265 type: "session/abortStream",
266 payload: undefined,
267 },
268 {
269 type: "session/clearDanglingMessages",
270 payload: undefined,
271 },
272 {
273 type: "chat/cancelStream/fulfilled",
274 meta: {
275 arg: undefined,
276 requestId: expect.any(String),
277 requestStatus: "fulfilled",
278 },
279 payload: undefined,
280 },
281 {
282 type: "ui/setDialogMessage",
283 payload: expect.objectContaining({
284 props: expect.objectContaining({
285 error: expect.objectContaining({
286 message: "No chat model selected",
287 }),
288 }),
289 }),
290 },
291 {
292 type: "ui/setShowDialog",
293 payload: true,
294 },
295 {
296 type: "chat/streamWrapper/fulfilled",
297 meta: {
298 arg: expect.any(Function),
299 requestId: expect.any(String),
300 requestStatus: "fulfilled",
301 },
302 payload: undefined,
303 },
304 {
305 type: "chat/streamResponse/fulfilled",
306 meta: {
307 arg: {
308 editorState: mockEditorState,
309 modifiers: mockModifiers,
310 },
311 requestId: expect.any(String),
312 requestStatus: "fulfilled",
313 },
314 payload: undefined,
315 },
316 ]);
317
318 // Verify no IDE messenger calls were made
319 expect(mockStoreNoModel.mockIdeMessenger.request).not.toHaveBeenCalled();
320 expect(
321 mockStoreNoModel.mockIdeMessenger.llmStreamChat,
322 ).not.toHaveBeenCalled();
323
324 // Verify final state shows error dialog and inactive streaming
325 const finalState = mockStoreNoModel.getState();
326 expect(finalState).toEqual({
327 session: {
328 history: [
329 {
330 contextItems: [],
331 isGatheringContext: false,
332 message: { id: "1", role: "user", content: "Hello" },
333 },
334 ],
335 hasReasoningEnabled: false,
336 isStreaming: false, // Set to inactive after error
337 id: "session-123",
338 mode: "chat",
339 streamAborter: expect.any(AbortController),
340 contextPercentage: 0,
341 isPruned: false,
342 isInEdit: false,
343 title: "",
344 lastSessionId: undefined,
345 isSessionMetadataLoading: false,
346 allSessionMetadata: [],
347 symbols: {},
348 codeBlockApplyStates: {
349 states: [],
350 curIndex: 0,
351 },
352 newestToolbarPreviewForInput: {},
353 compactionLoading: {},
354 inlineErrorMessage: undefined,
355 },
356 config: {
357 config: {
358 tools: [],
359 rules: [],
360 tabAutocompleteModel: undefined,
361 selectedModelByRole: {
362 chat: null, // No model selected
363 apply: null,
364 edit: null,
365 summarize: null,
366 autocomplete: null,
367 rerank: null,
368 embed: null,
369 },
370 experimental: {
371 onlyUseSystemMessageTools: false,
372 },
373 },
374 lastSelectedModelByRole: {},
375 loading: false,
376 configError: undefined,
377 },
378 ui: {
379 toolSettings: {},
380 ruleSettings: {},
381 showDialog: true, // Error dialog is shown
382 dialogMessage: expect.objectContaining({
383 props: expect.objectContaining({
384 error: expect.objectContaining({
385 message: "No chat model selected",
386 }),
387 }),
388 }),
389 },
390 editModeState: {
391 isInEdit: false,
392 returnToMode: "chat",
393 },
394 indexing: {
395 indexing: {
396 statuses: {},
397 hiddenChatPeekTypes: {
398 docs: false,
399 },
400 },
401 },
402 tabs: {
403 tabsItems: [],
404 },
405 profiles: {
406 organizations: [],
407 selectedProfileId: null,
408 selectedOrganizationId: null,
409 preferencesByProfileId: {},
410 },
411 });
412 });
413
414 it("should handle compilation error - not enough context", async () => {
415 const { mockStore, mockIdeMessenger } = setupTest();
416
417 // Mock compilation failure with "Not enough context" error
418 mockIdeMessenger.request.mockResolvedValue({
419 status: "error",
420 error: "Not enough context available for this request",
421 });
422
423 // Execute thunk
424 const result = await mockStore.dispatch(
425 streamResponseThunk({
426 editorState: mockEditorState,
427 modifiers: mockModifiers,
428 }) as any,
429 );
430
431 // Verify thunk completed successfully (doesn't throw, handles error gracefully)
432 expect(result.type).toBe("chat/streamResponse/fulfilled");
433
434 // Verify exact action sequence for this error path
435 const dispatchedActions = (mockStore as any).getActions();
436 expect(dispatchedActions).toEqual([
437 {
438 type: "chat/streamResponse/pending",
439 meta: {
440 arg: {
441 editorState: mockEditorState,
442 modifiers: mockModifiers,
443 },
444 requestId: expect.any(String),
445 requestStatus: "pending",
446 },
447 payload: undefined,
448 },
449 {
450 type: "chat/streamWrapper/pending",
451 meta: {
452 arg: expect.any(Function),
453 requestId: expect.any(String),
454 requestStatus: "pending",
455 },
456 payload: undefined,
457 },
458 {
459 type: "session/submitEditorAndInitAtIndex",
460 payload: {
461 editorState: mockEditorState,
462 index: 1,
463 },
464 },
465 {
466 type: "session/resetNextCodeBlockToApplyIndex",
467 payload: undefined,
468 },
469 {
470 type: "symbols/updateFromContextItems/pending",
471 meta: {
472 arg: [],
473 requestId: expect.any(String),
474 requestStatus: "pending",
475 },
476 payload: undefined,
477 },
478 {
479 type: "session/updateHistoryItemAtIndex",
480 payload: {
481 index: 1,
482 updates: {
483 contextItems: [],
484 message: {
485 content: "Hello, please help me with this code",
486 id: "mock-uuid-123",
487 role: "user",
488 },
489 },
490 },
491 },
492 {
493 type: "chat/streamNormalInput/pending",
494 meta: {
495 arg: {
496 legacySlashCommandData: undefined,
497 },
498 requestId: expect.any(String),
499 requestStatus: "pending",
500 },
501 payload: undefined,
502 },
503 {
504 type: "session/setAppliedRulesAtIndex",
505 payload: {
506 appliedRules: [],
507 index: 1,
508 },
509 },
510 {
511 type: "session/setActive",
512 payload: undefined,
513 },
514 {
515 type: "session/setInlineErrorMessage",
516 payload: undefined,
517 },
518 {
519 type: "session/setInlineErrorMessage",
520 payload: "out-of-context",
521 },
522 {
523 type: "session/setInactive",
524 payload: undefined,
525 },
526 {
527 type: "symbols/updateFromContextItems/fulfilled",
528 meta: {
529 arg: [],
530 requestId: expect.any(String),
531 requestStatus: "fulfilled",
532 },
533 payload: undefined,
534 },
535 {
536 type: "chat/streamNormalInput/fulfilled",
537 meta: {
538 arg: {
539 legacySlashCommandData: undefined,
540 },
541 requestId: expect.any(String),
542 requestStatus: "fulfilled",
543 },
544 payload: undefined,
545 },
546 {
547 type: "session/saveCurrent/pending",
548 meta: {
549 arg: {
550 generateTitle: true,
551 openNewSession: false,
552 },
553 requestId: expect.any(String),
554 requestStatus: "pending",
555 },
556 payload: undefined,
557 },
558 {
559 type: "session/update/pending",
560 meta: {
561 arg: expect.objectContaining({
562 history: expect.any(Array),
563 sessionId: "session-123",
564 title: "New Session",
565 workspaceDirectory: "",
566 }),
567 requestId: expect.any(String),
568 requestStatus: "pending",
569 },
570 payload: undefined,
571 },
572 {
573 type: "session/updateSessionMetadata",
574 payload: {
575 sessionId: "session-123",
576 title: "New Session",
577 },
578 },
579 {
580 type: "session/refreshMetadata/pending",
581 meta: {
582 arg: {},
583 requestId: expect.any(String),
584 requestStatus: "pending",
585 },
586 payload: undefined,
587 },
588 {
589 type: "session/refreshMetadata/rejected",
590 meta: {
591 aborted: false,
592 arg: {},
593 condition: false,
594 rejectedWithValue: false,
595 requestId: expect.any(String),
596 requestStatus: "rejected",
597 },
598 payload: undefined,
599 error: {
600 message: "Not enough context available for this request",
601 name: "Error",
602 stack: expect.any(String),
603 },
604 },
605 {
606 type: "session/update/fulfilled",
607 meta: {
608 arg: expect.objectContaining({
609 history: expect.any(Array),
610 sessionId: "session-123",
611 title: "New Session",
612 workspaceDirectory: "",
613 }),
614 requestId: expect.any(String),
615 requestStatus: "fulfilled",
616 },
617 payload: undefined,
618 },
619 {
620 type: "session/saveCurrent/fulfilled",
621 meta: {
622 arg: {
623 generateTitle: true,
624 openNewSession: false,
625 },
626 requestId: expect.any(String),
627 requestStatus: "fulfilled",
628 },
629 payload: undefined,
630 },
631 {
632 type: "chat/streamWrapper/fulfilled",
633 meta: {
634 arg: expect.any(Function),
635 requestId: expect.any(String),
636 requestStatus: "fulfilled",
637 },
638 payload: undefined,
639 },
640 {
641 type: "chat/streamResponse/fulfilled",
642 meta: {
643 arg: {
644 editorState: mockEditorState,
645 modifiers: mockModifiers,
646 },
647 requestId: expect.any(String),
648 requestStatus: "fulfilled",
649 },
650 payload: undefined,
651 },
652 ]);
653
654 // Verify IDE messenger was called for compilation but not streaming
655 expect(mockIdeMessenger.request).toHaveBeenCalledWith("llm/compileChat", {
656 messages: [
657 {
658 role: "system",
659 content: "You are a helpful assistant.",
660 },
661 {
662 role: "user",
663 content: [
664 {
665 text: "Hello",
666 type: "text",
667 },
668 ],
669 },
670 {
671 role: "user",
672 content: [
673 {
674 text: "Hello, please help me with this code",
675 type: "text",
676 },
677 ],
678 },
679 ],
680 options: {},
681 });
682 expect(mockIdeMessenger.llmStreamChat).not.toHaveBeenCalled();
683
684 // Verify final state shows error condition
685 const finalState = mockStore.getState();
686 expect(finalState).toEqual({
687 session: {
688 history: [
689 {
690 contextItems: [],
691 message: {
692 content: "Hello",
693 id: "1",
694 role: "user",
695 },
696 },
697 {
698 appliedRules: [],
699 contextItems: [],
700 editorState: {
701 type: "doc",
702 content: [
703 {
704 type: "paragraph",
705 content: [
706 {
707 type: "text",
708 text: "Hello, please help me with this code",
709 },
710 ],
711 },
712 ],
713 },
714 message: {
715 content: "Hello, please help me with this code",
716 id: "mock-uuid-123",
717 role: "user",
718 },
719 },
720 {
721 contextItems: [],
722 isGatheringContext: false,
723 message: {
724 content: "",
725 id: "mock-uuid-123",
726 role: "assistant",
727 },
728 },
729 ],
730 hasReasoningEnabled: false,
731 isStreaming: false, // Should be inactive due to error
732 id: "session-123",
733 mode: "chat",
734 streamAborter: expect.any(AbortController),
735 contextPercentage: 0, // Unchanged - no successful compilation
736 isPruned: false, // Unchanged - no successful compilation
737 isInEdit: false,
738 title: "New Session",
739 lastSessionId: undefined,
740 isSessionMetadataLoading: false,
741 allSessionMetadata: [],
742 symbols: {},
743 codeBlockApplyStates: {
744 states: [],
745 curIndex: 0,
746 },
747 newestToolbarPreviewForInput: {},
748 compactionLoading: {},
749 inlineErrorMessage: "out-of-context", // Error message set
750 },
751 config: {
752 config: {
753 tools: [],
754 rules: [],
755 tabAutocompleteModel: undefined,
756 selectedModelByRole: {
757 chat: mockClaudeModel,
758 apply: null,
759 edit: null,
760 summarize: null,
761 autocomplete: null,
762 rerank: null,
763 embed: null,
764 },
765 experimental: {
766 onlyUseSystemMessageTools: false,
767 },
768 },
769 lastSelectedModelByRole: {
770 chat: mockClaudeModel.title,
771 },
772 loading: false,
773 configError: undefined,
774 },
775 ui: {
776 toolSettings: {},
777 ruleSettings: {},
778 showDialog: false,
779 dialogMessage: undefined,
780 },
781 editModeState: {
782 isInEdit: false,
783 returnToMode: "chat",
784 },
785 indexing: {
786 indexing: {
787 statuses: {},
788 hiddenChatPeekTypes: {
789 docs: false,
790 },
791 },
792 },
793 tabs: {
794 tabsItems: [],
795 },
796 profiles: {
797 organizations: [],
798 selectedProfileId: null,
799 selectedOrganizationId: null,
800 preferencesByProfileId: {},
801 },
802 });
803 });
804
805 it("should throw error for other compilation errors", async () => {
806 const { mockStore, mockIdeMessenger } = setupTest();
807
808 // Mock compilation failure with generic error
809 mockIdeMessenger.request.mockResolvedValue({
810 status: "error",
811 error: "Model configuration is invalid",
812 });
813
814 // Execute thunk and expect it to be rejected
815 const result = await mockStore.dispatch(
816 streamResponseThunk({
817 editorState: mockEditorState,
818 modifiers: mockModifiers,
819 }) as any,
820 );
821
822 // Verify thunk completed successfully but shows error dialog
823 expect(result.type).toBe("chat/streamResponse/fulfilled");
824
825 // Verify exact action sequence for compilation error with dialog
826 const dispatchedActions = (mockStore as any).getActions();
827 expect(dispatchedActions).toEqual([
828 {
829 type: "chat/streamResponse/pending",
830 meta: {
831 arg: {
832 editorState: mockEditorState,
833 modifiers: mockModifiers,
834 },
835 requestId: expect.any(String),
836 requestStatus: "pending",
837 },
838 payload: undefined,
839 },
840 {
841 type: "chat/streamWrapper/pending",
842 meta: {
843 arg: expect.any(Function),
844 requestId: expect.any(String),
845 requestStatus: "pending",
846 },
847 payload: undefined,
848 },
849 {
850 type: "session/submitEditorAndInitAtIndex",
851 payload: {
852 editorState: mockEditorState,
853 index: 1,
854 },
855 },
856 {
857 type: "session/resetNextCodeBlockToApplyIndex",
858 payload: undefined,
859 },
860 {
861 type: "symbols/updateFromContextItems/pending",
862 meta: {
863 arg: [],
864 requestId: expect.any(String),
865 requestStatus: "pending",
866 },
867 payload: undefined,
868 },
869 {
870 type: "session/updateHistoryItemAtIndex",
871 payload: {
872 index: 1,
873 updates: {
874 contextItems: [],
875 message: {
876 content: "Hello, please help me with this code",
877 id: "mock-uuid-123",
878 role: "user",
879 },
880 },
881 },
882 },
883 {
884 type: "chat/streamNormalInput/pending",
885 meta: {
886 arg: {
887 legacySlashCommandData: undefined,
888 },
889 requestId: expect.any(String),
890 requestStatus: "pending",
891 },
892 payload: undefined,
893 },
894 {
895 type: "session/setAppliedRulesAtIndex",
896 payload: {
897 appliedRules: [],
898 index: 1,
899 },
900 },
901 {
902 type: "session/setActive",
903 payload: undefined,
904 },
905 {
906 type: "session/setInlineErrorMessage",
907 payload: undefined,
908 },
909 {
910 type: "symbols/updateFromContextItems/fulfilled",
911 meta: {
912 arg: [],
913 requestId: expect.any(String),
914 requestStatus: "fulfilled",
915 },
916 payload: undefined,
917 },
918 {
919 type: "chat/streamNormalInput/rejected",
920 meta: {
921 aborted: false,
922 arg: {
923 legacySlashCommandData: undefined,
924 },
925 condition: false,
926 rejectedWithValue: false,
927 requestId: expect.any(String),
928 requestStatus: "rejected",
929 },
930 payload: undefined,
931 error: {
932 message: "Model configuration is invalid",
933 name: "Error",
934 stack: expect.any(String),
935 },
936 },
937 {
938 type: "chat/cancelStream/pending",
939 meta: {
940 arg: undefined,
941 requestId: expect.any(String),
942 requestStatus: "pending",
943 },
944 payload: undefined,
945 },
946 {
947 type: "session/setInactive",
948 payload: undefined,
949 },
950 {
951 type: "session/abortStream",
952 payload: undefined,
953 },
954 {
955 type: "session/clearDanglingMessages",
956 payload: undefined,
957 },
958 {
959 type: "chat/cancelStream/fulfilled",
960 meta: {
961 arg: undefined,
962 requestId: expect.any(String),
963 requestStatus: "fulfilled",
964 },
965 payload: undefined,
966 },
967 {
968 type: "ui/setDialogMessage",
969 payload: expect.objectContaining({
970 props: expect.objectContaining({
971 error: expect.objectContaining({
972 message: "Model configuration is invalid",
973 }),
974 }),
975 }),
976 },
977 {
978 type: "ui/setShowDialog",
979 payload: true,
980 },
981 {
982 type: "chat/streamWrapper/fulfilled",
983 meta: {
984 arg: expect.any(Function),
985 requestId: expect.any(String),
986 requestStatus: "fulfilled",
987 },
988 payload: undefined,
989 },
990 {
991 type: "chat/streamResponse/fulfilled",
992 meta: {
993 arg: {
994 editorState: mockEditorState,
995 modifiers: mockModifiers,
996 },
997 requestId: expect.any(String),
998 requestStatus: "fulfilled",
999 },
1000 payload: undefined,
1001 },
1002 ]);
1003
1004 // Verify IDE messenger was called for compilation but not streaming
1005 expect(mockIdeMessenger.request).toHaveBeenCalledWith("llm/compileChat", {
1006 messages: [
1007 {
1008 role: "system",
1009 content: "You are a helpful assistant.",
1010 },
1011 {
1012 role: "user",
1013 content: [
1014 {
1015 type: "text",
1016 text: "Hello",
1017 },
1018 ],
1019 },
1020 {
1021 role: "user",
1022 content: [
1023 {
1024 type: "text",
1025 text: "Hello, please help me with this code",
1026 },
1027 ],
1028 },
1029 ],
1030 options: {},
1031 });
1032 expect(mockIdeMessenger.llmStreamChat).not.toHaveBeenCalled();
1033
1034 // Verify final state shows error dialog and inactive streaming
1035 const finalState = mockStore.getState();
1036 expect(finalState).toEqual({
1037 session: {
1038 history: [
1039 {
1040 contextItems: [],
1041 message: { id: "1", role: "user", content: "Hello" },
1042 },
1043 ],
1044 hasReasoningEnabled: false,
1045 isStreaming: false, // Set to inactive after error
1046 id: "session-123",
1047 mode: "chat",
1048 streamAborter: expect.any(AbortController),
1049 contextPercentage: 0,
1050 isPruned: false,
1051 isInEdit: false,
1052 title: "",
1053 lastSessionId: undefined,
1054 isSessionMetadataLoading: false,
1055 allSessionMetadata: [],
1056 symbols: {},
1057 codeBlockApplyStates: {
1058 states: [],
1059 curIndex: 0,
1060 },
1061 newestToolbarPreviewForInput: {},
1062 compactionLoading: {},
1063 inlineErrorMessage: undefined,
1064 mainEditorContentTrigger: mockEditorState, // Editor content that triggered the request
1065 },
1066 config: {
1067 config: {
1068 tools: [],
1069 rules: [],
1070 tabAutocompleteModel: undefined,
1071 selectedModelByRole: {
1072 chat: mockClaudeModel,
1073 apply: null,
1074 edit: null,
1075 summarize: null,
1076 autocomplete: null,
1077 rerank: null,
1078 embed: null,
1079 },
1080 experimental: {
1081 onlyUseSystemMessageTools: false,
1082 },
1083 },
1084 lastSelectedModelByRole: {
1085 chat: mockClaudeModel.title,
1086 },
1087 loading: false,
1088 configError: undefined,
1089 },
1090 ui: {
1091 toolSettings: {},
1092 ruleSettings: {},
1093 showDialog: true, // Error dialog is shown
1094 dialogMessage: expect.objectContaining({
1095 props: expect.objectContaining({
1096 error: expect.objectContaining({
1097 message: "Model configuration is invalid",
1098 }),
1099 }),
1100 }),
1101 },
1102 editModeState: {
1103 isInEdit: false,
1104 returnToMode: "chat",
1105 },
1106 indexing: {
1107 indexing: {
1108 statuses: {},
1109 hiddenChatPeekTypes: {
1110 docs: false,
1111 },
1112 },
1113 },
1114 tabs: {
1115 tabsItems: [],
1116 },
1117 profiles: {
1118 organizations: [],
1119 selectedProfileId: null,
1120 selectedOrganizationId: null,
1121 preferencesByProfileId: {},
1122 },
1123 });
1124 });
1125});