fixtures: add delta field to expected.json and improve code comments
FINDING 1: The formatted fixture previously only asserted plain text via toString(), which stripped formatting. Now all fixtures include a delta field from toDelta() that captures the full structure including formatting. This ensures the Rust implementation correctly decodes format operations. FINDING 2: Added explanatory comments: - emit() function: explain why clientID is assigned (determinism requirement) - formatted fixture: clarify what the delta field asserts - concurrent fixture: note that doc.clientID overrides emit's assignment The binary update files remain unchanged; all determinism tests pass.
5 files changed,
+46
−5
fixtures/data/concurrent.expected.json+6 −1fixtures/data/formatted.expected.json+15 −1fixtures/data/hello.expected.json+6 −1fixtures/data/unicode.expected.json+6 −1fixtures/generate.mjs+13 −1
diff --git a/fixtures/data/concurrent.expected.json b/fixtures/data/concurrent.expected.json| index ac35f31..618b154 100644 |
| --- a/fixtures/data/concurrent.expected.json |
| +++ b/fixtures/data/concurrent.expected.json |
| @@ -1,3 +1,8 @@ |
| { |
| - "text": "AAABBB" |
| + "text": "AAABBB", |
| + "delta": [ |
| + { |
| + "insert": "AAABBB" |
| + } |
| + ] |
| } |
diff --git a/fixtures/data/formatted.expected.json b/fixtures/data/formatted.expected.json| index e763dbd..99be463 100644 |
| --- a/fixtures/data/formatted.expected.json |
| +++ b/fixtures/data/formatted.expected.json |
| @@ -1,3 +1,17 @@ |
| { |
| - "text": "plain bold plain" |
| + "text": "plain bold plain", |
| + "delta": [ |
| + { |
| + "insert": "plain " |
| + }, |
| + { |
| + "insert": "bold", |
| + "attributes": { |
| + "bold": true |
| + } |
| + }, |
| + { |
| + "insert": " plain" |
| + } |
| + ] |
| } |
diff --git a/fixtures/data/hello.expected.json b/fixtures/data/hello.expected.json| index da7d1ad..54dafe8 100644 |
| --- a/fixtures/data/hello.expected.json |
| +++ b/fixtures/data/hello.expected.json |
| @@ -1,3 +1,8 @@ |
| { |
| - "text": "hello world" |
| + "text": "hello world", |
| + "delta": [ |
| + { |
| + "insert": "hello world" |
| + } |
| + ] |
| } |
diff --git a/fixtures/data/unicode.expected.json b/fixtures/data/unicode.expected.json| index 4320fb0..f45a648 100644 |
| --- a/fixtures/data/unicode.expected.json |
| +++ b/fixtures/data/unicode.expected.json |
| @@ -1,3 +1,8 @@ |
| { |
| - "text": "héllo 🌍 café" |
| + "text": "héllo 🌍 café", |
| + "delta": [ |
| + { |
| + "insert": "héllo 🌍 café" |
| + } |
| + ] |
| } |
diff --git a/fixtures/generate.mjs b/fixtures/generate.mjs| index a1cc897..d90154f 100644 |
| --- a/fixtures/generate.mjs |
| +++ b/fixtures/generate.mjs |
| @@ -11,13 +11,19 @@ mkdirSync(dataDir, { recursive: true }) |
| function emit(name, build) { |
| const doc = new Y.Doc() |
| + // new Y.Doc() assigns a random clientID. Fixed IDs ensure that running the |
| + // generator twice produces byte-identical fixtures (required for the |
| + // regeneration gate that later tasks add). |
| doc.clientID = 1 |
| build(doc) |
| const update = Y.encodeStateAsUpdate(doc) |
| writeFileSync(join(dataDir, `${name}.update.bin`), Buffer.from(update)) |
| writeFileSync( |
| join(dataDir, `${name}.expected.json`), |
| - JSON.stringify({ text: doc.getText('content').toString() }, null, 2) + '\n' |
| + JSON.stringify({ |
| + text: doc.getText('content').toString(), |
| + delta: doc.getText('content').toDelta() |
| + }, null, 2) + '\n' |
| ) |
| console.log(`${name}: ${update.length} bytes`) |
| } |
| @@ -33,6 +39,9 @@ emit('unicode', (doc) => { |
| }) |
| emit('formatted', (doc) => { |
| + // Rich text formatting: bold is the key assertion. The delta field captures |
| + // the formatting structure that toString() would strip, verifying that the |
| + // Rust side correctly decodes format operations. |
| const t = doc.getText('content') |
| t.insert(0, 'plain bold plain') |
| t.format(6, 4, { bold: true }) |
| @@ -45,6 +54,9 @@ emit('concurrent', (doc) => { |
| a.clientID = 1 |
| const b = new Y.Doc() |
| b.clientID = 2 |
| + // Note: doc.clientID (set to 3 here) overrides the emit() assignment above. |
| + // The clientID of this local doc must differ from a and b to ensure |
| + // deterministic merge ordering. |
| doc.clientID = 3 |
| a.getText('content').insert(0, 'AAA') |
| b.getText('content').insert(0, 'BBB') |