Files
gitmost/packages/git-sync/test/page-file.test.ts
T
claude code agent 227 24b903aaf3 build(git-sync): land the @docmost/git-sync package into develop, code-only (#326 step 1 / PR-A)
The git-sync converter + engine source lived only on the #119 branch; develop
had just the dead compiled build/. Bring the whole package (src + ~700 tests)
onto develop under CI, with NO consumer wired — git-sync stays fully inert in
develop (nothing in apps/server imports it), so runtime behavior is unchanged.
This unblocks #293 (extract the shared converter package from the landed source)
and lets #119's functionality land LAST, already writing the canonical format
(per the #326 landing order).

- packages/git-sync: src (lib converter + engine) + test corpus + configs.
- Remove develop's dead committed packages/git-sync/build/; gitignore it
  (built in CI/Docker via pnpm build, never committed — no src/build drift).
- pnpm-lock.yaml: add the @docmost/git-sync importer (a missing workspace
  package in the lock is a CI blocker). `pnpm install --frozen-lockfile` passes.
- NO server integration / loader / Dockerfile runtime changes (those come with
  #119 at step 6).

Verified: tsc clean; vitest 711 passed | 1 expected-fail, 0 failures, 0 type
errors; pnpm --frozen-lockfile EXIT 0; apps/server has no git-sync import.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-04 06:21:41 +03:00

34 lines
1.3 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { parsePageFile, serializePageFile } from "../src/lib/page-file";
describe("page-file thin format", () => {
it("round-trips id frontmatter + clean body", () => {
const text = serializePageFile("019ef6fc-2638", "# Hello\n\nbody text");
expect(text.startsWith("---\ngitmost_id: 019ef6fc-2638\n---\n")).toBe(true);
const { id, body } = parsePageFile(text);
expect(id).toBe("019ef6fc-2638");
expect(body).toBe("# Hello\n\nbody text");
});
it("serialization is deterministic (byte-identical for the same input)", () => {
expect(serializePageFile("p", "x")).toBe(serializePageFile("p", "x"));
});
it("reads id from frontmatter with quotes / extra fields", () => {
expect(parsePageFile('---\ngitmost_id: "abc"\ntitle: ignored\n---\nbody').id).toBe("abc");
expect(parsePageFile("---\ngitmost_id: 'xyz'\n---\nbody").id).toBe("xyz");
});
it("ADOPT: a plain hand-written file has no id and keeps its whole body", () => {
const { id, body } = parsePageFile("# Just a note\n\nwritten in Obsidian");
expect(id).toBeNull();
expect(body).toBe("# Just a note\n\nwritten in Obsidian");
});
it("tolerates empty / whitespace input", () => {
expect(parsePageFile("").id).toBeNull();
expect(parsePageFile(" \n ").body).toBe("");
});
});