@@ -2225,6 +2225,50 @@ describe("handle_agent_failure", () => {
22252225 expect ( result ) . toContain ( "tool1" ) ;
22262226 expect ( result ) . toContain ( "tool2" ) ;
22272227 } ) ;
2228+
2229+ it ( "suppresses generic context for repeated permission denied missing_tool entries" , ( ) => {
2230+ fs . writeFileSync (
2231+ path . join ( tmpDir , "agent_output.json" ) ,
2232+ JSON . stringify ( {
2233+ items : [ { type : "missing_tool" , tool : "tool/permission" , reason : "permission denied" , denied_commands : [ "go version 2>&1" ] } ] ,
2234+ } )
2235+ ) ;
2236+ vi . resetModules ( ) ;
2237+ ( { buildMissingToolContext } = require ( "./handle_agent_failure.cjs" ) ) ;
2238+ expect ( buildMissingToolContext ( ) ) . toBe ( "" ) ;
2239+ } ) ;
2240+
2241+ it ( "does not suppress tool/permission entry when denied_commands is empty" , ( ) => {
2242+ fs . writeFileSync (
2243+ path . join ( tmpDir , "agent_output.json" ) ,
2244+ JSON . stringify ( {
2245+ items : [ { type : "missing_tool" , tool : "tool/permission" , reason : "permission queried" , denied_commands : [ ] } ] ,
2246+ } )
2247+ ) ;
2248+ vi . resetModules ( ) ;
2249+ ( { buildMissingToolContext } = require ( "./handle_agent_failure.cjs" ) ) ;
2250+ const result = buildMissingToolContext ( ) ;
2251+ expect ( result ) . toContain ( "Missing Tools Reported" ) ;
2252+ expect ( result ) . toContain ( "tool/permission" ) ;
2253+ } ) ;
2254+
2255+ it ( "keeps non-permission missing tools when permission-denied entries are present" , ( ) => {
2256+ fs . writeFileSync (
2257+ path . join ( tmpDir , "agent_output.json" ) ,
2258+ JSON . stringify ( {
2259+ items : [
2260+ { type : "missing_tool" , tool : "tool/permission" , reason : "permission denied" , denied_commands : [ "go version 2>&1" ] } ,
2261+ { type : "missing_tool" , tool : "bash" , reason : "bash is not available" } ,
2262+ ] ,
2263+ } )
2264+ ) ;
2265+ vi . resetModules ( ) ;
2266+ ( { buildMissingToolContext } = require ( "./handle_agent_failure.cjs" ) ) ;
2267+ const result = buildMissingToolContext ( ) ;
2268+ expect ( result ) . toContain ( "Missing Tools Reported" ) ;
2269+ expect ( result ) . toContain ( "bash" ) ;
2270+ expect ( result ) . not . toContain ( "tool/permission" ) ;
2271+ } ) ;
22282272 } ) ;
22292273
22302274 // ──────────────────────────────────────────────────────
0 commit comments