Versions 127 to 318
new file, 51 lines
1+import assert from "node:assert/strict"; 2+import { test } from "node:test"; 3+import { answer } from "../../worker/project/http.ts"; 4+import { DiskFirstRuntime } from "../src/disk-first-runtime.ts"; 5+import { memoryStorage } from "./helpers.ts"; 7+test("disk runtime syncs overlapping edits after a published move", (t) => { 8+ const storage = memoryStorage(); 9+ t.after(() => storage.db.close()); 10+ const runtime = () => new DiskFirstRuntime(storage, "sync", "sync"); 11+ runtime().initialize( 12+ (c) => answer(c, "init", undefined, { files: { "a.txt": "one\ntwo\nthree\n" } }), 15+ while (!runtime().preparePage(() => {}).ready) {} 16+ const call = (op: string, agent: string, body: unknown) => 18+ (c) => answer(c, op, agent, body), 21+ assert.equal(call("move", "alice", { from: "a.txt", to: "b.txt" }).status, 200); 22+ assert.equal(call("publish", "alice", { message: "Move" }).status, 200); 23+ for (const agent of ["alice", "bob"]) assert.equal(call("sync", agent, {}).status, 200); 24+ assert.equal(call("record", "alice", { files: { "b.txt": "one\nalice\nthree\n" } }).status, 200); 25+ assert.equal(call("record", "bob", { files: { "b.txt": "one\nbob\nthree\n" } }).status, 200); 26+ assert.equal(call("publish", "alice", { message: "alice" }).status, 200); 29+ body: runtime().write( 30+ (c) => c.sync("bob"), 34+ assert.equal(result.status, 200, JSON.stringify(result)); 35+ const body = result.body as { 37+ files: Record<string, string>; 38+ collisions: { kind: string; marked?: boolean }[]; 40+ assert.equal(body.version, 2); 41+ assert.equal(body.collisions.length, 1); 42+ assert.equal(body.collisions[0]!.kind, "lines"); 43+ assert.equal(body.collisions[0]!.marked, true); 44+ assert.match(body.files["b.txt"]!, /<<<<<<< yours/); 45+ assert.match(body.files["b.txt"]!, /bob/); 46+ assert.match(body.files["b.txt"]!, /alice/); 47+ const repeated = call("sync", "bob", {}); 48+ assert.equal(repeated.status, 200); 49+ assert.equal((repeated.body as typeof body).collisions.length, 1); 50+ assert.equal((repeated.body as typeof body).collisions[0]!.marked, true);