chat / client / test / machines.test.mjs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
 * State-machine transcripts for the vendored p2p lib.
 *
 * The scenario drivers in helpers/fakes.mjs are rooms-kit's, copied verbatim
 * along with the fixtures they recorded (`vectors/rk-{net,relay,log}.json`).
 * That is the point: chat's lib/net.ts and lib/log.ts differed from rooms-kit's
 * pre-CLJS ancestors by exactly the three sanctioned browser deltas, and the
 * CLJS files here are DERIVED from rooms-kit's CLJS with only those deltas
 * applied — so the transcripts must replay identically, and any divergence is
 * a real finding in the derivation.
 *
 * This is what pins the parts of the port with no pure-function surface: the
 * membership machine (PROTOCOL.md §4a/§4b), the log's entry projection and
 * author binding (§5) — including the JS-truthiness details a Clojure port gets
 * wrong by default (`0`, `""` and `undefined` are all falsy in JS, truthy in
 * Clojure).
 */
import { test } from "node:test";
import assert from "node:assert/strict";
import { installDom } from "./harness/dom.mjs";
import { mods, readVector, priv, json } from "./helpers/load.mjs";
import { netScript, relayScript, logScript } from "./helpers/fakes.mjs";

installDom();
const M = await mods();

test("the membership state machine (presence, upgrade, stale sweep, stranger drop)", async () => {
  const expected = readVector("rk-net");
  const got = await netScript({ Net: M.Net, RoomCrypto: M.RoomCrypto, priv });
  assert.deepEqual(json(got.transcript), expected.transcript);
  assert.deepEqual(json(got.calls), expected.calls);
});

test("relay connection management and jittered redial backoff", async () => {
  const expected = readVector("rk-relay");
  assert.deepEqual(json(await relayScript({ Net: M.Net, RoomCrypto: M.RoomCrypto, priv })), expected);
});

test("the log's entry projection, author binding, ingest and DAG walk", async () => {
  const expected = readVector("rk-log");
  const got = await logScript({
    RoomLog: M.RoomLog,
    RoomCrypto: M.RoomCrypto,
    makeLogEncryption: M.makeLogEncryption,
    priv,
  });
  assert.deepEqual(json(got), expected);
});

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/chat.git