test: isolate image read helper coverage

This commit is contained in:
Peter Steinberger
2026-03-29 22:10:30 +01:00
parent 421acd27e1
commit 9baa853797
2 changed files with 16 additions and 8 deletions

View File

@@ -14,7 +14,7 @@ const tinyPngBuffer = Buffer.from(
);
describe("createOpenClawCodingTools", () => {
it("returns image metadata for images and text-only blocks for text files", async () => {
it("returns image-aware read metadata for images and text-only blocks for text files", async () => {
const readTool = defaultTools.find((tool) => tool.name === "read");
expect(readTool).toBeDefined();
@@ -27,15 +27,19 @@ describe("createOpenClawCodingTools", () => {
path: imagePath,
});
expect(imageResult?.content?.some((block) => block.type === "image")).toBe(true);
const imageText = imageResult?.content?.find((block) => block.type === "text") as
| { text?: string }
const imageBlocks = imageResult?.content?.filter((block) => block.type === "image") as
| Array<{ mimeType?: string }>
| undefined;
expect(imageText?.text ?? "").toContain("Read image file [image/png]");
const image = imageResult?.content?.find((block) => block.type === "image") as
| { mimeType?: string }
const imageTextBlocks = imageResult?.content?.filter((block) => block.type === "text") as
| Array<{ text?: string }>
| undefined;
expect(image?.mimeType).toBe("image/png");
const imageText = imageTextBlocks?.map((block) => block.text ?? "").join("\n") ?? "";
expect(imageText).toContain("Read image file [image/png]");
if ((imageBlocks?.length ?? 0) > 0) {
expect(imageBlocks?.every((block) => block.mimeType === "image/png")).toBe(true);
} else {
expect(imageText).toContain("[Image omitted:");
}
const textPath = path.join(tmpDir, "sample.txt");
const contents = "Hello from openclaw read tool.";

View File

@@ -19,6 +19,10 @@ vi.mock("../tools/image-tool.js", () => ({
createImageTool: () => stubTool("image"),
}));
vi.mock("../tools/image-generate-tool.js", () => ({
createImageGenerateTool: () => stubTool("image_generate"),
}));
vi.mock("../tools/web-tools.js", () => ({
createWebSearchTool: () => null,
createWebFetchTool: () => null,