Docs: the libraries panel and deleting (and restoring) a library in the README; no documents left: the seed's description of itself, docs/wikipedia.md (top-level trees, per-library paths), the tagline, comments, test names and the link evaluation script
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
1 parent
146437a01a
commit
fc7c222407
26 files changed
+167
-145
No files matched your search
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Convergence: replicas of a library that apply random concurrent ops through the op API (moving
|
||||
* and copying nodes between its documents among them) and exchange updates in random order must
|
||||
* and copying nodes between its top-level trees among them) and exchange updates in random order must
|
||||
* end in identical state, with a history that still verifies. Along the way every snapshot, which
|
||||
* is patched node by node after each change, must equal one read from scratch.
|
||||
*/
|
||||
@@ -39,8 +39,8 @@ function base(): Doc {
|
||||
{ op: "create", parent: "$0" as NodeId, title: "Two", body: "The second child." },
|
||||
{ op: "create", parent: "$1" as NodeId, title: "Deep", body: "A grandchild." },
|
||||
{ op: "create", parent: "$0" as NodeId, kind: "note", quote: "Beta", form: "gloss", body: "second letter" },
|
||||
{ op: "create", parent: lib, title: "Doc B", body: "Another document entirely." },
|
||||
{ op: "create", parent: "$5" as NodeId, title: "Three", body: "A section of the second document." },
|
||||
{ op: "create", parent: lib, title: "Doc B", body: "Another tree entirely." },
|
||||
{ op: "create", parent: "$5" as NodeId, title: "Three", body: "A section of the second tree." },
|
||||
],
|
||||
"Base",
|
||||
);
|
||||
|
||||
+15
-15
@@ -134,7 +134,7 @@ describe("history", () => {
|
||||
doc.apply([{ op: "delete", id: one }], "Delete one");
|
||||
doc.apply([{ op: "update", id: root, title: "Root!" }], "Rename");
|
||||
const h = history(doc);
|
||||
expect(h.map((c) => c.message)).toEqual(["Rename", "Delete one", "Edit one", "Add children", "Create document"]);
|
||||
expect(h.map((c) => c.message)).toEqual(["Rename", "Delete one", "Edit one", "Add children", "Create the tree"]);
|
||||
expect(verifyHistory(doc)).toEqual({ checked: 5, unhashed: 0, mismatches: [] });
|
||||
expect(at(doc, h[2]).canonical()).toBe(states[0]);
|
||||
revertTo(doc, h[2]);
|
||||
@@ -282,26 +282,26 @@ function library() {
|
||||
const staleIds = (doc: Doc) => Object.keys(doc.snap().nodes).filter((id) => isStale(doc.snap(), id as NodeId));
|
||||
|
||||
describe("library", () => {
|
||||
it("the root is never stale, and an edit inside a document marks neither the root nor the other documents", () => {
|
||||
it("the root is never stale, and an edit inside a top-level tree marks neither the root nor the other trees", () => {
|
||||
const { doc, lib, a, aPart, aLeaf, aNote, b } = library();
|
||||
expect(staleIds(doc)).toEqual([]);
|
||||
doc.apply([{ op: "update", id: a, body: "Alpha is now about something else." }], "Edit a document's text");
|
||||
doc.apply([{ op: "update", id: a, body: "Alpha is now about something else." }], "Edit a top's text");
|
||||
// Its own sections now elaborate text that changed; nothing outside it does.
|
||||
expect(staleIds(doc)).toEqual([aPart]);
|
||||
doc.apply([{ op: "bless", id: aPart }], "Accept");
|
||||
doc.apply([{ op: "update", id: aLeaf, body: "A rewritten leaf." }], "Edit a leaf");
|
||||
expect(staleIds(doc)).toEqual([aPart]);
|
||||
doc.apply([{ op: "update", id: aPart, body: "A rewritten part." }], "Edit the part");
|
||||
// Up to its document, which now summarises a changed part; down to its leaf and the note whose words went.
|
||||
// Up to its top, which now summarises a changed part; down to its leaf and the note whose words went.
|
||||
const inAlpha = [a, aLeaf, aNote].sort();
|
||||
expect(staleIds(doc).sort()).toEqual(inAlpha);
|
||||
// Renaming, adding and deleting documents changes the library's sections, which it does not summarise.
|
||||
// Renaming, adding and deleting top-level nodes changes the library's sections, which it does not summarise.
|
||||
doc.apply(retitleOps(doc.snap(), b, "Beta renamed"), "Rename");
|
||||
doc.apply([{ op: "create", parent: lib, title: "Gamma", body: "New." }], "New document");
|
||||
doc.apply([{ op: "delete", id: b }], "Delete a document");
|
||||
doc.apply([{ op: "create", parent: lib, title: "Gamma", body: "New." }], "New top");
|
||||
doc.apply([{ op: "delete", id: b }], "Delete a top");
|
||||
expect(staleIds(doc).sort()).toEqual(inAlpha);
|
||||
expect(staleness(doc.snap(), lib)).toEqual({ up: false, down: false, orphan: false });
|
||||
// The library's own text is the reader's; editing it marks no document.
|
||||
// The library's own text is the reader's; editing it marks no top.
|
||||
doc.apply([{ op: "update", id: lib, body: "My library." }], "Write the library's text");
|
||||
expect(staleIds(doc).sort()).toEqual(inAlpha);
|
||||
expect(topOf(doc.snap(), lib)).toBeNull();
|
||||
@@ -309,7 +309,7 @@ describe("library", () => {
|
||||
expect(ancestorsBelowRoot(doc.snap(), aLeaf)).toEqual([doc.snap().nodes[aLeaf].parent, a]);
|
||||
});
|
||||
|
||||
it("moves a node from one document to another with an ordinary move; its notes keep their anchors and undo moves it back", () => {
|
||||
it("moves a node from one top-level tree to another with an ordinary move; its notes keep their anchors and undo moves it back", () => {
|
||||
const { doc, a, aPart, aNote, b } = library();
|
||||
const undo = new UndoManager(doc.loro, { mergeInterval: 0, excludeOriginPrefixes: [SYSTEM_ORIGIN] });
|
||||
doc.group = { start: () => undo.groupStart(), end: () => undo.groupEnd() };
|
||||
@@ -319,7 +319,7 @@ describe("library", () => {
|
||||
expect(topOf(snap, aPart)).toBe(b);
|
||||
expect(snap.nodes[aNote].anchors[0].text).toBe("a phrase worth a note");
|
||||
expect(sections(snap, a)).toEqual([]);
|
||||
// Both documents' summaries are now out of date, as with any move.
|
||||
// Both tops' summaries are now out of date, as with any move.
|
||||
expect(staleness(snap, a).up && staleness(snap, b).up).toBe(true);
|
||||
expect(verifyHistory(doc).mismatches).toEqual([]);
|
||||
expect(undo.undo()).toBe(true);
|
||||
@@ -333,9 +333,9 @@ describe("library", () => {
|
||||
expect(tops(doc.snap())).toEqual([a, b, aPart]);
|
||||
});
|
||||
|
||||
it("loads a library whose nodes still carry slugs (and node targets a document slug), ignoring them", () => {
|
||||
it("loads a library whose nodes still carry slugs from before step 1 (and node targets naming one), ignoring them", () => {
|
||||
const { doc, a, aLeaf, b } = library();
|
||||
// As an older version wrote them: a slug on each top, and a target naming its document.
|
||||
// As an older version wrote them: a slug on each top, and a target naming its top by that slug.
|
||||
const old = doc.fork();
|
||||
old.apply([{ op: "create", parent: b, kind: "note", quote: "Beta", ref: { kind: "node", id: aLeaf, path: ["Alpha part"] } }], "Link");
|
||||
const link = notesOf(old.snap(), b)[0];
|
||||
@@ -367,13 +367,13 @@ describe("library", () => {
|
||||
expect(snap.nodes[note].anchors[0].text).toBe("a phrase worth a note");
|
||||
});
|
||||
|
||||
it("reverts one document to a commit and leaves the others as they are now", () => {
|
||||
it("reverts one top-level tree to a commit and leaves the others as they are now", () => {
|
||||
const { doc, a, aPart, aLeaf, b, bLeaf } = library();
|
||||
const mark = history(doc)[0];
|
||||
doc.apply([{ op: "update", id: aLeaf, body: "Changed later." }], "Change a leaf");
|
||||
doc.apply([{ op: "delete", id: aPart }], "Delete a part");
|
||||
doc.apply([{ op: "create", parent: a, title: "Added later" }], "Add a section");
|
||||
doc.apply([{ op: "update", id: bLeaf, body: "Beta changed later too." }], "Change the other document");
|
||||
doc.apply([{ op: "update", id: bLeaf, body: "Beta changed later too." }], "Change the other top");
|
||||
const beta = doc.shape(doc.snap(), b);
|
||||
revertSubtreeTo(doc, mark, a);
|
||||
const snap = doc.snap();
|
||||
@@ -384,7 +384,7 @@ describe("library", () => {
|
||||
expect(verifyHistory(doc).mismatches).toEqual([]);
|
||||
});
|
||||
|
||||
it("names the nodes a commit wrote, and syncs edits in different documents without comparing whole states", () => {
|
||||
it("names the nodes a commit wrote, and syncs edits in different top-level trees without comparing whole states", () => {
|
||||
const { doc, aLeaf, bLeaf } = library();
|
||||
doc.apply([{ op: "update", id: aLeaf, body: "Edited." }], "Edit");
|
||||
expect([...touched(doc, history(doc)[0].spans).nodes]).toContain(aLeaf);
|
||||
|
||||
@@ -130,7 +130,7 @@ describe("parsing", () => {
|
||||
expect(problems("")).toEqual([`doc.md: no "# Title" heading`]);
|
||||
});
|
||||
|
||||
it("makes slugs from titles and file names", () => {
|
||||
it("makes safe file names from titles and file names", () => {
|
||||
expect(slugify("Tuning & Temperament")).toBe("tuning-temperament");
|
||||
expect(slugify("Ça va? Déjà vu!")).toBe("ca-va-deja-vu");
|
||||
expect(slugify("../../etc/passwd")).toBe("etc-passwd");
|
||||
@@ -280,7 +280,7 @@ describe("export and import", () => {
|
||||
expect(canonBody(" one \n two\n\n\n\nthree \n \n")).toBe("one\ntwo\n\nthree");
|
||||
});
|
||||
|
||||
it("exports the first document without losing a note", () => {
|
||||
it("exports the first tree without losing a note", () => {
|
||||
const prompt = readFileSync(new URL("../src/seed/prompt.txt", import.meta.url), "utf8");
|
||||
const doc = Doc.library("test");
|
||||
const first = writeSeed(doc, prompt, seed);
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ describe("the hash and history", () => {
|
||||
|
||||
it("a tree without targets hashes as it did before targets existed", () => {
|
||||
// The row of a node with no target is unchanged, so old commits still verify: the first
|
||||
// document's seed commits are checked by the seed tests; here, a slug-only row.
|
||||
// tree's seed commits are checked by the seed tests; here, a library made now.
|
||||
const { doc } = library();
|
||||
expect(verifyHistory(doc).mismatches).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -89,7 +89,7 @@ describe("a research run with the mock", () => {
|
||||
expect(seen[0].messages[0].content).toContain("Web research is on for this request");
|
||||
});
|
||||
|
||||
it("is stopped by its signal, and nothing it did reaches the document", async () => {
|
||||
it("is stopped by its signal, and nothing it did reaches the library", async () => {
|
||||
const { doc, tides } = fixture();
|
||||
const ac = new AbortController();
|
||||
const before = doc.snap().nodes[tides].children.length;
|
||||
@@ -106,7 +106,7 @@ describe("citing only what was retrieved", () => {
|
||||
const result = await runAgent(mockLLM(), doc, "tides, unretrieved", tides, (e) => events.push(e), undefined, {}, research);
|
||||
const error = events.find((e) => e.kind === "error")!;
|
||||
expect(error.text).toMatch(/not among the search results or pages read in this run/);
|
||||
// It corrected itself to a page it did retrieve; the rejected address is nowhere in the document.
|
||||
// It corrected itself to a page it did retrieve; the rejected address is nowhere in the library.
|
||||
expect(result.sources.map((s) => s.url)).toEqual([MOCK_RESULTS[0].url]);
|
||||
expect(Object.values(doc.snap().nodes).some((n) => n.ref?.kind === "url" && n.ref.url === MOCK_UNRETRIEVED)).toBe(false);
|
||||
});
|
||||
|
||||
+8
-8
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* A library of about 5,000 nodes in 100 documents: an edit must cost what it touches, not the size
|
||||
* A library of about 5,000 nodes in 100 top-level trees: an edit must cost what it touches, not the size
|
||||
* of the library. Timings are printed; the assertions are budgets well inside one 16 ms frame for
|
||||
* the work a keystroke does, and a comparison with a library a tenth the size.
|
||||
*/
|
||||
@@ -14,12 +14,12 @@ import { renderContext } from "../src/llm/prompts";
|
||||
|
||||
const SENTENCE = "This sentence is about something that matters here. Another follows it, with a few more words. ";
|
||||
|
||||
/** `docs` documents of 50 nodes each: 7 sections of 6 leaves, and a note. */
|
||||
/** `docs` top-level trees of 50 nodes each: 7 sections of 6 leaves, and a note. */
|
||||
function synthetic(docs: number): Doc {
|
||||
const doc = Doc.library("scale");
|
||||
const lib = doc.snap().root;
|
||||
for (let d = 0; d < docs; d++) {
|
||||
const ops: Op[] = [{ op: "create", parent: lib, title: `Document ${d}`, body: SENTENCE.repeat(3) }];
|
||||
const ops: Op[] = [{ op: "create", parent: lib, title: `Tree ${d}`, body: SENTENCE.repeat(3) }];
|
||||
let n = 1;
|
||||
for (let s = 0; s < 7; s++) {
|
||||
const sec = n++;
|
||||
@@ -27,10 +27,10 @@ function synthetic(docs: number): Doc {
|
||||
for (let k = 0; k < 6; k++, n++) ops.push({ op: "create", parent: `$${sec}` as NodeId, title: `Leaf ${d}.${s}.${k}`, body: SENTENCE.repeat(2) });
|
||||
}
|
||||
ops.push({ op: "create", parent: "$0" as NodeId, kind: "note", quote: "something that matters", body: "A note." });
|
||||
// And a link to an article, shared by every tenth document, for the backlinks index to follow.
|
||||
// And a link to an article, shared by every tenth tree, for the backlinks index to follow.
|
||||
ops.push({ op: "create", parent: "$0" as NodeId, kind: "note", quote: "Another follows", ref: { kind: "wiki", title: `Topic ${d % 10}`, lang: "en" } });
|
||||
for (let i = 0; i < n; i++) ops.push({ op: "bless", id: `$${i}` as NodeId });
|
||||
doc.apply(ops, `Document ${d}`, { actor: "llm" });
|
||||
doc.apply(ops, `Tree ${d}`, { actor: "llm" });
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
@@ -55,7 +55,7 @@ function editCost(doc: Doc, rounds = 25) {
|
||||
}
|
||||
|
||||
describe("a large library", () => {
|
||||
it("costs what an edit touches: 5,000 nodes in 100 documents", () => {
|
||||
it("costs what an edit touches: 5,000 nodes in 100 top-level trees", () => {
|
||||
let t = performance.now();
|
||||
const big = synthetic(100);
|
||||
const built = performance.now() - t;
|
||||
@@ -80,7 +80,7 @@ describe("a large library", () => {
|
||||
const reread = (performance.now() - t) / 1000;
|
||||
expect(loaded.snap()).toBe(first);
|
||||
|
||||
// Server start: open the stored library and list its documents, as server/index.ts does.
|
||||
// Server start: open the stored library and list its top-level nodes, as the server does.
|
||||
const data = mkdtempSync(join(tmpdir(), "ie-scale-"));
|
||||
mkdirSync(join(data, "library"));
|
||||
writeFileSync(join(data, "library", "main.loro"), bytes);
|
||||
@@ -98,7 +98,7 @@ describe("a large library", () => {
|
||||
expect(ix.mentions("en", "Topic 3")).toHaveLength(10);
|
||||
const small = editCost(Doc.load(synthetic(10).snapshotBytes(), "reader"));
|
||||
console.log(
|
||||
`scale: ${nodes} nodes, ${(bytes.length / 1024).toFixed(0)} KB · built in ${built.toFixed(0)} ms · loaded and read in ${boot.toFixed(0)} ms · first state hash ${firstHash.toFixed(0)} ms · server store opened and listed in ${serverStart.toFixed(0)} ms · cached snapshot ${(reread * 1000).toFixed(1)} µs · backlinks index built in ${indexed.toFixed(1)} ms · body edit (op, commit, snapshot, staleness, context) median ${edit.toFixed(2)} ms at 100 documents, ${small.toFixed(2)} ms at 10`,
|
||||
`scale: ${nodes} nodes, ${(bytes.length / 1024).toFixed(0)} KB · built in ${built.toFixed(0)} ms · loaded and read in ${boot.toFixed(0)} ms · first state hash ${firstHash.toFixed(0)} ms · server store opened and listed in ${serverStart.toFixed(0)} ms · cached snapshot ${(reread * 1000).toFixed(1)} µs · backlinks index built in ${indexed.toFixed(1)} ms · body edit (op, commit, snapshot, staleness, context) median ${edit.toFixed(2)} ms at 100 trees, ${small.toFixed(2)} ms at 10`,
|
||||
);
|
||||
expect(edit).toBeLessThan(8);
|
||||
// An edit at a tenth of the size costs about the same: nothing it does walks the whole library.
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ describe("a node and everything under it, wherever it is", () => {
|
||||
lib.apply([{ op: "move", id: one, parent: b }, { op: "update", id: one, title: "Renamed" }], "move and rename");
|
||||
expect(address(lib.snap(), one)).toBe(`/n/${encodeURIComponent(one)}`);
|
||||
expect(resolve(lib.snap(), `/n/${encodeURIComponent(one)}`)).toEqual({ node: one });
|
||||
// What names nothing says so (the page then shows the library): a gone node, an old document address, anything else.
|
||||
// What names nothing says so (the page then shows the library): a gone node, an old `/doc/…` address, anything else.
|
||||
expect(resolve(lib.snap(), "/n/999%40999")).toEqual({ missing: "no node 999@999" });
|
||||
expect(resolve(lib.snap(), "/doc/tides")).toEqual({ missing: "no page /doc/tides" });
|
||||
expect(resolve(lib.snap(), "/n/%E0%A4%A")).toMatchObject({ missing: expect.any(String) });
|
||||
|
||||
Reference in new issue
Block a user