Fix #15: distinguish too-large clipboard images from empty - #23
Conversation
- readClipboardImage now returns a tagged result: {ok:true, image} |
{ok:false, reason:'empty'} | {ok:false, reason:'too_large', sizeBytes}
- exported MAX_IMAGE_BYTES so the repl can render the cap in the message
- ctrl+v handler in repl.ts shows the actual size + limit (was: silently
reported 'No image on the clipboard' for any image over 8MB, e.g. a
full-screen Retina screenshot)
- added src/utils/clipboard-image.test.ts covering too_large / success /
empty via a mocked spawnSync
mock.module('node:child_process', ...) replaces the module globally and
broke other tests that import spawn (headless-agent.test.ts). Exposed
wrapPng as a pure exported function and test that directly instead.
|
🤖 KlaatAI Review Bot (powered by Klaatu, advisory only — a maintainer makes the real call) Issue match Test coverage Correctness concerns Verdict This is an automated review to help triage faster, not a gate. Nothing here blocks merging. |
Fixes #15
What changed
readClipboardImage()returnednullfor both "no image on clipboard" and "image found but > 8MB", so pressingctrl+von a real Retina full-screen screenshot silently showed"No image on the clipboard"even though an image was there.src/utils/clipboard-image.tsReturn type changed to a discriminated union so callers can tell the two apart:
wrapPng(buf)helper that picks the right outcome based on sizeMAX_IMAGE_BYTESis now exported (callers want to render the cap in messages)fromMac/fromLinux/fromWindows) returnsnullonly on "no image at all", andreadClipboardImagecollapses that to{ ok: false, reason: "empty" }src/screens/repl.ts(ctrl+v handler, line ~4318)On
reason: "too_large", render:The
emptycase keeps the existing"No image on the clipboard..."message.src/utils/clipboard-image.test.ts(new)Covers the three observable states by mocking
node:child_process.spawnSyncto return a 13.9MB, 1KB, and failing osascript invocation against the darwin path:{ ok:false, reason:"too_large", sizeBytes }{ ok:true, image:{ mime:"image/png", b64 }}{ ok:false, reason:"empty" }MAX_IMAGE_BYTES === 8 * 1024 * 1024Verification
tsc --noEmitcleantsc --noEmit -p tests-tsconfig.jsonclean (only the standard `bun:test` type-resolution noise that already affects every test file)Follow-ups (not in this PR)
Issue suggests an optional follow-up to auto-downscale / re-encode an oversized clipboard image to JPEG before giving up. Left out intentionally to keep this fix minimal and reviewable.