test: share plugin secret collector setup

This commit is contained in:
Peter Steinberger
2026-04-20 22:23:09 +01:00
parent 99b933f160
commit cf4354ad83

View File

@@ -35,6 +35,46 @@ function loadablePluginOrigins(entries: Array<[string, PluginOrigin]>) {
return new Map(entries);
}
function createAcpxMcpSecretConfig(params: {
plugins?: Record<string, unknown>;
entry?: Record<string, unknown>;
}): 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);