From 5f82739e2b36fd756169c32959937e7911c8ed53 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 2 Jan 2026 17:49:20 +0100 Subject: [PATCH] test: cover camera snap mime mapping --- CHANGELOG.md | 1 + src/agents/clawdis-tools.camera.test.ts | 53 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/agents/clawdis-tools.camera.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index aadfe9650..1185280cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,7 @@ - macOS codesign: skip hardened runtime for ad-hoc signing and avoid empty options args (#70) — thanks @petter-b - macOS codesign: include camera entitlement so permission prompts work in the menu bar app. - Agent tools: map `camera.snap` JPEG payloads to `image/jpeg` to avoid MIME mismatch errors. +- Tests: cover `camera.snap` MIME mapping to prevent image/png vs image/jpeg mismatches. - macOS packaging: move rpath config into swift build for reliability (#69) — thanks @petter-b - macOS: prioritize main bundle for device resources to prevent crash (#73) — thanks @petter-b - macOS remote: route settings through gateway config and avoid local config reads in remote mode. diff --git a/src/agents/clawdis-tools.camera.test.ts b/src/agents/clawdis-tools.camera.test.ts new file mode 100644 index 000000000..d292f5ca9 --- /dev/null +++ b/src/agents/clawdis-tools.camera.test.ts @@ -0,0 +1,53 @@ +import { beforeEach, describe, expect, it, vi } from "vitest"; + +const callGateway = vi.fn(); + +vi.mock("../gateway/call.js", () => ({ callGateway })); +vi.mock("../media/image-ops.js", () => ({ + getImageMetadata: vi.fn(async () => ({ width: 1, height: 1 })), + resizeToJpeg: vi.fn(async () => Buffer.from("jpeg")), +})); + +import { createClawdisTools } from "./clawdis-tools.js"; + +describe("clawdis_nodes camera_snap", () => { + beforeEach(() => { + callGateway.mockReset(); + }); + + it("maps jpg payloads to image/jpeg", async () => { + callGateway.mockImplementation(async ({ method }) => { + if (method === "node.list") { + return { nodes: [{ nodeId: "mac-1" }] }; + } + if (method === "node.invoke") { + return { + payload: { + format: "jpg", + base64: "aGVsbG8=", + width: 1, + height: 1, + }, + }; + } + throw new Error(`unexpected method: ${String(method)}`); + }); + + const tool = createClawdisTools().find( + (candidate) => candidate.name === "clawdis_nodes", + ); + if (!tool) throw new Error("missing clawdis_nodes tool"); + + const result = await tool.execute("call1", { + action: "camera_snap", + node: "mac-1", + facing: "front", + }); + + const images = (result.content ?? []).filter( + (block) => block.type === "image", + ); + expect(images).toHaveLength(1); + expect(images[0]?.mimeType).toBe("image/jpeg"); + }); +});