Random decks: seeded source in its own module; items on a duplicate
generate-random-decks.mjs had grown to 309 lines. Its seeded random source (mulberry32) moves to fixtures/seeded.mjs, and the comment on steps, items, talk and arrive is shorter: 298 lines now. The decks a seed makes are unchanged (all 16 views identical for the test's seed). The items tests, Rust and JS, now check that duplicate_slide carries items unchanged, as the step and talk tests already did.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+35
−22
core/tests/ops.rs+8 −0fixtures/generate-random-decks.mjs+9 −20fixtures/ops.test.mjs+5 −2fixtures/seeded.mjs+13 −0
diff --git a/core/tests/ops.rs b/core/tests/ops.rs| index 6c1c282..dd50ff1 100644 |
| --- a/core/tests/ops.rs |
| +++ b/core/tests/ops.rs |
| @@ -880,6 +880,14 @@ fn set_block_refuses_items_on_a_non_list() { |
| ) |
| .expect("items on a list applies"); |
| assert_eq!(view(&d)["slides"][0]["blocks"][1]["items"], "each"); |
| + |
| + // A duplicate carries items unchanged. |
| + apply_ops( |
| + &d, |
| + r#"[{"op":"duplicate_slide","id":"s1","new_id":"s2","new_block_ids":["t2","l2"]}]"#, |
| + ) |
| + .expect("duplicate applies"); |
| + assert_eq!(view(&d)["slides"][1]["blocks"][1]["items"], "each"); |
| apply_ops( |
| &d, |
| r#"[{"op":"set_block","slide":"s1","id":"l1","items":"together"}]"#, |
diff --git a/fixtures/generate-random-decks.mjs b/fixtures/generate-random-decks.mjs| index a796500..cd4c695 100644 |
| --- a/fixtures/generate-random-decks.mjs |
| +++ b/fixtures/generate-random-decks.mjs |
| @@ -21,20 +21,17 @@ |
| // anybody remembering to (Docs' review 5: code blocks were missing from |
| // a hand list, and the gate missed their family). |
| // |
| -// Steps, a list's items, a slide's talk and the deck's arrive are set |
| -// from the deck's and block's numbers rather than drawn, so a seed still |
| -// draws the decks it drew before they existed. Talk is only |
| -// ever "full": the viewer never shows a parked slide (spec 2026-11-18 |
| -// §3), and the tests open every slide of these decks in the viewer. |
| +// Steps, items, talk and arrive are set by number, never drawn, so a seed |
| +// draws the decks it drew before them. Talk is never "parked": the viewer |
| +// hides a parked slide (spec 2026-11-18 §3), and the tests open them all. |
| // |
| // It refuses to finish unless every block type, template, layout, theme, |
| // arrive, items value and mark appeared, every mark in a table cell, and |
| // every shape of text (none, empty, trailing, leading and between |
| -// empties, words) in every |
| -// type the editor binds and in a cell on the editor's first slide, |
| -// counted on the decks as written: each update decoded back through view.mjs, the way |
| -// the server will read it (Docs' review 6). Seeded, so a failure |
| -// reproduces. |
| +// empties, words) in every type the editor binds and in a cell on the |
| +// editor's first slide, counted on the decks as written: each update |
| +// decoded back through view.mjs, the way the server will read it (Docs' |
| +// review 6). Seeded (seeded.mjs), so a failure reproduces. |
| import * as Y from 'yjs' |
| import { readFileSync, readdirSync, writeFileSync } from 'node:fs' |
| import { join } from 'node:path' |
| @@ -46,6 +43,7 @@ import { roots, getArray, orderedMaps } from './ydoc.mjs' |
| import { checkDoc } from './check.mjs' |
| import { FAMILY_KEYS } from './font-families.mjs' |
| import { BOUND_TYPES } from './stage.mjs' |
| +import { seeded } from './seeded.mjs' |
| const [seed = '1', dir, manifestPath] = process.argv.slice(2) |
| if (!dir || !manifestPath) { |
| @@ -54,16 +52,7 @@ if (!dir || !manifestPath) { |
| } |
| const manifest = JSON.parse(readFileSync(manifestPath, 'utf8')) |
| -let state = Number(seed) >>> 0 || 1 |
| -const rand = () => { |
| - state = (state + 0x6d2b79f5) >>> 0 |
| - let t = state |
| - t = Math.imul(t ^ (t >>> 15), t | 1) |
| - t ^= t + Math.imul(t ^ (t >>> 7), t | 61) |
| - return ((t ^ (t >>> 14)) >>> 0) / 4294967296 |
| -} |
| -const pick = a => a[Math.floor(rand() * a.length)] |
| -const chance = p => rand() < p |
| +const { rand, pick, chance } = seeded(seed) |
| const ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567' |
| const id = () => Array.from({ length: 12 }, () => ALPHABET[Math.floor(rand() * 32)]).join('') |
diff --git a/fixtures/ops.test.mjs b/fixtures/ops.test.mjs| index f1c186d..5c81c1c 100644 |
| --- a/fixtures/ops.test.mjs |
| +++ b/fixtures/ops.test.mjs |
| @@ -491,8 +491,11 @@ test('set_block refuses items on a non-list; on a list it round-trips and clears |
| assert.throws(() => applyOps(doc, [{ op: 'set_block', slide: 's1', id: 't1', items: 'each' }]), /block "t1" is a text; items is for lists only/) |
| assert.throws(() => applyOps(doc, [{ op: 'set_block', slide: 's1', id: 'l1', items: 'some' }]), /items "some" is not one of together, each/) |
| assert.deepEqual(view(doc), before) |
| - applyOps(doc, [{ op: 'set_block', slide: 's1', id: 'l1', items: 'each' }]) |
| - assert.equal(view(doc).slides[0].blocks[1].items, 'each') |
| + applyOps(doc, [ |
| + { op: 'set_block', slide: 's1', id: 'l1', items: 'each' }, |
| + { op: 'duplicate_slide', id: 's1', new_id: 's2', new_block_ids: ['t2', 'l2'] } |
| + ]) |
| + assert.deepEqual(view(doc).slides.map(s => s.blocks[1].items), ['each', 'each']) |
| applyOps(doc, [{ op: 'set_block', slide: 's1', id: 'l1', items: 'together' }]) |
| assert.equal(view(doc).slides[0].blocks[1].items, 'together') |
| applyOps(doc, [{ op: 'set_block', slide: 's1', id: 'l1', items: null }]) |
diff --git a/fixtures/seeded.mjs b/fixtures/seeded.mjs| new file mode 100644 |
| index 0000000..857806e |
| --- /dev/null |
| +++ b/fixtures/seeded.mjs |
| @@ -0,0 +1,13 @@ |
| +// A seeded random source (mulberry32): the same seed draws the same |
| +// numbers, so a run that failed can be run again exactly. |
| +export function seeded (seed) { |
| + let state = Number(seed) >>> 0 || 1 |
| + const rand = () => { |
| + state = (state + 0x6d2b79f5) >>> 0 |
| + let t = state |
| + t = Math.imul(t ^ (t >>> 15), t | 1) |
| + t ^= t + Math.imul(t ^ (t >>> 7), t | 61) |
| + return ((t ^ (t >>> 14)) >>> 0) / 4294967296 |
| + } |
| + return { rand, pick: a => a[Math.floor(rand() * a.length)], chance: p => rand() < p } |
| +} |