// Reads a Rust-produced v1 update on stdin and asserts JS yjs decodes it to // the expected text AND the expected formatting. This is the direction // Task 3 cannot test. Plain text alone cannot distinguish a correct // implementation from one that dropped formatting, so this also checks // toDelta(), the way fixtures/generate.mjs's expected.json does. import * as Y from 'yjs' import assert from 'node:assert/strict' const EXPECTED_TEXT = 'from rust 🦀 café' const EXPECTED_DELTA = [ { insert: 'from ' }, { insert: 'rust', attributes: { bold: true } }, { insert: ' 🦀 café' } ] const chunks = [] for await (const chunk of process.stdin) chunks.push(chunk) const update = new Uint8Array(Buffer.concat(chunks)) if (update.length === 0) { console.error('verify-rust: empty update on stdin') process.exit(1) } const doc = new Y.Doc() Y.applyUpdate(doc, update) const text = doc.getText('content') const actualText = text.toString() const actualDelta = text.toDelta() try { assert.strictEqual(actualText, EXPECTED_TEXT) assert.deepStrictEqual(actualDelta, EXPECTED_DELTA) } catch (err) { console.error('verify-rust: mismatch') console.error(` text: expected ${JSON.stringify(EXPECTED_TEXT)}, got ${JSON.stringify(actualText)}`) console.error(` delta: expected ${JSON.stringify(EXPECTED_DELTA)}, got ${JSON.stringify(actualDelta)}`) console.error(err.message) process.exit(1) } console.log(`verify-rust: ok (${update.length} bytes)`)