clone

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

feat/141-demo-review-fixes
lofi / package / scenario_sync_test.ts
scenario_sync_test.ts 2.1K
1// The scenario DSL against a real local Jazz server: the worked2// offline-rename-versus-remote-delete example, cross-peer visibility through3// converge, and a fixed-seed fuzz smoke run. Runs in its own task4// (test:scenario) because the server needs FFI.5import { schema as s } from "jazz-tools";6import { assertNoRow, assertRow, assertRowCount, converge, scenario } from "./testing/mod.ts";78const app = s.defineApp({9 documents: s.table({ title: s.string() }),10});11const permissions = s.definePermissions(app, ({ policy }) => {12 policy.documents.allowInsert.always();13 policy.documents.allowRead.always();14 policy.documents.allowUpdate.always();15 policy.documents.allowDelete.always();16});1718scenario("offline rename versus remote delete", { app, permissions }, async ({ alice, bob }) => {19 const doc = await alice.db.documents.insert({ title: "Untitled" });20 await converge(alice, bob);21 await assertRow(bob, app.documents, doc.id, { title: "Untitled" });2223 await alice.offline();24 await alice.db.documents.update(doc.id, { title: "Draft" });25 await bob.db.documents.remove(doc.id);26 await alice.online();27 await alice.settle();2829 // PINNED (alpha.53): the delete wins everywhere except in the live session30 // that made the doomed rename — that replica keeps showing its own write31 // until it restarts. If the first assert fails, upstream started applying32 // remote deletes to live writers; drop the restart from this scenario.33 await assertRow(alice, app.documents, doc.id, { title: "Draft" });34 await alice.restart();3536 await converge(alice, bob);37 await assertNoRow(alice, app.documents, doc.id);38 await assertNoRow(bob, app.documents, doc.id);39});4041scenario("a fresh reader sees the converged state", { app, permissions }, async (ctx) => {42 const { alice, bob, addPeer } = ctx;43 await alice.db.documents.insert({ title: "one" });44 await bob.db.documents.insert({ title: "two" });45 await converge(alice, bob);4647 const carol = await addPeer("carol");48 await converge(alice, bob, carol);49 await assertRowCount(carol, app.documents, 2);50});5152scenario.fuzz("fuzzed edits converge", {53 app,54 permissions,55 seed: 7,56 steps: 15,57});