@@ -165,6 +165,7 @@ const mockConfig = vi.hoisted(() => {
165165 } ;
166166} ) ;
167167const mockDaemonRestart = vi . hoisted ( ( ) => vi . fn ( async ( ) => true ) ) ;
168+ const runPluginInstallCommandMock = vi . hoisted ( ( ) => vi . fn ( async ( ) => undefined ) ) ;
168169const mockScheduleGatewayRestart = vi . hoisted ( ( ) =>
169170 vi . fn ( ( ) => ( {
170171 ok : true ,
@@ -182,6 +183,9 @@ vi.mock("../cli/daemon-cli/lifecycle.js", () => ({
182183 runDaemonStop : vi . fn ( async ( ) => { } ) ,
183184 runDaemonRestart : mockDaemonRestart ,
184185} ) ) ;
186+ vi . mock ( "../cli/plugins-install-command.js" , ( ) => ( {
187+ runPluginInstallCommand : runPluginInstallCommandMock ,
188+ } ) ) ;
185189vi . mock ( "../infra/restart.js" , async ( importOriginal ) => ( {
186190 ...( await importOriginal < typeof import ( "../infra/restart.js" ) > ( ) ) ,
187191 scheduleGatewaySigusr1Restart : mockScheduleGatewayRestart ,
@@ -237,6 +241,7 @@ describe("system agent operations", () => {
237241 beforeEach ( ( ) => {
238242 mockConfig . reset ( ) ;
239243 mockDaemonRestart . mockClear ( ) ;
244+ runPluginInstallCommandMock . mockClear ( ) ;
240245 mockScheduleGatewayRestart . mockClear ( ) ;
241246 stateDirSnapshot = captureEnv ( [ "OPENCLAW_STATE_DIR" ] ) ;
242247 vi . stubEnv ( "OPENCLAW_TEST_FAST" , "1" ) ;
@@ -957,36 +962,38 @@ describe("system agent operations", () => {
957962 const tempDir = opTempDirs . make ( "openclaw-plugin-install-" ) ;
958963 setTestEnvValue ( "OPENCLAW_STATE_DIR" , tempDir ) ;
959964 const { runtime, lines } = createSystemAgentTestRuntime ( ) ;
960- const runPluginInstall = vi . fn ( async ( spec : string , pluginRuntime : RuntimeEnv ) => {
961- pluginRuntime . log ( `installed ${ spec } ` ) ;
962- } ) ;
963965
964966 const plan = await executeSystemAgentOperation (
965967 { kind : "plugin-install" , spec : "clawhub:openclaw-demo" } ,
966968 runtime ,
967- { deps : { runPluginInstall } } ,
968969 ) ;
969970 expectRecordFields ( plan as unknown as Record < string , unknown > , {
970971 applied : false ,
971972 message : "Plan: install plugin clawhub:openclaw-demo. Say yes to apply." ,
972973 } ) ;
973- expect ( runPluginInstall ) . not . toHaveBeenCalled ( ) ;
974+ expect ( runPluginInstallCommandMock ) . not . toHaveBeenCalled ( ) ;
974975
975976 const result = await executeSystemAgentOperation (
976977 { kind : "plugin-install" , spec : "clawhub:openclaw-demo" } ,
977978 runtime ,
978979 {
979980 approved : true ,
980- deps : { runPluginInstall } ,
981981 auditDetails : { rescue : true } ,
982982 } ,
983983 ) ;
984984 expect ( result . applied ) . toBe ( true ) ;
985985
986- const installCall = requireFirstMockCall ( runPluginInstall , "runPluginInstall" ) ;
987- expect ( installCall [ 0 ] ) . toBe ( "clawhub:openclaw-demo" ) ;
988- expectRuntimeArg ( installCall [ 1 ] ) ;
989- expect ( installCall [ 2 ] ) . toEqual ( { allowInstallPolicyWarningPrompt : false } ) ;
986+ const [ installParams ] = requireFirstMockCall (
987+ runPluginInstallCommandMock ,
988+ "runPluginInstallCommand" ,
989+ ) ;
990+ const installRequest = requireRecord ( installParams , "plugin install request" ) ;
991+ expectRecordFields ( installRequest , {
992+ raw : "clawhub:openclaw-demo" ,
993+ opts : { } ,
994+ allowInstallPolicyWarningPrompt : false ,
995+ } ) ;
996+ expectRuntimeArg ( installRequest . runtime ) ;
990997 expect ( lines . join ( "\n" ) ) . toContain ( "[openclaw] done: plugin.install" ) ;
991998 const audit = readLastAuditEntry ( ) ;
992999 expectAuditRecord (
@@ -1000,7 +1007,6 @@ describe("system agent operations", () => {
10001007 } ) ;
10011008
10021009 it ( "rejects an invalid approved plugin spec without exiting inside the executor" , async ( ) => {
1003- const runPluginInstall = vi . fn ( ) ;
10041010 mockConfig . readConfigFileSnapshot . mockClear ( ) ;
10051011 const runtime : RuntimeEnv = {
10061012 log : vi . fn ( ) ,
@@ -1012,30 +1018,25 @@ describe("system agent operations", () => {
10121018 executeSystemAgentOperation (
10131019 { kind : "plugin-install" , spec : "https://example.test/plugin.tgz" } ,
10141020 runtime ,
1015- { approved : true , deps : { runPluginInstall } } ,
1021+ { approved : true } ,
10161022 ) ,
10171023 ) . rejects . toThrow ( "accepts npm or ClawHub package specs only" ) ;
10181024
10191025 expect ( runtime . error ) . not . toHaveBeenCalled ( ) ;
10201026 expect ( runtime . exit ) . not . toHaveBeenCalled ( ) ;
1021- expect ( runPluginInstall ) . not . toHaveBeenCalled ( ) ;
1027+ expect ( runPluginInstallCommandMock ) . not . toHaveBeenCalled ( ) ;
10221028 expect ( mockConfig . readConfigFileSnapshot ) . not . toHaveBeenCalled ( ) ;
10231029 } ) ;
10241030
10251031 it ( "rejects arbitrary plugin sources before proposing or installing them" , async ( ) => {
10261032 const { runtime } = createSystemAgentTestRuntime ( ) ;
1027- const runPluginInstall = vi . fn ( ) ;
10281033
10291034 // Untrusted spec must be rejected on the unapproved path too, so a
10301035 // formatted "plan" never surfaces an arbitrary source for approval.
10311036 await expect (
1032- executeSystemAgentOperation (
1033- { kind : "plugin-install" , spec : "npm:@example/plugin" } ,
1034- runtime ,
1035- { deps : { runPluginInstall } } ,
1036- ) ,
1037+ executeSystemAgentOperation ( { kind : "plugin-install" , spec : "npm:@example/plugin" } , runtime ) ,
10371038 ) . rejects . toThrow ( "trusted shell" ) ;
1038- expect ( runPluginInstall ) . not . toHaveBeenCalled ( ) ;
1039+ expect ( runPluginInstallCommandMock ) . not . toHaveBeenCalled ( ) ;
10391040 } ) ;
10401041
10411042 it ( "uninstalls a non-route plugin only after approval and audits the write" , async ( ) => {
0 commit comments