fix(coding-agent): process BMP images from disk

closes #6047
This commit is contained in:
Armin Ronacher
2026-06-25 12:51:21 +02:00
parent 6ca7ba7c05
commit 4cc339f58d
9 changed files with 329 additions and 67 deletions
+34
View File
@@ -34,6 +34,22 @@ function getTextOutput(result: any): string {
);
}
function createTinyBmp1x1Red24bpp(): Buffer {
const buffer = Buffer.alloc(58);
buffer.write("BM", 0, "ascii");
buffer.writeUInt32LE(buffer.length, 2);
buffer.writeUInt32LE(54, 10);
buffer.writeUInt32LE(40, 14);
buffer.writeInt32LE(1, 18);
buffer.writeInt32LE(1, 22);
buffer.writeUInt16LE(1, 26);
buffer.writeUInt16LE(24, 28);
buffer.writeUInt32LE(0, 30);
buffer.writeUInt32LE(4, 34);
buffer[56] = 0xff;
return buffer;
}
describe("Coding Agent Tools", () => {
let testDir: string;
@@ -191,6 +207,24 @@ describe("Coding Agent Tools", () => {
expect((imageBlock?.data ?? "").length).toBeGreaterThan(0);
});
it("should read BMP files from disk as PNG image attachments", async () => {
const testFile = join(testDir, "image.bmp");
writeFileSync(testFile, createTinyBmp1x1Red24bpp());
const result = await readTool.execute("test-call-img-bmp", { path: testFile });
expect(result.content[0]?.type).toBe("text");
expect(getTextOutput(result)).toContain("Read image file [image/png]");
expect(getTextOutput(result)).toContain("[Image converted from image/bmp to image/png.]");
const imageBlock = result.content.find(
(c): c is { type: "image"; mimeType: string; data: string } => c.type === "image",
);
expect(imageBlock).toBeDefined();
expect(imageBlock?.mimeType).toBe("image/png");
expect(Buffer.from(imageBlock?.data ?? "", "base64")[0]).toBe(0x89);
});
it("should treat files with image extension but non-image content as text", async () => {
const testFile = join(testDir, "not-an-image.png");
writeFileSync(testFile, "definitely not a png");