38 lines · 3.0 KB · TypeScriptRaw
/** * An erase a phone sends (`delete` with `erase`) beside the rest of the object, as phones and objects update unevenly * (CONTRACT.md "WhatsApp through the Mac", 23 Nov 2026). These hold on the object before the erase wire as after it: * run against the object as deployed before it (src/ of 0e86677ca2), they pass too. Every id and word is invented. */import { describe, expect, it } from "vitest";import { answer, http, personalObject } from "./personal.ts";async function act(slug: string, credential: string, name: string, args: Record<string, unknown>) { return http<Record<string, unknown>>(slug, "POST", "/v1/act", { act: name, args }, { authorization: `Bearer ${credential}` });}/** RULE (coordinator, 23 Nov 2026): a phone's erase is never refused and never stalls what follows it; an object that does not know it takes it as a plain delete; and no other row loses its undo. */describe("an erase beside everything else", () => { it("lands as a delete, the next write lands after it, and an edit elsewhere keeps its undo", async () => { const slug = "erase-compat"; const { credential, owner } = await personalObject(slug, { open: ["thread", "message", "note"] }); expect((await act(slug, credential, "create", { table: "thread", id: "t-c", data: { title: "Invented chat" } })).status).toBe(200); expect((await act(slug, credential, "create", { table: "message", id: "m-c", data: { thread_id: "t-c", channel: "whatsapp", body: "an invented line", sent_at: "2026-11-21T08:00:00.000Z" } })).status).toBe(200); const note = await answer<{ record: { id: string } }>(slug, owner, "create_record", { table: "note", data: { title: "Invented note" } }); const edited = await answer<{ change_id: number }>(slug, owner, "update_record", { table: "note", id: note.record.id, patch: { title: "Invented note, edited" } }); const erased = await act(slug, credential, "delete", { table: "message", id: "m-c", erase: "disappeared" }); expect(erased.status, JSON.stringify(erased.body)).toBe(200); // Sent again (a phone that did not hear the answer): no such record, which the phone takes as done. const again = await act(slug, credential, "delete", { table: "message", id: "m-c", erase: "disappeared" }); expect([200, 404]).toContain(again.status); expect((await act(slug, credential, "create", { table: "message", id: "m-next", data: { thread_id: "t-c", channel: "whatsapp", body: "the next one", sent_at: "2026-11-21T09:00:00.000Z" } })).status).toBe(200); const pulled = await http<{ rows: { id: string; deleted?: boolean }[] }>(slug, "GET", "/v1/sync?since=0", undefined, { authorization: `Bearer ${credential}` }); expect(pulled.body.rows.find((r) => r.id === "m-c")?.deleted).toBe(true); expect(pulled.body.rows.find((r) => r.id === "m-next")?.deleted).toBeUndefined(); const undone = await answer<{ record: { data: Record<string, unknown> } }>(slug, owner, "undo", { change_id: edited.change_id }); expect(undone.record.data.title).toBe("Invented note"); });});