@@ -8,11 +8,16 @@ type MockRegistryToolEntry = {
88} ;
99
1010const loadOpenClawPluginsMock = vi . fn ( ) ;
11+ const applyPluginAutoEnableMock = vi . fn ( ) ;
1112
1213vi . mock ( "./loader.js" , ( ) => ( {
1314 loadOpenClawPlugins : ( params : unknown ) => loadOpenClawPluginsMock ( params ) ,
1415} ) ) ;
1516
17+ vi . mock ( "../config/plugin-auto-enable.js" , ( ) => ( {
18+ applyPluginAutoEnable : ( params : unknown ) => applyPluginAutoEnableMock ( params ) ,
19+ } ) ) ;
20+
1621let resolvePluginTools : typeof import ( "./tools.js" ) . resolvePluginTools ;
1722let resetPluginRuntimeStateForTest : typeof import ( "./runtime.js" ) . resetPluginRuntimeStateForTest ;
1823
@@ -129,6 +134,11 @@ describe("resolvePluginTools optional tools", () => {
129134 beforeEach ( async ( ) => {
130135 vi . resetModules ( ) ;
131136 loadOpenClawPluginsMock . mockClear ( ) ;
137+ applyPluginAutoEnableMock . mockReset ( ) ;
138+ applyPluginAutoEnableMock . mockImplementation ( ( { config } : { config : unknown } ) => ( {
139+ config,
140+ changes : [ ] ,
141+ } ) ) ;
132142 ( { resetPluginRuntimeStateForTest } = await import ( "./runtime.js" ) ) ;
133143 resetPluginRuntimeStateForTest ( ) ;
134144 ( { resolvePluginTools } = await import ( "./tools.js" ) ) ;
@@ -227,4 +237,40 @@ describe("resolvePluginTools optional tools", () => {
227237
228238 expectLoaderCall ( expectedLoaderCall ) ;
229239 } ) ;
240+
241+ it ( "loads plugin tools from the auto-enabled config snapshot" , ( ) => {
242+ setOptionalDemoRegistry ( ) ;
243+ const rawContext = createContext ( ) ;
244+ const autoEnabledConfig = {
245+ ...rawContext . config ,
246+ plugins : {
247+ ...rawContext . config . plugins ,
248+ entries : {
249+ "optional-demo" : { enabled : true } ,
250+ } ,
251+ } ,
252+ } ;
253+ applyPluginAutoEnableMock . mockReturnValue ( { config : autoEnabledConfig , changes : [ ] } ) ;
254+
255+ resolvePluginTools ( {
256+ context : {
257+ ...rawContext ,
258+ config : rawContext . config as never ,
259+ } as never ,
260+ toolAllowlist : [ "optional_tool" ] ,
261+ } ) ;
262+
263+ expect ( applyPluginAutoEnableMock ) . toHaveBeenCalledWith (
264+ expect . objectContaining ( {
265+ config : expect . objectContaining ( {
266+ plugins : expect . objectContaining ( {
267+ allow : rawContext . config . plugins ?. allow ,
268+ load : rawContext . config . plugins ?. load ,
269+ } ) ,
270+ } ) ,
271+ env : process . env ,
272+ } ) ,
273+ ) ;
274+ expectLoaderCall ( { config : autoEnabledConfig } ) ;
275+ } ) ;
230276} ) ;
0 commit comments