@@ -290,7 +290,7 @@ describe("capturePluginToolDescriptor availability validation", () => {
290290 } ) ;
291291 expect ( warnSpy ) . toHaveBeenCalledTimes ( 1 ) ;
292292 expect ( warnSpy ) . toHaveBeenCalledWith (
293- expect . stringContaining ( "Non-array availability group" ) ,
293+ expect . stringContaining ( "Malformed availability group" ) ,
294294 ) ;
295295 // Malformed availability must be stripped so the evaluator never sees it
296296 expect ( cached . descriptor . availability ) . toBeUndefined ( ) ;
@@ -309,7 +309,7 @@ describe("capturePluginToolDescriptor availability validation", () => {
309309 } ) ;
310310 expect ( warnSpy ) . toHaveBeenCalledTimes ( 1 ) ;
311311 expect ( warnSpy ) . toHaveBeenCalledWith (
312- expect . stringContaining ( "Non-array availability group" ) ,
312+ expect . stringContaining ( "Malformed availability group" ) ,
313313 ) ;
314314 expect ( cached . descriptor . availability ) . toBeUndefined ( ) ;
315315 } finally {
@@ -335,7 +335,7 @@ describe("capturePluginToolDescriptor availability validation", () => {
335335 } ) ;
336336 // All groups are valid arrays — no shape warning expected
337337 const shapeWarnings = warnSpy . mock . calls . filter ( ( c ) =>
338- String ( c [ 0 ] ) . includes ( "Non-array availability group" ) ,
338+ String ( c [ 0 ] ) . includes ( "Malformed availability group" ) ,
339339 ) ;
340340 expect ( shapeWarnings ) . toHaveLength ( 0 ) ;
341341 // Descriptor should preserve the valid availability
@@ -359,7 +359,7 @@ describe("capturePluginToolDescriptor availability validation", () => {
359359 optional : false ,
360360 } ) ;
361361 expect ( warnSpy ) . toHaveBeenCalledWith (
362- expect . stringContaining ( "Non-array availability group" ) ,
362+ expect . stringContaining ( "Malformed availability group" ) ,
363363 ) ;
364364 // Descriptor should strip the malformed availability
365365 expect ( cached . descriptor . availability ) . toBeUndefined ( ) ;
@@ -368,10 +368,58 @@ describe("capturePluginToolDescriptor availability validation", () => {
368368 }
369369 } ) ;
370370
371- it ( "does not crash on non-object entries inside availability groups" , ( ) => {
371+ it ( "warns and strips availability when allOf contains null entries" , ( ) => {
372+ // Null entries crash the evaluator (TypeError on "kind" in null).
373+ // The shape guard must reject them so the whole expression is stripped
374+ // with a warning instead of crashing tool registration.
375+ const warnSpy = vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } ) ;
376+ try {
377+ const result = capturePluginToolDescriptor ( {
378+ pluginId : "test-plugin" ,
379+ tool : makeTool ( {
380+ availability : {
381+ allOf : [ { kind : "always" } , null as never ] ,
382+ } ,
383+ } ) ,
384+ optional : false ,
385+ } ) ;
386+ expect ( warnSpy ) . toHaveBeenCalledWith (
387+ expect . stringContaining ( "Malformed availability group" ) ,
388+ ) ;
389+ // Malformed availability must be stripped so the evaluator never sees it
390+ expect ( result . descriptor . availability ) . toBeUndefined ( ) ;
391+ } finally {
392+ warnSpy . mockRestore ( ) ;
393+ }
394+ } ) ;
395+
396+ it ( "warns and strips availability when anyOf contains non-object entries" , ( ) => {
397+ // Non-object primitives (string, number, boolean) also crash the
398+ // evaluator. The shape guard must reject them.
399+ const warnSpy = vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } ) ;
400+ try {
401+ const result = capturePluginToolDescriptor ( {
402+ pluginId : "test-plugin" ,
403+ tool : makeTool ( {
404+ availability : {
405+ anyOf : [ "not-an-object" as never , 42 as never ] ,
406+ } ,
407+ } ) ,
408+ optional : false ,
409+ } ) ;
410+ expect ( warnSpy ) . toHaveBeenCalledWith (
411+ expect . stringContaining ( "Malformed availability group" ) ,
412+ ) ;
413+ expect ( result . descriptor . availability ) . toBeUndefined ( ) ;
414+ } finally {
415+ warnSpy . mockRestore ( ) ;
416+ }
417+ } ) ;
418+
419+ it ( "does not crash when availability group contains non-object entries" , ( ) => {
372420 // Plugin-authored data is arbitrary JS — null, primitives, and arrays
373- // inside allOf/anyOf should not throw during the shape check. The
374- // evaluator will diagnose them as malformed expressions later .
421+ // inside allOf/anyOf should never throw. They are rejected by the
422+ // shape guard and the availability is stripped with a warning .
375423 const warnSpy = vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } ) ;
376424 try {
377425 const result = capturePluginToolDescriptor ( {
@@ -390,13 +438,13 @@ describe("capturePluginToolDescriptor availability validation", () => {
390438 } ) ,
391439 optional : false ,
392440 } ) ;
393- // Should not throw — non-object entries are silently skipped
441+ // Should not throw — malformed entries are detected and stripped
394442 const shapeWarnings = warnSpy . mock . calls . filter ( ( c ) =>
395- String ( c [ 0 ] ) . includes ( "Non-array availability group" ) ,
443+ String ( c [ 0 ] ) . includes ( "Malformed availability group" ) ,
396444 ) ;
397- expect ( shapeWarnings ) . toHaveLength ( 0 ) ;
398- // Valid availability preserved (non-object entries are evaluator's problem)
399- expect ( result . descriptor . availability ) . toBeDefined ( ) ;
445+ expect ( shapeWarnings . length ) . toBeGreaterThanOrEqual ( 1 ) ;
446+ // Availability is stripped because the group contained null/primitives
447+ expect ( result . descriptor . availability ) . toBeUndefined ( ) ;
400448 } finally {
401449 warnSpy . mockRestore ( ) ;
402450 }
0 commit comments