First step of docs/git-sync-plan.md. New workspace package @docmost/git-sync vendoring the PURE parts from docmost-sync (HEAD b03eb35): - lib: markdown-converter, markdown-document, canonicalize, docmost-schema, node-ops, diff, and an extracted markdown-to-prosemirror (only the pure marked->HTML->generateJSON path from upstream collaboration.ts; no websocket). - engine (pure, no IO): reconcile, layout, sanitize, stabilize, loop-guard. Ported the upstream pure-module + round-trip corpus tests (vitest): 314 pass, 3 expected upstream known-limitation fails. tsc clean. No server wiring yet. docmost-schema inlines getStyleProperty (as packages/mcp does — @tiptap/core 3.20.4 doesn't export it). IO engine (pull/push/git/settings) deferred to later Phase A/B steps; the editor-ext idempotency gate (plan §13.1) is the next step. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
import { readFile } from 'node:fs/promises';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { dirname, join } from 'node:path';
|
|
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
convertProseMirrorToMarkdown,
|
|
markdownToProseMirror,
|
|
} from 'docmost-client';
|
|
|
|
// Resolve the fixture relative to this test file so the test is CWD-independent.
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const FIXTURE = join(here, 'fixtures', 'sample-doc.json');
|
|
|
|
describe('round-trip idempotency (SPEC §11)', () => {
|
|
it('markdown is byte-stable across export -> import -> export', async () => {
|
|
const doc = JSON.parse(await readFile(FIXTURE, 'utf8'));
|
|
|
|
// export -> import -> export
|
|
const md1 = convertProseMirrorToMarkdown(doc);
|
|
const doc2 = await markdownToProseMirror(md1);
|
|
const md2 = convertProseMirrorToMarkdown(doc2);
|
|
|
|
// The property git actually needs: a second export reproduces the first
|
|
// byte-for-byte. We intentionally do NOT deep-equal doc vs doc2 — the
|
|
// converter reconstructs schema default attrs (e.g. indent:null), a known
|
|
// SPEC §11 divergence that does not affect markdown stability.
|
|
expect(md2).toBe(md1);
|
|
});
|
|
});
|