chore: update deps and extend read tool tests

This commit is contained in:
Peter Steinberger
2026-01-02 23:47:28 +01:00
parent fc54e905c0
commit 88ed58b3d0
4 changed files with 260 additions and 163 deletions

View File

@@ -1,3 +1,8 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import sharp from "sharp";
import { describe, expect, it } from "vitest";
import { createClawdisCodingTools } from "./pi-tools.js";
@@ -77,4 +82,75 @@ describe("createClawdisCodingTools", () => {
expect(tools.some((tool) => tool.name === "bash")).toBe(true);
expect(tools.some((tool) => tool.name === "process")).toBe(true);
});
it("keeps read tool image metadata intact", async () => {
const tools = createClawdisCodingTools();
const readTool = tools.find((tool) => tool.name === "read");
expect(readTool).toBeDefined();
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdis-read-"));
try {
const imagePath = path.join(tmpDir, "sample.png");
const png = await sharp({
create: {
width: 8,
height: 8,
channels: 3,
background: { r: 0, g: 128, b: 255 },
},
})
.png()
.toBuffer();
await fs.writeFile(imagePath, png);
const result = await readTool?.execute("tool-1", {
path: imagePath,
});
expect(result?.content?.some((block) => block.type === "image")).toBe(
true,
);
const text = result?.content?.find((block) => block.type === "text") as
| { text?: string }
| undefined;
expect(text?.text ?? "").toContain("Read image file [image/png]");
const image = result?.content?.find((block) => block.type === "image") as
| { mimeType?: string }
| undefined;
expect(image?.mimeType).toBe("image/png");
} finally {
await fs.rm(tmpDir, { recursive: true, force: true });
}
});
it("returns text content without image blocks for text files", async () => {
const tools = createClawdisCodingTools();
const readTool = tools.find((tool) => tool.name === "read");
expect(readTool).toBeDefined();
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdis-read-"));
try {
const textPath = path.join(tmpDir, "sample.txt");
const contents = "Hello from clawdis read tool.";
await fs.writeFile(textPath, contents, "utf8");
const result = await readTool?.execute("tool-2", {
path: textPath,
});
expect(result?.content?.some((block) => block.type === "image")).toBe(
false,
);
const textBlocks = result?.content?.filter(
(block) => block.type === "text",
) as Array<{ text?: string }> | undefined;
expect(textBlocks?.length ?? 0).toBeGreaterThan(0);
const combinedText = textBlocks
?.map((block) => block.text ?? "")
.join("\n");
expect(combinedText).toContain(contents);
} finally {
await fs.rm(tmpDir, { recursive: true, force: true });
}
});
});