Files
explicata/tests/library.test.ts
T
thalladaandClaude Opus 5.5 44d2e437eb Core without documents: no slugs; a node's top; targets by titles from the library root
The model has no slug any more (field, ops, canonical row, slugFor, freeSlug, RESERVED,
findDoc). The child of the root a node is under is a derived relation, topOf (docOf and
documents stay as deprecated aliases for the UI until step 2); ancestorsInDoc becomes
ancestorsBelowRoot. Slug keys and a target's old `doc` in stored libraries are ignored.

A node target's path is the titles down from the library root; `rel` marks a path read
below a top (a file being imported, what the agent or a person typed). Where two sections
share a title, the one the link is written in wins. The text format writes /Top title/…,
and ./… inside the exported subtree. The agent may give a node id as a target.

renderContext renders the top's outline in an <outline> tag, and steps down the focus
path when even titles are over budget. Prompts, the reviewer and the scanner speak of
the library, trees and tops; the scanner's unit is the top, with the same behaviour
(scripts/linkEval.ts gives identical metrics).

src/core/library.ts keeps a slug-free shim for the UI's document features (names made
from titles) until step 2 removes them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
2026-11-16 23:32:08 -05:00

43 lines
1.7 KiB
TypeScript

/**
* Every starter file in library/ parses and builds. A failure names the file, the line, the
* section and the quote, all of them at once, so the files can be fixed in one pass.
*/
import { readFileSync, readdirSync } from "node:fs";
import { describe, expect, it } from "vitest";
import { FormatError } from "../src/core/format";
import { Doc, descendants, isStale } from "../src/core/model";
import { writeText } from "../src/core/seed";
import { slugify } from "../src/core/text";
const dir = new URL("../library/", import.meta.url);
const files = (() => {
try {
return readdirSync(dir).filter((f) => f.endsWith(".md")).sort();
} catch {
return [];
}
})();
describe("library", () => {
it("parses and builds every file into one library, with nothing stale", () => {
const failures: string[] = [];
const lib = Doc.library("test");
for (const f of files) {
const id = f.slice(0, -3);
if (slugify(id) !== id) failures.push(`${f}: the file name is not a valid id (lowercase letters, digits, hyphens); it would be imported as "${slugify(id)}"`);
try {
const id = writeText(lib, readFileSync(new URL(f, dir), "utf8"), f);
const snap = lib.snap();
const stale = [id, ...descendants(snap, id)].filter((n) => isStale(snap, n));
if (stale.length) failures.push(`${f}: ${stale.length} nodes start out stale`);
if (!snap.nodes[id].title) failures.push(`${f}: the file has no title`);
} catch (err) {
if (!(err instanceof FormatError)) throw err;
failures.push(...err.problems);
}
}
console.log(`library: ${files.length} files, ${failures.length} problems${failures.length ? `\n ${failures.join("\n ")}` : ""}`);
expect(failures).toEqual([]);
});
});