clone

a deno framework for local-first web apps that open instantly, work offline and sync when users choose

feat/fix-sync-enrollment-startup
lofi / package / runtime / inspector_test.ts
inspector_test.ts 2.1K
1import { inspectorRows, type InspectorSnapshot } from "./inspector.ts";2// Package contract tests.34const test = (globalThis as unknown as {5 Deno: { test(name: string, body: () => void | Promise<void>): void };6}).Deno.test;78function assert(condition: unknown, message: string): asserts condition {9 if (!condition) throw new Error(message);10}1112const snapshot: InspectorSnapshot = {13 identity: { state: "device-local key active", backup: "recovery phrase" },14 storage: {15 driver: "persistent open",16 persistence: "granted",17 fallback: "none",18 startupFailure: "broker-incompatible",19 },20 sync: {21 mode: "managed configured",22 transport: "live detail unavailable",23 store: "no schema deployed — provision the store",24 pendingLocalWrites: 1,25 pendingGlobalWrites: 2,26 lastWrite: "local",27 },28 runtime: {29 clients: 1,30 consumers: 2,31 vendorSubscriptions: 1,32 mutationListeners: 1,33 mutationErrors: 0,34 },35 lifecycle: {36 mode: "managed",37 status: "completed",38 attempts: 2,39 lastReason: "visibilitychange",40 transportDetail: "live detail unavailable",41 },42 multiTab: {43 role: "unavailable",44 detail: "Jazz alpha.53 exposes no supported leader/follower signal",45 },46};4748test("inspector rows retain truthful unavailable and pending states", () => {49 const rows = Object.fromEntries(inspectorRows(snapshot).map((row) => [row.label, row.value]));50 assert(rows.Transport === "live detail unavailable", "transport precision was fabricated");51 assert(rows["Pending lofi local"] === "1", "local pending work was omitted");52 assert(rows["Pending lofi global"] === "2", "global pending work was omitted");53 assert(54 rows["Storage startup"] === "broker-incompatible",55 "startup failure classification was omitted",56 );57 assert(58 rows.Store === "no schema deployed — provision the store",59 "the store preflight state was omitted",60 );61 assert(rows["Multi-tab role"] === "unavailable", "multi-tab role was fabricated");62 assert(!JSON.stringify(rows).includes("secret"), "inspector rows exposed a secret-shaped field");63});