@@ -59,6 +59,9 @@ vi.mock('./services/CommandService.js', () => ({
5959 } ,
6060} ) ) ;
6161
62+ vi . mock ( './services/FileCommandLoader.js' ) ;
63+ vi . mock ( './services/McpPromptLoader.js' ) ;
64+
6265describe ( 'runNonInteractive' , ( ) => {
6366 let mockConfig : Config ;
6467 let mockSettings : LoadedSettings ;
@@ -938,6 +941,46 @@ describe('runNonInteractive', () => {
938941 expect ( processStdoutSpy ) . toHaveBeenCalledWith ( 'Acknowledged' ) ;
939942 } ) ;
940943
944+ it ( 'should instantiate CommandService with correct loaders for slash commands' , async ( ) => {
945+ // This test indirectly checks that handleSlashCommand is using the right loaders.
946+ const { FileCommandLoader } = await import (
947+ './services/FileCommandLoader.js'
948+ ) ;
949+ const { McpPromptLoader } = await import ( './services/McpPromptLoader.js' ) ;
950+
951+ mockGetCommands . mockReturnValue ( [ ] ) ; // No commands found, so it will fall through
952+ const events : ServerGeminiStreamEvent [ ] = [
953+ { type : GeminiEventType . Content , value : 'Acknowledged' } ,
954+ {
955+ type : GeminiEventType . Finished ,
956+ value : { reason : undefined , usageMetadata : { totalTokenCount : 1 } } ,
957+ } ,
958+ ] ;
959+ mockGeminiClient . sendMessageStream . mockReturnValue (
960+ createStreamFromEvents ( events ) ,
961+ ) ;
962+
963+ await runNonInteractive (
964+ mockConfig ,
965+ mockSettings ,
966+ '/mycommand' ,
967+ 'prompt-id-loaders' ,
968+ ) ;
969+
970+ // Check that loaders were instantiated with the config
971+ expect ( FileCommandLoader ) . toHaveBeenCalledTimes ( 1 ) ;
972+ expect ( FileCommandLoader ) . toHaveBeenCalledWith ( mockConfig ) ;
973+ expect ( McpPromptLoader ) . toHaveBeenCalledTimes ( 1 ) ;
974+ expect ( McpPromptLoader ) . toHaveBeenCalledWith ( mockConfig ) ;
975+
976+ // Check that instances were passed to CommandService.create
977+ expect ( mockCommandServiceCreate ) . toHaveBeenCalledTimes ( 1 ) ;
978+ const loadersArg = mockCommandServiceCreate . mock . calls [ 0 ] [ 0 ] ;
979+ expect ( loadersArg ) . toHaveLength ( 2 ) ;
980+ expect ( loadersArg [ 0 ] ) . toBe ( vi . mocked ( McpPromptLoader ) . mock . instances [ 0 ] ) ;
981+ expect ( loadersArg [ 1 ] ) . toBe ( vi . mocked ( FileCommandLoader ) . mock . instances [ 0 ] ) ;
982+ } ) ;
983+
941984 it ( 'should allow a normally-excluded tool when --allowed-tools is set' , async ( ) => {
942985 // By default, ShellTool is excluded in non-interactive mode.
943986 // This test ensures that --allowed-tools overrides this exclusion.
0 commit comments