/** * RESTORE PROOF (coordinator, 27 Nov 2026): the admin routes over Durable Object point-in-time recovery. The admin token * alone; dev and test Workers alone. PITR itself does not run in local development (Cloudflare's docs: no durable log is * kept locally), so here the routes must say so plainly (501 pitr_unavailable) or answer a bookmark: never pretend. The * restore itself is proved on the dev Worker by its restore proof script. */import { describe, expect, it } from"vitest";import { ADMIN, http, personalObject } from"./personal.ts";describe("point-in-time recovery's admin routes", () => {const slug = "restore-proof"; it("take the admin token alone, and answer a bookmark or say plainly that this runtime has none", async () => {const { owner } = await personalObject(slug); expect((await http(slug, "GET", "/v1/admin/restore/bookmark", undefined, { authorization: `Bearer ${owner}` })).status).toBe(403); expect((await http(slug, "POST", "/v1/admin/restore", { bookmark: "x" }, { authorization: `Bearer ${owner}` })).status).toBe(403);const got = await http<{ now?: string; code?: string }>(slug, "GET", "/v1/admin/restore/bookmark", undefined, ADMIN);if (got.status === 200) expect(got.body.now).toMatch(/^[0-9a-f-]+$/);else expect([got.status, got.body.code]).toEqual([501, "pitr_unavailable"]);// RESTORE 2: a restore is asked only on a frozen account, with the bookmark and the moment it stands for. expect((await http<{ code: string }>(slug, "POST", "/v1/admin/restore", { bookmark: "x", restored_to: newDate().toISOString() }, ADMIN)).body.code).toBe("not_frozen"); expect((await http(slug, "POST", "/v1/admin/restore/freeze", {}, ADMIN)).status).toBe(200); expect((await http(slug, "POST", "/v1/admin/restore", {}, ADMIN)).status).toBe(400);// Locally the restore itself is refused in Cloudflare's words (no durable log kept here); on dev it answers an undo bookmark.const restore = await http<{ undo?: string; code?: string }>(slug, "POST", "/v1/admin/restore", { bookmark: got.body.now ?? "x", restored_to: newDate().toISOString(), override_devices: true }, ADMIN);if (restore.status === 200) expect(restore.body.undo).toMatch(/^[0-9a-f-]+$/);else expect([restore.status, restore.body.code]).toEqual([501, "pitr_unavailable"]);const counted = await http<{ rows?: number }>(slug, "GET", "/v1/admin/restore/bookmark?table=note", undefined, ADMIN); expect(typeof counted.body.rows).toBe("number"); expect((await http(slug, "POST", "/v1/admin/restore/unfreeze", {}, ADMIN)).status).toBe(200); });});