fix(media): strip MEDIA: prefix in loadWebMediaInternal (#13107)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 9d95e6af5a
Co-authored-by: mcaxtr <7562095+mcaxtr@users.noreply.github.com>
Co-authored-by: steipete <58493+steipete@users.noreply.github.com>
Reviewed-by: @steipete
This commit is contained in:
Marcus Castro
2026-02-14 17:41:26 -03:00
committed by GitHub
parent 1bde33c0bc
commit 07850e8a93
9 changed files with 110 additions and 40 deletions

View File

@@ -108,6 +108,51 @@ describe("web media loading", () => {
});
});
it("strips MEDIA: prefix before reading local file", async () => {
const buffer = await sharp({
create: { width: 2, height: 2, channels: 3, background: "#0000ff" },
})
.png()
.toBuffer();
const file = await writeTempFile(buffer, ".png");
const result = await loadWebMedia(`MEDIA:${file}`, 1024 * 1024);
expect(result.kind).toBe("image");
expect(result.buffer.length).toBeGreaterThan(0);
});
it("strips MEDIA: prefix with whitespace after colon", async () => {
const buffer = await sharp({
create: { width: 2, height: 2, channels: 3, background: "#0000ff" },
})
.png()
.toBuffer();
const file = await writeTempFile(buffer, ".png");
const result = await loadWebMedia(`MEDIA: ${file}`, 1024 * 1024);
expect(result.kind).toBe("image");
expect(result.buffer.length).toBeGreaterThan(0);
});
it("strips MEDIA: prefix with extra whitespace (LLM-friendly)", async () => {
const buffer = await sharp({
create: { width: 2, height: 2, channels: 3, background: "#0000ff" },
})
.png()
.toBuffer();
const file = await writeTempFile(buffer, ".png");
const result = await loadWebMedia(` MEDIA : ${file}`, 1024 * 1024);
expect(result.kind).toBe("image");
expect(result.buffer.length).toBeGreaterThan(0);
});
it("compresses large local images under the provided cap", async () => {
const { buffer, file } = await createLargeTestJpeg();