1import { MAX_BLOB_BYTES, MAX_UNIQUE_BLOBS } from "./limits.ts";2import { validateManifest } from "./manifest.ts";3import type { Manifest } from "./types.ts";45function manifestWithUniqueBlobs(count: number): Manifest {6 const files: Manifest["files"] = {};7 for (let i = 0; i < count; i++) {8 files[`file-${i}.txt`] = {9 h: i.toString(16).padStart(64, "0"),10 s: 1,11 ct: "text/plain",12 };13 }14 return { v: 1, files };15}1617function assertThrows(fn: () => void, message: string): void {18 try {19 fn();20 } catch (error) {21 if (error instanceof Error && error.message.includes(message)) return;22 throw error;23 }24 throw new Error(`expected error containing: ${message}`);25}2627Deno.test("manifest accepts the Workers Free unique-blob ceiling", () => {28 validateManifest(manifestWithUniqueBlobs(MAX_UNIQUE_BLOBS));29});3031Deno.test("manifest rejects one unique blob above the Workers Free ceiling", () => {32 assertThrows(33 () => validateManifest(manifestWithUniqueBlobs(MAX_UNIQUE_BLOBS + 1)),34 `too many unique blobs (max ${MAX_UNIQUE_BLOBS})`,35 );36});3738Deno.test("duplicate hashes do not consume additional unique-blob capacity", () => {39 const manifest = manifestWithUniqueBlobs(MAX_UNIQUE_BLOBS);40 manifest.files["duplicate.txt"] = { ...manifest.files["file-0.txt"] };41 validateManifest(manifest);42 if (Object.keys(manifest.files).length !== MAX_UNIQUE_BLOBS + 1) {43 throw new Error("duplicate manifest entry was not retained");44 }45});4647Deno.test("manifest rejects blobs larger than the upload limit", () => {48 const manifest = manifestWithUniqueBlobs(1);49 manifest.files["file-0.txt"].s = MAX_BLOB_BYTES + 1;50 assertThrows(() => validateManifest(manifest), "blob too large");51});