{"file":"server/test/blobs.test.ts","version":318,"total":44,"from":1,"to":44,"lines":[{"n":1,"text":"import assert from \"node:assert/strict\";","atom":"a1466","author":"speed","version":150},{"n":2,"text":"import { createHash } from \"node:crypto\";","atom":"a1466","author":"speed","version":150},{"n":3,"text":"import { before, describe, it } from \"node:test\";","atom":"a1466","author":"speed","version":150},{"n":4,"text":"import { BlobStore } from \"../src/blobs.ts\";","atom":"a1466","author":"speed","version":150},{"n":5,"text":"import { installDigestStream, memoryStorage, streamOf } from \"./helpers.ts\";","atom":"a1466","author":"speed","version":150},{"n":6,"text":"","atom":"a1466","author":"speed","version":150},{"n":7,"text":"const sha = (text: string) => createHash(\"sha256\").update(text).digest(\"hex\");","atom":"a1466","author":"speed","version":150},{"n":8,"text":"","atom":"a1466","author":"speed","version":150},{"n":9,"text":"describe(\"the blob store\", () => {","atom":"a1466","author":"speed","version":150},{"n":10,"text":"\tbefore(installDigestStream);","atom":"a1466","author":"speed","version":150},{"n":11,"text":"","atom":"a1466","author":"speed","version":150},{"n":12,"text":"\tit(\"keeps bytes whose SHA-256 is their name\", async () => {","atom":"a1466","author":"speed","version":150},{"n":13,"text":"\t\tconst store = new BlobStore(memoryStorage());","atom":"a1466","author":"speed","version":150},{"n":14,"text":"\t\tconst a = await store.put(sha(\"hello\"), streamOf(\"hello\"));","atom":"a1466","author":"speed","version":150},{"n":15,"text":"\t\tassert.deepEqual(a, { status: 200, body: { sha256: sha(\"hello\"), size: 5, stored: true } });","atom":"a1466","author":"speed","version":150},{"n":16,"text":"\t\tassert.equal(store.has(sha(\"hello\")), true);","atom":"a1466","author":"speed","version":150},{"n":17,"text":"\t\tassert.equal(new TextDecoder().decode(store.read(sha(\"hello\"))!), \"hello\");","atom":"a1466","author":"speed","version":150},{"n":18,"text":"\t\tconst again = await store.put(sha(\"hello\"), streamOf(\"hello\"));","atom":"a1466","author":"speed","version":150},{"n":19,"text":"\t\tassert.equal((again.body as { stored: boolean }).stored, false);","atom":"a1466","author":"speed","version":150},{"n":20,"text":"\t});","atom":"a1466","author":"speed","version":150},{"n":21,"text":"","atom":"a1466","author":"speed","version":150},{"n":22,"text":"\tit(\"refuses bytes that hash to something else, and keeps nothing\", async () => {","atom":"a1466","author":"speed","version":150},{"n":23,"text":"\t\tconst store = new BlobStore(memoryStorage());","atom":"a1466","author":"speed","version":150},{"n":24,"text":"\t\tconst a = await store.put(sha(\"hello\"), streamOf(\"goodbye\"));","atom":"a1466","author":"speed","version":150},{"n":25,"text":"\t\tassert.equal(a.status, 400);","atom":"a1466","author":"speed","version":150},{"n":26,"text":"\t\tassert.match((a.body as { error: string }).error, new RegExp(`hash to ${sha(\"goodbye\")}`));","atom":"a1466","author":"speed","version":150},{"n":27,"text":"\t\tassert.equal(store.has(sha(\"hello\")), false);","atom":"a1466","author":"speed","version":150},{"n":28,"text":"\t\tassert.equal(store.has(sha(\"goodbye\")), false);","atom":"a1466","author":"speed","version":150},{"n":29,"text":"\t\tassert.deepEqual(store.list(\"\", 10), { blobs: [], next: null });","atom":"a1466","author":"speed","version":150},{"n":30,"text":"\t});","atom":"a1466","author":"speed","version":150},{"n":31,"text":"","atom":"a1466","author":"speed","version":150},{"n":32,"text":"\tit(\"refuses a name that isn't a lowercase SHA-256\", async () => {","atom":"a1466","author":"speed","version":150},{"n":33,"text":"\t\tconst store = new BlobStore(memoryStorage());","atom":"a1466","author":"speed","version":150},{"n":34,"text":"\t\tassert.equal((await store.put(\"abc\", streamOf(\"x\"))).status, 400);","atom":"a1466","author":"speed","version":150},{"n":35,"text":"\t\tassert.equal((await store.put(sha(\"x\").toUpperCase(), streamOf(\"x\"))).status, 400);","atom":"a1466","author":"speed","version":150},{"n":36,"text":"\t});","atom":"a1466","author":"speed","version":150},{"n":37,"text":"","atom":"a1466","author":"speed","version":150},{"n":38,"text":"\tit(\"refuses a blob over the size cap\", async () => {","atom":"a1466","author":"speed","version":150},{"n":39,"text":"\t\tconst store = new BlobStore(memoryStorage());","atom":"a1466","author":"speed","version":150},{"n":40,"text":"\t\tconst a = await store.put(sha(\"too big\"), streamOf(\"too big\"), 3);","atom":"a1466","author":"speed","version":150},{"n":41,"text":"\t\tassert.equal(a.status, 413);","atom":"a1466","author":"speed","version":150},{"n":42,"text":"\t\tassert.equal(store.total(), 0);","atom":"a1466","author":"speed","version":150},{"n":43,"text":"\t});","atom":"a1466","author":"speed","version":150},{"n":44,"text":"});","atom":"a1466","author":"speed","version":150}],"atoms":[{"atom":"a1466","author":"speed","message":"","time":1791907182721,"timeIso":"2026-10-13T15:59:42.721Z","publish":{"draft":null,"version":150,"agent":"speed","message":"Open server: the project Worker, Durable Object and Artifacts (issue 17)","time":1791907522179,"timeIso":"2026-10-13T16:05:22.179Z"}}]}