88} from "../infra/agent-events.js" ;
99import { setActivePluginRegistry } from "../plugins/runtime.js" ;
1010import { createChannelTestPluginBase , createTestRegistry } from "../test-utils/channel-plugins.js" ;
11+ import { recordAdjustedParamsForToolCall } from "./agent-tools.before-tool-call.js" ;
1112import type { MessagingToolSend } from "./embedded-agent-messaging.types.js" ;
1213import {
1314 handleToolExecutionEnd ,
@@ -333,6 +334,7 @@ describe("handleToolExecutionStart read path checks", () => {
333334describe ( "handleToolExecutionEnd cron.add commitment tracking" , ( ) => {
334335 it ( "increments successfulCronAdds when cron add succeeds" , async ( ) => {
335336 const { ctx } = createTestContext ( ) ;
337+ ctx . mutationClassifiedToolNames = new Set ( [ "cron" ] ) ;
336338 await handleToolExecutionStart (
337339 ctx as never ,
338340 {
@@ -356,12 +358,18 @@ describe("handleToolExecutionEnd cron.add commitment tracking", () => {
356358
357359 expect ( ctx . state . successfulCronAdds ) . toBe ( 1 ) ;
358360 expect ( ctx . state . toolMetas ) . toContainEqual (
359- expect . objectContaining ( { toolName : "cron" , mutatingAction : true } ) ,
361+ expect . objectContaining ( {
362+ toolName : "cron" ,
363+ mutatingAction : true ,
364+ mutationClassified : true ,
365+ } ) ,
360366 ) ;
367+ expect ( ctx . state . successfulCronAdds ) . toBe ( 1 ) ;
361368 } ) ;
362369
363370 it ( "retains read-only cron action metadata for replay classification" , async ( ) => {
364371 const { ctx } = createTestContext ( ) ;
372+ ctx . mutationClassifiedToolNames = new Set ( [ "cron" ] ) ;
365373 await handleToolExecutionStart (
366374 ctx as never ,
367375 {
@@ -384,7 +392,82 @@ describe("handleToolExecutionEnd cron.add commitment tracking", () => {
384392 ) ;
385393
386394 expect ( ctx . state . toolMetas ) . toContainEqual (
387- expect . objectContaining ( { toolName : "cron" , mutatingAction : false } ) ,
395+ expect . objectContaining ( {
396+ toolName : "cron" ,
397+ mutatingAction : false ,
398+ mutationClassified : true ,
399+ } ) ,
400+ ) ;
401+ } ) ;
402+
403+ it ( "reclassifies mutation from hook-adjusted execution arguments" , async ( ) => {
404+ const { ctx } = createTestContext ( ) ;
405+ ctx . mutationClassifiedToolNames = new Set ( [ "cron" ] ) ;
406+ await handleToolExecutionStart (
407+ ctx as never ,
408+ {
409+ type : "tool_execution_start" ,
410+ toolName : "cron" ,
411+ toolCallId : "tool-cron-adjusted" ,
412+ args : { action : "status" } ,
413+ } as never ,
414+ ) ;
415+ recordAdjustedParamsForToolCall (
416+ "tool-cron-adjusted" ,
417+ { action : "add" , job : { name : "reminder" } } ,
418+ "run-test" ,
419+ ) ;
420+
421+ await handleToolExecutionEnd (
422+ ctx as never ,
423+ {
424+ type : "tool_execution_end" ,
425+ toolName : "cron" ,
426+ toolCallId : "tool-cron-adjusted" ,
427+ isError : false ,
428+ result : { details : { status : "ok" } } ,
429+ } as never ,
430+ ) ;
431+
432+ expect ( ctx . state . toolMetas ) . toContainEqual (
433+ expect . objectContaining ( {
434+ toolName : "cron" ,
435+ mutatingAction : true ,
436+ mutationClassified : true ,
437+ } ) ,
438+ ) ;
439+ } ) ;
440+
441+ it ( "marks plugin tool mutation behavior as unclassified" , async ( ) => {
442+ const { ctx } = createTestContext ( ) ;
443+ ctx . mutationClassifiedToolNames = new Set ( [ "cron" ] ) ;
444+ await handleToolExecutionStart (
445+ ctx as never ,
446+ {
447+ type : "tool_execution_start" ,
448+ toolName : "custom_side_effect_tool" ,
449+ toolCallId : "tool-plugin-side-effect" ,
450+ args : { action : "publish" } ,
451+ } as never ,
452+ ) ;
453+
454+ await handleToolExecutionEnd (
455+ ctx as never ,
456+ {
457+ type : "tool_execution_end" ,
458+ toolName : "custom_side_effect_tool" ,
459+ toolCallId : "tool-plugin-side-effect" ,
460+ isError : false ,
461+ result : { ok : true } ,
462+ } as never ,
463+ ) ;
464+
465+ expect ( ctx . state . toolMetas ) . toContainEqual (
466+ expect . objectContaining ( {
467+ toolName : "custom_side_effect_tool" ,
468+ mutatingAction : false ,
469+ mutationClassified : false ,
470+ } ) ,
388471 ) ;
389472 } ) ;
390473
0 commit comments