@@ -12,18 +12,10 @@ import {
1212 EmbeddedPluginApprovalBroker ,
1313 setEmbeddedPluginApprovalBroker ,
1414} from "../infra/embedded-plugin-approval-broker.js" ;
15- import {
16- getGlobalHookRunner ,
17- initializeGlobalHookRunner ,
18- resetGlobalHookRunner ,
19- } from "../plugins/hook-runner-global.js" ;
15+ import { getGlobalHookRunner , resetGlobalHookRunner } from "../plugins/hook-runner-global.js" ;
2016import type { HookRunner } from "../plugins/hooks.js" ;
2117import { createEmptyPluginRegistry } from "../plugins/registry-empty.js" ;
22- import {
23- pinActivePluginChannelRegistry ,
24- releasePinnedPluginChannelRegistry ,
25- setActivePluginRegistry ,
26- } from "../plugins/runtime.js" ;
18+ import { setActivePluginRegistry } from "../plugins/runtime.js" ;
2719import { PluginApprovalResolutions } from "../plugins/types.js" ;
2820import { runBeforeToolCallHook } from "./agent-tools.before-tool-call.js" ;
2921import { callGatewayTool } from "./tools/gateway.js" ;
@@ -711,94 +703,6 @@ describe("runBeforeToolCallHook — embedded mode approvals", () => {
711703 expect ( runBeforeToolCallMock ) . not . toHaveBeenCalled ( ) ;
712704 } ) ;
713705
714- it ( "runs trusted policies from the global hook registry after the active registry changes" , async ( ) => {
715- const evaluatePolicy = vi . fn ( ( ) => ( {
716- block : true ,
717- blockReason : "gateway registry policy blocked" ,
718- } ) ) ;
719- const gatewayRegistry = createEmptyPluginRegistry ( ) ;
720- gatewayRegistry . trustedToolPolicies = [
721- {
722- pluginId : "gateway-policy" ,
723- pluginName : "Gateway Policy" ,
724- source : "test" ,
725- policy : {
726- id : "gateway-block" ,
727- description : "Gateway policy" ,
728- evaluate : evaluatePolicy ,
729- } ,
730- } ,
731- ] ;
732- initializeGlobalHookRunner ( gatewayRegistry ) ;
733- setActivePluginRegistry ( createEmptyPluginRegistry ( ) ) ;
734- runBeforeToolCallMock . mockResolvedValue ( undefined ) ;
735-
736- const result = await runBeforeToolCallHook ( {
737- toolName : "bash" ,
738- params : { command : "deploy" } ,
739- toolCallId : "call-gateway-policy" ,
740- ctx : { agentId : "main" , sessionKey : "main" } ,
741- } ) ;
742-
743- expect ( result ) . toEqual ( {
744- blocked : true ,
745- kind : "veto" ,
746- deniedReason : "plugin-before-tool-call" ,
747- reason : "gateway registry policy blocked" ,
748- params : { command : "deploy" } ,
749- } ) ;
750- expect ( evaluatePolicy ) . toHaveBeenCalledTimes ( 1 ) ;
751- expect ( runBeforeToolCallMock ) . not . toHaveBeenCalled ( ) ;
752- } ) ;
753-
754- it ( "runs pinned gateway trusted policies after a later global runner initialization" , async ( ) => {
755- const evaluatePolicy = vi . fn ( ( ) => ( {
756- block : true ,
757- blockReason : "pinned gateway policy blocked" ,
758- } ) ) ;
759- const gatewayRegistry = createEmptyPluginRegistry ( ) ;
760- gatewayRegistry . trustedToolPolicies = [
761- {
762- pluginId : "gateway-policy" ,
763- pluginName : "Gateway Policy" ,
764- source : "test" ,
765- policy : {
766- id : "gateway-block" ,
767- description : "Gateway policy" ,
768- evaluate : evaluatePolicy ,
769- } ,
770- } ,
771- ] ;
772- setActivePluginRegistry ( gatewayRegistry ) ;
773- initializeGlobalHookRunner ( gatewayRegistry ) ;
774- pinActivePluginChannelRegistry ( gatewayRegistry ) ;
775- try {
776- const laterRegistry = createEmptyPluginRegistry ( ) ;
777- setActivePluginRegistry ( laterRegistry ) ;
778- initializeGlobalHookRunner ( laterRegistry ) ;
779- runBeforeToolCallMock . mockResolvedValue ( undefined ) ;
780-
781- const result = await runBeforeToolCallHook ( {
782- toolName : "bash" ,
783- params : { command : "deploy" } ,
784- toolCallId : "call-pinned-gateway-policy" ,
785- ctx : { agentId : "main" , sessionKey : "main" } ,
786- } ) ;
787-
788- expect ( result ) . toEqual ( {
789- blocked : true ,
790- kind : "veto" ,
791- deniedReason : "plugin-before-tool-call" ,
792- reason : "pinned gateway policy blocked" ,
793- params : { command : "deploy" } ,
794- } ) ;
795- expect ( evaluatePolicy ) . toHaveBeenCalledTimes ( 1 ) ;
796- expect ( runBeforeToolCallMock ) . not . toHaveBeenCalled ( ) ;
797- } finally {
798- releasePinnedPluginChannelRegistry ( gatewayRegistry ) ;
799- }
800- } ) ;
801-
802706 it ( "does not require skill_workshop lifecycle approval by default" , async ( ) => {
803707 ( hookRunner . hasHooks as ReturnType < typeof vi . fn > ) . mockReturnValue ( false ) ;
804708
0 commit comments