Add web-editor golden fixtures verifying GPUI ProseMirror schema and JSON round trips

Closed
DE
2mo ago
+3369-10

Summary

Problem: ANLG-320 Phase 4 requires proof that the native GPUI editor reads and writes the same TipTap-dialect ProseMirror JSON as the web editor, with no schema drift. The GPUI pm module had paste fixtures but nothing pinning the note schema itself or whole-document round trips, so a mismatch in node/mark attrs or serialization would only surface as corrupted notes after a save.

Fix: The web editor is the source of truth and generates the fixture; the GPUI crate asserts against it.

  • packages/editor/src/note/roundtrip-fixtures.gen.test.ts (vitest) dumps the note schema spec (nodes/marks, attrs + defaults, inline/atom/marks/excludes) and 25 documents (19 hand-written covering every node and mark, 6 via md2json → schema.nodeFromJSON(...).check().toJSON()), each with nodeSize, textContent, textBetween. With UPDATE_ROUNDTRIP_FIXTURES=1 it rewrites apps/desktop-gpui/src/editor/pm/fixtures/roundtrip.gen.json; otherwise it fails on drift and tells you how to regenerate.
  • apps/desktop-gpui/src/editor/pm/roundtrip.rs: schema_matches_web_fixture (same node/mark names in the same order, attrs + defaults, inline/atom, empty mark sets, excludes: "_") and documents_round_trip_through_gpui_model (Node::from_json → to_json equality, node_size, text_content, Doc::parse/to_json stability, identity re-parse), reporting all failures in one aggregated message.

Divergences found and pinned in KNOWN_DIVERGENCES (fixture kept as web truth, not adjusted to Rust):

  1. node_size counts Unicode scalar values; ProseMirror counts UTF-16 code units (basic-unicode, markdown-table). This affects any position exchanged with web-authored data (comment anchors, selections) for non-BMP text and should be fixed in the GPUI model — tracked as follow-up.
  2. Fragment::from merges adjacent text nodes with identical marks; nodeFromJSON preserves them (marks-overlap-and-adjacency). Semantically equivalent, but not byte-stable on re-save.

Not compared (no Rust-side representation exposed): node.content, node.group, mark.inclusive, mark.group; Rust has no textBetween.

Verification

  • UPDATE_ROUNDTRIP_FIXTURES=1 pnpm -F @anlg/editor test then pnpm -F @anlg/editor test (201 tests, fixture byte-stable across two generations)
  • pnpm -F @anlg/editor typecheck
  • ubuntu-24.04 CI-equivalent container: cargo test --locked -p desktop-gpui roundtrip (2 passed), cargo clippy --locked -p desktop-gpui --all-targets --no-deps -- -D warnings
  • dprint fmt/check and rustfmt --edition 2024 on changed files

Link to Devin session: https://app.devin.ai/sessions/f83ed73d85c648fcbdbd041cd4f15720
Open in Devin Desktop: https://app.devin.ai/desktop/session/f83ed73d85c648fcbdbd041cd4f15720?variant=devin
Requested by: @ComputelessComputer