import { computeContentHash } from "../../src/crypto"; describe("computeContentHash", () => { test("returns an 8-character lowercase hex string", async () => { const hash = await computeContentHash("hello world"); expect(hash).toMatch(/^[0-9a-f]{8}$/); }); test("is deterministic for the same string input", async () => { const a = await computeContentHash("same content"); const b = await computeContentHash("same content"); expect(a).toBe(b); }); test("is deterministic for the same Uint8Array input", async () => { const data = new Uint8Array([1, 2, 3, 4, 5]); const a = await computeContentHash(data); const b = await computeContentHash(data); expect(a).toBe(b); }); test("produces different hashes for different inputs", async () => { const a = await computeContentHash("content A"); const b = await computeContentHash("content B"); expect(a).not.toBe(b); }); test("string and its UTF-8 Uint8Array encoding produce the same hash", async () => { const str = "hello"; const bytes = new TextEncoder().encode(str); const fromString = await computeContentHash(str); const fromBytes = await computeContentHash(bytes); expect(fromString).toBe(fromBytes); }); test("handles empty string", async () => { const hash = await computeContentHash(""); expect(hash).toMatch(/^[0-9a-f]{8}$/); }); test("handles empty Uint8Array", async () => { const hash = await computeContentHash(new Uint8Array(0)); expect(hash).toMatch(/^[0-9a-f]{8}$/); }); });