Files
oh-my-pi/packages/coding-agent/test/image-input-normalization.test.ts
T
can1357 af07faec11 feat: Bun 1.3.14
- Raised the Bun minimum version to >=1.3.14 across package metadata, install scripts, and changelog notes.
- Removed the Photon native image pipeline and added SIXEL-based `sixel` support in pi-natives.
- Migrated coding-agent image handling and resizing to `Bun.Image`, including updated tests and a JPEG quality bump to 80.
- Added HTTP/2 fetch bootstrap with HTTPS-only fallback and updated Bun build flags for autoload suppression/`--keep-names`.
2026-05-13 13:21:59 +02:00

44 lines
1.6 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { ensureSupportedImageInput } from "../src/utils/image-loading";
// 1x1 red PNG (69 bytes). Bun.Image sniffs format from bytes, so we can pass
// this with a non-supported MIME type and the conversion path runs over the
// real native pipeline.
const RED_1X1_PNG_BASE64 =
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGP4z8AAAAMBAQDJ/pLvAAAAAElFTkSuQmCC";
describe("ensureSupportedImageInput", () => {
test("passes supported mime types through unchanged", async () => {
const input = { type: "image" as const, data: RED_1X1_PNG_BASE64, mimeType: "image/png" };
const result = await ensureSupportedImageInput(input);
expect(result).toEqual(input);
});
test("converts unsupported image input to png", async () => {
const result = await ensureSupportedImageInput({
type: "image",
data: RED_1X1_PNG_BASE64,
mimeType: "image/bmp",
});
expect(result).not.toBeNull();
expect(result?.mimeType).toBe("image/png");
// PNG re-encode of a 1x1 image must yield a valid (non-empty) PNG signature
// (`89 50 4E 47`) when decoded from base64.
const bytes = Buffer.from(result!.data, "base64");
expect(bytes.length).toBeGreaterThan(0);
expect(bytes[0]).toBe(0x89);
expect(bytes[1]).toBe(0x50);
expect(bytes[2]).toBe(0x4e);
expect(bytes[3]).toBe(0x47);
});
test("returns null when input bytes are not a decodable image", async () => {
const result = await ensureSupportedImageInput({
type: "image",
data: Buffer.from("not an image").toString("base64"),
mimeType: "image/bmp",
});
expect(result).toBeNull();
});
});