mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 19:20:22 +00:00
test: dedupe plugin provider runtime suites
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user