mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-01 04:11:03 +00:00
test: isolate image read helper coverage
This commit is contained in:
@@ -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.";
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user