@@ -316,17 +316,44 @@ describe("generic tool action decision receipts", () => {
316316 } ) ;
317317
318318 it . each ( [
319- { label : "returns adjusted params" , result : { params : { ownerAdjusted : true } } } ,
320- { label : "returns void" , result : undefined } ,
319+ {
320+ label : "returns adjusted params" ,
321+ result : { params : { ownerAdjusted : true } } ,
322+ matcher : undefined ,
323+ toolName : undefined ,
324+ expectedHandlerCalls : 1 ,
325+ expectedGenericReceipts : 0 ,
326+ expectedOwnerReceipts : 1 ,
327+ } ,
328+ {
329+ label : "returns void" ,
330+ result : undefined ,
331+ matcher : undefined ,
332+ toolName : undefined ,
333+ expectedHandlerCalls : 1 ,
334+ expectedGenericReceipts : 0 ,
335+ expectedOwnerReceipts : 1 ,
336+ } ,
337+ {
338+ label : "does not match the tool" ,
339+ result : undefined ,
340+ matcher : [ "exec" ] ,
341+ toolName : "read" ,
342+ expectedHandlerCalls : 0 ,
343+ expectedGenericReceipts : 1 ,
344+ expectedOwnerReceipts : 0 ,
345+ } ,
321346 ] as const ) (
322- "does not follow an owner-native plugin allow receipt with a generic allow fact when it $label" ,
323- async ( { result } ) => {
347+ "routes generic attribution only when a plugin hook $label" ,
348+ async ( { result, ... testCase } ) => {
324349 const registry = createEmptyPluginRegistry ( ) ;
350+ const handler = vi . fn ( ( ) => result ) ;
325351 addTestHook ( {
326352 registry,
327353 pluginId : "owner-plugin" ,
328354 hookName : "before_tool_call" ,
329- handler : ( ( ) => result ) as PluginHookRegistration [ "handler" ] ,
355+ handler : handler as PluginHookRegistration [ "handler" ] ,
356+ ...( testCase . matcher ? { matcher : [ ...testCase . matcher ] } : { } ) ,
330357 } ) ;
331358 setActivePluginRegistry ( registry ) ;
332359 initializeGlobalHookRunner ( registry ) ;
@@ -337,7 +364,11 @@ describe("generic tool action decision receipts", () => {
337364 return true ;
338365 } ) ;
339366 const tool = wrapToolWithBeforeToolCallHook (
340- assembledTool ( "data" , "hook_allow_subject" , vi . fn ( ) . mockResolvedValue ( { content : [ ] } ) ) ,
367+ assembledTool (
368+ "data" ,
369+ testCase . toolName ?? "hook_allow_subject" ,
370+ vi . fn ( ) . mockResolvedValue ( { content : [ ] } ) ,
371+ ) ,
341372 ) ;
342373
343374 try {
@@ -346,12 +377,21 @@ describe("generic tool action decision receipts", () => {
346377 clearOwnerSink ( ) ;
347378 }
348379
349- expect ( works ) . toEqual ( [ ] ) ;
350- expect ( ownerReceipts ) . toHaveLength ( 1 ) ;
351- expect ( ownerReceipts [ 0 ] ) . toMatchObject ( {
352- decision : { outcome : "allowed" , reasonCode : "plugin_hook_allowed" } ,
353- source : { owner : "plugin-hook" } ,
354- } ) ;
380+ expect ( handler ) . toHaveBeenCalledTimes ( testCase . expectedHandlerCalls ) ;
381+ expect ( works ) . toHaveLength ( testCase . expectedGenericReceipts ) ;
382+ expect ( ownerReceipts ) . toHaveLength ( testCase . expectedOwnerReceipts ) ;
383+ if ( testCase . expectedGenericReceipts === 1 ) {
384+ expect ( works [ 0 ] ?. receipt ) . toMatchObject ( {
385+ decision : { outcome : "allowed" , reasonCode : "generic_action_attributed" } ,
386+ source : { owner : "tool-action" } ,
387+ } ) ;
388+ }
389+ if ( testCase . expectedOwnerReceipts === 1 ) {
390+ expect ( ownerReceipts [ 0 ] ) . toMatchObject ( {
391+ decision : { outcome : "allowed" , reasonCode : "plugin_hook_allowed" } ,
392+ source : { owner : "plugin-hook" } ,
393+ } ) ;
394+ }
355395 } ,
356396 ) ;
357397
0 commit comments