From cf4354ad83b644c310d6b99e061bfb1b127061c5 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 20 Apr 2026 22:23:09 +0100 Subject: [PATCH] test: share plugin secret collector setup --- .../runtime-config-collectors-plugins.test.ts | 207 +++++------------- 1 file changed, 59 insertions(+), 148 deletions(-) diff --git a/src/secrets/runtime-config-collectors-plugins.test.ts b/src/secrets/runtime-config-collectors-plugins.test.ts index fbc88897808..33174d5fa23 100644 --- a/src/secrets/runtime-config-collectors-plugins.test.ts +++ b/src/secrets/runtime-config-collectors-plugins.test.ts @@ -35,6 +35,46 @@ function loadablePluginOrigins(entries: Array<[string, PluginOrigin]>) { return new Map(entries); } +function createAcpxMcpSecretConfig(params: { + plugins?: Record; + entry?: Record; +}): OpenClawConfig { + return asConfig({ + plugins: { + ...params.plugins, + entries: { + acpx: { + ...params.entry, + config: { + mcpServers: { + s1: { command: "node", env: { K: envRef("K") } }, + }, + }, + }, + }, + }, + }); +} + +function collectAcpxConfigAssignments(config: OpenClawConfig): ResolverContext { + const context = makeContext(config); + collectPluginConfigAssignments({ + config, + defaults: undefined, + context, + loadablePluginOrigins: loadablePluginOrigins([["acpx", "bundled"]]), + }); + return context; +} + +function expectInactiveAcpxConfig(config: OpenClawConfig): void { + const context = collectAcpxConfigAssignments(config); + expect(context.assignments).toHaveLength(0); + expect(context.warnings.some((w) => w.code === "SECRETS_REF_IGNORED_INACTIVE_SURFACE")).toBe( + true, + ); +} + describe("collectPluginConfigAssignments", () => { beforeEach(() => { loadPluginManifestRegistryMock.mockReset(); @@ -225,172 +265,43 @@ describe("collectPluginConfigAssignments", () => { }); it("skips assignments when plugins.enabled is false", () => { - const config = asConfig({ - plugins: { - enabled: false, - entries: { - acpx: { - enabled: true, - config: { - mcpServers: { - s1: { command: "node", env: { K: envRef("K") } }, - }, - }, - }, - }, - }, - }); - const context = makeContext(config); - - collectPluginConfigAssignments({ - config, - defaults: undefined, - context, - loadablePluginOrigins: loadablePluginOrigins([["acpx", "bundled"]]), - }); - - expect(context.assignments).toHaveLength(0); - expect(context.warnings.some((w) => w.code === "SECRETS_REF_IGNORED_INACTIVE_SURFACE")).toBe( - true, + expectInactiveAcpxConfig( + createAcpxMcpSecretConfig({ + plugins: { enabled: false }, + entry: { enabled: true }, + }), ); }); it("skips assignments when entry.enabled is false", () => { - const config = asConfig({ - plugins: { - entries: { - acpx: { - enabled: false, - config: { - mcpServers: { - s1: { command: "node", env: { K: envRef("K") } }, - }, - }, - }, - }, - }, - }); - const context = makeContext(config); - - collectPluginConfigAssignments({ - config, - defaults: undefined, - context, - loadablePluginOrigins: loadablePluginOrigins([["acpx", "bundled"]]), - }); - - expect(context.assignments).toHaveLength(0); - expect(context.warnings.some((w) => w.code === "SECRETS_REF_IGNORED_INACTIVE_SURFACE")).toBe( - true, - ); + expectInactiveAcpxConfig(createAcpxMcpSecretConfig({ entry: { enabled: false } })); }); it("treats bundled acpx SecretRef surfaces as inactive until enabled", () => { - const config = asConfig({ - plugins: { - enabled: true, - entries: { - acpx: { - config: { - mcpServers: { - s1: { command: "node", env: { K: envRef("K") } }, - }, - }, - }, - }, - }, - }); - const context = makeContext(config); - - collectPluginConfigAssignments({ - config, - defaults: undefined, - context, - loadablePluginOrigins: loadablePluginOrigins([["acpx", "bundled"]]), - }); - - expect(context.assignments).toHaveLength(0); - expect(context.warnings.some((w) => w.code === "SECRETS_REF_IGNORED_INACTIVE_SURFACE")).toBe( - true, - ); + expectInactiveAcpxConfig(createAcpxMcpSecretConfig({ plugins: { enabled: true } })); }); it("skips assignments when plugin is in denylist", () => { - const config = asConfig({ - plugins: { - deny: ["acpx"], - entries: { - acpx: { - enabled: true, - config: { - mcpServers: { - s1: { command: "node", env: { K: envRef("K") } }, - }, - }, - }, - }, - }, - }); - const context = makeContext(config); - - collectPluginConfigAssignments({ - config, - defaults: undefined, - context, - loadablePluginOrigins: loadablePluginOrigins([["acpx", "bundled"]]), - }); - - expect(context.assignments).toHaveLength(0); - expect(context.warnings.some((w) => w.code === "SECRETS_REF_IGNORED_INACTIVE_SURFACE")).toBe( - true, + expectInactiveAcpxConfig( + createAcpxMcpSecretConfig({ + plugins: { deny: ["acpx"] }, + entry: { enabled: true }, + }), ); }); it("skips assignments when allowlist is set and plugin is not in it", () => { - const config = asConfig({ - plugins: { - allow: ["other-plugin"], - entries: { - acpx: { - enabled: true, - config: { - mcpServers: { - s1: { command: "node", env: { K: envRef("K") } }, - }, - }, - }, - }, - }, - }); - const context = makeContext(config); - - collectPluginConfigAssignments({ - config, - defaults: undefined, - context, - loadablePluginOrigins: loadablePluginOrigins([["acpx", "bundled"]]), - }); - - expect(context.assignments).toHaveLength(0); - expect(context.warnings.some((w) => w.code === "SECRETS_REF_IGNORED_INACTIVE_SURFACE")).toBe( - true, + expectInactiveAcpxConfig( + createAcpxMcpSecretConfig({ + plugins: { allow: ["other-plugin"] }, + entry: { enabled: true }, + }), ); }); it("collects assignments when plugin is in allowlist", () => { - const config = asConfig({ - plugins: { - allow: ["acpx"], - entries: { - acpx: { - config: { - mcpServers: { - s1: { command: "node", env: { K: envRef("K") } }, - }, - }, - }, - }, - }, + const config = createAcpxMcpSecretConfig({ + plugins: { allow: ["acpx"] }, }); const context = makeContext(config);