fix(git-sync): subpages round-trips (was {{SUBPAGES}} literal) + exhaustive all-node round-trip test
subpages exported to the literal `{{SUBPAGES}}`, which has no markdown/HTML
inverse, so on re-import it came back as a plain paragraph holding the visible
text "{{SUBPAGES}}" — the embed rendered as that literal string on the page
after a sync (round-trip data loss, seen live). It now emits the schema-matching
`<div data-type="subpages">` like every other embed node, so the schema's
parseHTML rebuilds the subpages node. Also dropped the leaf-atom content-hole
in the subpages renderHTML.
New committed regression coverage:
- packages/git-sync/test/roundtrip-all-nodes.test.ts — exhaustive serialize ->
deserialize round trip for ALL 40 node/mark types; each asserts the node/mark
survives and no `{{...}}` literal leaks. This is the test that caught subpages.
- §13.1 gate (git-sync-converter-gate.spec.ts): subpages added to the green
corpus (round-trips through the REAL server schema).
- Corrected two PR-authored tests that asserted the old {{SUBPAGES}} loss as
"by design" — they now assert the fixed round trip.
Also folds in review #1679 coverage-gap tests (no prod change): orchestrator
pollTick/enabledSpaces, datasource 3-way merge dispatch, page.repo
last_updated_source provenance SQL.
git-sync vitest 659 (+1 expected-fail), server tsc clean, server specs green.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -68,28 +68,27 @@ describe('pageBreak data loss (no converter case — SPEC §11 divergence)', ()
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 2. subpages LOSSY round-trip (`case "subpages"` emits `{{SUBPAGES}}`).
|
||||
// 2. subpages round-trip (`case "subpages"` emits the schema-matching div).
|
||||
//
|
||||
// The golden test only pins the EMISSION string. The token has no markdown or
|
||||
// HTML meaning, so on re-import marked treats `{{SUBPAGES}}` as ordinary text:
|
||||
// the subpages BLOCK comes back as a plain PARAGRAPH carrying that literal
|
||||
// string, NOT a `subpages` node. The export is "lossy but legible" by design;
|
||||
// this test pins the actual lossy round-trip behavior.
|
||||
// It used to emit the literal `{{SUBPAGES}}`, which has no markdown/HTML meaning,
|
||||
// so on re-import the subpages BLOCK came back as a plain PARAGRAPH carrying the
|
||||
// literal string (the embed rendered as visible "{{SUBPAGES}}" text on the page
|
||||
// after a sync — data loss). It now emits `<div data-type="subpages">` like the
|
||||
// other embed nodes, so the schema's parseHTML rebuilds the subpages node.
|
||||
// ---------------------------------------------------------------------------
|
||||
describe('subpages lossy round-trip ({{SUBPAGES}} placeholder)', () => {
|
||||
it('emits {{SUBPAGES}} which re-imports as a paragraph, not a subpages node', async () => {
|
||||
describe('subpages round-trip (schema-matching div)', () => {
|
||||
it('emits the subpages div and re-imports as a subpages node (no literal leak)', async () => {
|
||||
const { md1, doc2 } = await roundTrip({ type: 'subpages' });
|
||||
expect(md1).toBe('{{SUBPAGES}}');
|
||||
expect(md1).toBe('<div data-type="subpages"></div>');
|
||||
|
||||
// The re-imported doc has a single paragraph holding the literal token.
|
||||
const top = doc2.content || [];
|
||||
expect(top).toHaveLength(1);
|
||||
expect(top[0].type).toBe('paragraph');
|
||||
expect(top[0].content?.[0]).toMatchObject({ type: 'text', text: '{{SUBPAGES}}' });
|
||||
|
||||
// The subpages node itself is gone: nothing in the doc is a subpages node.
|
||||
const allTypes = top.map((n: any) => n.type);
|
||||
expect(allTypes).not.toContain('subpages');
|
||||
const collect = (n: any): string[] => [
|
||||
n.type,
|
||||
...((n.content || []) as any[]).flatMap(collect),
|
||||
];
|
||||
const allTypes = (doc2.content || []).flatMap(collect);
|
||||
// The subpages node survives, and no literal {{SUBPAGES}} text leaked back.
|
||||
expect(allTypes).toContain('subpages');
|
||||
expect(JSON.stringify(doc2)).not.toContain('{{SUBPAGES}}');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -142,8 +142,8 @@ describe('paragraph.textAlign -> <div align>', () => {
|
||||
});
|
||||
|
||||
describe('subpages token + unknown-in-container fallback', () => {
|
||||
it('subpages emits the {{SUBPAGES}} placeholder token', () => {
|
||||
expect(c({ type: 'subpages' })).toBe('{{SUBPAGES}}');
|
||||
it('subpages emits the schema-matching div (round-trips, unlike the old {{SUBPAGES}} literal)', () => {
|
||||
expect(c({ type: 'subpages' })).toBe('<div data-type="subpages"></div>');
|
||||
});
|
||||
|
||||
it('an unknown block inside a raw-HTML container is wrapped in <div> (never markdown)', () => {
|
||||
|
||||
109
packages/git-sync/test/roundtrip-all-nodes.test.ts
Normal file
109
packages/git-sync/test/roundtrip-all-nodes.test.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { convertProseMirrorToMarkdown } from '../src/lib/markdown-converter.js';
|
||||
import { markdownToProseMirror } from '../src/lib/markdown-to-prosemirror.js';
|
||||
|
||||
/**
|
||||
* Exhaustive serialize -> deserialize round trip for EVERY node and mark type the
|
||||
* Docmost document schema supports. The git-sync converter exports a page body to
|
||||
* Markdown and imports it back; any node type that has no parseHTML inverse (or is
|
||||
* serialized to a literal that never re-parses) silently degrades to plain text on
|
||||
* a round trip — e.g. `subpages` used to export as the literal `{{SUBPAGES}}` and
|
||||
* came back as the visible text "{{SUBPAGES}}" instead of the embed.
|
||||
*
|
||||
* This guards the whole class: for one representative fixture per type, the node
|
||||
* (or mark) MUST still be present after convert -> import, and the exported
|
||||
* Markdown must not contain a `{{...}}` template literal (the old lossy form).
|
||||
*/
|
||||
|
||||
const T = (t: string, marks?: any[]) =>
|
||||
marks ? { type: 'text', text: t, marks } : { type: 'text', text: t };
|
||||
const P = (...c: any[]) => ({ type: 'paragraph', content: c });
|
||||
const doc = (...c: any[]) => ({ type: 'doc', content: c });
|
||||
|
||||
// `primary` is the node/mark type that must survive the round trip.
|
||||
const FIXTURES: Record<string, { doc: any; primary: string }> = {
|
||||
paragraph: { doc: doc(P(T('hello'))), primary: 'paragraph' },
|
||||
heading: { doc: doc({ type: 'heading', attrs: { level: 2 }, content: [T('H2')] }), primary: 'heading' },
|
||||
blockquote: { doc: doc({ type: 'blockquote', content: [P(T('q'))] }), primary: 'blockquote' },
|
||||
codeBlock: { doc: doc({ type: 'codeBlock', attrs: { language: 'js' }, content: [T('foo()')] }), primary: 'codeBlock' },
|
||||
bulletList: { doc: doc({ type: 'bulletList', content: [{ type: 'listItem', content: [P(T('a'))] }] }), primary: 'bulletList' },
|
||||
orderedList: { doc: doc({ type: 'orderedList', attrs: { start: 1 }, content: [{ type: 'listItem', content: [P(T('a'))] }] }), primary: 'orderedList' },
|
||||
taskList: { doc: doc({ type: 'taskList', content: [{ type: 'taskItem', attrs: { checked: true }, content: [P(T('done'))] }] }), primary: 'taskList' },
|
||||
horizontalRule: { doc: doc({ type: 'horizontalRule' }), primary: 'horizontalRule' },
|
||||
image: { doc: doc({ type: 'image', attrs: { src: '/f/x.png', width: '320', align: 'center' } }), primary: 'image' },
|
||||
hardBreak: { doc: doc(P(T('a'), { type: 'hardBreak' }, T('b'))), primary: 'hardBreak' },
|
||||
callout: { doc: doc({ type: 'callout', attrs: { type: 'info' }, content: [P(T('note'))] }), primary: 'callout' },
|
||||
columns: {
|
||||
doc: doc({ type: 'columns', content: [
|
||||
{ type: 'column', attrs: { width: '50%' }, content: [P(T('L'))] },
|
||||
{ type: 'column', attrs: { width: '50%' }, content: [P(T('R'))] }] }),
|
||||
primary: 'column',
|
||||
},
|
||||
details: {
|
||||
doc: doc({ type: 'details', content: [
|
||||
{ type: 'detailsSummary', content: [T('Sum')] },
|
||||
{ type: 'detailsContent', content: [P(T('body'))] }] }),
|
||||
primary: 'details',
|
||||
},
|
||||
table: {
|
||||
doc: doc({ type: 'table', content: [
|
||||
{ type: 'tableRow', content: [{ type: 'tableHeader', content: [P(T('H1'))] }, { type: 'tableHeader', content: [P(T('H2'))] }] },
|
||||
{ type: 'tableRow', content: [{ type: 'tableCell', content: [P(T('C1'))] }, { type: 'tableCell', content: [P(T('C2'))] }] }] }),
|
||||
primary: 'tableCell',
|
||||
},
|
||||
mathBlock: { doc: doc({ type: 'mathBlock', attrs: { math: 'x^2' } }), primary: 'mathBlock' },
|
||||
mathInline: { doc: doc(P({ type: 'mathInline', attrs: { math: 'x^2' } })), primary: 'mathInline' },
|
||||
mention: { doc: doc(P({ type: 'mention', attrs: { id: 'u1', label: 'Bob', entityType: 'user', entityId: 'u1' } })), primary: 'mention' },
|
||||
drawio: { doc: doc({ type: 'drawio', attrs: { src: '/f/d.drawio', attachmentId: 'a1' } }), primary: 'drawio' },
|
||||
excalidraw: { doc: doc({ type: 'excalidraw', attrs: { src: '/f/e.excalidraw', attachmentId: 'a1' } }), primary: 'excalidraw' },
|
||||
embed: { doc: doc({ type: 'embed', attrs: { src: 'https://youtube.com/x', provider: 'iframe' } }), primary: 'embed' },
|
||||
pdf: { doc: doc({ type: 'pdf', attrs: { src: '/f/x.pdf', attachmentId: 'a1' } }), primary: 'pdf' },
|
||||
video: { doc: doc({ type: 'video', attrs: { src: '/f/v.mp4', width: '640' } }), primary: 'video' },
|
||||
audio: { doc: doc({ type: 'audio', attrs: { src: '/f/a.mp3' } }), primary: 'audio' },
|
||||
attachment: { doc: doc({ type: 'attachment', attrs: { url: '/f/x.zip', name: 'x.zip', attachmentId: 'a1' } }), primary: 'attachment' },
|
||||
youtube: { doc: doc({ type: 'youtube', attrs: { src: 'https://youtube.com/watch?v=x' } }), primary: 'youtube' },
|
||||
subpages: { doc: doc({ type: 'subpages' }), primary: 'subpages' },
|
||||
pageBreak: { doc: doc({ type: 'pageBreak' }), primary: 'pageBreak' },
|
||||
htmlEmbed: { doc: doc({ type: 'htmlEmbed', attrs: { source: '<b>hi</b>' } }), primary: 'htmlEmbed' },
|
||||
pageEmbed: { doc: doc({ type: 'pageEmbed', attrs: { pageId: 'p1' } }), primary: 'pageEmbed' },
|
||||
transclusion: { doc: doc({ type: 'transclusionSource', attrs: { pageId: 'p1' } }), primary: 'transclusionSource' },
|
||||
footnote: {
|
||||
doc: doc(
|
||||
P(T('x'), { type: 'footnoteReference', attrs: { id: 'fn1' } }),
|
||||
{ type: 'footnotesList', content: [{ type: 'footnoteDefinition', attrs: { id: 'fn1' }, content: [P(T('note'))] }] }),
|
||||
primary: 'footnoteReference',
|
||||
},
|
||||
status: { doc: doc(P({ type: 'status', attrs: { text: 'Done', color: 'green' } })), primary: 'status' },
|
||||
// marks
|
||||
bold: { doc: doc(P(T('b', [{ type: 'bold' }]))), primary: 'bold' },
|
||||
italic: { doc: doc(P(T('i', [{ type: 'italic' }]))), primary: 'italic' },
|
||||
strike: { doc: doc(P(T('s', [{ type: 'strike' }]))), primary: 'strike' },
|
||||
code: { doc: doc(P(T('c', [{ type: 'code' }]))), primary: 'code' },
|
||||
underline: { doc: doc(P(T('u', [{ type: 'underline' }]))), primary: 'underline' },
|
||||
superscript: { doc: doc(P(T('x', [{ type: 'superscript' }]))), primary: 'superscript' },
|
||||
subscript: { doc: doc(P(T('x', [{ type: 'subscript' }]))), primary: 'subscript' },
|
||||
highlight: { doc: doc(P(T('h', [{ type: 'highlight', attrs: { color: 'yellow' } }]))), primary: 'highlight' },
|
||||
link: { doc: doc(P(T('l', [{ type: 'link', attrs: { href: 'https://x.com' } }]))), primary: 'link' },
|
||||
};
|
||||
|
||||
function collectTypes(n: any, set = new Set<string>()): Set<string> {
|
||||
if (!n || typeof n !== 'object') return set;
|
||||
if (n.type) set.add(n.type);
|
||||
if (Array.isArray(n.content)) n.content.forEach((c: any) => collectTypes(c, set));
|
||||
if (Array.isArray(n.marks)) n.marks.forEach((m: any) => m?.type && set.add(m.type));
|
||||
return set;
|
||||
}
|
||||
|
||||
describe('git-sync converter: every node/mark type survives a Markdown round trip', () => {
|
||||
for (const [name, { doc: original, primary }] of Object.entries(FIXTURES)) {
|
||||
it(`round-trips ${name} (keeps the ${primary} node/mark, no literal leak)`, async () => {
|
||||
const md = convertProseMirrorToMarkdown(original);
|
||||
// The lossy old form serialized embeds to `{{...}}` literals that never
|
||||
// re-parsed; no node may export to one.
|
||||
expect(md).not.toMatch(/\{\{.*\}\}/);
|
||||
const back = await markdownToProseMirror(md);
|
||||
const types = collectTypes(back);
|
||||
expect(types.has(primary)).toBe(true);
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user