oficina / slides Public

Slides: the scene and clip block tests get a file of their own

scenes.test.mjs ran to 309 lines, past the fixtures' 300. Its scene and
clip block tests move, as they were, to scene-blocks.test.mjs (94
lines), leaving the scenes map, its ops and the version in
scenes.test.mjs (240). scenes.mjs's limit comment is cut to one line
so the module stays at 299 after the update cap joined it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c40808c8e3a1add16f8fa02eb81c135925aeb0f1 parent 2c4c2b7
3 files changed, +98 −78
  • fixtures/scene-blocks.test.mjs +94 −0
  • fixtures/scenes.mjs +1 −6
  • fixtures/scenes.test.mjs +3 −72
diff --git a/fixtures/scene-blocks.test.mjs b/fixtures/scene-blocks.test.mjs
new file mode 100644
index 0000000..de94db8
--- /dev/null
+++ b/fixtures/scene-blocks.test.mjs
@@ -0,0 +1,94 @@
+// scene-blocks.test.mjs — the scene and clip block types (scenes and
+// clips spec §2, plan task 2), the blocks' half of core/tests/scenes.rs,
+// split from scenes.test.mjs: a scene block names a scene and two of its
+// states in order, a removed scene or state leaves it as it was, a clip
+// plays on a press, in a loop or once, and a duplicated slide's scene
+// block is still checked.
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import * as Y from 'yjs'
+import { applyOps, view, OpsError } from './ops.mjs'
+
+function deck () {
+ const doc = new Y.Doc({ guid: 'scenes' })
+ doc.clientID = 1
+ applyOps(doc, [{
+ op: 'add_scene',
+ id: 'worldsceneaa',
+ name: 'The world',
+ code: '0123456789abcdef'.repeat(4),
+ states: [{ id: 'a' }, { id: 'b' }, { id: 'c' }]
+ }, { op: 'add_slide', id: 's1', layout: 'flow' }])
+ return doc
+}
+
+const sceneBlock = (id, props) => ({ op: 'add_block', slide: 's1', id, type: 'scene', props })
+const json = doc => JSON.stringify(view(doc))
+
+test('a scene block names a scene and two of its states', () => {
+ const doc = deck()
+ applyOps(doc, [sceneBlock('sb', { scene: 'worldsceneaa', from: 'a', to: 'c' })])
+ applyOps(doc, [sceneBlock('eq', { scene: 'worldsceneaa', from: 'b', to: 'b' })])
+ applyOps(doc, [sceneBlock('empty', {})])
+ const b = view(doc).slides[0].blocks[0]
+ assert.equal(b.type, 'scene')
+ assert.deepEqual(b.props, { scene: 'worldsceneaa', from: 'a', to: 'c' })
+ const before = json(doc)
+ for (const props of [
+ { scene: 'nope', from: 'a', to: 'c' },
+ { scene: 'worldsceneaa', from: 'a', to: 'zz' },
+ { scene: 'worldsceneaa', from: 'zz', to: 'a' },
+ { scene: 'worldsceneaa', from: 'c', to: 'a' },
+ { scene: 5 },
+ { scene: 'worldsceneaa', from: 1 },
+ { from: 'a', to: 'b' }
+ ]) {
+ assert.throws(() => applyOps(doc, [sceneBlock('x', props)]), OpsError, JSON.stringify(props))
+ assert.equal(json(doc), before)
+ }
+ for (const props of [{ to: 'zz' }, { from: 'b', to: 'a' }, { scene: 'nope' }]) {
+ assert.throws(() => applyOps(doc, [{ op: 'set_block', slide: 's1', id: 'sb', props }]), OpsError, JSON.stringify(props))
+ assert.equal(json(doc), before)
+ }
+ applyOps(doc, [{ op: 'set_block', slide: 's1', id: 'sb', props: { from: 'b' } }])
+})
+
+test('a removed scene or state leaves the block as it was', () => {
+ const doc = deck()
+ applyOps(doc, [sceneBlock('sb', { scene: 'worldsceneaa', from: 'a', to: 'c' }), { op: 'set_scene', id: 'worldsceneaa', states: [{ id: 'a' }, { id: 'b' }] }])
+ applyOps(doc, [{ op: 'remove_scene', id: 'worldsceneaa' }])
+ const v = view(doc)
+ assert.equal('scenes' in v, false)
+ assert.deepEqual(v.slides[0].blocks[0].props, { scene: 'worldsceneaa', from: 'a', to: 'c' })
+ applyOps(doc, [{ op: 'set_block', slide: 's1', id: 'sb', step: 2, props: { alt: 'x' } }])
+ const d2 = deck()
+ assert.throws(() => applyOps(d2, [{ op: 'remove_scene', id: 'worldsceneaa' }, sceneBlock('sb', { scene: 'worldsceneaa', from: 'a', to: 'b' })]), OpsError)
+})
+
+test('a clip block plays on a press, in a loop or once', () => {
+ const doc = deck()
+ for (const [id, play] of [['c1', 'press'], ['c2', 'loop'], ['c3', 'once']]) {
+ applyOps(doc, [{ op: 'add_block', slide: 's1', id, type: 'clip', props: { asset: 'v1', play } }])
+ }
+ const before = json(doc)
+ for (const op of [
+ { op: 'add_block', slide: 's1', id: 'c4', type: 'clip', props: { asset: 'v1', play: 'bounce' } },
+ { op: 'add_block', slide: 's1', id: 'c4', type: 'clip', props: { asset: 3 } },
+ { op: 'set_block', slide: 's1', id: 'c1', props: { play: 'forever' } }
+ ]) {
+ assert.throws(() => applyOps(doc, [op]), OpsError, JSON.stringify(op))
+ assert.equal(json(doc), before)
+ }
+ applyOps(doc, [{ op: 'set_block', slide: 's1', id: 'c1', props: { play: 'loop' } }])
+ assert.equal(view(doc).slides[0].blocks[0].props.play, 'loop')
+})
+
+test('duplicate_slide keeps a scene block checkable', () => {
+ const doc = deck()
+ applyOps(doc, [
+ sceneBlock('sb', { scene: 'worldsceneaa', from: 'a', to: 'b' }),
+ { op: 'duplicate_slide', id: 's1', new_id: 's2', new_block_ids: ['sb2'] },
+ { op: 'set_block', slide: 's2', id: 'sb2', props: { to: 'c' } }
+ ])
+ assert.throws(() => applyOps(doc, [{ op: 'set_block', slide: 's2', id: 'sb2', props: { from: 'zz' } }]), OpsError)
+})
diff --git a/fixtures/scenes.mjs b/fixtures/scenes.mjs
index 52b86c2..767c1d3 100644
--- a/fixtures/scenes.mjs
+++ b/fixtures/scenes.mjs
@@ -16,13 +16,8 @@ import { canonicalJSON, utf8 } from './scene-version.mjs'
export { canonicalJSON, sceneCanonical, sceneVersion, stillsCurrent } from './scene-version.mjs'
-// 960 KiB of canonical JSON. That alone does not make a set_scene fit
-// one live update: a number takes nine bytes in the update and as few
-// as two in JSON, so a batch with a scene op is also measured
-// (ops.mjs, MAX_UPDATE_BYTES).
+// 960 KiB of JSON; ops.mjs also holds a scene batch to one update (live.go maxUpdateBytes).
export const MAX_SCENE_DATA = 960 * 1024
-// The most one posted update may be (internal/slides/live.go
-// maxUpdateBytes): 1 MiB.
export const MAX_UPDATE_BYTES = 1 << 20
export const CLIP_PLAYS = ['press', 'loop', 'once']
diff --git a/fixtures/scenes.test.mjs b/fixtures/scenes.test.mjs
index c5ef738..8f684f7 100644
--- a/fixtures/scenes.test.mjs
+++ b/fixtures/scenes.test.mjs
@@ -1,8 +1,8 @@
// scenes.test.mjs — scenes in the document (scenes and clips spec §2,
// plan task 2), the twin of core/tests/scenes.rs: the deck-level scenes
-// map and its three ops, the scene and clip block types, and a scene's
-// version (plan call R1) against vectors/scene-version.json, which the
-// core and internal/slides/deck read too.
+// map and its three ops, and a scene's version (plan call R1) against
+// vectors/scene-version.json, which the core and internal/slides/deck
+// read too. The scene and clip block types are scene-blocks.test.mjs.
import test from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
@@ -43,7 +43,6 @@ function deck () {
return doc
}
-const sceneBlock = (id, props) => ({ op: 'add_block', slide: 's1', id, type: 'scene', props })
const json = doc => JSON.stringify(view(doc))
test('a deck without scenes has no scenes key', () => {
@@ -174,74 +173,6 @@ test('data up to 960 KiB of canonical JSON is taken', () => {
assert.throws(() => applyOps(doc, [{ op: 'set_scene', id: 'worldsceneaa', data: 'é'.repeat(LIMIT / 2) }]), OpsError)
})
-test('a scene block names a scene and two of its states', () => {
- const doc = deck()
- applyOps(doc, [sceneBlock('sb', { scene: 'worldsceneaa', from: 'a', to: 'c' })])
- applyOps(doc, [sceneBlock('eq', { scene: 'worldsceneaa', from: 'b', to: 'b' })])
- applyOps(doc, [sceneBlock('empty', {})])
- const b = view(doc).slides[0].blocks[0]
- assert.equal(b.type, 'scene')
- assert.deepEqual(b.props, { scene: 'worldsceneaa', from: 'a', to: 'c' })
- const before = json(doc)
- for (const props of [
- { scene: 'nope', from: 'a', to: 'c' },
- { scene: 'worldsceneaa', from: 'a', to: 'zz' },
- { scene: 'worldsceneaa', from: 'zz', to: 'a' },
- { scene: 'worldsceneaa', from: 'c', to: 'a' },
- { scene: 5 },
- { scene: 'worldsceneaa', from: 1 },
- { from: 'a', to: 'b' }
- ]) {
- assert.throws(() => applyOps(doc, [sceneBlock('x', props)]), OpsError, JSON.stringify(props))
- assert.equal(json(doc), before)
- }
- for (const props of [{ to: 'zz' }, { from: 'b', to: 'a' }, { scene: 'nope' }]) {
- assert.throws(() => applyOps(doc, [{ op: 'set_block', slide: 's1', id: 'sb', props }]), OpsError, JSON.stringify(props))
- assert.equal(json(doc), before)
- }
- applyOps(doc, [{ op: 'set_block', slide: 's1', id: 'sb', props: { from: 'b' } }])
-})
-
-test('a removed scene or state leaves the block as it was', () => {
- const doc = deck()
- applyOps(doc, [sceneBlock('sb', { scene: 'worldsceneaa', from: 'a', to: 'c' }), { op: 'set_scene', id: 'worldsceneaa', states: [{ id: 'a' }, { id: 'b' }] }])
- applyOps(doc, [{ op: 'remove_scene', id: 'worldsceneaa' }])
- const v = view(doc)
- assert.equal('scenes' in v, false)
- assert.deepEqual(v.slides[0].blocks[0].props, { scene: 'worldsceneaa', from: 'a', to: 'c' })
- applyOps(doc, [{ op: 'set_block', slide: 's1', id: 'sb', step: 2, props: { alt: 'x' } }])
- const d2 = deck()
- assert.throws(() => applyOps(d2, [{ op: 'remove_scene', id: 'worldsceneaa' }, sceneBlock('sb', { scene: 'worldsceneaa', from: 'a', to: 'b' })]), OpsError)
-})
-
-test('a clip block plays on a press, in a loop or once', () => {
- const doc = deck()
- for (const [id, play] of [['c1', 'press'], ['c2', 'loop'], ['c3', 'once']]) {
- applyOps(doc, [{ op: 'add_block', slide: 's1', id, type: 'clip', props: { asset: 'v1', play } }])
- }
- const before = json(doc)
- for (const op of [
- { op: 'add_block', slide: 's1', id: 'c4', type: 'clip', props: { asset: 'v1', play: 'bounce' } },
- { op: 'add_block', slide: 's1', id: 'c4', type: 'clip', props: { asset: 3 } },
- { op: 'set_block', slide: 's1', id: 'c1', props: { play: 'forever' } }
- ]) {
- assert.throws(() => applyOps(doc, [op]), OpsError, JSON.stringify(op))
- assert.equal(json(doc), before)
- }
- applyOps(doc, [{ op: 'set_block', slide: 's1', id: 'c1', props: { play: 'loop' } }])
- assert.equal(view(doc).slides[0].blocks[0].props.play, 'loop')
-})
-
-test('duplicate_slide keeps a scene block checkable', () => {
- const doc = deck()
- applyOps(doc, [
- sceneBlock('sb', { scene: 'worldsceneaa', from: 'a', to: 'b' }),
- { op: 'duplicate_slide', id: 's1', new_id: 's2', new_block_ids: ['sb2'] },
- { op: 'set_block', slide: 's2', id: 'sb2', props: { to: 'c' } }
- ])
- assert.throws(() => applyOps(doc, [{ op: 'set_block', slide: 's2', id: 'sb2', props: { from: 'zz' } }]), OpsError)
-})
-
test('scene version vectors', async t => {
const cases = JSON.parse(readFileSync(new URL('./vectors/scene-version.json', import.meta.url)))
assert.ok(cases.length >= 5)