mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-01 22:16:13 +00:00
refactor: deduplicate shared helpers and test setup
This commit is contained in:
@@ -52,6 +52,25 @@ function setRegistry(entries: MockRegistryToolEntry[]) {
|
||||
return registry;
|
||||
}
|
||||
|
||||
function setMultiToolRegistry() {
|
||||
return setRegistry([
|
||||
{
|
||||
pluginId: "multi",
|
||||
optional: false,
|
||||
source: "/tmp/multi.js",
|
||||
factory: () => [makeTool("message"), makeTool("other_tool")],
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
function resolveWithConflictingCoreName(options?: { suppressNameConflicts?: boolean }) {
|
||||
return resolvePluginTools({
|
||||
context: createContext() as never,
|
||||
existingToolNames: new Set(["message"]),
|
||||
...(options?.suppressNameConflicts ? { suppressNameConflicts: true } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
describe("resolvePluginTools optional tools", () => {
|
||||
beforeEach(() => {
|
||||
loadOpenClawPluginsMock.mockClear();
|
||||
@@ -136,19 +155,8 @@ describe("resolvePluginTools optional tools", () => {
|
||||
});
|
||||
|
||||
it("skips conflicting tool names but keeps other tools", () => {
|
||||
const registry = setRegistry([
|
||||
{
|
||||
pluginId: "multi",
|
||||
optional: false,
|
||||
source: "/tmp/multi.js",
|
||||
factory: () => [makeTool("message"), makeTool("other_tool")],
|
||||
},
|
||||
]);
|
||||
|
||||
const tools = resolvePluginTools({
|
||||
context: createContext() as never,
|
||||
existingToolNames: new Set(["message"]),
|
||||
});
|
||||
const registry = setMultiToolRegistry();
|
||||
const tools = resolveWithConflictingCoreName();
|
||||
|
||||
expect(tools.map((tool) => tool.name)).toEqual(["other_tool"]);
|
||||
expect(registry.diagnostics).toHaveLength(1);
|
||||
@@ -156,20 +164,8 @@ describe("resolvePluginTools optional tools", () => {
|
||||
});
|
||||
|
||||
it("suppresses conflict diagnostics when requested", () => {
|
||||
const registry = setRegistry([
|
||||
{
|
||||
pluginId: "multi",
|
||||
optional: false,
|
||||
source: "/tmp/multi.js",
|
||||
factory: () => [makeTool("message"), makeTool("other_tool")],
|
||||
},
|
||||
]);
|
||||
|
||||
const tools = resolvePluginTools({
|
||||
context: createContext() as never,
|
||||
existingToolNames: new Set(["message"]),
|
||||
suppressNameConflicts: true,
|
||||
});
|
||||
const registry = setMultiToolRegistry();
|
||||
const tools = resolveWithConflictingCoreName({ suppressNameConflicts: true });
|
||||
|
||||
expect(tools.map((tool) => tool.name)).toEqual(["other_tool"]);
|
||||
expect(registry.diagnostics).toHaveLength(0);
|
||||
|
||||
Reference in New Issue
Block a user