From bdfb97994058f2fd0240f309f6ecdd9ddb940047 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 21 Feb 2026 19:36:52 +0000 Subject: [PATCH] test(cli): dedupe camera fetch stubs and cover empty-body download rejection --- src/cli/nodes-camera.test.ts | 38 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/cli/nodes-camera.test.ts b/src/cli/nodes-camera.test.ts index 9834d8521..73e0fce84 100644 --- a/src/cli/nodes-camera.test.ts +++ b/src/cli/nodes-camera.test.ts @@ -22,6 +22,13 @@ async function withTempDir(prefix: string, run: (dir: string) => Promise): } describe("nodes camera helpers", () => { + function stubFetchResponse(response: Response) { + vi.stubGlobal( + "fetch", + vi.fn(async () => response), + ); + } + it("parses camera.snap payload", () => { expect( parseCameraSnapPayload({ @@ -97,10 +104,7 @@ describe("nodes camera helpers", () => { }); it("writes url payload to file", async () => { - vi.stubGlobal( - "fetch", - vi.fn(async () => new Response("url-content", { status: 200 })), - ); + stubFetchResponse(new Response("url-content", { status: 200 })); await withTempDir("openclaw-test-", async (dir) => { const out = path.join(dir, "x.bin"); await writeUrlToFile(out, "https://example.com/clip.mp4"); @@ -115,15 +119,11 @@ describe("nodes camera helpers", () => { }); it("rejects oversized content-length for url payload", async () => { - vi.stubGlobal( - "fetch", - vi.fn( - async () => - new Response("tiny", { - status: 200, - headers: { "content-length": String(999_999_999) }, - }), - ), + stubFetchResponse( + new Response("tiny", { + status: 200, + headers: { "content-length": String(999_999_999) }, + }), ); await expect(writeUrlToFile("/tmp/ignored", "https://example.com/huge.bin")).rejects.toThrow( /exceeds max/i, @@ -131,14 +131,18 @@ describe("nodes camera helpers", () => { }); it("rejects non-ok https url payload responses", async () => { - vi.stubGlobal( - "fetch", - vi.fn(async () => new Response("down", { status: 503, statusText: "Service Unavailable" })), - ); + stubFetchResponse(new Response("down", { status: 503, statusText: "Service Unavailable" })); await expect(writeUrlToFile("/tmp/ignored", "https://example.com/down.bin")).rejects.toThrow( /503/i, ); }); + + it("rejects empty https response body", async () => { + stubFetchResponse(new Response(null, { status: 200 })); + await expect(writeUrlToFile("/tmp/ignored", "https://example.com/empty.bin")).rejects.toThrow( + /empty response body/i, + ); + }); }); describe("nodes screen helpers", () => {