test: dedupe plugin provider runtime suites

This commit is contained in:
Peter Steinberger
2026-03-28 02:33:50 +00:00
parent 0454612083
commit a9be5421d0
10 changed files with 335 additions and 382 deletions

View File

@@ -40,6 +40,23 @@ function createContext() {
};
}
function createResolveToolsParams(params?: {
toolAllowlist?: readonly string[];
existingToolNames?: Set<string>;
env?: NodeJS.ProcessEnv;
suppressNameConflicts?: boolean;
allowGatewaySubagentBinding?: boolean;
}) {
return {
context: createContext() as never,
...(params?.toolAllowlist ? { toolAllowlist: [...params.toolAllowlist] } : {}),
...(params?.existingToolNames ? { existingToolNames: params.existingToolNames } : {}),
...(params?.env ? { env: params.env } : {}),
...(params?.suppressNameConflicts ? { suppressNameConflicts: true } : {}),
...(params?.allowGatewaySubagentBinding ? { allowGatewaySubagentBinding: true } : {}),
};
}
function setRegistry(entries: MockRegistryToolEntry[]) {
const registry = {
tools: entries,
@@ -66,11 +83,12 @@ function setMultiToolRegistry() {
}
function resolveWithConflictingCoreName(options?: { suppressNameConflicts?: boolean }) {
return resolvePluginTools({
context: createContext() as never,
existingToolNames: new Set(["message"]),
...(options?.suppressNameConflicts ? { suppressNameConflicts: true } : {}),
});
return resolvePluginTools(
createResolveToolsParams({
existingToolNames: new Set(["message"]),
...(options?.suppressNameConflicts ? { suppressNameConflicts: true } : {}),
}),
);
}
function setOptionalDemoRegistry() {
@@ -84,11 +102,8 @@ function setOptionalDemoRegistry() {
]);
}
function resolveOptionalDemoTools(toolAllowlist?: string[]) {
return resolvePluginTools({
context: createContext() as never,
...(toolAllowlist ? { toolAllowlist } : {}),
});
function resolveOptionalDemoTools(toolAllowlist?: readonly string[]) {
return resolvePluginTools(createResolveToolsParams({ toolAllowlist }));
}
describe("resolvePluginTools optional tools", () => {
@@ -107,22 +122,26 @@ describe("resolvePluginTools optional tools", () => {
expect(tools).toHaveLength(0);
});
it("allows optional tools by tool name", () => {
it.each([
{
name: "allows optional tools by tool name",
toolAllowlist: ["optional_tool"],
},
{
name: "allows optional tools via plugin id",
toolAllowlist: ["optional-demo"],
},
{
name: "allows optional tools via plugin-scoped allowlist entries",
toolAllowlist: ["group:plugins"],
},
] as const)("$name", ({ toolAllowlist }) => {
setOptionalDemoRegistry();
const tools = resolveOptionalDemoTools(["optional_tool"]);
const tools = resolveOptionalDemoTools(toolAllowlist);
expect(tools.map((tool) => tool.name)).toEqual(["optional_tool"]);
});
it("allows optional tools via plugin-scoped allowlist entries", () => {
setOptionalDemoRegistry();
const toolsByPlugin = resolveOptionalDemoTools(["optional-demo"]);
const toolsByGroup = resolveOptionalDemoTools(["group:plugins"]);
expect(toolsByPlugin.map((tool) => tool.name)).toEqual(["optional_tool"]);
expect(toolsByGroup.map((tool) => tool.name)).toEqual(["optional_tool"]);
});
it("rejects plugin id collisions with core tool names", () => {
const registry = setRegistry([
{
@@ -133,10 +152,11 @@ describe("resolvePluginTools optional tools", () => {
},
]);
const tools = resolvePluginTools({
context: createContext() as never,
existingToolNames: new Set(["message"]),
});
const tools = resolvePluginTools(
createResolveToolsParams({
existingToolNames: new Set(["message"]),
}),
);
expect(tools).toHaveLength(0);
expect(registry.diagnostics).toHaveLength(1);
@@ -164,11 +184,12 @@ describe("resolvePluginTools optional tools", () => {
setOptionalDemoRegistry();
const env = { OPENCLAW_HOME: "/srv/openclaw-home" } as NodeJS.ProcessEnv;
resolvePluginTools({
context: createContext() as never,
env,
toolAllowlist: ["optional_tool"],
});
resolvePluginTools(
createResolveToolsParams({
env,
toolAllowlist: ["optional_tool"],
}),
);
expect(loadOpenClawPluginsMock).toHaveBeenCalledWith(
expect.objectContaining({
@@ -180,11 +201,12 @@ describe("resolvePluginTools optional tools", () => {
it("forwards gateway subagent binding to plugin runtime options", () => {
setOptionalDemoRegistry();
resolvePluginTools({
context: createContext() as never,
allowGatewaySubagentBinding: true,
toolAllowlist: ["optional_tool"],
});
resolvePluginTools(
createResolveToolsParams({
allowGatewaySubagentBinding: true,
toolAllowlist: ["optional_tool"],
}),
);
expect(loadOpenClawPluginsMock).toHaveBeenCalledWith(
expect.objectContaining({