Download src/media/image-processor.pixel-limits.test.ts from SaylorTwift/openclaw: direct link, hf CLI and curl.
- Browser
- Download file 1.54 kB
-
https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/media/image-processor.pixel-limits.test.ts
- Command line
-
hf download hf://SaylorTwift/openclaw/src/media/image-processor.pixel-limits.test.ts
-
curl -L -o image-processor.pixel-limits.test.ts https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/media/image-processor.pixel-limits.test.ts
1.54 kB
| import { describe, expect, it } from "vitest"; | |
| import { createImageProcessor, createImageProcessorWithPixelLimits } from "./image-processor.js"; | |
| const image = Buffer.from( | |
| "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAEUlEQVR4nGMwSJiAFTEMLQkACmxIAasRElQAAAAASUVORK5CYII=", | |
| "base64", | |
| ); | |
| describe("operation-specific pixel limits through the image worker", () => { | |
| it("keeps local probes, worker encodes and later default requests consistent", async () => { | |
| const restricted = createImageProcessorWithPixelLimits({ inputPixels: 32, outputPixels: 16 }); | |
| expect(await restricted.probe(image)).toBeNull(); | |
| await expect( | |
| restricted.encode(image, { format: "png", resize: { maxSide: 4 } }), | |
| ).rejects.toThrow(); | |
| const downscale = createImageProcessorWithPixelLimits({ inputPixels: 64, outputPixels: 16 }); | |
| expect(await downscale.probe(image)).toMatchObject({ width: 8, height: 8 }); | |
| const encoded = await downscale.encode(image, { format: "png", resize: { maxSide: 4 } }); | |
| expect(encoded).toMatchObject({ width: 4, height: 4, format: "png" }); | |
| expect(encoded.data.length).toBeGreaterThan(0); | |
| await expect(downscale.encode(image, { format: "png" })).rejects.toMatchObject({ | |
| code: "RASTERMILL_OUTPUT_TOO_LARGE", | |
| }); | |
| // A scoped downscale limit must not change the shared worker's subsequent default policy. | |
| const normal = await createImageProcessor().encode(image, { format: "png" }); | |
| expect(normal).toMatchObject({ width: 8, height: 8, format: "png" }); | |
| }); | |
| }); | |