fix(plugins): preserve source activation config

This commit is contained in:
Peter Steinberger
2026-04-22 19:25:50 +01:00
parent 6d003cbcee
commit 4b2b261367
8 changed files with 226 additions and 5 deletions

View File

@@ -12,6 +12,8 @@ const resolveDefaultAgentIdMock = vi.fn<
let resolvePluginRuntimeLoadContext: typeof import("./load-context.js").resolvePluginRuntimeLoadContext;
let buildPluginRuntimeLoadOptions: typeof import("./load-context.js").buildPluginRuntimeLoadOptions;
let clearRuntimeConfigSnapshot: typeof import("../../config/runtime-snapshot.js").clearRuntimeConfigSnapshot;
let setRuntimeConfigSnapshot: typeof import("../../config/runtime-snapshot.js").setRuntimeConfigSnapshot;
vi.mock("../../config/config.js", () => ({
loadConfig: loadConfigMock,
@@ -29,6 +31,8 @@ vi.mock("../../agents/agent-scope.js", () => ({
describe("resolvePluginRuntimeLoadContext", () => {
beforeEach(async () => {
vi.resetModules();
({ clearRuntimeConfigSnapshot, setRuntimeConfigSnapshot } =
await import("../../config/runtime-snapshot.js"));
({ resolvePluginRuntimeLoadContext, buildPluginRuntimeLoadOptions } =
await import("./load-context.js"));
loadConfigMock.mockReset();
@@ -42,6 +46,7 @@ describe("resolvePluginRuntimeLoadContext", () => {
changes: [],
autoEnabledReasons: {},
}));
clearRuntimeConfigSnapshot();
});
it("builds the runtime plugin load context from the auto-enabled config", () => {
@@ -88,6 +93,27 @@ describe("resolvePluginRuntimeLoadContext", () => {
expect(resolveAgentWorkspaceDirMock).toHaveBeenCalledWith(resolvedConfig, "default");
});
it("uses the source runtime snapshot for plugin activation source config", () => {
const runtimeConfig = { plugins: {} };
const sourceConfig = {
plugins: {
allow: ["trusted-plugin"],
},
};
setRuntimeConfigSnapshot(runtimeConfig, sourceConfig);
loadConfigMock.mockReturnValue(runtimeConfig);
const context = resolvePluginRuntimeLoadContext();
expect(context.rawConfig).toBe(runtimeConfig);
expect(context.activationSourceConfig).toBe(sourceConfig);
expect(applyPluginAutoEnableMock).toHaveBeenCalledWith({
config: runtimeConfig,
env: process.env,
});
});
it("builds plugin load options from the shared runtime context", () => {
const context = resolvePluginRuntimeLoadContext({
config: { plugins: {} },

View File

@@ -3,6 +3,7 @@ import { loadConfig } from "../../config/config.js";
import { applyPluginAutoEnable } from "../../config/plugin-auto-enable.js";
import type { OpenClawConfig } from "../../config/types.openclaw.js";
import { createSubsystemLogger } from "../../logging.js";
import { resolvePluginActivationSourceConfig } from "../activation-source-config.js";
import type { PluginLoadOptions } from "../loader.js";
import type { PluginLogger } from "../types.js";
@@ -45,6 +46,10 @@ export function resolvePluginRuntimeLoadContext(
): PluginRuntimeLoadContext {
const env = options?.env ?? process.env;
const rawConfig = options?.config ?? loadConfig();
const activationSourceConfig = resolvePluginActivationSourceConfig({
config: rawConfig,
activationSourceConfig: options?.activationSourceConfig,
});
const autoEnabled = applyPluginAutoEnable({ config: rawConfig, env });
const config = autoEnabled.config;
const workspaceDir =
@@ -52,7 +57,7 @@ export function resolvePluginRuntimeLoadContext(
return {
rawConfig,
config,
activationSourceConfig: options?.activationSourceConfig ?? rawConfig,
activationSourceConfig,
autoEnabledReasons: autoEnabled.autoEnabledReasons,
workspaceDir,
env,