mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:20:43 +00:00
test(agents): share generation tool registration helper
This commit is contained in:
35
src/agents/openclaw-tools.generation.test-support.ts
Normal file
35
src/agents/openclaw-tools.generation.test-support.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { collectPresentOpenClawTools } from "./openclaw-tools.registration.js";
|
||||
import { textResult, type AnyAgentTool } from "./tools/common.js";
|
||||
|
||||
function stubAgentTool(name: string): AnyAgentTool {
|
||||
return {
|
||||
label: name,
|
||||
name,
|
||||
description: `${name} stub`,
|
||||
parameters: { type: "object", properties: {} },
|
||||
async execute() {
|
||||
return textResult("ok", {});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function describeOpenClawGenerationToolRegistration(params: {
|
||||
suiteName: string;
|
||||
toolName: string;
|
||||
toolLabel: string;
|
||||
}) {
|
||||
describe(params.suiteName, () => {
|
||||
it(`registers ${params.toolName} when ${params.toolLabel} is present`, () => {
|
||||
const tool = stubAgentTool(params.toolName);
|
||||
|
||||
expect(collectPresentOpenClawTools([tool])).toEqual([tool]);
|
||||
});
|
||||
|
||||
it(`omits ${params.toolName} when ${params.toolLabel} is absent`, () => {
|
||||
expect(collectPresentOpenClawTools([null]).map((tool) => tool.name)).not.toContain(
|
||||
params.toolName,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,29 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { collectPresentOpenClawTools } from "./openclaw-tools.registration.js";
|
||||
import { textResult, type AnyAgentTool } from "./tools/common.js";
|
||||
import { describeOpenClawGenerationToolRegistration } from "./openclaw-tools.generation.test-support.js";
|
||||
|
||||
function stubAgentTool(name: string): AnyAgentTool {
|
||||
return {
|
||||
label: name,
|
||||
name,
|
||||
description: `${name} stub`,
|
||||
parameters: { type: "object", properties: {} },
|
||||
async execute() {
|
||||
return textResult("ok", {});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("openclaw tools image generation registration", () => {
|
||||
it("registers image_generate when an image-generation tool is present", () => {
|
||||
const imageGenerateTool = stubAgentTool("image_generate");
|
||||
|
||||
expect(collectPresentOpenClawTools([imageGenerateTool])).toEqual([imageGenerateTool]);
|
||||
});
|
||||
|
||||
it("omits image_generate when the image-generation tool is absent", () => {
|
||||
expect(collectPresentOpenClawTools([null]).map((tool) => tool.name)).not.toContain(
|
||||
"image_generate",
|
||||
);
|
||||
});
|
||||
describeOpenClawGenerationToolRegistration({
|
||||
suiteName: "openclaw tools image generation registration",
|
||||
toolName: "image_generate",
|
||||
toolLabel: "an image-generation tool",
|
||||
});
|
||||
|
||||
@@ -1,29 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { collectPresentOpenClawTools } from "./openclaw-tools.registration.js";
|
||||
import { textResult, type AnyAgentTool } from "./tools/common.js";
|
||||
import { describeOpenClawGenerationToolRegistration } from "./openclaw-tools.generation.test-support.js";
|
||||
|
||||
function stubAgentTool(name: string): AnyAgentTool {
|
||||
return {
|
||||
label: name,
|
||||
name,
|
||||
description: `${name} stub`,
|
||||
parameters: { type: "object", properties: {} },
|
||||
async execute() {
|
||||
return textResult("ok", {});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("openclaw tools video generation registration", () => {
|
||||
it("registers video_generate when a video-generation tool is present", () => {
|
||||
const videoGenerateTool = stubAgentTool("video_generate");
|
||||
|
||||
expect(collectPresentOpenClawTools([videoGenerateTool])).toEqual([videoGenerateTool]);
|
||||
});
|
||||
|
||||
it("omits video_generate when the video-generation tool is absent", () => {
|
||||
expect(collectPresentOpenClawTools([null]).map((tool) => tool.name)).not.toContain(
|
||||
"video_generate",
|
||||
);
|
||||
});
|
||||
describeOpenClawGenerationToolRegistration({
|
||||
suiteName: "openclaw tools video generation registration",
|
||||
toolName: "video_generate",
|
||||
toolLabel: "a video-generation tool",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user