// Independent browser replay of rule_wire_probe's synthetic incremental updates. import assert from 'node:assert/strict' import fs from 'node:fs' import path from 'node:path' import * as Y from '../../fixtures/node_modules/yjs/dist/yjs.mjs' const directory = process.argv[2] assert.ok(directory, 'usage: node native/scripts/check-rule-wire.mjs OUTPUT_DIRECTORY') let comparisons = 0 for (const variant of ['retained', 'fresh']) { for (const gc of [true, false]) { const base = path.join(directory, variant) const remote = new Y.Doc({ gc }) for (let step = 0; step <= 6; step++) { Y.applyUpdate(remote, fs.readFileSync(path.join(base, step + '.bin'))) if (step === 0) continue const snapshot = new Y.Doc({ gc }) Y.applyUpdate(snapshot, fs.readFileSync(path.join(base, step + '.snapshot'))) assert.equal(remote.getXmlFragment('prosemirror').toString(), snapshot.getXmlFragment('prosemirror').toString(), `${variant}, gc=${gc}, step=${step}`) comparisons++ snapshot.destroy() } assert.equal(remote.getXmlFragment('prosemirror').toString(), '- AlphaBeta') remote.destroy() } } console.log(`Rule wire replay passed ${comparisons} incremental/snapshot comparisons and four exact final bodies.`)