fss-link 1.0.49 → 1.0.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +0 -0
- package/dist/package.json +2 -2
- package/dist/src/config/auth.js +8 -5
- package/dist/src/config/auth.js.map +1 -1
- package/dist/src/config/database.d.ts +103 -11
- package/dist/src/config/database.js +301 -59
- package/dist/src/config/database.js.map +1 -1
- package/dist/src/config/databaseBackup.d.ts +114 -0
- package/dist/src/config/databaseBackup.js +334 -0
- package/dist/src/config/databaseBackup.js.map +1 -0
- package/dist/src/config/databaseMigrations.d.ts +63 -0
- package/dist/src/config/databaseMigrations.js +379 -0
- package/dist/src/config/databaseMigrations.js.map +1 -0
- package/dist/src/config/databasePool.d.ts +70 -0
- package/dist/src/config/databasePool.js +193 -0
- package/dist/src/config/databasePool.js.map +1 -0
- package/dist/src/config/queryOptimizer.d.ts +127 -0
- package/dist/src/config/queryOptimizer.js +309 -0
- package/dist/src/config/queryOptimizer.js.map +1 -0
- package/dist/src/utils/sandbox.js +2 -8
- package/dist/src/utils/sandbox.js.map +1 -1
- package/dist/src/validateNonInterActiveAuth.js +3 -7
- package/dist/src/validateNonInterActiveAuth.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/commands/mcp/add.test.ts +0 -122
- package/dist/commands/mcp/add.ts +0 -222
- package/dist/commands/mcp/list.test.ts +0 -154
- package/dist/commands/mcp/list.ts +0 -139
- package/dist/commands/mcp/remove.test.ts +0 -69
- package/dist/commands/mcp/remove.ts +0 -60
- package/dist/commands/mcp.test.ts +0 -55
- package/dist/commands/mcp.ts +0 -27
- package/dist/config/apiValidation.test.ts +0 -118
- package/dist/config/auth.test.ts +0 -79
- package/dist/config/auth.ts +0 -100
- package/dist/config/config.integration.test.ts +0 -407
- package/dist/config/config.test.ts +0 -1952
- package/dist/config/config.ts +0 -690
- package/dist/config/database.test.ts +0 -96
- package/dist/config/database.ts +0 -824
- package/dist/config/extension.test.ts +0 -236
- package/dist/config/extension.ts +0 -180
- package/dist/config/keyBindings.test.ts +0 -62
- package/dist/config/keyBindings.ts +0 -184
- package/dist/config/modelManager.ts +0 -326
- package/dist/config/providerManager.ts +0 -244
- package/dist/config/providerPersistence.test.ts +0 -377
- package/dist/config/providerPersistence.ts +0 -105
- package/dist/config/sandboxConfig.ts +0 -107
- package/dist/config/settings.test.ts +0 -1424
- package/dist/config/settings.ts +0 -517
- package/dist/config/settingsSchema.test.ts +0 -252
- package/dist/config/settingsSchema.ts +0 -728
- package/dist/config/trustedFolders.test.ts +0 -208
- package/dist/config/trustedFolders.ts +0 -167
- package/dist/gemini.test.tsx +0 -252
- package/dist/gemini.tsx +0 -357
- package/dist/generated/git-commit.ts +0 -10
- package/dist/index.ts +0 -21
- package/dist/nonInteractiveCli.test.ts +0 -276
- package/dist/nonInteractiveCli.ts +0 -143
- package/dist/patches/is-in-ci.ts +0 -17
- package/dist/services/BuiltinCommandLoader.test.ts +0 -127
- package/dist/services/BuiltinCommandLoader.ts +0 -95
- package/dist/services/CommandService.test.ts +0 -352
- package/dist/services/CommandService.ts +0 -103
- package/dist/services/FileCommandLoader.test.ts +0 -1002
- package/dist/services/FileCommandLoader.ts +0 -289
- package/dist/services/McpPromptLoader.ts +0 -231
- package/dist/services/SearchEngineConfigProvider.ts +0 -100
- package/dist/services/prompt-processors/argumentProcessor.test.ts +0 -41
- package/dist/services/prompt-processors/argumentProcessor.ts +0 -23
- package/dist/services/prompt-processors/shellProcessor.test.ts +0 -709
- package/dist/services/prompt-processors/shellProcessor.ts +0 -248
- package/dist/services/prompt-processors/types.ts +0 -44
- package/dist/services/types.ts +0 -24
- package/dist/src/config/apiValidation.test.d.ts +0 -6
- package/dist/src/config/apiValidation.test.js +0 -99
- package/dist/src/config/apiValidation.test.js.map +0 -1
- package/dist/src/config/database.test.d.ts +0 -6
- package/dist/src/config/database.test.js +0 -80
- package/dist/src/config/database.test.js.map +0 -1
- package/dist/src/config/providerManager.d.ts +0 -74
- package/dist/src/config/providerManager.js +0 -203
- package/dist/src/config/providerManager.js.map +0 -1
- package/dist/src/config/providerPersistence.test.d.ts +0 -6
- package/dist/src/config/providerPersistence.test.js +0 -283
- package/dist/src/config/providerPersistence.test.js.map +0 -1
- package/dist/src/ui/components/GeminiKeyDialog.d.ts +0 -11
- package/dist/src/ui/components/GeminiKeyDialog.js +0 -156
- package/dist/src/ui/components/GeminiKeyDialog.js.map +0 -1
- package/dist/src/ui/components/OpenAIEndpointDialog.d.ts +0 -19
- package/dist/src/ui/components/OpenAIEndpointDialog.js +0 -163
- package/dist/src/ui/components/OpenAIEndpointDialog.js.map +0 -1
- package/dist/test-setup.ts +0 -12
- package/dist/test-utils/customMatchers.ts +0 -65
- package/dist/test-utils/mockCommandContext.test.ts +0 -62
- package/dist/test-utils/mockCommandContext.ts +0 -105
- package/dist/test-utils/render.tsx +0 -18
- package/dist/ui/App.test.tsx +0 -2181
- package/dist/ui/App.tsx +0 -1344
- package/dist/ui/IdeIntegrationNudge.tsx +0 -98
- package/dist/ui/__snapshots__/App.test.tsx.snap +0 -124
- package/dist/ui/colors.ts +0 -56
- package/dist/ui/commands/aboutCommand.test.ts +0 -153
- package/dist/ui/commands/aboutCommand.ts +0 -49
- package/dist/ui/commands/authCommand.test.ts +0 -36
- package/dist/ui/commands/authCommand.ts +0 -17
- package/dist/ui/commands/bugCommand.test.ts +0 -114
- package/dist/ui/commands/bugCommand.ts +0 -92
- package/dist/ui/commands/chatCommand.test.ts +0 -414
- package/dist/ui/commands/chatCommand.ts +0 -280
- package/dist/ui/commands/clearCommand.test.ts +0 -100
- package/dist/ui/commands/clearCommand.ts +0 -29
- package/dist/ui/commands/compressCommand.test.ts +0 -129
- package/dist/ui/commands/compressCommand.ts +0 -78
- package/dist/ui/commands/contextCommand.ts +0 -132
- package/dist/ui/commands/copyCommand.test.ts +0 -296
- package/dist/ui/commands/copyCommand.ts +0 -67
- package/dist/ui/commands/corgiCommand.test.ts +0 -34
- package/dist/ui/commands/corgiCommand.ts +0 -16
- package/dist/ui/commands/directoryCommand.test.tsx +0 -185
- package/dist/ui/commands/directoryCommand.tsx +0 -179
- package/dist/ui/commands/docsCommand.test.ts +0 -99
- package/dist/ui/commands/docsCommand.ts +0 -42
- package/dist/ui/commands/editorCommand.test.ts +0 -30
- package/dist/ui/commands/editorCommand.ts +0 -21
- package/dist/ui/commands/extensionsCommand.test.ts +0 -67
- package/dist/ui/commands/extensionsCommand.ts +0 -46
- package/dist/ui/commands/helpCommand.test.ts +0 -52
- package/dist/ui/commands/helpCommand.ts +0 -23
- package/dist/ui/commands/ideCommand.test.ts +0 -255
- package/dist/ui/commands/ideCommand.ts +0 -283
- package/dist/ui/commands/initCommand.test.ts +0 -127
- package/dist/ui/commands/initCommand.ts +0 -117
- package/dist/ui/commands/mcpCommand.test.ts +0 -1057
- package/dist/ui/commands/mcpCommand.ts +0 -531
- package/dist/ui/commands/memoryCommand.test.ts +0 -344
- package/dist/ui/commands/memoryCommand.ts +0 -305
- package/dist/ui/commands/privacyCommand.test.ts +0 -38
- package/dist/ui/commands/privacyCommand.ts +0 -17
- package/dist/ui/commands/quitCommand.test.ts +0 -55
- package/dist/ui/commands/quitCommand.ts +0 -36
- package/dist/ui/commands/restoreCommand.test.ts +0 -250
- package/dist/ui/commands/restoreCommand.ts +0 -157
- package/dist/ui/commands/searchEngineSetupCommand.ts +0 -18
- package/dist/ui/commands/settingsCommand.test.ts +0 -36
- package/dist/ui/commands/settingsCommand.ts +0 -17
- package/dist/ui/commands/setupGithubCommand.test.ts +0 -238
- package/dist/ui/commands/setupGithubCommand.ts +0 -212
- package/dist/ui/commands/speakCommand.ts +0 -175
- package/dist/ui/commands/statsCommand.test.ts +0 -78
- package/dist/ui/commands/statsCommand.ts +0 -70
- package/dist/ui/commands/terminalSetupCommand.test.ts +0 -85
- package/dist/ui/commands/terminalSetupCommand.ts +0 -45
- package/dist/ui/commands/themeCommand.test.ts +0 -38
- package/dist/ui/commands/themeCommand.ts +0 -17
- package/dist/ui/commands/toolsCommand.test.ts +0 -105
- package/dist/ui/commands/toolsCommand.ts +0 -71
- package/dist/ui/commands/ttsCommand.ts +0 -143
- package/dist/ui/commands/types.ts +0 -204
- package/dist/ui/commands/vimCommand.ts +0 -25
- package/dist/ui/commands/voiceCommand.ts +0 -125
- package/dist/ui/components/AboutBox.tsx +0 -133
- package/dist/ui/components/AsciiArt.ts +0 -54
- package/dist/ui/components/AuthDialog.test.tsx +0 -334
- package/dist/ui/components/AuthDialog.tsx +0 -289
- package/dist/ui/components/AuthInProgress.tsx +0 -62
- package/dist/ui/components/AutoAcceptIndicator.tsx +0 -47
- package/dist/ui/components/ConsoleSummaryDisplay.tsx +0 -35
- package/dist/ui/components/ContextSummaryDisplay.test.tsx +0 -85
- package/dist/ui/components/ContextSummaryDisplay.tsx +0 -120
- package/dist/ui/components/ContextUsageDisplay.tsx +0 -77
- package/dist/ui/components/DebugProfiler.tsx +0 -36
- package/dist/ui/components/DetailedMessagesDisplay.tsx +0 -82
- package/dist/ui/components/EditorSettingsDialog.tsx +0 -172
- package/dist/ui/components/FolderTrustDialog.test.tsx +0 -36
- package/dist/ui/components/FolderTrustDialog.tsx +0 -74
- package/dist/ui/components/Footer.test.tsx +0 -159
- package/dist/ui/components/Footer.tsx +0 -158
- package/dist/ui/components/GeminiKeyDialog.tsx +0 -252
- package/dist/ui/components/GeminiRespondingSpinner.tsx +0 -34
- package/dist/ui/components/Header.test.tsx +0 -44
- package/dist/ui/components/Header.tsx +0 -70
- package/dist/ui/components/Help.tsx +0 -174
- package/dist/ui/components/HistoryItemDisplay.test.tsx +0 -125
- package/dist/ui/components/HistoryItemDisplay.tsx +0 -98
- package/dist/ui/components/InputPrompt.test.tsx +0 -1467
- package/dist/ui/components/InputPrompt.tsx +0 -641
- package/dist/ui/components/LMStudioModelPrompt.tsx +0 -215
- package/dist/ui/components/LoadingIndicator.test.tsx +0 -296
- package/dist/ui/components/LoadingIndicator.tsx +0 -82
- package/dist/ui/components/MemoryUsageDisplay.tsx +0 -36
- package/dist/ui/components/ModelStatsDisplay.test.tsx +0 -252
- package/dist/ui/components/ModelStatsDisplay.tsx +0 -197
- package/dist/ui/components/OllamaModelPrompt.tsx +0 -206
- package/dist/ui/components/OpenAIEndpointDialog.tsx +0 -261
- package/dist/ui/components/OpenAIKeyPrompt.test.tsx +0 -64
- package/dist/ui/components/OpenAIKeyPrompt.tsx +0 -197
- package/dist/ui/components/PrepareLabel.tsx +0 -48
- package/dist/ui/components/SearchEngineConfigDialog.tsx +0 -280
- package/dist/ui/components/SessionSummaryDisplay.test.tsx +0 -75
- package/dist/ui/components/SessionSummaryDisplay.tsx +0 -18
- package/dist/ui/components/SettingsDialog.test.tsx +0 -865
- package/dist/ui/components/SettingsDialog.tsx +0 -753
- package/dist/ui/components/ShellConfirmationDialog.test.tsx +0 -53
- package/dist/ui/components/ShellConfirmationDialog.tsx +0 -103
- package/dist/ui/components/ShellModeIndicator.tsx +0 -18
- package/dist/ui/components/ShowMoreLines.tsx +0 -40
- package/dist/ui/components/StatsDisplay.test.tsx +0 -401
- package/dist/ui/components/StatsDisplay.tsx +0 -273
- package/dist/ui/components/SuggestionsDisplay.tsx +0 -102
- package/dist/ui/components/ThemeDialog.tsx +0 -310
- package/dist/ui/components/Tips.tsx +0 -45
- package/dist/ui/components/TodoDisplay.test.tsx +0 -97
- package/dist/ui/components/TodoDisplay.tsx +0 -72
- package/dist/ui/components/ToolStatsDisplay.test.tsx +0 -180
- package/dist/ui/components/ToolStatsDisplay.tsx +0 -208
- package/dist/ui/components/UpdateNotification.tsx +0 -23
- package/dist/ui/components/WelcomeBackDialog.tsx +0 -290
- package/dist/ui/components/__snapshots__/IDEContextDetailDisplay.test.tsx.snap +0 -24
- package/dist/ui/components/__snapshots__/ModelStatsDisplay.test.tsx.snap +0 -121
- package/dist/ui/components/__snapshots__/SessionSummaryDisplay.test.tsx.snap +0 -30
- package/dist/ui/components/__snapshots__/ShellConfirmationDialog.test.tsx.snap +0 -21
- package/dist/ui/components/__snapshots__/StatsDisplay.test.tsx.snap +0 -264
- package/dist/ui/components/__snapshots__/ToolStatsDisplay.test.tsx.snap +0 -91
- package/dist/ui/components/messages/CompressionMessage.tsx +0 -49
- package/dist/ui/components/messages/DiffRenderer.test.tsx +0 -365
- package/dist/ui/components/messages/DiffRenderer.tsx +0 -358
- package/dist/ui/components/messages/ErrorMessage.tsx +0 -31
- package/dist/ui/components/messages/GeminiMessage.tsx +0 -43
- package/dist/ui/components/messages/GeminiMessageContent.tsx +0 -43
- package/dist/ui/components/messages/InfoMessage.tsx +0 -32
- package/dist/ui/components/messages/ToolConfirmationMessage.test.tsx +0 -58
- package/dist/ui/components/messages/ToolConfirmationMessage.tsx +0 -297
- package/dist/ui/components/messages/ToolGroupMessage.tsx +0 -126
- package/dist/ui/components/messages/ToolMessage.test.tsx +0 -183
- package/dist/ui/components/messages/ToolMessage.tsx +0 -296
- package/dist/ui/components/messages/UserMessage.tsx +0 -43
- package/dist/ui/components/messages/UserShellMessage.tsx +0 -25
- package/dist/ui/components/shared/MaxSizedBox.test.tsx +0 -425
- package/dist/ui/components/shared/MaxSizedBox.tsx +0 -624
- package/dist/ui/components/shared/RadioButtonSelect.test.tsx +0 -181
- package/dist/ui/components/shared/RadioButtonSelect.tsx +0 -234
- package/dist/ui/components/shared/__snapshots__/RadioButtonSelect.test.tsx.snap +0 -47
- package/dist/ui/components/shared/text-buffer.test.ts +0 -1728
- package/dist/ui/components/shared/text-buffer.ts +0 -2227
- package/dist/ui/components/shared/vim-buffer-actions.test.ts +0 -1119
- package/dist/ui/components/shared/vim-buffer-actions.ts +0 -814
- package/dist/ui/constants.ts +0 -17
- package/dist/ui/contexts/KeypressContext.test.tsx +0 -391
- package/dist/ui/contexts/KeypressContext.tsx +0 -440
- package/dist/ui/contexts/OverflowContext.tsx +0 -87
- package/dist/ui/contexts/SessionContext.test.tsx +0 -132
- package/dist/ui/contexts/SessionContext.tsx +0 -143
- package/dist/ui/contexts/SettingsContext.tsx +0 -20
- package/dist/ui/contexts/StreamingContext.tsx +0 -22
- package/dist/ui/contexts/VimModeContext.tsx +0 -79
- package/dist/ui/editors/editorSettingsManager.ts +0 -66
- package/dist/ui/hooks/atCommandProcessor.test.ts +0 -1102
- package/dist/ui/hooks/atCommandProcessor.ts +0 -485
- package/dist/ui/hooks/shellCommandProcessor.test.ts +0 -481
- package/dist/ui/hooks/shellCommandProcessor.ts +0 -314
- package/dist/ui/hooks/slashCommandProcessor.test.ts +0 -1044
- package/dist/ui/hooks/slashCommandProcessor.ts +0 -595
- package/dist/ui/hooks/useAtCompletion.test.ts +0 -497
- package/dist/ui/hooks/useAtCompletion.ts +0 -244
- package/dist/ui/hooks/useAuthCommand.ts +0 -129
- package/dist/ui/hooks/useAutoAcceptIndicator.test.ts +0 -300
- package/dist/ui/hooks/useAutoAcceptIndicator.ts +0 -52
- package/dist/ui/hooks/useBracketedPaste.ts +0 -37
- package/dist/ui/hooks/useCommandCompletion.test.ts +0 -518
- package/dist/ui/hooks/useCommandCompletion.tsx +0 -238
- package/dist/ui/hooks/useCompletion.ts +0 -128
- package/dist/ui/hooks/useConsoleMessages.test.ts +0 -147
- package/dist/ui/hooks/useConsoleMessages.ts +0 -110
- package/dist/ui/hooks/useEditorSettings.test.ts +0 -283
- package/dist/ui/hooks/useEditorSettings.ts +0 -75
- package/dist/ui/hooks/useFocus.test.ts +0 -119
- package/dist/ui/hooks/useFocus.ts +0 -48
- package/dist/ui/hooks/useFolderTrust.test.ts +0 -159
- package/dist/ui/hooks/useFolderTrust.ts +0 -72
- package/dist/ui/hooks/useGeminiStream.test.tsx +0 -1998
- package/dist/ui/hooks/useGeminiStream.ts +0 -1017
- package/dist/ui/hooks/useGitBranchName.test.ts +0 -280
- package/dist/ui/hooks/useGitBranchName.ts +0 -79
- package/dist/ui/hooks/useHistoryManager.test.ts +0 -202
- package/dist/ui/hooks/useHistoryManager.ts +0 -111
- package/dist/ui/hooks/useInputHistory.test.ts +0 -261
- package/dist/ui/hooks/useInputHistory.ts +0 -111
- package/dist/ui/hooks/useKeypress.test.ts +0 -280
- package/dist/ui/hooks/useKeypress.ts +0 -39
- package/dist/ui/hooks/useKittyKeyboardProtocol.ts +0 -31
- package/dist/ui/hooks/useLoadingIndicator.test.ts +0 -139
- package/dist/ui/hooks/useLoadingIndicator.ts +0 -57
- package/dist/ui/hooks/useLogger.ts +0 -32
- package/dist/ui/hooks/useMessageQueue.test.ts +0 -226
- package/dist/ui/hooks/useMessageQueue.ts +0 -69
- package/dist/ui/hooks/usePhraseCycler.test.ts +0 -145
- package/dist/ui/hooks/usePhraseCycler.ts +0 -198
- package/dist/ui/hooks/usePrivacySettings.test.ts +0 -242
- package/dist/ui/hooks/usePrivacySettings.ts +0 -150
- package/dist/ui/hooks/useReactToolScheduler.ts +0 -309
- package/dist/ui/hooks/useRefreshMemoryCommand.ts +0 -7
- package/dist/ui/hooks/useReverseSearchCompletion.test.tsx +0 -260
- package/dist/ui/hooks/useReverseSearchCompletion.tsx +0 -95
- package/dist/ui/hooks/useSettingsCommand.ts +0 -25
- package/dist/ui/hooks/useShellHistory.test.ts +0 -219
- package/dist/ui/hooks/useShellHistory.ts +0 -133
- package/dist/ui/hooks/useShowMemoryCommand.ts +0 -75
- package/dist/ui/hooks/useSlashCompletion.test.ts +0 -434
- package/dist/ui/hooks/useSlashCompletion.ts +0 -187
- package/dist/ui/hooks/useStateAndRef.ts +0 -36
- package/dist/ui/hooks/useTerminalSize.ts +0 -32
- package/dist/ui/hooks/useThemeCommand.ts +0 -110
- package/dist/ui/hooks/useTimer.test.ts +0 -120
- package/dist/ui/hooks/useTimer.ts +0 -65
- package/dist/ui/hooks/useToolScheduler.test.ts +0 -1123
- package/dist/ui/hooks/useWelcomeBack.ts +0 -253
- package/dist/ui/hooks/vim.test.ts +0 -1691
- package/dist/ui/hooks/vim.ts +0 -784
- package/dist/ui/keyMatchers.test.ts +0 -337
- package/dist/ui/keyMatchers.ts +0 -105
- package/dist/ui/privacy/CloudFreePrivacyNotice.tsx +0 -117
- package/dist/ui/privacy/CloudPaidPrivacyNotice.tsx +0 -59
- package/dist/ui/privacy/GeminiPrivacyNotice.tsx +0 -62
- package/dist/ui/privacy/PrivacyNotice.tsx +0 -42
- package/dist/ui/semantic-colors.ts +0 -26
- package/dist/ui/themes/ansi-light.ts +0 -150
- package/dist/ui/themes/ansi.ts +0 -159
- package/dist/ui/themes/atom-one-dark.ts +0 -147
- package/dist/ui/themes/ayu-light.ts +0 -139
- package/dist/ui/themes/ayu.ts +0 -113
- package/dist/ui/themes/color-utils.test.ts +0 -221
- package/dist/ui/themes/color-utils.ts +0 -231
- package/dist/ui/themes/default-light.ts +0 -108
- package/dist/ui/themes/default.ts +0 -151
- package/dist/ui/themes/dracula.ts +0 -124
- package/dist/ui/themes/fss-code-dark.ts +0 -156
- package/dist/ui/themes/fss-dark.ts +0 -113
- package/dist/ui/themes/fss-light.ts +0 -139
- package/dist/ui/themes/github-dark.ts +0 -147
- package/dist/ui/themes/github-light.ts +0 -149
- package/dist/ui/themes/googlecode.ts +0 -146
- package/dist/ui/themes/no-color.ts +0 -125
- package/dist/ui/themes/qwen-dark.ts +0 -118
- package/dist/ui/themes/qwen-light.ts +0 -144
- package/dist/ui/themes/semantic-tokens.ts +0 -127
- package/dist/ui/themes/shades-of-purple.ts +0 -352
- package/dist/ui/themes/theme-manager.test.ts +0 -99
- package/dist/ui/themes/theme-manager.ts +0 -257
- package/dist/ui/themes/theme.test.ts +0 -97
- package/dist/ui/themes/theme.ts +0 -451
- package/dist/ui/themes/xcode.ts +0 -154
- package/dist/ui/types.ts +0 -255
- package/dist/ui/utils/CodeColorizer.tsx +0 -217
- package/dist/ui/utils/ConsolePatcher.ts +0 -71
- package/dist/ui/utils/InlineMarkdownRenderer.tsx +0 -173
- package/dist/ui/utils/MarkdownDisplay.test.tsx +0 -244
- package/dist/ui/utils/MarkdownDisplay.tsx +0 -415
- package/dist/ui/utils/TableRenderer.tsx +0 -159
- package/dist/ui/utils/__snapshots__/MarkdownDisplay.test.tsx.snap +0 -93
- package/dist/ui/utils/clipboardUtils.test.ts +0 -76
- package/dist/ui/utils/clipboardUtils.ts +0 -149
- package/dist/ui/utils/commandUtils.test.ts +0 -384
- package/dist/ui/utils/commandUtils.ts +0 -106
- package/dist/ui/utils/computeStats.test.ts +0 -292
- package/dist/ui/utils/computeStats.ts +0 -86
- package/dist/ui/utils/displayUtils.test.ts +0 -58
- package/dist/ui/utils/displayUtils.ts +0 -32
- package/dist/ui/utils/formatters.test.ts +0 -72
- package/dist/ui/utils/formatters.ts +0 -63
- package/dist/ui/utils/isNarrowWidth.ts +0 -9
- package/dist/ui/utils/kittyProtocolDetector.ts +0 -105
- package/dist/ui/utils/markdownUtilities.test.ts +0 -50
- package/dist/ui/utils/markdownUtilities.ts +0 -125
- package/dist/ui/utils/platformConstants.ts +0 -52
- package/dist/ui/utils/terminalSetup.ts +0 -342
- package/dist/ui/utils/textUtils.ts +0 -40
- package/dist/ui/utils/updateCheck.test.ts +0 -163
- package/dist/ui/utils/updateCheck.ts +0 -100
- package/dist/utils/checks.ts +0 -28
- package/dist/utils/cleanup.test.ts +0 -68
- package/dist/utils/cleanup.ts +0 -36
- package/dist/utils/dialogScopeUtils.ts +0 -64
- package/dist/utils/events.ts +0 -14
- package/dist/utils/gitUtils.test.ts +0 -149
- package/dist/utils/gitUtils.ts +0 -116
- package/dist/utils/handleAutoUpdate.test.ts +0 -272
- package/dist/utils/handleAutoUpdate.ts +0 -145
- package/dist/utils/installationInfo.test.ts +0 -315
- package/dist/utils/installationInfo.ts +0 -176
- package/dist/utils/package.ts +0 -38
- package/dist/utils/readStdin.ts +0 -51
- package/dist/utils/resolvePath.ts +0 -21
- package/dist/utils/sandbox-macos-permissive-closed.sb +0 -32
- package/dist/utils/sandbox-macos-permissive-open.sb +0 -25
- package/dist/utils/sandbox-macos-permissive-proxied.sb +0 -37
- package/dist/utils/sandbox-macos-restrictive-closed.sb +0 -93
- package/dist/utils/sandbox-macos-restrictive-open.sb +0 -96
- package/dist/utils/sandbox-macos-restrictive-proxied.sb +0 -98
- package/dist/utils/sandbox.ts +0 -962
- package/dist/utils/settingsUtils.test.ts +0 -797
- package/dist/utils/settingsUtils.ts +0 -489
- package/dist/utils/spawnWrapper.ts +0 -9
- package/dist/utils/startupWarnings.test.ts +0 -83
- package/dist/utils/startupWarnings.ts +0 -40
- package/dist/utils/updateEventEmitter.ts +0 -13
- package/dist/utils/userStartupWarnings.test.ts +0 -87
- package/dist/utils/userStartupWarnings.ts +0 -69
- package/dist/utils/version.ts +0 -12
- package/dist/validateNonInterActiveAuth.test.ts +0 -260
- package/dist/validateNonInterActiveAuth.ts +0 -51
- package/dist/vitest.config.ts +0 -37
- package/dist/zed-integration/acp.ts +0 -366
- package/dist/zed-integration/fileSystemService.ts +0 -47
- package/dist/zed-integration/schema.ts +0 -466
- package/dist/zed-integration/zedIntegration.ts +0 -944
|
@@ -1,1998 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2025 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
describe,
|
|
10
|
-
it,
|
|
11
|
-
expect,
|
|
12
|
-
vi,
|
|
13
|
-
beforeEach,
|
|
14
|
-
Mock,
|
|
15
|
-
MockInstance,
|
|
16
|
-
} from 'vitest';
|
|
17
|
-
import { renderHook, act, waitFor } from '@testing-library/react';
|
|
18
|
-
import { useGeminiStream, mergePartListUnions } from './useGeminiStream.js';
|
|
19
|
-
import { useKeypress } from './useKeypress.js';
|
|
20
|
-
import * as atCommandProcessor from './atCommandProcessor.js';
|
|
21
|
-
import {
|
|
22
|
-
useReactToolScheduler,
|
|
23
|
-
TrackedToolCall,
|
|
24
|
-
TrackedCompletedToolCall,
|
|
25
|
-
TrackedExecutingToolCall,
|
|
26
|
-
TrackedCancelledToolCall,
|
|
27
|
-
} from './useReactToolScheduler.js';
|
|
28
|
-
import {
|
|
29
|
-
Config,
|
|
30
|
-
EditorType,
|
|
31
|
-
AuthType,
|
|
32
|
-
GeminiClient,
|
|
33
|
-
GeminiEventType as ServerGeminiEventType,
|
|
34
|
-
AnyToolInvocation,
|
|
35
|
-
ToolErrorType,
|
|
36
|
-
} from 'fss-link-core';
|
|
37
|
-
import { Part, PartListUnion } from '@google/genai';
|
|
38
|
-
import { UseHistoryManagerReturn } from './useHistoryManager.js';
|
|
39
|
-
import {
|
|
40
|
-
HistoryItem,
|
|
41
|
-
MessageType,
|
|
42
|
-
SlashCommandProcessorResult,
|
|
43
|
-
StreamingState,
|
|
44
|
-
} from '../types.js';
|
|
45
|
-
import { LoadedSettings } from '../../config/settings.js';
|
|
46
|
-
|
|
47
|
-
// --- MOCKS ---
|
|
48
|
-
const mockSendMessageStream = vi
|
|
49
|
-
.fn()
|
|
50
|
-
.mockReturnValue((async function* () {})());
|
|
51
|
-
const mockStartChat = vi.fn();
|
|
52
|
-
|
|
53
|
-
const MockedGeminiClientClass = vi.hoisted(() =>
|
|
54
|
-
vi.fn().mockImplementation(function (this: any, _config: any) {
|
|
55
|
-
// _config
|
|
56
|
-
this.startChat = mockStartChat;
|
|
57
|
-
this.sendMessageStream = mockSendMessageStream;
|
|
58
|
-
this.addHistory = vi.fn();
|
|
59
|
-
}),
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
const MockedUserPromptEvent = vi.hoisted(() =>
|
|
63
|
-
vi.fn().mockImplementation(() => {}),
|
|
64
|
-
);
|
|
65
|
-
const mockParseAndFormatApiError = vi.hoisted(() => vi.fn());
|
|
66
|
-
|
|
67
|
-
vi.mock('fss-link-core', async (importOriginal) => {
|
|
68
|
-
const actualCoreModule = (await importOriginal()) as any;
|
|
69
|
-
return {
|
|
70
|
-
...actualCoreModule,
|
|
71
|
-
GitService: vi.fn(),
|
|
72
|
-
GeminiClient: MockedGeminiClientClass,
|
|
73
|
-
UserPromptEvent: MockedUserPromptEvent,
|
|
74
|
-
parseAndFormatApiError: mockParseAndFormatApiError,
|
|
75
|
-
};
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const mockUseReactToolScheduler = useReactToolScheduler as Mock;
|
|
79
|
-
vi.mock('./useReactToolScheduler.js', async (importOriginal) => {
|
|
80
|
-
const actualSchedulerModule = (await importOriginal()) as any;
|
|
81
|
-
return {
|
|
82
|
-
...(actualSchedulerModule || {}),
|
|
83
|
-
useReactToolScheduler: vi.fn(),
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
vi.mock('./useKeypress.js', () => ({
|
|
88
|
-
useKeypress: vi.fn(),
|
|
89
|
-
}));
|
|
90
|
-
|
|
91
|
-
vi.mock('./shellCommandProcessor.js', () => ({
|
|
92
|
-
useShellCommandProcessor: vi.fn().mockReturnValue({
|
|
93
|
-
handleShellCommand: vi.fn(),
|
|
94
|
-
}),
|
|
95
|
-
}));
|
|
96
|
-
|
|
97
|
-
vi.mock('./atCommandProcessor.js');
|
|
98
|
-
|
|
99
|
-
vi.mock('../utils/markdownUtilities.js', () => ({
|
|
100
|
-
findLastSafeSplitPoint: vi.fn((s: string) => s.length),
|
|
101
|
-
}));
|
|
102
|
-
|
|
103
|
-
vi.mock('./useStateAndRef.js', () => ({
|
|
104
|
-
useStateAndRef: vi.fn((initial) => {
|
|
105
|
-
let val = initial;
|
|
106
|
-
const ref = { current: val };
|
|
107
|
-
const setVal = vi.fn((updater) => {
|
|
108
|
-
if (typeof updater === 'function') {
|
|
109
|
-
val = updater(val);
|
|
110
|
-
} else {
|
|
111
|
-
val = updater;
|
|
112
|
-
}
|
|
113
|
-
ref.current = val;
|
|
114
|
-
});
|
|
115
|
-
return [ref, setVal];
|
|
116
|
-
}),
|
|
117
|
-
}));
|
|
118
|
-
|
|
119
|
-
vi.mock('./useLogger.js', () => ({
|
|
120
|
-
useLogger: vi.fn().mockReturnValue({
|
|
121
|
-
logMessage: vi.fn().mockResolvedValue(undefined),
|
|
122
|
-
}),
|
|
123
|
-
}));
|
|
124
|
-
|
|
125
|
-
const mockStartNewPrompt = vi.fn();
|
|
126
|
-
const mockAddUsage = vi.fn();
|
|
127
|
-
vi.mock('../contexts/SessionContext.js', () => ({
|
|
128
|
-
useSessionStats: vi.fn(() => ({
|
|
129
|
-
startNewPrompt: mockStartNewPrompt,
|
|
130
|
-
addUsage: mockAddUsage,
|
|
131
|
-
getPromptCount: vi.fn(() => 5),
|
|
132
|
-
})),
|
|
133
|
-
}));
|
|
134
|
-
|
|
135
|
-
vi.mock('./slashCommandProcessor.js', () => ({
|
|
136
|
-
handleSlashCommand: vi.fn().mockReturnValue(false),
|
|
137
|
-
}));
|
|
138
|
-
|
|
139
|
-
// --- END MOCKS ---
|
|
140
|
-
|
|
141
|
-
describe('mergePartListUnions', () => {
|
|
142
|
-
it('should merge multiple PartListUnion arrays', () => {
|
|
143
|
-
const list1: PartListUnion = [{ text: 'Hello' }];
|
|
144
|
-
const list2: PartListUnion = [
|
|
145
|
-
{ inlineData: { mimeType: 'image/png', data: 'abc' } },
|
|
146
|
-
];
|
|
147
|
-
const list3: PartListUnion = [{ text: 'World' }, { text: '!' }];
|
|
148
|
-
const result = mergePartListUnions([list1, list2, list3]);
|
|
149
|
-
expect(result).toEqual([
|
|
150
|
-
{ text: 'Hello' },
|
|
151
|
-
{ inlineData: { mimeType: 'image/png', data: 'abc' } },
|
|
152
|
-
{ text: 'World' },
|
|
153
|
-
{ text: '!' },
|
|
154
|
-
]);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('should handle empty arrays in the input list', () => {
|
|
158
|
-
const list1: PartListUnion = [{ text: 'First' }];
|
|
159
|
-
const list2: PartListUnion = [];
|
|
160
|
-
const list3: PartListUnion = [{ text: 'Last' }];
|
|
161
|
-
const result = mergePartListUnions([list1, list2, list3]);
|
|
162
|
-
expect(result).toEqual([{ text: 'First' }, { text: 'Last' }]);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('should handle a single PartListUnion array', () => {
|
|
166
|
-
const list1: PartListUnion = [
|
|
167
|
-
{ text: 'One' },
|
|
168
|
-
{ inlineData: { mimeType: 'image/jpeg', data: 'xyz' } },
|
|
169
|
-
];
|
|
170
|
-
const result = mergePartListUnions([list1]);
|
|
171
|
-
expect(result).toEqual(list1);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('should return an empty array if all input arrays are empty', () => {
|
|
175
|
-
const list1: PartListUnion = [];
|
|
176
|
-
const list2: PartListUnion = [];
|
|
177
|
-
const result = mergePartListUnions([list1, list2]);
|
|
178
|
-
expect(result).toEqual([]);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('should handle input list being empty', () => {
|
|
182
|
-
const result = mergePartListUnions([]);
|
|
183
|
-
expect(result).toEqual([]);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('should correctly merge when PartListUnion items are single Parts not in arrays', () => {
|
|
187
|
-
const part1: Part = { text: 'Single part 1' };
|
|
188
|
-
const part2: Part = { inlineData: { mimeType: 'image/gif', data: 'gif' } };
|
|
189
|
-
const listContainingSingleParts: PartListUnion[] = [
|
|
190
|
-
part1,
|
|
191
|
-
[part2],
|
|
192
|
-
{ text: 'Another single part' },
|
|
193
|
-
];
|
|
194
|
-
const result = mergePartListUnions(listContainingSingleParts);
|
|
195
|
-
expect(result).toEqual([
|
|
196
|
-
{ text: 'Single part 1' },
|
|
197
|
-
{ inlineData: { mimeType: 'image/gif', data: 'gif' } },
|
|
198
|
-
{ text: 'Another single part' },
|
|
199
|
-
]);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it('should handle a mix of arrays and single parts, including empty arrays and undefined/null parts if they were possible (though PartListUnion typing restricts this)', () => {
|
|
203
|
-
const list1: PartListUnion = [{ text: 'A' }];
|
|
204
|
-
const list2: PartListUnion = [];
|
|
205
|
-
const part3: Part = { text: 'B' };
|
|
206
|
-
const list4: PartListUnion = [
|
|
207
|
-
{ text: 'C' },
|
|
208
|
-
{ inlineData: { mimeType: 'text/plain', data: 'D' } },
|
|
209
|
-
];
|
|
210
|
-
const result = mergePartListUnions([list1, list2, part3, list4]);
|
|
211
|
-
expect(result).toEqual([
|
|
212
|
-
{ text: 'A' },
|
|
213
|
-
{ text: 'B' },
|
|
214
|
-
{ text: 'C' },
|
|
215
|
-
{ inlineData: { mimeType: 'text/plain', data: 'D' } },
|
|
216
|
-
]);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it('should preserve the order of parts from the input arrays', () => {
|
|
220
|
-
const listA: PartListUnion = [{ text: '1' }, { text: '2' }];
|
|
221
|
-
const listB: PartListUnion = [{ text: '3' }];
|
|
222
|
-
const listC: PartListUnion = [{ text: '4' }, { text: '5' }];
|
|
223
|
-
const result = mergePartListUnions([listA, listB, listC]);
|
|
224
|
-
expect(result).toEqual([
|
|
225
|
-
{ text: '1' },
|
|
226
|
-
{ text: '2' },
|
|
227
|
-
{ text: '3' },
|
|
228
|
-
{ text: '4' },
|
|
229
|
-
{ text: '5' },
|
|
230
|
-
]);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('should handle cases where some PartListUnion items are single Parts and others are arrays of Parts', () => {
|
|
234
|
-
const singlePart1: Part = { text: 'First single' };
|
|
235
|
-
const arrayPart1: Part[] = [
|
|
236
|
-
{ text: 'Array item 1' },
|
|
237
|
-
{ text: 'Array item 2' },
|
|
238
|
-
];
|
|
239
|
-
const singlePart2: Part = {
|
|
240
|
-
inlineData: { mimeType: 'application/json', data: 'e30=' },
|
|
241
|
-
}; // {}
|
|
242
|
-
const arrayPart2: Part[] = [{ text: 'Last array item' }];
|
|
243
|
-
|
|
244
|
-
const result = mergePartListUnions([
|
|
245
|
-
singlePart1,
|
|
246
|
-
arrayPart1,
|
|
247
|
-
singlePart2,
|
|
248
|
-
arrayPart2,
|
|
249
|
-
]);
|
|
250
|
-
expect(result).toEqual([
|
|
251
|
-
{ text: 'First single' },
|
|
252
|
-
{ text: 'Array item 1' },
|
|
253
|
-
{ text: 'Array item 2' },
|
|
254
|
-
{ inlineData: { mimeType: 'application/json', data: 'e30=' } },
|
|
255
|
-
{ text: 'Last array item' },
|
|
256
|
-
]);
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
// --- Tests for useGeminiStream Hook ---
|
|
261
|
-
describe('useGeminiStream', () => {
|
|
262
|
-
let mockAddItem: Mock;
|
|
263
|
-
let mockConfig: Config;
|
|
264
|
-
let mockOnDebugMessage: Mock;
|
|
265
|
-
let mockHandleSlashCommand: Mock;
|
|
266
|
-
let mockScheduleToolCalls: Mock;
|
|
267
|
-
let mockCancelAllToolCalls: Mock;
|
|
268
|
-
let mockMarkToolsAsSubmitted: Mock;
|
|
269
|
-
let handleAtCommandSpy: MockInstance;
|
|
270
|
-
|
|
271
|
-
beforeEach(() => {
|
|
272
|
-
vi.clearAllMocks(); // Clear mocks before each test
|
|
273
|
-
|
|
274
|
-
mockAddItem = vi.fn();
|
|
275
|
-
// Define the mock for getGeminiClient
|
|
276
|
-
const mockGetGeminiClient = vi.fn().mockImplementation(() => {
|
|
277
|
-
// MockedGeminiClientClass is defined in the module scope by the previous change.
|
|
278
|
-
// It will use the mockStartChat and mockSendMessageStream that are managed within beforeEach.
|
|
279
|
-
const clientInstance = new MockedGeminiClientClass(mockConfig);
|
|
280
|
-
return clientInstance;
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
const contentGeneratorConfig = {
|
|
284
|
-
model: 'test-model',
|
|
285
|
-
apiKey: 'test-key',
|
|
286
|
-
vertexai: false,
|
|
287
|
-
authType: AuthType.USE_GEMINI,
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
mockConfig = {
|
|
291
|
-
apiKey: 'test-api-key',
|
|
292
|
-
model: 'gemini-pro',
|
|
293
|
-
sandbox: false,
|
|
294
|
-
targetDir: '/test/dir',
|
|
295
|
-
debugMode: false,
|
|
296
|
-
question: undefined,
|
|
297
|
-
fullContext: false,
|
|
298
|
-
coreTools: [],
|
|
299
|
-
toolDiscoveryCommand: undefined,
|
|
300
|
-
toolCallCommand: undefined,
|
|
301
|
-
mcpServerCommand: undefined,
|
|
302
|
-
mcpServers: undefined,
|
|
303
|
-
userAgent: 'test-agent',
|
|
304
|
-
userMemory: '',
|
|
305
|
-
geminiMdFileCount: 0,
|
|
306
|
-
alwaysSkipModificationConfirmation: false,
|
|
307
|
-
vertexai: false,
|
|
308
|
-
showMemoryUsage: false,
|
|
309
|
-
contextFileName: undefined,
|
|
310
|
-
getToolRegistry: vi.fn(
|
|
311
|
-
() => ({ getToolSchemaList: vi.fn(() => []) }) as any,
|
|
312
|
-
),
|
|
313
|
-
getProjectRoot: vi.fn(() => '/test/dir'),
|
|
314
|
-
getCheckpointingEnabled: vi.fn(() => false),
|
|
315
|
-
getGeminiClient: mockGetGeminiClient,
|
|
316
|
-
getUsageStatisticsEnabled: () => true,
|
|
317
|
-
getDebugMode: () => false,
|
|
318
|
-
addHistory: vi.fn(),
|
|
319
|
-
getSessionId() {
|
|
320
|
-
return 'test-session-id';
|
|
321
|
-
},
|
|
322
|
-
setQuotaErrorOccurred: vi.fn(),
|
|
323
|
-
getQuotaErrorOccurred: vi.fn(() => false),
|
|
324
|
-
getModel: vi.fn(() => 'gemini-2.5-pro'),
|
|
325
|
-
getContentGeneratorConfig: vi
|
|
326
|
-
.fn()
|
|
327
|
-
.mockReturnValue(contentGeneratorConfig),
|
|
328
|
-
} as unknown as Config;
|
|
329
|
-
mockOnDebugMessage = vi.fn();
|
|
330
|
-
mockHandleSlashCommand = vi.fn().mockResolvedValue(false);
|
|
331
|
-
|
|
332
|
-
// Mock return value for useReactToolScheduler
|
|
333
|
-
mockScheduleToolCalls = vi.fn();
|
|
334
|
-
mockCancelAllToolCalls = vi.fn();
|
|
335
|
-
mockMarkToolsAsSubmitted = vi.fn();
|
|
336
|
-
|
|
337
|
-
// Default mock for useReactToolScheduler to prevent toolCalls being undefined initially
|
|
338
|
-
mockUseReactToolScheduler.mockReturnValue([
|
|
339
|
-
[], // Default to empty array for toolCalls
|
|
340
|
-
mockScheduleToolCalls,
|
|
341
|
-
mockCancelAllToolCalls,
|
|
342
|
-
mockMarkToolsAsSubmitted,
|
|
343
|
-
]);
|
|
344
|
-
|
|
345
|
-
// Reset mocks for GeminiClient instance methods (startChat and sendMessageStream)
|
|
346
|
-
// The GeminiClient constructor itself is mocked at the module level.
|
|
347
|
-
mockStartChat.mockClear().mockResolvedValue({
|
|
348
|
-
sendMessageStream: mockSendMessageStream,
|
|
349
|
-
} as unknown as any); // GeminiChat -> any
|
|
350
|
-
mockSendMessageStream
|
|
351
|
-
.mockClear()
|
|
352
|
-
.mockReturnValue((async function* () {})());
|
|
353
|
-
handleAtCommandSpy = vi.spyOn(atCommandProcessor, 'handleAtCommand');
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
const mockLoadedSettings: LoadedSettings = {
|
|
357
|
-
merged: { preferredEditor: 'vscode' },
|
|
358
|
-
user: { path: '/user/settings.json', settings: {} },
|
|
359
|
-
workspace: { path: '/workspace/.fss-link/settings.json', settings: {} },
|
|
360
|
-
errors: [],
|
|
361
|
-
forScope: vi.fn(),
|
|
362
|
-
setValue: vi.fn(),
|
|
363
|
-
} as unknown as LoadedSettings;
|
|
364
|
-
|
|
365
|
-
const renderTestHook = (
|
|
366
|
-
initialToolCalls: TrackedToolCall[] = [],
|
|
367
|
-
geminiClient?: any,
|
|
368
|
-
) => {
|
|
369
|
-
let currentToolCalls = initialToolCalls;
|
|
370
|
-
const setToolCalls = (newToolCalls: TrackedToolCall[]) => {
|
|
371
|
-
currentToolCalls = newToolCalls;
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
mockUseReactToolScheduler.mockImplementation(() => [
|
|
375
|
-
currentToolCalls,
|
|
376
|
-
mockScheduleToolCalls,
|
|
377
|
-
mockCancelAllToolCalls,
|
|
378
|
-
mockMarkToolsAsSubmitted,
|
|
379
|
-
]);
|
|
380
|
-
|
|
381
|
-
const client = geminiClient || mockConfig.getGeminiClient();
|
|
382
|
-
|
|
383
|
-
const { result, rerender } = renderHook(
|
|
384
|
-
(props: {
|
|
385
|
-
client: any;
|
|
386
|
-
history: HistoryItem[];
|
|
387
|
-
addItem: UseHistoryManagerReturn['addItem'];
|
|
388
|
-
config: Config;
|
|
389
|
-
onDebugMessage: (message: string) => void;
|
|
390
|
-
handleSlashCommand: (
|
|
391
|
-
cmd: PartListUnion,
|
|
392
|
-
) => Promise<SlashCommandProcessorResult | false>;
|
|
393
|
-
shellModeActive: boolean;
|
|
394
|
-
loadedSettings: LoadedSettings;
|
|
395
|
-
toolCalls?: TrackedToolCall[]; // Allow passing updated toolCalls
|
|
396
|
-
}) => {
|
|
397
|
-
// Update the mock's return value if new toolCalls are passed in props
|
|
398
|
-
if (props.toolCalls) {
|
|
399
|
-
setToolCalls(props.toolCalls);
|
|
400
|
-
}
|
|
401
|
-
return useGeminiStream(
|
|
402
|
-
props.client,
|
|
403
|
-
props.history,
|
|
404
|
-
props.addItem,
|
|
405
|
-
props.config,
|
|
406
|
-
props.onDebugMessage,
|
|
407
|
-
props.handleSlashCommand,
|
|
408
|
-
props.shellModeActive,
|
|
409
|
-
() => 'vscode' as EditorType,
|
|
410
|
-
() => {},
|
|
411
|
-
() => Promise.resolve(),
|
|
412
|
-
false,
|
|
413
|
-
() => {},
|
|
414
|
-
() => {},
|
|
415
|
-
() => {},
|
|
416
|
-
);
|
|
417
|
-
},
|
|
418
|
-
{
|
|
419
|
-
initialProps: {
|
|
420
|
-
client,
|
|
421
|
-
history: [],
|
|
422
|
-
addItem: mockAddItem as unknown as UseHistoryManagerReturn['addItem'],
|
|
423
|
-
config: mockConfig,
|
|
424
|
-
onDebugMessage: mockOnDebugMessage,
|
|
425
|
-
handleSlashCommand: mockHandleSlashCommand as unknown as (
|
|
426
|
-
cmd: PartListUnion,
|
|
427
|
-
) => Promise<SlashCommandProcessorResult | false>,
|
|
428
|
-
shellModeActive: false,
|
|
429
|
-
loadedSettings: mockLoadedSettings,
|
|
430
|
-
toolCalls: initialToolCalls,
|
|
431
|
-
},
|
|
432
|
-
},
|
|
433
|
-
);
|
|
434
|
-
return {
|
|
435
|
-
result,
|
|
436
|
-
rerender,
|
|
437
|
-
mockMarkToolsAsSubmitted,
|
|
438
|
-
mockSendMessageStream,
|
|
439
|
-
client,
|
|
440
|
-
};
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
it('should not submit tool responses if not all tool calls are completed', () => {
|
|
444
|
-
const toolCalls: TrackedToolCall[] = [
|
|
445
|
-
{
|
|
446
|
-
request: {
|
|
447
|
-
callId: 'call1',
|
|
448
|
-
name: 'tool1',
|
|
449
|
-
args: {},
|
|
450
|
-
isClientInitiated: false,
|
|
451
|
-
prompt_id: 'prompt-id-1',
|
|
452
|
-
},
|
|
453
|
-
status: 'success',
|
|
454
|
-
responseSubmittedToGemini: false,
|
|
455
|
-
response: {
|
|
456
|
-
callId: 'call1',
|
|
457
|
-
responseParts: [{ text: 'tool 1 response' }],
|
|
458
|
-
error: undefined,
|
|
459
|
-
errorType: undefined,
|
|
460
|
-
resultDisplay: 'Tool 1 success display',
|
|
461
|
-
},
|
|
462
|
-
tool: {
|
|
463
|
-
name: 'tool1',
|
|
464
|
-
displayName: 'tool1',
|
|
465
|
-
description: 'desc1',
|
|
466
|
-
build: vi.fn(),
|
|
467
|
-
} as any,
|
|
468
|
-
invocation: {
|
|
469
|
-
getDescription: () => `Mock description`,
|
|
470
|
-
} as unknown as AnyToolInvocation,
|
|
471
|
-
startTime: Date.now(),
|
|
472
|
-
endTime: Date.now(),
|
|
473
|
-
} as TrackedCompletedToolCall,
|
|
474
|
-
{
|
|
475
|
-
request: {
|
|
476
|
-
callId: 'call2',
|
|
477
|
-
name: 'tool2',
|
|
478
|
-
args: {},
|
|
479
|
-
prompt_id: 'prompt-id-1',
|
|
480
|
-
},
|
|
481
|
-
status: 'executing',
|
|
482
|
-
responseSubmittedToGemini: false,
|
|
483
|
-
tool: {
|
|
484
|
-
name: 'tool2',
|
|
485
|
-
displayName: 'tool2',
|
|
486
|
-
description: 'desc2',
|
|
487
|
-
build: vi.fn(),
|
|
488
|
-
} as any,
|
|
489
|
-
invocation: {
|
|
490
|
-
getDescription: () => `Mock description`,
|
|
491
|
-
} as unknown as AnyToolInvocation,
|
|
492
|
-
startTime: Date.now(),
|
|
493
|
-
liveOutput: '...',
|
|
494
|
-
} as TrackedExecutingToolCall,
|
|
495
|
-
];
|
|
496
|
-
|
|
497
|
-
const { mockMarkToolsAsSubmitted, mockSendMessageStream } =
|
|
498
|
-
renderTestHook(toolCalls);
|
|
499
|
-
|
|
500
|
-
// Effect for submitting tool responses depends on toolCalls and isResponding
|
|
501
|
-
// isResponding is initially false, so the effect should run.
|
|
502
|
-
|
|
503
|
-
expect(mockMarkToolsAsSubmitted).not.toHaveBeenCalled();
|
|
504
|
-
expect(mockSendMessageStream).not.toHaveBeenCalled(); // submitQuery uses this
|
|
505
|
-
});
|
|
506
|
-
|
|
507
|
-
it('should submit tool responses when all tool calls are completed and ready', async () => {
|
|
508
|
-
const toolCall1ResponseParts: PartListUnion = [
|
|
509
|
-
{ text: 'tool 1 final response' },
|
|
510
|
-
];
|
|
511
|
-
const toolCall2ResponseParts: PartListUnion = [
|
|
512
|
-
{ text: 'tool 2 final response' },
|
|
513
|
-
];
|
|
514
|
-
const completedToolCalls: TrackedToolCall[] = [
|
|
515
|
-
{
|
|
516
|
-
request: {
|
|
517
|
-
callId: 'call1',
|
|
518
|
-
name: 'tool1',
|
|
519
|
-
args: {},
|
|
520
|
-
isClientInitiated: false,
|
|
521
|
-
prompt_id: 'prompt-id-2',
|
|
522
|
-
},
|
|
523
|
-
status: 'success',
|
|
524
|
-
responseSubmittedToGemini: false,
|
|
525
|
-
response: {
|
|
526
|
-
callId: 'call1',
|
|
527
|
-
responseParts: toolCall1ResponseParts,
|
|
528
|
-
errorType: undefined, // FIX: Added missing property
|
|
529
|
-
},
|
|
530
|
-
tool: {
|
|
531
|
-
displayName: 'MockTool',
|
|
532
|
-
},
|
|
533
|
-
invocation: {
|
|
534
|
-
getDescription: () => `Mock description`,
|
|
535
|
-
} as unknown as AnyToolInvocation,
|
|
536
|
-
} as TrackedCompletedToolCall,
|
|
537
|
-
{
|
|
538
|
-
request: {
|
|
539
|
-
callId: 'call2',
|
|
540
|
-
name: 'tool2',
|
|
541
|
-
args: {},
|
|
542
|
-
isClientInitiated: false,
|
|
543
|
-
prompt_id: 'prompt-id-2',
|
|
544
|
-
},
|
|
545
|
-
status: 'error',
|
|
546
|
-
responseSubmittedToGemini: false,
|
|
547
|
-
response: {
|
|
548
|
-
callId: 'call2',
|
|
549
|
-
responseParts: toolCall2ResponseParts,
|
|
550
|
-
errorType: ToolErrorType.UNHANDLED_EXCEPTION, // FIX: Added missing property
|
|
551
|
-
},
|
|
552
|
-
} as TrackedCompletedToolCall, // Treat error as a form of completion for submission
|
|
553
|
-
];
|
|
554
|
-
|
|
555
|
-
// Capture the onComplete callback
|
|
556
|
-
let capturedOnComplete:
|
|
557
|
-
| ((completedTools: TrackedToolCall[]) => Promise<void>)
|
|
558
|
-
| null = null;
|
|
559
|
-
|
|
560
|
-
mockUseReactToolScheduler.mockImplementation((onComplete) => {
|
|
561
|
-
capturedOnComplete = onComplete;
|
|
562
|
-
return [[], mockScheduleToolCalls, mockMarkToolsAsSubmitted];
|
|
563
|
-
});
|
|
564
|
-
|
|
565
|
-
renderHook(() =>
|
|
566
|
-
useGeminiStream(
|
|
567
|
-
new MockedGeminiClientClass(mockConfig),
|
|
568
|
-
[],
|
|
569
|
-
mockAddItem,
|
|
570
|
-
mockConfig,
|
|
571
|
-
mockOnDebugMessage,
|
|
572
|
-
mockHandleSlashCommand,
|
|
573
|
-
false,
|
|
574
|
-
() => 'vscode' as EditorType,
|
|
575
|
-
() => {},
|
|
576
|
-
() => Promise.resolve(),
|
|
577
|
-
false,
|
|
578
|
-
() => {},
|
|
579
|
-
() => {},
|
|
580
|
-
() => {},
|
|
581
|
-
),
|
|
582
|
-
);
|
|
583
|
-
|
|
584
|
-
// Trigger the onComplete callback with completed tools
|
|
585
|
-
await act(async () => {
|
|
586
|
-
if (capturedOnComplete) {
|
|
587
|
-
await capturedOnComplete(completedToolCalls);
|
|
588
|
-
}
|
|
589
|
-
});
|
|
590
|
-
|
|
591
|
-
await waitFor(() => {
|
|
592
|
-
expect(mockMarkToolsAsSubmitted).toHaveBeenCalledTimes(1);
|
|
593
|
-
expect(mockSendMessageStream).toHaveBeenCalledTimes(1);
|
|
594
|
-
});
|
|
595
|
-
|
|
596
|
-
const expectedMergedResponse = mergePartListUnions([
|
|
597
|
-
toolCall1ResponseParts,
|
|
598
|
-
toolCall2ResponseParts,
|
|
599
|
-
]);
|
|
600
|
-
expect(mockSendMessageStream).toHaveBeenCalledWith(
|
|
601
|
-
expectedMergedResponse,
|
|
602
|
-
expect.any(AbortSignal),
|
|
603
|
-
'prompt-id-2',
|
|
604
|
-
);
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
it('should handle all tool calls being cancelled', async () => {
|
|
608
|
-
const cancelledToolCalls: TrackedToolCall[] = [
|
|
609
|
-
{
|
|
610
|
-
request: {
|
|
611
|
-
callId: '1',
|
|
612
|
-
name: 'testTool',
|
|
613
|
-
args: {},
|
|
614
|
-
isClientInitiated: false,
|
|
615
|
-
prompt_id: 'prompt-id-3',
|
|
616
|
-
},
|
|
617
|
-
status: 'cancelled',
|
|
618
|
-
response: {
|
|
619
|
-
callId: '1',
|
|
620
|
-
responseParts: [{ text: 'cancelled' }],
|
|
621
|
-
errorType: undefined, // FIX: Added missing property
|
|
622
|
-
},
|
|
623
|
-
responseSubmittedToGemini: false,
|
|
624
|
-
tool: {
|
|
625
|
-
displayName: 'mock tool',
|
|
626
|
-
},
|
|
627
|
-
invocation: {
|
|
628
|
-
getDescription: () => `Mock description`,
|
|
629
|
-
} as unknown as AnyToolInvocation,
|
|
630
|
-
} as TrackedCancelledToolCall,
|
|
631
|
-
];
|
|
632
|
-
const client = new MockedGeminiClientClass(mockConfig);
|
|
633
|
-
|
|
634
|
-
// Capture the onComplete callback
|
|
635
|
-
let capturedOnComplete:
|
|
636
|
-
| ((completedTools: TrackedToolCall[]) => Promise<void>)
|
|
637
|
-
| null = null;
|
|
638
|
-
|
|
639
|
-
mockUseReactToolScheduler.mockImplementation((onComplete) => {
|
|
640
|
-
capturedOnComplete = onComplete;
|
|
641
|
-
return [[], mockScheduleToolCalls, mockMarkToolsAsSubmitted];
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
renderHook(() =>
|
|
645
|
-
useGeminiStream(
|
|
646
|
-
client,
|
|
647
|
-
[],
|
|
648
|
-
mockAddItem,
|
|
649
|
-
mockConfig,
|
|
650
|
-
mockOnDebugMessage,
|
|
651
|
-
mockHandleSlashCommand,
|
|
652
|
-
false,
|
|
653
|
-
() => 'vscode' as EditorType,
|
|
654
|
-
() => {},
|
|
655
|
-
() => Promise.resolve(),
|
|
656
|
-
false,
|
|
657
|
-
() => {},
|
|
658
|
-
() => {},
|
|
659
|
-
() => {},
|
|
660
|
-
),
|
|
661
|
-
);
|
|
662
|
-
|
|
663
|
-
// Trigger the onComplete callback with cancelled tools
|
|
664
|
-
await act(async () => {
|
|
665
|
-
if (capturedOnComplete) {
|
|
666
|
-
await capturedOnComplete(cancelledToolCalls);
|
|
667
|
-
}
|
|
668
|
-
});
|
|
669
|
-
|
|
670
|
-
await waitFor(() => {
|
|
671
|
-
expect(mockMarkToolsAsSubmitted).toHaveBeenCalledWith(['1']);
|
|
672
|
-
expect(client.addHistory).toHaveBeenCalledWith({
|
|
673
|
-
role: 'user',
|
|
674
|
-
parts: [{ text: 'cancelled' }],
|
|
675
|
-
});
|
|
676
|
-
// Ensure we do NOT call back to the API
|
|
677
|
-
expect(mockSendMessageStream).not.toHaveBeenCalled();
|
|
678
|
-
});
|
|
679
|
-
});
|
|
680
|
-
|
|
681
|
-
it('should group multiple cancelled tool call responses into a single history entry', async () => {
|
|
682
|
-
const cancelledToolCall1: TrackedCancelledToolCall = {
|
|
683
|
-
request: {
|
|
684
|
-
callId: 'cancel-1',
|
|
685
|
-
name: 'toolA',
|
|
686
|
-
args: {},
|
|
687
|
-
isClientInitiated: false,
|
|
688
|
-
prompt_id: 'prompt-id-7',
|
|
689
|
-
},
|
|
690
|
-
tool: {
|
|
691
|
-
name: 'toolA',
|
|
692
|
-
displayName: 'toolA',
|
|
693
|
-
description: 'descA',
|
|
694
|
-
build: vi.fn(),
|
|
695
|
-
} as any,
|
|
696
|
-
invocation: {
|
|
697
|
-
getDescription: () => `Mock description`,
|
|
698
|
-
} as unknown as AnyToolInvocation,
|
|
699
|
-
status: 'cancelled',
|
|
700
|
-
response: {
|
|
701
|
-
callId: 'cancel-1',
|
|
702
|
-
responseParts: [
|
|
703
|
-
{ functionResponse: { name: 'toolA', id: 'cancel-1' } },
|
|
704
|
-
],
|
|
705
|
-
resultDisplay: undefined,
|
|
706
|
-
error: undefined,
|
|
707
|
-
errorType: undefined,
|
|
708
|
-
},
|
|
709
|
-
responseSubmittedToGemini: false,
|
|
710
|
-
};
|
|
711
|
-
const cancelledToolCall2: TrackedCancelledToolCall = {
|
|
712
|
-
request: {
|
|
713
|
-
callId: 'cancel-2',
|
|
714
|
-
name: 'toolB',
|
|
715
|
-
args: {},
|
|
716
|
-
isClientInitiated: false,
|
|
717
|
-
prompt_id: 'prompt-id-8',
|
|
718
|
-
},
|
|
719
|
-
tool: {
|
|
720
|
-
name: 'toolB',
|
|
721
|
-
displayName: 'toolB',
|
|
722
|
-
description: 'descB',
|
|
723
|
-
build: vi.fn(),
|
|
724
|
-
} as any,
|
|
725
|
-
invocation: {
|
|
726
|
-
getDescription: () => `Mock description`,
|
|
727
|
-
} as unknown as AnyToolInvocation,
|
|
728
|
-
status: 'cancelled',
|
|
729
|
-
response: {
|
|
730
|
-
callId: 'cancel-2',
|
|
731
|
-
responseParts: [
|
|
732
|
-
{ functionResponse: { name: 'toolB', id: 'cancel-2' } },
|
|
733
|
-
],
|
|
734
|
-
resultDisplay: undefined,
|
|
735
|
-
error: undefined,
|
|
736
|
-
errorType: undefined,
|
|
737
|
-
},
|
|
738
|
-
responseSubmittedToGemini: false,
|
|
739
|
-
};
|
|
740
|
-
const allCancelledTools = [cancelledToolCall1, cancelledToolCall2];
|
|
741
|
-
const client = new MockedGeminiClientClass(mockConfig);
|
|
742
|
-
|
|
743
|
-
let capturedOnComplete:
|
|
744
|
-
| ((completedTools: TrackedToolCall[]) => Promise<void>)
|
|
745
|
-
| null = null;
|
|
746
|
-
|
|
747
|
-
mockUseReactToolScheduler.mockImplementation((onComplete) => {
|
|
748
|
-
capturedOnComplete = onComplete;
|
|
749
|
-
return [[], mockScheduleToolCalls, mockMarkToolsAsSubmitted];
|
|
750
|
-
});
|
|
751
|
-
|
|
752
|
-
renderHook(() =>
|
|
753
|
-
useGeminiStream(
|
|
754
|
-
client,
|
|
755
|
-
[],
|
|
756
|
-
mockAddItem,
|
|
757
|
-
mockConfig,
|
|
758
|
-
mockOnDebugMessage,
|
|
759
|
-
mockHandleSlashCommand,
|
|
760
|
-
false,
|
|
761
|
-
() => 'vscode' as EditorType,
|
|
762
|
-
() => {},
|
|
763
|
-
() => Promise.resolve(),
|
|
764
|
-
false,
|
|
765
|
-
() => {},
|
|
766
|
-
() => {},
|
|
767
|
-
() => {},
|
|
768
|
-
),
|
|
769
|
-
);
|
|
770
|
-
|
|
771
|
-
// Trigger the onComplete callback with multiple cancelled tools
|
|
772
|
-
await act(async () => {
|
|
773
|
-
if (capturedOnComplete) {
|
|
774
|
-
await capturedOnComplete(allCancelledTools);
|
|
775
|
-
}
|
|
776
|
-
});
|
|
777
|
-
|
|
778
|
-
await waitFor(() => {
|
|
779
|
-
// The tools should be marked as submitted locally
|
|
780
|
-
expect(mockMarkToolsAsSubmitted).toHaveBeenCalledWith([
|
|
781
|
-
'cancel-1',
|
|
782
|
-
'cancel-2',
|
|
783
|
-
]);
|
|
784
|
-
|
|
785
|
-
// Crucially, addHistory should be called only ONCE
|
|
786
|
-
expect(client.addHistory).toHaveBeenCalledTimes(1);
|
|
787
|
-
|
|
788
|
-
// And that single call should contain BOTH function responses
|
|
789
|
-
expect(client.addHistory).toHaveBeenCalledWith({
|
|
790
|
-
role: 'user',
|
|
791
|
-
parts: [
|
|
792
|
-
...(cancelledToolCall1.response.responseParts as Part[]),
|
|
793
|
-
...(cancelledToolCall2.response.responseParts as Part[]),
|
|
794
|
-
],
|
|
795
|
-
});
|
|
796
|
-
|
|
797
|
-
// No message should be sent back to the API for a turn with only cancellations
|
|
798
|
-
expect(mockSendMessageStream).not.toHaveBeenCalled();
|
|
799
|
-
});
|
|
800
|
-
});
|
|
801
|
-
|
|
802
|
-
it('should not flicker streaming state to Idle between tool completion and submission', async () => {
|
|
803
|
-
const toolCallResponseParts: PartListUnion = [
|
|
804
|
-
{ text: 'tool 1 final response' },
|
|
805
|
-
];
|
|
806
|
-
|
|
807
|
-
const initialToolCalls: TrackedToolCall[] = [
|
|
808
|
-
{
|
|
809
|
-
request: {
|
|
810
|
-
callId: 'call1',
|
|
811
|
-
name: 'tool1',
|
|
812
|
-
args: {},
|
|
813
|
-
isClientInitiated: false,
|
|
814
|
-
prompt_id: 'prompt-id-4',
|
|
815
|
-
},
|
|
816
|
-
status: 'executing',
|
|
817
|
-
responseSubmittedToGemini: false,
|
|
818
|
-
tool: {
|
|
819
|
-
name: 'tool1',
|
|
820
|
-
displayName: 'tool1',
|
|
821
|
-
description: 'desc',
|
|
822
|
-
build: vi.fn(),
|
|
823
|
-
} as any,
|
|
824
|
-
invocation: {
|
|
825
|
-
getDescription: () => `Mock description`,
|
|
826
|
-
} as unknown as AnyToolInvocation,
|
|
827
|
-
startTime: Date.now(),
|
|
828
|
-
} as TrackedExecutingToolCall,
|
|
829
|
-
];
|
|
830
|
-
|
|
831
|
-
const completedToolCalls: TrackedToolCall[] = [
|
|
832
|
-
{
|
|
833
|
-
...(initialToolCalls[0] as TrackedExecutingToolCall),
|
|
834
|
-
status: 'success',
|
|
835
|
-
response: {
|
|
836
|
-
callId: 'call1',
|
|
837
|
-
responseParts: toolCallResponseParts,
|
|
838
|
-
error: undefined,
|
|
839
|
-
errorType: undefined,
|
|
840
|
-
resultDisplay: 'Tool 1 success display',
|
|
841
|
-
},
|
|
842
|
-
endTime: Date.now(),
|
|
843
|
-
} as TrackedCompletedToolCall,
|
|
844
|
-
];
|
|
845
|
-
|
|
846
|
-
// Capture the onComplete callback
|
|
847
|
-
let capturedOnComplete:
|
|
848
|
-
| ((completedTools: TrackedToolCall[]) => Promise<void>)
|
|
849
|
-
| null = null;
|
|
850
|
-
let currentToolCalls = initialToolCalls;
|
|
851
|
-
|
|
852
|
-
mockUseReactToolScheduler.mockImplementation((onComplete) => {
|
|
853
|
-
capturedOnComplete = onComplete;
|
|
854
|
-
return [
|
|
855
|
-
currentToolCalls,
|
|
856
|
-
mockScheduleToolCalls,
|
|
857
|
-
mockMarkToolsAsSubmitted,
|
|
858
|
-
];
|
|
859
|
-
});
|
|
860
|
-
|
|
861
|
-
const { result, rerender } = renderHook(() =>
|
|
862
|
-
useGeminiStream(
|
|
863
|
-
new MockedGeminiClientClass(mockConfig),
|
|
864
|
-
[],
|
|
865
|
-
mockAddItem,
|
|
866
|
-
mockConfig,
|
|
867
|
-
mockOnDebugMessage,
|
|
868
|
-
mockHandleSlashCommand,
|
|
869
|
-
false,
|
|
870
|
-
() => 'vscode' as EditorType,
|
|
871
|
-
() => {},
|
|
872
|
-
() => Promise.resolve(),
|
|
873
|
-
false,
|
|
874
|
-
() => {},
|
|
875
|
-
() => {},
|
|
876
|
-
() => {},
|
|
877
|
-
),
|
|
878
|
-
);
|
|
879
|
-
|
|
880
|
-
// 1. Initial state should be Responding because a tool is executing.
|
|
881
|
-
expect(result.current.streamingState).toBe(StreamingState.Responding);
|
|
882
|
-
|
|
883
|
-
// 2. Update the tool calls to completed state and rerender
|
|
884
|
-
currentToolCalls = completedToolCalls;
|
|
885
|
-
mockUseReactToolScheduler.mockImplementation((onComplete) => {
|
|
886
|
-
capturedOnComplete = onComplete;
|
|
887
|
-
return [
|
|
888
|
-
completedToolCalls,
|
|
889
|
-
mockScheduleToolCalls,
|
|
890
|
-
mockMarkToolsAsSubmitted,
|
|
891
|
-
];
|
|
892
|
-
});
|
|
893
|
-
|
|
894
|
-
act(() => {
|
|
895
|
-
rerender();
|
|
896
|
-
});
|
|
897
|
-
|
|
898
|
-
// 3. The state should *still* be Responding, not Idle.
|
|
899
|
-
// This is because the completed tool's response has not been submitted yet.
|
|
900
|
-
expect(result.current.streamingState).toBe(StreamingState.Responding);
|
|
901
|
-
|
|
902
|
-
// 4. Trigger the onComplete callback to simulate tool completion
|
|
903
|
-
await act(async () => {
|
|
904
|
-
if (capturedOnComplete) {
|
|
905
|
-
await capturedOnComplete(completedToolCalls);
|
|
906
|
-
}
|
|
907
|
-
});
|
|
908
|
-
|
|
909
|
-
// 5. Wait for submitQuery to be called
|
|
910
|
-
await waitFor(() => {
|
|
911
|
-
expect(mockSendMessageStream).toHaveBeenCalledWith(
|
|
912
|
-
toolCallResponseParts,
|
|
913
|
-
expect.any(AbortSignal),
|
|
914
|
-
'prompt-id-4',
|
|
915
|
-
);
|
|
916
|
-
});
|
|
917
|
-
|
|
918
|
-
// 6. After submission, the state should remain Responding until the stream completes.
|
|
919
|
-
expect(result.current.streamingState).toBe(StreamingState.Responding);
|
|
920
|
-
});
|
|
921
|
-
|
|
922
|
-
describe('User Cancellation', () => {
|
|
923
|
-
let keypressCallback: (key: any) => void;
|
|
924
|
-
const mockUseKeypress = useKeypress as Mock;
|
|
925
|
-
|
|
926
|
-
beforeEach(() => {
|
|
927
|
-
// Capture the callback passed to useKeypress
|
|
928
|
-
mockUseKeypress.mockImplementation((callback, options) => {
|
|
929
|
-
if (options.isActive) {
|
|
930
|
-
keypressCallback = callback;
|
|
931
|
-
} else {
|
|
932
|
-
keypressCallback = () => {};
|
|
933
|
-
}
|
|
934
|
-
});
|
|
935
|
-
});
|
|
936
|
-
|
|
937
|
-
const simulateEscapeKeyPress = () => {
|
|
938
|
-
act(() => {
|
|
939
|
-
keypressCallback({ name: 'escape' });
|
|
940
|
-
});
|
|
941
|
-
};
|
|
942
|
-
|
|
943
|
-
it('should cancel an in-progress stream when escape is pressed', async () => {
|
|
944
|
-
const mockStream = (async function* () {
|
|
945
|
-
yield { type: 'content', value: 'Part 1' };
|
|
946
|
-
// Keep the stream open
|
|
947
|
-
await new Promise(() => {});
|
|
948
|
-
})();
|
|
949
|
-
mockSendMessageStream.mockReturnValue(mockStream);
|
|
950
|
-
|
|
951
|
-
const { result } = renderTestHook();
|
|
952
|
-
|
|
953
|
-
// Start a query
|
|
954
|
-
await act(async () => {
|
|
955
|
-
result.current.submitQuery('test query');
|
|
956
|
-
});
|
|
957
|
-
|
|
958
|
-
// Wait for the first part of the response
|
|
959
|
-
await waitFor(() => {
|
|
960
|
-
expect(result.current.streamingState).toBe(StreamingState.Responding);
|
|
961
|
-
});
|
|
962
|
-
|
|
963
|
-
// Simulate escape key press
|
|
964
|
-
simulateEscapeKeyPress();
|
|
965
|
-
|
|
966
|
-
// Verify cancellation message is added
|
|
967
|
-
await waitFor(() => {
|
|
968
|
-
expect(mockAddItem).toHaveBeenCalledWith(
|
|
969
|
-
{
|
|
970
|
-
type: MessageType.INFO,
|
|
971
|
-
text: 'Request cancelled.',
|
|
972
|
-
},
|
|
973
|
-
expect.any(Number),
|
|
974
|
-
);
|
|
975
|
-
});
|
|
976
|
-
|
|
977
|
-
// Verify state is reset
|
|
978
|
-
expect(result.current.streamingState).toBe(StreamingState.Idle);
|
|
979
|
-
});
|
|
980
|
-
|
|
981
|
-
it('should call onCancelSubmit handler when escape is pressed', async () => {
|
|
982
|
-
const cancelSubmitSpy = vi.fn();
|
|
983
|
-
const mockStream = (async function* () {
|
|
984
|
-
yield { type: 'content', value: 'Part 1' };
|
|
985
|
-
// Keep the stream open
|
|
986
|
-
await new Promise(() => {});
|
|
987
|
-
})();
|
|
988
|
-
mockSendMessageStream.mockReturnValue(mockStream);
|
|
989
|
-
|
|
990
|
-
const { result } = renderHook(() =>
|
|
991
|
-
useGeminiStream(
|
|
992
|
-
mockConfig.getGeminiClient(),
|
|
993
|
-
[],
|
|
994
|
-
mockAddItem,
|
|
995
|
-
mockConfig,
|
|
996
|
-
mockOnDebugMessage,
|
|
997
|
-
mockHandleSlashCommand,
|
|
998
|
-
false,
|
|
999
|
-
() => 'vscode' as EditorType,
|
|
1000
|
-
() => {},
|
|
1001
|
-
() => Promise.resolve(),
|
|
1002
|
-
false,
|
|
1003
|
-
() => {},
|
|
1004
|
-
() => {},
|
|
1005
|
-
cancelSubmitSpy,
|
|
1006
|
-
),
|
|
1007
|
-
);
|
|
1008
|
-
|
|
1009
|
-
// Start a query
|
|
1010
|
-
await act(async () => {
|
|
1011
|
-
result.current.submitQuery('test query');
|
|
1012
|
-
});
|
|
1013
|
-
|
|
1014
|
-
simulateEscapeKeyPress();
|
|
1015
|
-
|
|
1016
|
-
expect(cancelSubmitSpy).toHaveBeenCalled();
|
|
1017
|
-
});
|
|
1018
|
-
|
|
1019
|
-
it('should not do anything if escape is pressed when not responding', () => {
|
|
1020
|
-
const { result } = renderTestHook();
|
|
1021
|
-
|
|
1022
|
-
expect(result.current.streamingState).toBe(StreamingState.Idle);
|
|
1023
|
-
|
|
1024
|
-
// Simulate escape key press
|
|
1025
|
-
simulateEscapeKeyPress();
|
|
1026
|
-
|
|
1027
|
-
// No change should happen, no cancellation message
|
|
1028
|
-
expect(mockAddItem).not.toHaveBeenCalledWith(
|
|
1029
|
-
expect.objectContaining({
|
|
1030
|
-
text: 'Request cancelled.',
|
|
1031
|
-
}),
|
|
1032
|
-
expect.any(Number),
|
|
1033
|
-
);
|
|
1034
|
-
});
|
|
1035
|
-
|
|
1036
|
-
it('should prevent further processing after cancellation', async () => {
|
|
1037
|
-
let continueStream: () => void;
|
|
1038
|
-
const streamPromise = new Promise<void>((resolve) => {
|
|
1039
|
-
continueStream = resolve;
|
|
1040
|
-
});
|
|
1041
|
-
|
|
1042
|
-
const mockStream = (async function* () {
|
|
1043
|
-
yield { type: 'content', value: 'Initial' };
|
|
1044
|
-
await streamPromise; // Wait until we manually continue
|
|
1045
|
-
yield { type: 'content', value: ' Canceled' };
|
|
1046
|
-
})();
|
|
1047
|
-
mockSendMessageStream.mockReturnValue(mockStream);
|
|
1048
|
-
|
|
1049
|
-
const { result } = renderTestHook();
|
|
1050
|
-
|
|
1051
|
-
await act(async () => {
|
|
1052
|
-
result.current.submitQuery('long running query');
|
|
1053
|
-
});
|
|
1054
|
-
|
|
1055
|
-
await waitFor(() => {
|
|
1056
|
-
expect(result.current.streamingState).toBe(StreamingState.Responding);
|
|
1057
|
-
});
|
|
1058
|
-
|
|
1059
|
-
// Cancel the request
|
|
1060
|
-
simulateEscapeKeyPress();
|
|
1061
|
-
|
|
1062
|
-
// Allow the stream to continue
|
|
1063
|
-
act(() => {
|
|
1064
|
-
continueStream();
|
|
1065
|
-
});
|
|
1066
|
-
|
|
1067
|
-
// Wait a bit to see if the second part is processed
|
|
1068
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
1069
|
-
|
|
1070
|
-
// The text should not have been updated with " Canceled"
|
|
1071
|
-
const lastCall = mockAddItem.mock.calls.find(
|
|
1072
|
-
(call) => call[0].type === 'gemini',
|
|
1073
|
-
);
|
|
1074
|
-
expect(lastCall?.[0].text).toBe('Initial');
|
|
1075
|
-
|
|
1076
|
-
// The final state should be idle after cancellation
|
|
1077
|
-
expect(result.current.streamingState).toBe(StreamingState.Idle);
|
|
1078
|
-
});
|
|
1079
|
-
|
|
1080
|
-
it('should not cancel if a tool call is in progress (not just responding)', async () => {
|
|
1081
|
-
const toolCalls: TrackedToolCall[] = [
|
|
1082
|
-
{
|
|
1083
|
-
request: { callId: 'call1', name: 'tool1', args: {} },
|
|
1084
|
-
status: 'executing',
|
|
1085
|
-
responseSubmittedToGemini: false,
|
|
1086
|
-
tool: {
|
|
1087
|
-
name: 'tool1',
|
|
1088
|
-
description: 'desc1',
|
|
1089
|
-
build: vi.fn().mockImplementation((_) => ({
|
|
1090
|
-
getDescription: () => `Mock description`,
|
|
1091
|
-
})),
|
|
1092
|
-
} as any,
|
|
1093
|
-
invocation: {
|
|
1094
|
-
getDescription: () => `Mock description`,
|
|
1095
|
-
},
|
|
1096
|
-
startTime: Date.now(),
|
|
1097
|
-
liveOutput: '...',
|
|
1098
|
-
} as TrackedExecutingToolCall,
|
|
1099
|
-
];
|
|
1100
|
-
|
|
1101
|
-
const abortSpy = vi.spyOn(AbortController.prototype, 'abort');
|
|
1102
|
-
const { result } = renderTestHook(toolCalls);
|
|
1103
|
-
|
|
1104
|
-
// State is `Responding` because a tool is running
|
|
1105
|
-
expect(result.current.streamingState).toBe(StreamingState.Responding);
|
|
1106
|
-
|
|
1107
|
-
// Try to cancel
|
|
1108
|
-
simulateEscapeKeyPress();
|
|
1109
|
-
|
|
1110
|
-
// Nothing should happen because the state is not `Responding`
|
|
1111
|
-
expect(abortSpy).not.toHaveBeenCalled();
|
|
1112
|
-
});
|
|
1113
|
-
});
|
|
1114
|
-
|
|
1115
|
-
describe('Slash Command Handling', () => {
|
|
1116
|
-
it('should schedule a tool call when the command processor returns a schedule_tool action', async () => {
|
|
1117
|
-
const clientToolRequest: SlashCommandProcessorResult = {
|
|
1118
|
-
type: 'schedule_tool',
|
|
1119
|
-
toolName: 'save_memory',
|
|
1120
|
-
toolArgs: { fact: 'test fact' },
|
|
1121
|
-
};
|
|
1122
|
-
mockHandleSlashCommand.mockResolvedValue(clientToolRequest);
|
|
1123
|
-
|
|
1124
|
-
const { result } = renderTestHook();
|
|
1125
|
-
|
|
1126
|
-
await act(async () => {
|
|
1127
|
-
await result.current.submitQuery('/memory add "test fact"');
|
|
1128
|
-
});
|
|
1129
|
-
|
|
1130
|
-
await waitFor(() => {
|
|
1131
|
-
expect(mockScheduleToolCalls).toHaveBeenCalledWith(
|
|
1132
|
-
[
|
|
1133
|
-
expect.objectContaining({
|
|
1134
|
-
name: 'save_memory',
|
|
1135
|
-
args: { fact: 'test fact' },
|
|
1136
|
-
isClientInitiated: true,
|
|
1137
|
-
}),
|
|
1138
|
-
],
|
|
1139
|
-
expect.any(AbortSignal),
|
|
1140
|
-
);
|
|
1141
|
-
expect(mockSendMessageStream).not.toHaveBeenCalled();
|
|
1142
|
-
});
|
|
1143
|
-
});
|
|
1144
|
-
|
|
1145
|
-
it('should stop processing and not call Gemini when a command is handled without a tool call', async () => {
|
|
1146
|
-
const uiOnlyCommandResult: SlashCommandProcessorResult = {
|
|
1147
|
-
type: 'handled',
|
|
1148
|
-
};
|
|
1149
|
-
mockHandleSlashCommand.mockResolvedValue(uiOnlyCommandResult);
|
|
1150
|
-
|
|
1151
|
-
const { result } = renderTestHook();
|
|
1152
|
-
|
|
1153
|
-
await act(async () => {
|
|
1154
|
-
await result.current.submitQuery('/help');
|
|
1155
|
-
});
|
|
1156
|
-
|
|
1157
|
-
await waitFor(() => {
|
|
1158
|
-
expect(mockHandleSlashCommand).toHaveBeenCalledWith('/help');
|
|
1159
|
-
expect(mockScheduleToolCalls).not.toHaveBeenCalled();
|
|
1160
|
-
expect(mockSendMessageStream).not.toHaveBeenCalled(); // No LLM call made
|
|
1161
|
-
});
|
|
1162
|
-
});
|
|
1163
|
-
|
|
1164
|
-
it('should call Gemini with prompt content when slash command returns a `submit_prompt` action', async () => {
|
|
1165
|
-
const customCommandResult: SlashCommandProcessorResult = {
|
|
1166
|
-
type: 'submit_prompt',
|
|
1167
|
-
content: 'This is the actual prompt from the command file.',
|
|
1168
|
-
};
|
|
1169
|
-
mockHandleSlashCommand.mockResolvedValue(customCommandResult);
|
|
1170
|
-
|
|
1171
|
-
const { result, mockSendMessageStream: localMockSendMessageStream } =
|
|
1172
|
-
renderTestHook();
|
|
1173
|
-
|
|
1174
|
-
await act(async () => {
|
|
1175
|
-
await result.current.submitQuery('/my-custom-command');
|
|
1176
|
-
});
|
|
1177
|
-
|
|
1178
|
-
await waitFor(() => {
|
|
1179
|
-
expect(mockHandleSlashCommand).toHaveBeenCalledWith(
|
|
1180
|
-
'/my-custom-command',
|
|
1181
|
-
);
|
|
1182
|
-
|
|
1183
|
-
expect(localMockSendMessageStream).not.toHaveBeenCalledWith(
|
|
1184
|
-
'/my-custom-command',
|
|
1185
|
-
expect.anything(),
|
|
1186
|
-
expect.anything(),
|
|
1187
|
-
);
|
|
1188
|
-
|
|
1189
|
-
expect(localMockSendMessageStream).toHaveBeenCalledWith(
|
|
1190
|
-
'This is the actual prompt from the command file.',
|
|
1191
|
-
expect.any(AbortSignal),
|
|
1192
|
-
expect.any(String),
|
|
1193
|
-
);
|
|
1194
|
-
|
|
1195
|
-
expect(mockScheduleToolCalls).not.toHaveBeenCalled();
|
|
1196
|
-
});
|
|
1197
|
-
});
|
|
1198
|
-
|
|
1199
|
-
it('should correctly handle a submit_prompt action with empty content', async () => {
|
|
1200
|
-
const emptyPromptResult: SlashCommandProcessorResult = {
|
|
1201
|
-
type: 'submit_prompt',
|
|
1202
|
-
content: '',
|
|
1203
|
-
};
|
|
1204
|
-
mockHandleSlashCommand.mockResolvedValue(emptyPromptResult);
|
|
1205
|
-
|
|
1206
|
-
const { result, mockSendMessageStream: localMockSendMessageStream } =
|
|
1207
|
-
renderTestHook();
|
|
1208
|
-
|
|
1209
|
-
await act(async () => {
|
|
1210
|
-
await result.current.submitQuery('/emptycmd');
|
|
1211
|
-
});
|
|
1212
|
-
|
|
1213
|
-
await waitFor(() => {
|
|
1214
|
-
expect(mockHandleSlashCommand).toHaveBeenCalledWith('/emptycmd');
|
|
1215
|
-
expect(localMockSendMessageStream).toHaveBeenCalledWith(
|
|
1216
|
-
'',
|
|
1217
|
-
expect.any(AbortSignal),
|
|
1218
|
-
expect.any(String),
|
|
1219
|
-
);
|
|
1220
|
-
});
|
|
1221
|
-
});
|
|
1222
|
-
});
|
|
1223
|
-
|
|
1224
|
-
describe('Memory Refresh on save_memory', () => {
|
|
1225
|
-
it('should call performMemoryRefresh when a save_memory tool call completes successfully', async () => {
|
|
1226
|
-
const mockPerformMemoryRefresh = vi.fn();
|
|
1227
|
-
const completedToolCall: TrackedCompletedToolCall = {
|
|
1228
|
-
request: {
|
|
1229
|
-
callId: 'save-mem-call-1',
|
|
1230
|
-
name: 'save_memory',
|
|
1231
|
-
args: { fact: 'test' },
|
|
1232
|
-
isClientInitiated: true,
|
|
1233
|
-
prompt_id: 'prompt-id-6',
|
|
1234
|
-
},
|
|
1235
|
-
status: 'success',
|
|
1236
|
-
responseSubmittedToGemini: false,
|
|
1237
|
-
response: {
|
|
1238
|
-
callId: 'save-mem-call-1',
|
|
1239
|
-
responseParts: [{ text: 'Memory saved' }],
|
|
1240
|
-
resultDisplay: 'Success: Memory saved',
|
|
1241
|
-
error: undefined,
|
|
1242
|
-
errorType: undefined,
|
|
1243
|
-
},
|
|
1244
|
-
tool: {
|
|
1245
|
-
name: 'save_memory',
|
|
1246
|
-
displayName: 'save_memory',
|
|
1247
|
-
description: 'Saves memory',
|
|
1248
|
-
build: vi.fn(),
|
|
1249
|
-
} as any,
|
|
1250
|
-
invocation: {
|
|
1251
|
-
getDescription: () => `Mock description`,
|
|
1252
|
-
} as unknown as AnyToolInvocation,
|
|
1253
|
-
};
|
|
1254
|
-
|
|
1255
|
-
// Capture the onComplete callback
|
|
1256
|
-
let capturedOnComplete:
|
|
1257
|
-
| ((completedTools: TrackedToolCall[]) => Promise<void>)
|
|
1258
|
-
| null = null;
|
|
1259
|
-
|
|
1260
|
-
mockUseReactToolScheduler.mockImplementation((onComplete) => {
|
|
1261
|
-
capturedOnComplete = onComplete;
|
|
1262
|
-
return [[], mockScheduleToolCalls, mockMarkToolsAsSubmitted];
|
|
1263
|
-
});
|
|
1264
|
-
|
|
1265
|
-
renderHook(() =>
|
|
1266
|
-
useGeminiStream(
|
|
1267
|
-
new MockedGeminiClientClass(mockConfig),
|
|
1268
|
-
[],
|
|
1269
|
-
mockAddItem,
|
|
1270
|
-
mockConfig,
|
|
1271
|
-
mockOnDebugMessage,
|
|
1272
|
-
mockHandleSlashCommand,
|
|
1273
|
-
false,
|
|
1274
|
-
() => 'vscode' as EditorType,
|
|
1275
|
-
() => {},
|
|
1276
|
-
mockPerformMemoryRefresh,
|
|
1277
|
-
false,
|
|
1278
|
-
() => {},
|
|
1279
|
-
() => {},
|
|
1280
|
-
() => {},
|
|
1281
|
-
),
|
|
1282
|
-
);
|
|
1283
|
-
|
|
1284
|
-
// Trigger the onComplete callback with the completed save_memory tool
|
|
1285
|
-
await act(async () => {
|
|
1286
|
-
if (capturedOnComplete) {
|
|
1287
|
-
await capturedOnComplete([completedToolCall]);
|
|
1288
|
-
}
|
|
1289
|
-
});
|
|
1290
|
-
|
|
1291
|
-
await waitFor(() => {
|
|
1292
|
-
expect(mockPerformMemoryRefresh).toHaveBeenCalledTimes(1);
|
|
1293
|
-
});
|
|
1294
|
-
});
|
|
1295
|
-
});
|
|
1296
|
-
|
|
1297
|
-
describe('Error Handling', () => {
|
|
1298
|
-
it('should call parseAndFormatApiError with the correct authType on stream initialization failure', async () => {
|
|
1299
|
-
// 1. Setup
|
|
1300
|
-
const mockError = new Error('Rate limit exceeded');
|
|
1301
|
-
const mockAuthType = AuthType.LOGIN_WITH_GOOGLE;
|
|
1302
|
-
mockParseAndFormatApiError.mockClear();
|
|
1303
|
-
mockSendMessageStream.mockReturnValue(
|
|
1304
|
-
(async function* () {
|
|
1305
|
-
yield { type: 'content', value: '' };
|
|
1306
|
-
throw mockError;
|
|
1307
|
-
})(),
|
|
1308
|
-
);
|
|
1309
|
-
|
|
1310
|
-
const testConfig = {
|
|
1311
|
-
...mockConfig,
|
|
1312
|
-
getContentGeneratorConfig: vi.fn(() => ({
|
|
1313
|
-
authType: mockAuthType,
|
|
1314
|
-
})),
|
|
1315
|
-
getModel: vi.fn(() => 'gemini-2.5-pro'),
|
|
1316
|
-
} as unknown as Config;
|
|
1317
|
-
|
|
1318
|
-
const { result } = renderHook(() =>
|
|
1319
|
-
useGeminiStream(
|
|
1320
|
-
new MockedGeminiClientClass(testConfig),
|
|
1321
|
-
[],
|
|
1322
|
-
mockAddItem,
|
|
1323
|
-
testConfig,
|
|
1324
|
-
mockOnDebugMessage,
|
|
1325
|
-
mockHandleSlashCommand,
|
|
1326
|
-
false,
|
|
1327
|
-
() => 'vscode' as EditorType,
|
|
1328
|
-
() => {},
|
|
1329
|
-
() => Promise.resolve(),
|
|
1330
|
-
false,
|
|
1331
|
-
() => {},
|
|
1332
|
-
() => {},
|
|
1333
|
-
() => {},
|
|
1334
|
-
),
|
|
1335
|
-
);
|
|
1336
|
-
|
|
1337
|
-
// 2. Action
|
|
1338
|
-
await act(async () => {
|
|
1339
|
-
await result.current.submitQuery('test query');
|
|
1340
|
-
});
|
|
1341
|
-
|
|
1342
|
-
// 3. Assertion
|
|
1343
|
-
await waitFor(() => {
|
|
1344
|
-
expect(mockParseAndFormatApiError).toHaveBeenCalledWith(
|
|
1345
|
-
'Rate limit exceeded',
|
|
1346
|
-
mockAuthType,
|
|
1347
|
-
undefined,
|
|
1348
|
-
'gemini-2.5-pro',
|
|
1349
|
-
'gemini-2.5-flash',
|
|
1350
|
-
);
|
|
1351
|
-
});
|
|
1352
|
-
});
|
|
1353
|
-
});
|
|
1354
|
-
|
|
1355
|
-
describe('handleFinishedEvent', () => {
|
|
1356
|
-
it('should add info message for MAX_TOKENS finish reason', async () => {
|
|
1357
|
-
// Setup mock to return a stream with MAX_TOKENS finish reason
|
|
1358
|
-
mockSendMessageStream.mockReturnValue(
|
|
1359
|
-
(async function* () {
|
|
1360
|
-
yield {
|
|
1361
|
-
type: ServerGeminiEventType.Content,
|
|
1362
|
-
value: 'This is a truncated response...',
|
|
1363
|
-
};
|
|
1364
|
-
yield { type: ServerGeminiEventType.Finished, value: 'MAX_TOKENS' };
|
|
1365
|
-
})(),
|
|
1366
|
-
);
|
|
1367
|
-
|
|
1368
|
-
const { result } = renderHook(() =>
|
|
1369
|
-
useGeminiStream(
|
|
1370
|
-
new MockedGeminiClientClass(mockConfig),
|
|
1371
|
-
[],
|
|
1372
|
-
mockAddItem,
|
|
1373
|
-
mockConfig,
|
|
1374
|
-
mockOnDebugMessage,
|
|
1375
|
-
mockHandleSlashCommand,
|
|
1376
|
-
false,
|
|
1377
|
-
() => 'vscode' as EditorType,
|
|
1378
|
-
() => {},
|
|
1379
|
-
() => Promise.resolve(),
|
|
1380
|
-
false,
|
|
1381
|
-
() => {},
|
|
1382
|
-
() => {},
|
|
1383
|
-
() => {},
|
|
1384
|
-
),
|
|
1385
|
-
);
|
|
1386
|
-
|
|
1387
|
-
// Submit a query
|
|
1388
|
-
await act(async () => {
|
|
1389
|
-
await result.current.submitQuery('Generate long text');
|
|
1390
|
-
});
|
|
1391
|
-
|
|
1392
|
-
// Check that the info message was added
|
|
1393
|
-
await waitFor(() => {
|
|
1394
|
-
expect(mockAddItem).toHaveBeenCalledWith(
|
|
1395
|
-
{
|
|
1396
|
-
type: 'info',
|
|
1397
|
-
text: '⚠️ Response truncated due to token limits.',
|
|
1398
|
-
},
|
|
1399
|
-
expect.any(Number),
|
|
1400
|
-
);
|
|
1401
|
-
});
|
|
1402
|
-
});
|
|
1403
|
-
|
|
1404
|
-
it('should not add message for STOP finish reason', async () => {
|
|
1405
|
-
// Setup mock to return a stream with STOP finish reason
|
|
1406
|
-
mockSendMessageStream.mockReturnValue(
|
|
1407
|
-
(async function* () {
|
|
1408
|
-
yield {
|
|
1409
|
-
type: ServerGeminiEventType.Content,
|
|
1410
|
-
value: 'Complete response',
|
|
1411
|
-
};
|
|
1412
|
-
yield { type: ServerGeminiEventType.Finished, value: 'STOP' };
|
|
1413
|
-
})(),
|
|
1414
|
-
);
|
|
1415
|
-
|
|
1416
|
-
const { result } = renderHook(() =>
|
|
1417
|
-
useGeminiStream(
|
|
1418
|
-
new MockedGeminiClientClass(mockConfig),
|
|
1419
|
-
[],
|
|
1420
|
-
mockAddItem,
|
|
1421
|
-
mockConfig,
|
|
1422
|
-
mockOnDebugMessage,
|
|
1423
|
-
mockHandleSlashCommand,
|
|
1424
|
-
false,
|
|
1425
|
-
() => 'vscode' as EditorType,
|
|
1426
|
-
() => {},
|
|
1427
|
-
() => Promise.resolve(),
|
|
1428
|
-
false,
|
|
1429
|
-
() => {},
|
|
1430
|
-
() => {},
|
|
1431
|
-
() => {},
|
|
1432
|
-
),
|
|
1433
|
-
);
|
|
1434
|
-
|
|
1435
|
-
// Submit a query
|
|
1436
|
-
await act(async () => {
|
|
1437
|
-
await result.current.submitQuery('Test normal completion');
|
|
1438
|
-
});
|
|
1439
|
-
|
|
1440
|
-
// Wait a bit to ensure no message is added
|
|
1441
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1442
|
-
|
|
1443
|
-
// Check that no info message was added for STOP
|
|
1444
|
-
const infoMessages = mockAddItem.mock.calls.filter(
|
|
1445
|
-
(call) => call[0].type === 'info',
|
|
1446
|
-
);
|
|
1447
|
-
expect(infoMessages).toHaveLength(0);
|
|
1448
|
-
});
|
|
1449
|
-
|
|
1450
|
-
it('should not add message for FINISH_REASON_UNSPECIFIED', async () => {
|
|
1451
|
-
// Setup mock to return a stream with FINISH_REASON_UNSPECIFIED
|
|
1452
|
-
mockSendMessageStream.mockReturnValue(
|
|
1453
|
-
(async function* () {
|
|
1454
|
-
yield {
|
|
1455
|
-
type: ServerGeminiEventType.Content,
|
|
1456
|
-
value: 'Response with unspecified finish',
|
|
1457
|
-
};
|
|
1458
|
-
yield {
|
|
1459
|
-
type: ServerGeminiEventType.Finished,
|
|
1460
|
-
value: 'FINISH_REASON_UNSPECIFIED',
|
|
1461
|
-
};
|
|
1462
|
-
})(),
|
|
1463
|
-
);
|
|
1464
|
-
|
|
1465
|
-
const { result } = renderHook(() =>
|
|
1466
|
-
useGeminiStream(
|
|
1467
|
-
new MockedGeminiClientClass(mockConfig),
|
|
1468
|
-
[],
|
|
1469
|
-
mockAddItem,
|
|
1470
|
-
mockConfig,
|
|
1471
|
-
mockOnDebugMessage,
|
|
1472
|
-
mockHandleSlashCommand,
|
|
1473
|
-
false,
|
|
1474
|
-
() => 'vscode' as EditorType,
|
|
1475
|
-
() => {},
|
|
1476
|
-
() => Promise.resolve(),
|
|
1477
|
-
false,
|
|
1478
|
-
() => {},
|
|
1479
|
-
() => {},
|
|
1480
|
-
() => {},
|
|
1481
|
-
),
|
|
1482
|
-
);
|
|
1483
|
-
|
|
1484
|
-
// Submit a query
|
|
1485
|
-
await act(async () => {
|
|
1486
|
-
await result.current.submitQuery('Test unspecified finish');
|
|
1487
|
-
});
|
|
1488
|
-
|
|
1489
|
-
// Wait a bit to ensure no message is added
|
|
1490
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1491
|
-
|
|
1492
|
-
// Check that no info message was added
|
|
1493
|
-
const infoMessages = mockAddItem.mock.calls.filter(
|
|
1494
|
-
(call) => call[0].type === 'info',
|
|
1495
|
-
);
|
|
1496
|
-
expect(infoMessages).toHaveLength(0);
|
|
1497
|
-
});
|
|
1498
|
-
|
|
1499
|
-
it('should add appropriate messages for other finish reasons', async () => {
|
|
1500
|
-
const testCases = [
|
|
1501
|
-
{
|
|
1502
|
-
reason: 'SAFETY',
|
|
1503
|
-
message: '⚠️ Response stopped due to safety reasons.',
|
|
1504
|
-
},
|
|
1505
|
-
{
|
|
1506
|
-
reason: 'RECITATION',
|
|
1507
|
-
message: '⚠️ Response stopped due to recitation policy.',
|
|
1508
|
-
},
|
|
1509
|
-
{
|
|
1510
|
-
reason: 'LANGUAGE',
|
|
1511
|
-
message: '⚠️ Response stopped due to unsupported language.',
|
|
1512
|
-
},
|
|
1513
|
-
{
|
|
1514
|
-
reason: 'BLOCKLIST',
|
|
1515
|
-
message: '⚠️ Response stopped due to forbidden terms.',
|
|
1516
|
-
},
|
|
1517
|
-
{
|
|
1518
|
-
reason: 'PROHIBITED_CONTENT',
|
|
1519
|
-
message: '⚠️ Response stopped due to prohibited content.',
|
|
1520
|
-
},
|
|
1521
|
-
{
|
|
1522
|
-
reason: 'SPII',
|
|
1523
|
-
message:
|
|
1524
|
-
'⚠️ Response stopped due to sensitive personally identifiable information.',
|
|
1525
|
-
},
|
|
1526
|
-
{ reason: 'OTHER', message: '⚠️ Response stopped for other reasons.' },
|
|
1527
|
-
{
|
|
1528
|
-
reason: 'MALFORMED_FUNCTION_CALL',
|
|
1529
|
-
message: '⚠️ Response stopped due to malformed function call.',
|
|
1530
|
-
},
|
|
1531
|
-
{
|
|
1532
|
-
reason: 'IMAGE_SAFETY',
|
|
1533
|
-
message: '⚠️ Response stopped due to image safety violations.',
|
|
1534
|
-
},
|
|
1535
|
-
{
|
|
1536
|
-
reason: 'UNEXPECTED_TOOL_CALL',
|
|
1537
|
-
message: '⚠️ Response stopped due to unexpected tool call.',
|
|
1538
|
-
},
|
|
1539
|
-
];
|
|
1540
|
-
|
|
1541
|
-
for (const { reason, message } of testCases) {
|
|
1542
|
-
// Reset mocks for each test case
|
|
1543
|
-
mockAddItem.mockClear();
|
|
1544
|
-
mockSendMessageStream.mockReturnValue(
|
|
1545
|
-
(async function* () {
|
|
1546
|
-
yield {
|
|
1547
|
-
type: ServerGeminiEventType.Content,
|
|
1548
|
-
value: `Response for ${reason}`,
|
|
1549
|
-
};
|
|
1550
|
-
yield { type: ServerGeminiEventType.Finished, value: reason };
|
|
1551
|
-
})(),
|
|
1552
|
-
);
|
|
1553
|
-
|
|
1554
|
-
const { result } = renderHook(() =>
|
|
1555
|
-
useGeminiStream(
|
|
1556
|
-
new MockedGeminiClientClass(mockConfig),
|
|
1557
|
-
[],
|
|
1558
|
-
mockAddItem,
|
|
1559
|
-
mockConfig,
|
|
1560
|
-
mockOnDebugMessage,
|
|
1561
|
-
mockHandleSlashCommand,
|
|
1562
|
-
false,
|
|
1563
|
-
() => 'vscode' as EditorType,
|
|
1564
|
-
() => {},
|
|
1565
|
-
() => Promise.resolve(),
|
|
1566
|
-
false,
|
|
1567
|
-
() => {},
|
|
1568
|
-
() => {},
|
|
1569
|
-
() => {},
|
|
1570
|
-
),
|
|
1571
|
-
);
|
|
1572
|
-
|
|
1573
|
-
await act(async () => {
|
|
1574
|
-
await result.current.submitQuery(`Test ${reason}`);
|
|
1575
|
-
});
|
|
1576
|
-
|
|
1577
|
-
await waitFor(() => {
|
|
1578
|
-
expect(mockAddItem).toHaveBeenCalledWith(
|
|
1579
|
-
{
|
|
1580
|
-
type: 'info',
|
|
1581
|
-
text: message,
|
|
1582
|
-
},
|
|
1583
|
-
expect.any(Number),
|
|
1584
|
-
);
|
|
1585
|
-
});
|
|
1586
|
-
}
|
|
1587
|
-
});
|
|
1588
|
-
});
|
|
1589
|
-
|
|
1590
|
-
describe('Thought Reset', () => {
|
|
1591
|
-
it('should reset thought to null when starting a new prompt', async () => {
|
|
1592
|
-
// First, simulate a response with a thought
|
|
1593
|
-
mockSendMessageStream.mockReturnValue(
|
|
1594
|
-
(async function* () {
|
|
1595
|
-
yield {
|
|
1596
|
-
type: ServerGeminiEventType.Thought,
|
|
1597
|
-
value: {
|
|
1598
|
-
subject: 'Previous thought',
|
|
1599
|
-
description: 'Old description',
|
|
1600
|
-
},
|
|
1601
|
-
};
|
|
1602
|
-
yield {
|
|
1603
|
-
type: ServerGeminiEventType.Content,
|
|
1604
|
-
value: 'Some response content',
|
|
1605
|
-
};
|
|
1606
|
-
yield { type: ServerGeminiEventType.Finished, value: 'STOP' };
|
|
1607
|
-
})(),
|
|
1608
|
-
);
|
|
1609
|
-
|
|
1610
|
-
const { result } = renderHook(() =>
|
|
1611
|
-
useGeminiStream(
|
|
1612
|
-
new MockedGeminiClientClass(mockConfig),
|
|
1613
|
-
[],
|
|
1614
|
-
mockAddItem,
|
|
1615
|
-
mockConfig,
|
|
1616
|
-
mockOnDebugMessage,
|
|
1617
|
-
mockHandleSlashCommand,
|
|
1618
|
-
false,
|
|
1619
|
-
() => 'vscode' as EditorType,
|
|
1620
|
-
() => {},
|
|
1621
|
-
() => Promise.resolve(),
|
|
1622
|
-
false,
|
|
1623
|
-
() => {},
|
|
1624
|
-
() => {},
|
|
1625
|
-
() => {},
|
|
1626
|
-
),
|
|
1627
|
-
);
|
|
1628
|
-
|
|
1629
|
-
// Submit first query to set a thought
|
|
1630
|
-
await act(async () => {
|
|
1631
|
-
await result.current.submitQuery('First query');
|
|
1632
|
-
});
|
|
1633
|
-
|
|
1634
|
-
// Wait for the first response to complete
|
|
1635
|
-
await waitFor(() => {
|
|
1636
|
-
expect(mockAddItem).toHaveBeenCalledWith(
|
|
1637
|
-
expect.objectContaining({
|
|
1638
|
-
type: 'gemini',
|
|
1639
|
-
text: 'Some response content',
|
|
1640
|
-
}),
|
|
1641
|
-
expect.any(Number),
|
|
1642
|
-
);
|
|
1643
|
-
});
|
|
1644
|
-
|
|
1645
|
-
// Now simulate a new response without a thought
|
|
1646
|
-
mockSendMessageStream.mockReturnValue(
|
|
1647
|
-
(async function* () {
|
|
1648
|
-
yield {
|
|
1649
|
-
type: ServerGeminiEventType.Content,
|
|
1650
|
-
value: 'New response content',
|
|
1651
|
-
};
|
|
1652
|
-
yield { type: ServerGeminiEventType.Finished, value: 'STOP' };
|
|
1653
|
-
})(),
|
|
1654
|
-
);
|
|
1655
|
-
|
|
1656
|
-
// Submit second query - thought should be reset
|
|
1657
|
-
await act(async () => {
|
|
1658
|
-
await result.current.submitQuery('Second query');
|
|
1659
|
-
});
|
|
1660
|
-
|
|
1661
|
-
// The thought should be reset to null when starting the new prompt
|
|
1662
|
-
// We can verify this by checking that the LoadingIndicator would not show the previous thought
|
|
1663
|
-
// The actual thought state is internal to the hook, but we can verify the behavior
|
|
1664
|
-
// by ensuring the second response doesn't show the previous thought
|
|
1665
|
-
await waitFor(() => {
|
|
1666
|
-
expect(mockAddItem).toHaveBeenCalledWith(
|
|
1667
|
-
expect.objectContaining({
|
|
1668
|
-
type: 'gemini',
|
|
1669
|
-
text: 'New response content',
|
|
1670
|
-
}),
|
|
1671
|
-
expect.any(Number),
|
|
1672
|
-
);
|
|
1673
|
-
});
|
|
1674
|
-
});
|
|
1675
|
-
|
|
1676
|
-
it('should reset thought to null when user cancels', async () => {
|
|
1677
|
-
// Mock a stream that yields a thought then gets cancelled
|
|
1678
|
-
mockSendMessageStream.mockReturnValue(
|
|
1679
|
-
(async function* () {
|
|
1680
|
-
yield {
|
|
1681
|
-
type: ServerGeminiEventType.Thought,
|
|
1682
|
-
value: { subject: 'Some thought', description: 'Description' },
|
|
1683
|
-
};
|
|
1684
|
-
yield { type: ServerGeminiEventType.UserCancelled };
|
|
1685
|
-
})(),
|
|
1686
|
-
);
|
|
1687
|
-
|
|
1688
|
-
const { result } = renderHook(() =>
|
|
1689
|
-
useGeminiStream(
|
|
1690
|
-
new MockedGeminiClientClass(mockConfig),
|
|
1691
|
-
[],
|
|
1692
|
-
mockAddItem,
|
|
1693
|
-
mockConfig,
|
|
1694
|
-
mockOnDebugMessage,
|
|
1695
|
-
mockHandleSlashCommand,
|
|
1696
|
-
false,
|
|
1697
|
-
() => 'vscode' as EditorType,
|
|
1698
|
-
() => {},
|
|
1699
|
-
() => Promise.resolve(),
|
|
1700
|
-
false,
|
|
1701
|
-
() => {},
|
|
1702
|
-
() => {},
|
|
1703
|
-
() => {},
|
|
1704
|
-
),
|
|
1705
|
-
);
|
|
1706
|
-
|
|
1707
|
-
// Submit query
|
|
1708
|
-
await act(async () => {
|
|
1709
|
-
await result.current.submitQuery('Test query');
|
|
1710
|
-
});
|
|
1711
|
-
|
|
1712
|
-
// Verify cancellation message was added
|
|
1713
|
-
await waitFor(() => {
|
|
1714
|
-
expect(mockAddItem).toHaveBeenCalledWith(
|
|
1715
|
-
expect.objectContaining({
|
|
1716
|
-
type: 'info',
|
|
1717
|
-
text: 'User cancelled the request.',
|
|
1718
|
-
}),
|
|
1719
|
-
expect.any(Number),
|
|
1720
|
-
);
|
|
1721
|
-
});
|
|
1722
|
-
|
|
1723
|
-
// Verify state is reset to idle
|
|
1724
|
-
expect(result.current.streamingState).toBe(StreamingState.Idle);
|
|
1725
|
-
});
|
|
1726
|
-
|
|
1727
|
-
it('should reset thought to null when there is an error', async () => {
|
|
1728
|
-
// Mock a stream that yields a thought then encounters an error
|
|
1729
|
-
mockSendMessageStream.mockReturnValue(
|
|
1730
|
-
(async function* () {
|
|
1731
|
-
yield {
|
|
1732
|
-
type: ServerGeminiEventType.Thought,
|
|
1733
|
-
value: { subject: 'Some thought', description: 'Description' },
|
|
1734
|
-
};
|
|
1735
|
-
yield {
|
|
1736
|
-
type: ServerGeminiEventType.Error,
|
|
1737
|
-
value: { error: { message: 'Test error' } },
|
|
1738
|
-
};
|
|
1739
|
-
})(),
|
|
1740
|
-
);
|
|
1741
|
-
|
|
1742
|
-
const { result } = renderHook(() =>
|
|
1743
|
-
useGeminiStream(
|
|
1744
|
-
new MockedGeminiClientClass(mockConfig),
|
|
1745
|
-
[],
|
|
1746
|
-
mockAddItem,
|
|
1747
|
-
mockConfig,
|
|
1748
|
-
mockOnDebugMessage,
|
|
1749
|
-
mockHandleSlashCommand,
|
|
1750
|
-
false,
|
|
1751
|
-
() => 'vscode' as EditorType,
|
|
1752
|
-
() => {},
|
|
1753
|
-
() => Promise.resolve(),
|
|
1754
|
-
false,
|
|
1755
|
-
() => {},
|
|
1756
|
-
() => {},
|
|
1757
|
-
() => {},
|
|
1758
|
-
),
|
|
1759
|
-
);
|
|
1760
|
-
|
|
1761
|
-
// Submit query
|
|
1762
|
-
await act(async () => {
|
|
1763
|
-
await result.current.submitQuery('Test query');
|
|
1764
|
-
});
|
|
1765
|
-
|
|
1766
|
-
// Verify error message was added
|
|
1767
|
-
await waitFor(() => {
|
|
1768
|
-
expect(mockAddItem).toHaveBeenCalledWith(
|
|
1769
|
-
expect.objectContaining({
|
|
1770
|
-
type: 'error',
|
|
1771
|
-
}),
|
|
1772
|
-
expect.any(Number),
|
|
1773
|
-
);
|
|
1774
|
-
});
|
|
1775
|
-
|
|
1776
|
-
// Verify parseAndFormatApiError was called
|
|
1777
|
-
expect(mockParseAndFormatApiError).toHaveBeenCalledWith(
|
|
1778
|
-
{ message: 'Test error' },
|
|
1779
|
-
expect.any(String),
|
|
1780
|
-
undefined,
|
|
1781
|
-
'gemini-2.5-pro',
|
|
1782
|
-
'gemini-2.5-flash',
|
|
1783
|
-
);
|
|
1784
|
-
});
|
|
1785
|
-
});
|
|
1786
|
-
|
|
1787
|
-
describe('Concurrent Execution Prevention', () => {
|
|
1788
|
-
it('should prevent concurrent submitQuery calls', async () => {
|
|
1789
|
-
let resolveFirstCall!: () => void;
|
|
1790
|
-
let resolveSecondCall!: () => void;
|
|
1791
|
-
|
|
1792
|
-
const firstCallPromise = new Promise<void>((resolve) => {
|
|
1793
|
-
resolveFirstCall = resolve;
|
|
1794
|
-
});
|
|
1795
|
-
|
|
1796
|
-
const secondCallPromise = new Promise<void>((resolve) => {
|
|
1797
|
-
resolveSecondCall = resolve;
|
|
1798
|
-
});
|
|
1799
|
-
|
|
1800
|
-
// Mock a long-running stream for the first call
|
|
1801
|
-
const firstStream = (async function* () {
|
|
1802
|
-
yield {
|
|
1803
|
-
type: ServerGeminiEventType.Content,
|
|
1804
|
-
value: 'First call content',
|
|
1805
|
-
};
|
|
1806
|
-
await firstCallPromise; // Wait until we manually resolve
|
|
1807
|
-
yield { type: ServerGeminiEventType.Finished, value: 'STOP' };
|
|
1808
|
-
})();
|
|
1809
|
-
|
|
1810
|
-
// Mock a stream for the second call (should not be used)
|
|
1811
|
-
const secondStream = (async function* () {
|
|
1812
|
-
yield {
|
|
1813
|
-
type: ServerGeminiEventType.Content,
|
|
1814
|
-
value: 'Second call content',
|
|
1815
|
-
};
|
|
1816
|
-
await secondCallPromise;
|
|
1817
|
-
yield { type: ServerGeminiEventType.Finished, value: 'STOP' };
|
|
1818
|
-
})();
|
|
1819
|
-
|
|
1820
|
-
let callCount = 0;
|
|
1821
|
-
mockSendMessageStream.mockImplementation(() => {
|
|
1822
|
-
callCount++;
|
|
1823
|
-
if (callCount === 1) {
|
|
1824
|
-
return firstStream;
|
|
1825
|
-
} else {
|
|
1826
|
-
return secondStream;
|
|
1827
|
-
}
|
|
1828
|
-
});
|
|
1829
|
-
|
|
1830
|
-
const { result } = renderTestHook();
|
|
1831
|
-
|
|
1832
|
-
// Start first call
|
|
1833
|
-
const firstCallResult = act(async () => {
|
|
1834
|
-
await result.current.submitQuery('First query');
|
|
1835
|
-
});
|
|
1836
|
-
|
|
1837
|
-
// Wait a bit to ensure first call has started
|
|
1838
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
1839
|
-
|
|
1840
|
-
// Try to start second call while first is still running
|
|
1841
|
-
const secondCallResult = act(async () => {
|
|
1842
|
-
await result.current.submitQuery('Second query');
|
|
1843
|
-
});
|
|
1844
|
-
|
|
1845
|
-
// Resolve both calls
|
|
1846
|
-
resolveFirstCall();
|
|
1847
|
-
resolveSecondCall();
|
|
1848
|
-
|
|
1849
|
-
await Promise.all([firstCallResult, secondCallResult]);
|
|
1850
|
-
|
|
1851
|
-
// Verify only one call was made to sendMessageStream
|
|
1852
|
-
expect(mockSendMessageStream).toHaveBeenCalledTimes(1);
|
|
1853
|
-
expect(mockSendMessageStream).toHaveBeenCalledWith(
|
|
1854
|
-
'First query',
|
|
1855
|
-
expect.any(AbortSignal),
|
|
1856
|
-
expect.any(String),
|
|
1857
|
-
);
|
|
1858
|
-
|
|
1859
|
-
// Verify only the first query was added to history
|
|
1860
|
-
const userMessages = mockAddItem.mock.calls.filter(
|
|
1861
|
-
(call) => call[0].type === MessageType.USER,
|
|
1862
|
-
);
|
|
1863
|
-
expect(userMessages).toHaveLength(1);
|
|
1864
|
-
expect(userMessages[0][0].text).toBe('First query');
|
|
1865
|
-
});
|
|
1866
|
-
|
|
1867
|
-
it('should allow subsequent calls after first call completes', async () => {
|
|
1868
|
-
// Mock streams that complete immediately
|
|
1869
|
-
mockSendMessageStream
|
|
1870
|
-
.mockReturnValueOnce(
|
|
1871
|
-
(async function* () {
|
|
1872
|
-
yield {
|
|
1873
|
-
type: ServerGeminiEventType.Content,
|
|
1874
|
-
value: 'First response',
|
|
1875
|
-
};
|
|
1876
|
-
yield { type: ServerGeminiEventType.Finished, value: 'STOP' };
|
|
1877
|
-
})(),
|
|
1878
|
-
)
|
|
1879
|
-
.mockReturnValueOnce(
|
|
1880
|
-
(async function* () {
|
|
1881
|
-
yield {
|
|
1882
|
-
type: ServerGeminiEventType.Content,
|
|
1883
|
-
value: 'Second response',
|
|
1884
|
-
};
|
|
1885
|
-
yield { type: ServerGeminiEventType.Finished, value: 'STOP' };
|
|
1886
|
-
})(),
|
|
1887
|
-
);
|
|
1888
|
-
|
|
1889
|
-
const { result } = renderTestHook();
|
|
1890
|
-
|
|
1891
|
-
// First call
|
|
1892
|
-
await act(async () => {
|
|
1893
|
-
await result.current.submitQuery('First query');
|
|
1894
|
-
});
|
|
1895
|
-
|
|
1896
|
-
// Second call after first completes
|
|
1897
|
-
await act(async () => {
|
|
1898
|
-
await result.current.submitQuery('Second query');
|
|
1899
|
-
});
|
|
1900
|
-
|
|
1901
|
-
// Both calls should have been made
|
|
1902
|
-
expect(mockSendMessageStream).toHaveBeenCalledTimes(2);
|
|
1903
|
-
expect(mockSendMessageStream).toHaveBeenNthCalledWith(
|
|
1904
|
-
1,
|
|
1905
|
-
'First query',
|
|
1906
|
-
expect.any(AbortSignal),
|
|
1907
|
-
expect.any(String),
|
|
1908
|
-
);
|
|
1909
|
-
expect(mockSendMessageStream).toHaveBeenNthCalledWith(
|
|
1910
|
-
2,
|
|
1911
|
-
'Second query',
|
|
1912
|
-
expect.any(AbortSignal),
|
|
1913
|
-
expect.any(String),
|
|
1914
|
-
);
|
|
1915
|
-
});
|
|
1916
|
-
|
|
1917
|
-
it('should reset execution flag even when query preparation fails', async () => {
|
|
1918
|
-
const { result } = renderTestHook();
|
|
1919
|
-
|
|
1920
|
-
// First call with empty query (should fail in preparation)
|
|
1921
|
-
await act(async () => {
|
|
1922
|
-
await result.current.submitQuery(' '); // Empty trimmed query
|
|
1923
|
-
});
|
|
1924
|
-
|
|
1925
|
-
// Second call should work normally
|
|
1926
|
-
await act(async () => {
|
|
1927
|
-
await result.current.submitQuery('Second query');
|
|
1928
|
-
});
|
|
1929
|
-
|
|
1930
|
-
// Verify that only the second call was made (empty query is filtered out)
|
|
1931
|
-
expect(mockSendMessageStream).toHaveBeenCalledTimes(1);
|
|
1932
|
-
expect(mockSendMessageStream).toHaveBeenCalledWith(
|
|
1933
|
-
'Second query',
|
|
1934
|
-
expect.any(AbortSignal),
|
|
1935
|
-
expect.any(String),
|
|
1936
|
-
);
|
|
1937
|
-
});
|
|
1938
|
-
});
|
|
1939
|
-
|
|
1940
|
-
it('should process @include commands, adding user turn after processing to prevent race conditions', async () => {
|
|
1941
|
-
const rawQuery = '@include file.txt Summarize this.';
|
|
1942
|
-
const processedQueryParts = [
|
|
1943
|
-
{ text: 'Summarize this with content from @file.txt' },
|
|
1944
|
-
{ text: 'File content...' },
|
|
1945
|
-
];
|
|
1946
|
-
const userMessageTimestamp = Date.now();
|
|
1947
|
-
vi.spyOn(Date, 'now').mockReturnValue(userMessageTimestamp);
|
|
1948
|
-
|
|
1949
|
-
handleAtCommandSpy.mockResolvedValue({
|
|
1950
|
-
processedQuery: processedQueryParts,
|
|
1951
|
-
shouldProceed: true,
|
|
1952
|
-
});
|
|
1953
|
-
|
|
1954
|
-
const { result } = renderHook(() =>
|
|
1955
|
-
useGeminiStream(
|
|
1956
|
-
mockConfig.getGeminiClient() as GeminiClient,
|
|
1957
|
-
[],
|
|
1958
|
-
mockAddItem,
|
|
1959
|
-
mockConfig,
|
|
1960
|
-
mockOnDebugMessage,
|
|
1961
|
-
mockHandleSlashCommand,
|
|
1962
|
-
false,
|
|
1963
|
-
vi.fn(),
|
|
1964
|
-
vi.fn(),
|
|
1965
|
-
vi.fn(),
|
|
1966
|
-
false,
|
|
1967
|
-
vi.fn(),
|
|
1968
|
-
vi.fn(),
|
|
1969
|
-
vi.fn(),
|
|
1970
|
-
),
|
|
1971
|
-
);
|
|
1972
|
-
|
|
1973
|
-
await act(async () => {
|
|
1974
|
-
await result.current.submitQuery(rawQuery);
|
|
1975
|
-
});
|
|
1976
|
-
|
|
1977
|
-
expect(handleAtCommandSpy).toHaveBeenCalledWith(
|
|
1978
|
-
expect.objectContaining({
|
|
1979
|
-
query: rawQuery,
|
|
1980
|
-
}),
|
|
1981
|
-
);
|
|
1982
|
-
|
|
1983
|
-
expect(mockAddItem).toHaveBeenCalledWith(
|
|
1984
|
-
{
|
|
1985
|
-
type: MessageType.USER,
|
|
1986
|
-
text: rawQuery,
|
|
1987
|
-
},
|
|
1988
|
-
userMessageTimestamp,
|
|
1989
|
-
);
|
|
1990
|
-
|
|
1991
|
-
// FIX: This expectation now correctly matches the actual function call signature.
|
|
1992
|
-
expect(mockSendMessageStream).toHaveBeenCalledWith(
|
|
1993
|
-
processedQueryParts, // Argument 1: The parts array directly
|
|
1994
|
-
expect.any(AbortSignal), // Argument 2: An AbortSignal
|
|
1995
|
-
expect.any(String), // Argument 3: The prompt_id string
|
|
1996
|
-
);
|
|
1997
|
-
});
|
|
1998
|
-
});
|