import { describe, expect, it, vi } from "vitest"; import { http, personalObject } from "./personal.ts"; const seal = (bytes: number) => `s1:${"A".repeat(Math.ceil((bytes * 4) / 3))}`; const dek = () => `d1:${"B".repeat(80)}`; const email = (id: string, bytes: number) => ({ act: "create", args: { table: "email", id, import: true, data: { thread_id: "t1", sent_at: "2011-03-04T10:00:00.000Z", sealed_enc: seal(bytes), dek_enc: dek(), seal_v: 1 } } }); describe("a row too large for the object's SQLite", () => { it("is refused in words (413 row_too_large), never a 500, and the next row still lands", async () => { const { credential } = await personalObject("big-row"); const auth = { authorization: `Bearer ${credential}` }; const thread = await http("big-row", "POST", "/v1/act", { act: "create", args: { table: "email_thread", id: "t1", import: true, data: { first_at: "2011-03-04T10:00:00.000Z", last_at: "2011-03-04T10:00:00.000Z", sealed_enc: seal(200), dek_enc: dek(), seal_v: 1 } } }, auth); expect(thread.status, JSON.stringify(thread.body)).toBe(200); const quiet = vi.spyOn(console, "error").mockImplementation(() => {}); // 12 MiB sealed: the dev Worker answered this 500 internal_error (23 Nov 2026). const big = await http<{ code: string; message: string }>("big-row", "POST", "/v1/act", email("e-big", 12 * 1024 * 1024), auth); quiet.mockRestore(); expect(big.status, JSON.stringify(big.body)).toBe(413); expect(big.body.code).toBe("row_too_large"); expect(big.body.message).toMatch(/^email e-big is too large to keep \(\d+ characters\)/); const small = await http("big-row", "POST", "/v1/act", email("e-small", 4096), auth); expect(small.status, JSON.stringify(small.body)).toBe(200); const update = await http<{ code: string }>("big-row", "POST", "/v1/act", { ...email("e-small", 12 * 1024 * 1024), act: "update" }, auth); expect(update.status, JSON.stringify(update.body)).toBe(413); expect(update.body.code).toBe("row_too_large"); }); });