Skip to content

Commit cfd1e94

Browse files
committed
fix(regression): auto-enable plugin tool loads
1 parent a6e597e commit cfd1e94

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

src/plugins/tools.optional.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ type MockRegistryToolEntry = {
88
};
99

1010
const loadOpenClawPluginsMock = vi.fn();
11+
const applyPluginAutoEnableMock = vi.fn();
1112

1213
vi.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+
1621
let resolvePluginTools: typeof import("./tools.js").resolvePluginTools;
1722
let 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
});

src/plugins/tools.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { normalizeToolName } from "../agents/tool-policy.js";
22
import type { AnyAgentTool } from "../agents/tools/common.js";
3+
import { applyPluginAutoEnable } from "../config/plugin-auto-enable.js";
34
import { createSubsystemLogger } from "../logging/subsystem.js";
45
import { applyTestPluginDefaults, normalizePluginsConfig } from "./config-state.js";
56
import { loadOpenClawPlugins } from "./loader.js";
@@ -61,7 +62,8 @@ export function resolvePluginTools(params: {
6162
// Fast path: when plugins are effectively disabled, avoid discovery/jiti entirely.
6263
// This matters a lot for unit tests and for tool construction hot paths.
6364
const env = params.env ?? process.env;
64-
const effectiveConfig = applyTestPluginDefaults(params.context.config ?? {}, env);
65+
const baseConfig = applyTestPluginDefaults(params.context.config ?? {}, env);
66+
const effectiveConfig = applyPluginAutoEnable({ config: baseConfig, env }).config;
6567
const normalized = normalizePluginsConfig(effectiveConfig.plugins);
6668
if (!normalized.enabled) {
6769
return [];

0 commit comments

Comments
 (0)