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