From 296be393b5e45dcffec5a3a967386faad67136ee Mon Sep 17 00:00:00 2001 From: Aiden Cline Date: Sun, 10 May 2026 23:50:58 -0500 Subject: [PATCH] fix, rm early return --- packages/opencode/src/image/image.ts | 7 +------ packages/opencode/test/image/image.test.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/opencode/src/image/image.ts b/packages/opencode/src/image/image.ts index aec8e2b1ff..05830989a1 100644 --- a/packages/opencode/src/image/image.ts +++ b/packages/opencode/src/image/image.ts @@ -84,7 +84,6 @@ export const layer = Layer.effect( const base64 = input.url.slice(input.url.indexOf(";base64,") + ";base64,".length) const bytes = Buffer.byteLength(base64, "utf8") - if (bytes <= info.maxBase64Bytes) return input const photon = yield* loadPhoton @@ -99,11 +98,7 @@ export const layer = Layer.effect( try { const originalWidth = decoded.get_width() const originalHeight = decoded.get_height() - if ( - originalWidth <= info.maxWidth && - originalHeight <= info.maxHeight && - bytes <= info.maxBase64Bytes - ) + if (originalWidth <= info.maxWidth && originalHeight <= info.maxHeight && bytes <= info.maxBase64Bytes) return input if (!info.autoResize) return yield* new SizeError({ diff --git a/packages/opencode/test/image/image.test.ts b/packages/opencode/test/image/image.test.ts index bf5c0b3948..27b1326812 100644 --- a/packages/opencode/test/image/image.test.ts +++ b/packages/opencode/test/image/image.test.ts @@ -57,6 +57,23 @@ describe("Image", () => { }), ) + it.effect("resizes images that fit the byte limit but exceed dimension limits", () => + Effect.gen(function* () { + const photon = yield* Effect.promise(() => import("@silvia-odwyer/photon-node")) + const source = new photon.PhotonImage(new Uint8Array(Array.from({ length: 9_000 * 4 }, () => 255)), 9_000, 1) + const image = yield* Image.Service + const result = yield* image.normalize(part("image/png", Buffer.from(source.get_bytes()).toString("base64"))) + const resized = photon.PhotonImage.new_from_byteslice( + Buffer.from(result.url.slice(result.url.indexOf(";base64,") + ";base64,".length), "base64"), + ) + + source.free() + expect(resized.get_width()).toBeLessThanOrEqual(2_000) + expect(resized.get_height()).toBeLessThanOrEqual(2_000) + resized.free() + }), + ) + tiny.effect("fails with a typed size error when no resized candidate fits", () => Effect.gen(function* () { const photon = yield* Effect.promise(() => import("@silvia-odwyer/photon-node"))