11// Command startup policy tests cover which CLI commands require startup side effects.
22import { importFreshModule } from "openclaw/plugin-sdk/test-fixtures" ;
3- import { afterEach , describe , expect , it , vi } from "vitest" ;
3+ import { describe , expect , it , vi } from "vitest" ;
44import { cliCommandCatalog } from "./command-catalog.js" ;
55import { resolveCliExecutionStartupContext } from "./command-execution-startup.js" ;
66import { resolveCliStartupPolicy } from "./command-startup-policy.js" ;
@@ -18,11 +18,6 @@ function resolvePolicy(params: {
1818}
1919
2020describe ( "command-startup-policy" , ( ) => {
21- afterEach ( ( ) => {
22- vi . doUnmock ( "./command-path-policy.js" ) ;
23- vi . resetModules ( ) ;
24- } ) ;
25-
2621 it ( "resolves config guard policy for Commander and invocation-aware commands" , ( ) => {
2722 for ( const commandPath of [
2823 [ "backup" , "create" ] ,
@@ -165,27 +160,34 @@ describe("command-startup-policy", () => {
165160 } ) ;
166161
167162 it ( "skips when-suppressed guards only for suppressed output" , async ( ) => {
168- vi . doMock ( "./command-path-policy.js" , ( ) => ( {
169- resolveCliCommandPathPolicy : ( ) => ( {
170- configGuard : "when-suppressed" ,
171- loadPlugins : "never" ,
172- pluginRegistry : { scope : "all" } ,
173- ownsProtocolStdout : false ,
174- hideBanner : false ,
175- ensureCliPath : true ,
176- networkProxy : "default" ,
177- } ) ,
178- } ) ) ;
179- const { resolveCliStartupPolicy : resolveWithSuppressedGuard } = await importFreshModule <
180- typeof import ( "./command-startup-policy.js" )
181- > ( import . meta. url , "./command-startup-policy.js?when-suppressed" ) ;
163+ vi . resetModules ( ) ;
164+ try {
165+ vi . doMock ( "./command-path-policy.js" , ( ) => ( {
166+ resolveCliCommandPathPolicy : ( ) => ( {
167+ configGuard : "when-suppressed" ,
168+ loadPlugins : "never" ,
169+ pluginRegistry : { scope : "all" } ,
170+ ownsProtocolStdout : false ,
171+ hideBanner : false ,
172+ ensureCliPath : true ,
173+ networkProxy : "default" ,
174+ } ) ,
175+ } ) ) ;
176+ const { resolveCliStartupPolicy : resolveWithSuppressedGuard } = await importFreshModule <
177+ typeof import ( "./command-startup-policy.js" )
178+ > ( import . meta. url , "./command-startup-policy.js?when-suppressed" ) ;
182179
183- expect (
184- resolveWithSuppressedGuard ( { commandPath : [ "test" ] , jsonOutputMode : false } ) . skipConfigGuard ,
185- ) . toBe ( false ) ;
186- expect (
187- resolveWithSuppressedGuard ( { commandPath : [ "test" ] , jsonOutputMode : true } ) . skipConfigGuard ,
188- ) . toBe ( true ) ;
180+ expect (
181+ resolveWithSuppressedGuard ( { commandPath : [ "test" ] , jsonOutputMode : false } )
182+ . skipConfigGuard ,
183+ ) . toBe ( false ) ;
184+ expect (
185+ resolveWithSuppressedGuard ( { commandPath : [ "test" ] , jsonOutputMode : true } ) . skipConfigGuard ,
186+ ) . toBe ( true ) ;
187+ } finally {
188+ vi . doUnmock ( "./command-path-policy.js" ) ;
189+ vi . resetModules ( ) ;
190+ }
189191 } ) ;
190192
191193 it ( "matches plugin preload policy" , ( ) => {
0 commit comments