Elffuss BraidHub

kikocis/continue public

c04584525d2e · 28.3 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 indexingState: "disabled",
396 },
397 tabs: {
398 tabsItems: [],
399 },
400 profiles: {
401 profiles: [],
402 },
403 });
404 });
405
406 it("should handle compilation error - not enough context", async () => {
407 const { mockStore, mockIdeMessenger } = setupTest();
408
409 // Mock compilation failure with "Not enough context" error
410 mockIdeMessenger.request.mockResolvedValue({
411 status: "error",
412 error: "Not enough context available for this request",
413 });
414
415 // Execute thunk
416 const result = await mockStore.dispatch(
417 streamResponseThunk({
418 editorState: mockEditorState,
419 modifiers: mockModifiers,
420 }) as any,
421 );
422
423 // Verify thunk completed successfully (doesn't throw, handles error gracefully)
424 expect(result.type).toBe("chat/streamResponse/fulfilled");
425
426 // Verify exact action sequence for this error path
427 const dispatchedActions = (mockStore as any).getActions();
428 expect(dispatchedActions).toEqual([
429 {
430 type: "chat/streamResponse/pending",
431 meta: {
432 arg: {
433 editorState: mockEditorState,
434 modifiers: mockModifiers,
435 },
436 requestId: expect.any(String),
437 requestStatus: "pending",
438 },
439 payload: undefined,
440 },
441 {
442 type: "chat/streamWrapper/pending",
443 meta: {
444 arg: expect.any(Function),
445 requestId: expect.any(String),
446 requestStatus: "pending",
447 },
448 payload: undefined,
449 },
450 {
451 type: "session/submitEditorAndInitAtIndex",
452 payload: {
453 editorState: mockEditorState,
454 index: 1,
455 },
456 },
457 {
458 type: "session/resetNextCodeBlockToApplyIndex",
459 payload: undefined,
460 },
461 {
462 type: "symbols/updateFromContextItems/pending",
463 meta: {
464 arg: [],
465 requestId: expect.any(String),
466 requestStatus: "pending",
467 },
468 payload: undefined,
469 },
470 {
471 type: "session/updateHistoryItemAtIndex",
472 payload: {
473 index: 1,
474 updates: {
475 contextItems: [],
476 message: {
477 content: "Hello, please help me with this code",
478 id: "mock-uuid-123",
479 role: "user",
480 },
481 },
482 },
483 },
484 {
485 type: "chat/streamNormalInput/pending",
486 meta: {
487 arg: {
488 legacySlashCommandData: undefined,
489 },
490 requestId: expect.any(String),
491 requestStatus: "pending",
492 },
493 payload: undefined,
494 },
495 {
496 type: "session/setAppliedRulesAtIndex",
497 payload: {
498 appliedRules: [],
499 index: 1,
500 },
501 },
502 {
503 type: "session/setActive",
504 payload: undefined,
505 },
506 {
507 type: "session/setInlineErrorMessage",
508 payload: undefined,
509 },
510 {
511 type: "session/setInlineErrorMessage",
512 payload: "out-of-context",
513 },
514 {
515 type: "session/setInactive",
516 payload: undefined,
517 },
518 {
519 type: "symbols/updateFromContextItems/fulfilled",
520 meta: {
521 arg: [],
522 requestId: expect.any(String),
523 requestStatus: "fulfilled",
524 },
525 payload: undefined,
526 },
527 {
528 type: "chat/streamNormalInput/fulfilled",
529 meta: {
530 arg: {
531 legacySlashCommandData: undefined,
532 },
533 requestId: expect.any(String),
534 requestStatus: "fulfilled",
535 },
536 payload: undefined,
537 },
538 {
539 type: "session/saveCurrent/pending",
540 meta: {
541 arg: {
542 generateTitle: true,
543 openNewSession: false,
544 },
545 requestId: expect.any(String),
546 requestStatus: "pending",
547 },
548 payload: undefined,
549 },
550 {
551 type: "session/update/pending",
552 meta: {
553 arg: expect.objectContaining({
554 history: expect.any(Array),
555 sessionId: "session-123",
556 title: "New Session",
557 workspaceDirectory: "",
558 }),
559 requestId: expect.any(String),
560 requestStatus: "pending",
561 },
562 payload: undefined,
563 },
564 {
565 type: "session/updateSessionMetadata",
566 payload: {
567 sessionId: "session-123",
568 title: "New Session",
569 },
570 },
571 {
572 type: "session/refreshMetadata/pending",
573 meta: {
574 arg: {},
575 requestId: expect.any(String),
576 requestStatus: "pending",
577 },
578 payload: undefined,
579 },
580 {
581 type: "session/refreshMetadata/rejected",
582 meta: {
583 aborted: false,
584 arg: {},
585 condition: false,
586 rejectedWithValue: false,
587 requestId: expect.any(String),
588 requestStatus: "rejected",
589 },
590 payload: undefined,
591 error: {
592 message: "Not enough context available for this request",
593 name: "Error",
594 stack: expect.any(String),
595 },
596 },
597 {
598 type: "session/update/fulfilled",
599 meta: {
600 arg: expect.objectContaining({
601 history: expect.any(Array),
602 sessionId: "session-123",
603 title: "New Session",
604 workspaceDirectory: "",
605 }),
606 requestId: expect.any(String),
607 requestStatus: "fulfilled",
608 },
609 payload: undefined,
610 },
611 {
612 type: "session/saveCurrent/fulfilled",
613 meta: {
614 arg: {
615 generateTitle: true,
616 openNewSession: false,
617 },
618 requestId: expect.any(String),
619 requestStatus: "fulfilled",
620 },
621 payload: undefined,
622 },
623 {
624 type: "chat/streamWrapper/fulfilled",
625 meta: {
626 arg: expect.any(Function),
627 requestId: expect.any(String),
628 requestStatus: "fulfilled",
629 },
630 payload: undefined,
631 },
632 {
633 type: "chat/streamResponse/fulfilled",
634 meta: {
635 arg: {
636 editorState: mockEditorState,
637 modifiers: mockModifiers,
638 },
639 requestId: expect.any(String),
640 requestStatus: "fulfilled",
641 },
642 payload: undefined,
643 },
644 ]);
645
646 // Verify IDE messenger was called for compilation but not streaming
647 expect(mockIdeMessenger.request).toHaveBeenCalledWith("llm/compileChat", {
648 messages: [
649 {
650 role: "system",
651 content: "You are a helpful assistant.",
652 },
653 {
654 role: "user",
655 content: [
656 {
657 text: "Hello",
658 type: "text",
659 },
660 ],
661 },
662 {
663 role: "user",
664 content: [
665 {
666 text: "Hello, please help me with this code",
667 type: "text",
668 },
669 ],
670 },
671 ],
672 options: {},
673 });
674 expect(mockIdeMessenger.llmStreamChat).not.toHaveBeenCalled();
675
676 // Verify final state shows error condition
677 const finalState = mockStore.getState();
678 expect(finalState).toEqual({
679 session: {
680 history: [
681 {
682 contextItems: [],
683 message: {
684 content: "Hello",
685 id: "1",
686 role: "user",
687 },
688 },
689 {
690 appliedRules: [],
691 contextItems: [],
692 editorState: {
693 type: "doc",
694 content: [
695 {
696 type: "paragraph",
697 content: [
698 {
699 type: "text",
700 text: "Hello, please help me with this code",
701 },
702 ],
703 },
704 ],
705 },
706 message: {
707 content: "Hello, please help me with this code",
708 id: "mock-uuid-123",
709 role: "user",
710 },
711 },
712 {
713 contextItems: [],
714 isGatheringContext: false,
715 message: {
716 content: "",
717 id: "mock-uuid-123",
718 role: "assistant",
719 },
720 },
721 ],
722 hasReasoningEnabled: false,
723 isStreaming: false, // Should be inactive due to error
724 id: "session-123",
725 mode: "chat",
726 streamAborter: expect.any(AbortController),
727 contextPercentage: 0, // Unchanged - no successful compilation
728 isPruned: false, // Unchanged - no successful compilation
729 isInEdit: false,
730 title: "New Session",
731 lastSessionId: undefined,
732 isSessionMetadataLoading: false,
733 allSessionMetadata: [],
734 symbols: {},
735 codeBlockApplyStates: {
736 states: [],
737 curIndex: 0,
738 },
739 newestToolbarPreviewForInput: {},
740 compactionLoading: {},
741 inlineErrorMessage: "out-of-context", // Error message set
742 },
743 config: {
744 config: {
745 tools: [],
746 rules: [],
747 tabAutocompleteModel: undefined,
748 selectedModelByRole: {
749 chat: mockClaudeModel,
750 apply: null,
751 edit: null,
752 summarize: null,
753 autocomplete: null,
754 rerank: null,
755 embed: null,
756 },
757 experimental: {
758 onlyUseSystemMessageTools: false,
759 },
760 },
761 lastSelectedModelByRole: {
762 chat: mockClaudeModel.title,
763 },
764 loading: false,
765 configError: undefined,
766 },
767 ui: {
768 toolSettings: {},
769 ruleSettings: {},
770 showDialog: false,
771 dialogMessage: undefined,
772 },
773 editModeState: {
774 isInEdit: false,
775 returnToMode: "chat",
776 },
777 indexing: {
778 indexingState: "disabled",
779 },
780 tabs: {
781 tabsItems: [],
782 },
783 profiles: {
784 profiles: [],
785 },
786 });
787 });
788
789 it("should throw error for other compilation errors", async () => {
790 const { mockStore, mockIdeMessenger } = setupTest();
791
792 // Mock compilation failure with generic error
793 mockIdeMessenger.request.mockResolvedValue({
794 status: "error",
795 error: "Model configuration is invalid",
796 });
797
798 // Execute thunk and expect it to be rejected
799 const result = await mockStore.dispatch(
800 streamResponseThunk({
801 editorState: mockEditorState,
802 modifiers: mockModifiers,
803 }) as any,
804 );
805
806 // Verify thunk completed successfully but shows error dialog
807 expect(result.type).toBe("chat/streamResponse/fulfilled");
808
809 // Verify exact action sequence for compilation error with dialog
810 const dispatchedActions = (mockStore as any).getActions();
811 expect(dispatchedActions).toEqual([
812 {
813 type: "chat/streamResponse/pending",
814 meta: {
815 arg: {
816 editorState: mockEditorState,
817 modifiers: mockModifiers,
818 },
819 requestId: expect.any(String),
820 requestStatus: "pending",
821 },
822 payload: undefined,
823 },
824 {
825 type: "chat/streamWrapper/pending",
826 meta: {
827 arg: expect.any(Function),
828 requestId: expect.any(String),
829 requestStatus: "pending",
830 },
831 payload: undefined,
832 },
833 {
834 type: "session/submitEditorAndInitAtIndex",
835 payload: {
836 editorState: mockEditorState,
837 index: 1,
838 },
839 },
840 {
841 type: "session/resetNextCodeBlockToApplyIndex",
842 payload: undefined,
843 },
844 {
845 type: "symbols/updateFromContextItems/pending",
846 meta: {
847 arg: [],
848 requestId: expect.any(String),
849 requestStatus: "pending",
850 },
851 payload: undefined,
852 },
853 {
854 type: "session/updateHistoryItemAtIndex",
855 payload: {
856 index: 1,
857 updates: {
858 contextItems: [],
859 message: {
860 content: "Hello, please help me with this code",
861 id: "mock-uuid-123",
862 role: "user",
863 },
864 },
865 },
866 },
867 {
868 type: "chat/streamNormalInput/pending",
869 meta: {
870 arg: {
871 legacySlashCommandData: undefined,
872 },
873 requestId: expect.any(String),
874 requestStatus: "pending",
875 },
876 payload: undefined,
877 },
878 {
879 type: "session/setAppliedRulesAtIndex",
880 payload: {
881 appliedRules: [],
882 index: 1,
883 },
884 },
885 {
886 type: "session/setActive",
887 payload: undefined,
888 },
889 {
890 type: "session/setInlineErrorMessage",
891 payload: undefined,
892 },
893 {
894 type: "symbols/updateFromContextItems/fulfilled",
895 meta: {
896 arg: [],
897 requestId: expect.any(String),
898 requestStatus: "fulfilled",
899 },
900 payload: undefined,
901 },
902 {
903 type: "chat/streamNormalInput/rejected",
904 meta: {
905 aborted: false,
906 arg: {
907 legacySlashCommandData: undefined,
908 },
909 condition: false,
910 rejectedWithValue: false,
911 requestId: expect.any(String),
912 requestStatus: "rejected",
913 },
914 payload: undefined,
915 error: {
916 message: "Model configuration is invalid",
917 name: "Error",
918 stack: expect.any(String),
919 },
920 },
921 {
922 type: "chat/cancelStream/pending",
923 meta: {
924 arg: undefined,
925 requestId: expect.any(String),
926 requestStatus: "pending",
927 },
928 payload: undefined,
929 },
930 {
931 type: "session/setInactive",
932 payload: undefined,
933 },
934 {
935 type: "session/abortStream",
936 payload: undefined,
937 },
938 {
939 type: "session/clearDanglingMessages",
940 payload: undefined,
941 },
942 {
943 type: "chat/cancelStream/fulfilled",
944 meta: {
945 arg: undefined,
946 requestId: expect.any(String),
947 requestStatus: "fulfilled",
948 },
949 payload: undefined,
950 },
951 {
952 type: "ui/setDialogMessage",
953 payload: expect.objectContaining({
954 props: expect.objectContaining({
955 error: expect.objectContaining({
956 message: "Model configuration is invalid",
957 }),
958 }),
959 }),
960 },
961 {
962 type: "ui/setShowDialog",
963 payload: true,
964 },
965 {
966 type: "chat/streamWrapper/fulfilled",
967 meta: {
968 arg: expect.any(Function),
969 requestId: expect.any(String),
970 requestStatus: "fulfilled",
971 },
972 payload: undefined,
973 },
974 {
975 type: "chat/streamResponse/fulfilled",
976 meta: {
977 arg: {
978 editorState: mockEditorState,
979 modifiers: mockModifiers,
980 },
981 requestId: expect.any(String),
982 requestStatus: "fulfilled",
983 },
984 payload: undefined,
985 },
986 ]);
987
988 // Verify IDE messenger was called for compilation but not streaming
989 expect(mockIdeMessenger.request).toHaveBeenCalledWith("llm/compileChat", {
990 messages: [
991 {
992 role: "system",
993 content: "You are a helpful assistant.",
994 },
995 {
996 role: "user",
997 content: [
998 {
999 type: "text",
1000 text: "Hello",
1001 },
1002 ],
1003 },
1004 {
1005 role: "user",
1006 content: [
1007 {
1008 type: "text",
1009 text: "Hello, please help me with this code",
1010 },
1011 ],
1012 },
1013 ],
1014 options: {},
1015 });
1016 expect(mockIdeMessenger.llmStreamChat).not.toHaveBeenCalled();
1017
1018 // Verify final state shows error dialog and inactive streaming
1019 const finalState = mockStore.getState();
1020 expect(finalState).toEqual({
1021 session: {
1022 history: [
1023 {
1024 contextItems: [],
1025 message: { id: "1", role: "user", content: "Hello" },
1026 },
1027 ],
1028 hasReasoningEnabled: false,
1029 isStreaming: false, // Set to inactive after error
1030 id: "session-123",
1031 mode: "chat",
1032 streamAborter: expect.any(AbortController),
1033 contextPercentage: 0,
1034 isPruned: false,
1035 isInEdit: false,
1036 title: "",
1037 lastSessionId: undefined,
1038 isSessionMetadataLoading: false,
1039 allSessionMetadata: [],
1040 symbols: {},
1041 codeBlockApplyStates: {
1042 states: [],
1043 curIndex: 0,
1044 },
1045 newestToolbarPreviewForInput: {},
1046 compactionLoading: {},
1047 inlineErrorMessage: undefined,
1048 mainEditorContentTrigger: mockEditorState, // Editor content that triggered the request
1049 },
1050 config: {
1051 config: {
1052 tools: [],
1053 rules: [],
1054 tabAutocompleteModel: undefined,
1055 selectedModelByRole: {
1056 chat: mockClaudeModel,
1057 apply: null,
1058 edit: null,
1059 summarize: null,
1060 autocomplete: null,
1061 rerank: null,
1062 embed: null,
1063 },
1064 experimental: {
1065 onlyUseSystemMessageTools: false,
1066 },
1067 },
1068 lastSelectedModelByRole: {
1069 chat: mockClaudeModel.title,
1070 },
1071 loading: false,
1072 configError: undefined,
1073 },
1074 ui: {
1075 toolSettings: {},
1076 ruleSettings: {},
1077 showDialog: true, // Error dialog is shown
1078 dialogMessage: expect.objectContaining({
1079 props: expect.objectContaining({
1080 error: expect.objectContaining({
1081 message: "Model configuration is invalid",
1082 }),
1083 }),
1084 }),
1085 },
1086 editModeState: {
1087 isInEdit: false,
1088 returnToMode: "chat",
1089 },
1090 indexing: {
1091 indexingState: "disabled",
1092 },
1093 tabs: {
1094 tabsItems: [],
1095 },
1096 profiles: {
1097 profiles: [],
1098 },
1099 });
1100 });
1101});