gitflarePublicPartly agent-ready40
sketch-rush
Multiplayer draw-and-guess game on Cloudflare Workers, Durable Objects and D1.
- LicenseApache-2.0
- LanguageJavaScript
- Last landed
dbe1e99Oct 23, 2026
Add the Apache-2.0 licence
dbe1e99import test from "node:test";import assert from "node:assert/strict";globalThis.sessionStorage = { getItem() { return null; }, setItem() {} };globalThis.location = { protocol: "http:", host: "x" };const { Net } = await import("../public/net.js"); function mk() { const n = new Net("ABCDEF", "me", { status() {}, welcome() {}, state() {}, event() {}, board() {}, }); n.ws = { readyState: 1, send() {} }; n.onMessage(["w", "p1", "tok", "ABCDEF", "player", 1, { ph: "waiting", tm: 0 }]); n.onMessage(["k", 0, 0, 0]); return n;} test("local stroke + server echo yields exactly one stroke with all points", () => { const n = mk(); n.stroke(7, 1, 1, [1, 2, 3, 4]); assert.equal(n.board.strokes.length, 1); n.stroke(7, 1, 1, [5, 6]); n.onMessage(["k", 0, 0, ["a", 7, "p1", 1, 1], ["p", 0, 1, 2, 3, 4], 2]); assert.equal(n.board.strokes.length, 1); n.onMessage(["k", 0, 2, ["p", 0, 5, 6], 3]); assert.equal(n.board.strokes.length, 1); assert.deepEqual(n.board.strokes[0].pts, [1, 2, 3, 4, 5, 6]);}); test("remote undo/clear replay empties board", () => { const n = mk(); n.onMessage(["k", 0, 0, ["a", 1, "p2", 0, 0], ["p", 0, 1, 2], 2]); assert.equal(n.board.strokes.length, 1); n.onMessage(["k", 0, 0, 3]); // undo => compact replay of empty board assert.equal(n.board.strokes.length, 0); n.onMessage(["k", 1, 0, 4]); // clear => epoch change assert.equal(n.board.strokes.length, 0);}); test("incremental after replay with undone strokes still applies (opCount continuity)", () => { const n = mk(); // server did add+pts+undo+add (4 ops); replay compacts to one stroke, opCount 5 n.onMessage(["k", 0, 0, ["a", 2, "p2", 0, 0], ["p", 0, 9, 9], 5]); n.onMessage(["k", 0, 5, ["p", 0, 8, 8], 6]); assert.deepEqual(n.board.strokes[0].pts, [9, 9, 8, 8]);});