@@ -1083,6 +1083,85 @@ describe("shouldSkipLocalCliCredentialEpoch", () => {
10831083 }
10841084 } ) ;
10851085
1086+ it ( "does not advertise loopback prompt tools when the runtime is unavailable" , async ( ) => {
1087+ const { dir, sessionFile } = createSessionFile ( ) ;
1088+ try {
1089+ registerMemoryPromptSection ( ( { availableTools } ) =>
1090+ availableTools . has ( "memory_search" )
1091+ ? [ "## Memory Recall" , `tools=${ [ ...availableTools ] . toSorted ( ) . join ( "," ) } ` , "" ]
1092+ : [ ] ,
1093+ ) ;
1094+ const getActiveMcpLoopbackRuntime = vi . fn ( ( ) => undefined ) ;
1095+ const ensureMcpLoopbackServer = vi . fn ( async ( ) => {
1096+ throw new Error ( "loopback unavailable" ) ;
1097+ } ) ;
1098+ const createMcpLoopbackServerConfig = vi . fn ( createTestMcpLoopbackServerConfig ) ;
1099+ const resolveMcpLoopbackScopedTools = vi . fn ( ( ) => ( {
1100+ agentId : "main" ,
1101+ tools : [
1102+ {
1103+ name : "memory_search" ,
1104+ label : "Memory Search" ,
1105+ description : "Search memory" ,
1106+ parameters : { type : "object" , properties : { } } ,
1107+ execute : vi . fn ( ) ,
1108+ } ,
1109+ ] ,
1110+ } ) ) ;
1111+ setCliRunnerPrepareTestDeps ( {
1112+ getActiveMcpLoopbackRuntime,
1113+ ensureMcpLoopbackServer,
1114+ createMcpLoopbackServerConfig,
1115+ resolveMcpLoopbackScopedTools,
1116+ } ) ;
1117+ cliBackendsTesting . setDepsForTest ( {
1118+ resolvePluginSetupCliBackend : ( ) => undefined ,
1119+ resolveRuntimeCliBackends : ( ) => [
1120+ {
1121+ id : "native-cli" ,
1122+ pluginId : "native-plugin" ,
1123+ bundleMcp : true ,
1124+ bundleMcpMode : "claude-config-file" ,
1125+ config : {
1126+ command : "native-cli" ,
1127+ args : [ "--print" ] ,
1128+ systemPromptArg : "--system-prompt" ,
1129+ systemPromptWhen : "first" ,
1130+ output : "text" ,
1131+ input : "arg" ,
1132+ sessionMode : "existing" ,
1133+ } ,
1134+ } ,
1135+ ] ,
1136+ } ) ;
1137+
1138+ const context = await prepareCliRunContext ( {
1139+ sessionId : "session-test" ,
1140+ sessionKey : "agent:main:test" ,
1141+ sessionFile,
1142+ workspaceDir : dir ,
1143+ prompt : "latest ask" ,
1144+ provider : "native-cli" ,
1145+ model : "test-model" ,
1146+ timeoutMs : 1_000 ,
1147+ runId : "run-test-loopback-prompt-tools-fallback" ,
1148+ config : createCliBackendConfig ( { bundleMcp : true , systemPromptOverride : null } ) ,
1149+ } ) ;
1150+
1151+ expect ( ensureMcpLoopbackServer ) . toHaveBeenCalledTimes ( 1 ) ;
1152+ expect ( getActiveMcpLoopbackRuntime ) . toHaveBeenCalledTimes ( 2 ) ;
1153+ expect ( createMcpLoopbackServerConfig ) . not . toHaveBeenCalled ( ) ;
1154+ expect ( resolveMcpLoopbackScopedTools ) . not . toHaveBeenCalled ( ) ;
1155+ expect ( context . systemPrompt ) . not . toContain ( "## Memory Recall" ) ;
1156+ expect ( context . systemPrompt ) . not . toContain ( "memory_search" ) ;
1157+ expect ( context . systemPromptReport . tools . entries ) . toEqual ( [ ] ) ;
1158+ expect ( context . promptToolNamesHash ) . toBeUndefined ( ) ;
1159+ expect ( context . preparedBackend . env ) . toBeUndefined ( ) ;
1160+ } finally {
1161+ fs . rmSync ( dir , { recursive : true , force : true } ) ;
1162+ }
1163+ } ) ;
1164+
10861165 it ( "passes current turn kind into bundle MCP loopback env" , async ( ) => {
10871166 const { dir, sessionFile } = createSessionFile ( ) ;
10881167 try {
0 commit comments