oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1// Generates the documents the suite conformance test seeds Docs with
2// (internal/docs/suite_test.go): one real Yjs update per case of the suite
3// contract's custody fixture, a single paragraph holding that case's
4// s3_body, on the "prosemirror" root Store.Text reads. Run from fixtures/
5// with the fixture's path:
6//
7// node generate-suite.mjs "$(go list -m -f '{{.Dir}}' amadan.net/oficina/suite)/fixtures/custody.json"
8//
9// The client id is pinned so the bytes are reproducible, as in
10// generate-fragment.mjs. A fixture whose text changes needs this rerun; the
11// conformance test fails on the body until it is.
12import * as Y from 'yjs'
13import { writeFileSync, mkdirSync, readFileSync } from 'node:fs'
14
15const path = process.argv[2]
16if (!path) {
17 console.error('usage: node generate-suite.mjs <custody.json>')
18 process.exit(2)
19}
20const fixture = JSON.parse(readFileSync(path, 'utf8'))
21mkdirSync('vectors/suite', { recursive: true })
22for (const c of fixture.cases) {
23 if (!c.s3_body) continue
24 const doc = new Y.Doc()
25 doc.clientID = 1
26 const p = new Y.XmlElement('paragraph')
27 const t = new Y.XmlText()
28 t.insert(0, c.s3_body)
29 p.insert(0, [t])
30 doc.getXmlFragment('prosemirror').insert(0, [p])
31 writeFileSync(`vectors/suite/${c.item_id}.update.bin`, Y.encodeStateAsUpdate(doc))
32}
33