- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/src/engine/test/state-source.test.ts?version=110&format=json
96 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 109, 1 version changed it
You're reading version 110. The newest is 318, and 14 versions since then changed this file.
codex-capacity-policy has unpushed changes at lines 1–89no start notelast edit
1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { checkDraft, Graph, View } from "../index.ts";
4import { lines, Repo } from "./helpers.ts";
5import { SqlState } from "./storage-helper.ts";
7test("stored graph reopens without replay and preserves moves, conflicts and new edits", () => {
8 const oracle = Repo.init({ "a.txt": lines("one", "two", "three"), "b.txt": "" });
9 oracle.edit({ edits: [{ file: "a.txt", old: "two", new: "TWO" }] });
10 oracle.edit({ move: { file: "a.txt", start: 1, end: 2, to: "b.txt", at: 0 } });
11 const storage = new SqlState();
12 const original = new Graph({ storage });
13 for (const atom of oracle.graph.atoms()) original.add(atom);
14 original.setLabel({ name: "saved", head: "a2", title: "Saved", message: "" });
15 const reads = storage.reads;
16 const reopened = new Graph({ storage });
17 assert.equal(storage.reads, reads, "opening does not hydrate historical collections");
18 assert.equal(storage.scans, 0);
19 assert.equal(reopened.size, oracle.graph.size);
20 assert.equal(reopened.lineCount, oracle.graph.lineCount);
21 assert.deepEqual([...reopened.movers()], [...oracle.graph.movers()]);
22 for (const atom of oracle.graph.atoms()) {
23 assert.deepEqual(reopened.filesOf(atom.id), oracle.graph.filesOf(atom.id));
24 for (const move of atom.moves ?? []) {
25 assert.deepEqual(reopened.relocationsOf(move.line), oracle.graph.relocationsOf(move.line));
26 assert.deepEqual(reopened.relocatedTo(move.parent), oracle.graph.relocatedTo(move.parent));
27 assert.equal(reopened.codeOf(move.parent), oracle.graph.codeOf(move.parent));
28 }
29 }
30 assert.deepEqual(new View(reopened, oracle.shared).files(), oracle.files());
31 assert.equal(reopened.label("saved")?.head, "a2");
32 const draft = oracle.draft({ edits: [{ file: "a.txt", old: "one", new: "ONE" }] });
33 assert.deepEqual(checkDraft(reopened, oracle.shared, draft), oracle.check(draft));
34 oracle.graph.add(draft);
35 reopened.add(draft);
36 oracle.shared.add(draft.id);
37 assert.deepEqual(new View(new Graph({ storage }), oracle.shared).files(), oracle.files());
38 for (let n = 0; n < oracle.graph.lineCount; n++) {
39 const id = oracle.graph.lineIdOf(n);
40 assert.deepEqual(reopened.line(id), oracle.graph.line(id));
41 assert.deepEqual(reopened.deletersOf(id), oracle.graph.deletersOf(id));
42 }
43 assert.ok(Object.isFrozen(reopened.atom("a0")));
44 storage.db.close();
45});
47test("stored indexes retain multiple claimants and preserve a real divergent conflict", () => {
48 const oracle = Repo.init({ "a.txt": lines("one", "two", "three") });
49 oracle.edit({ edits: [{ file: "a.txt", old: "one", new: "ONE" }], author: "left" });
50 const right = oracle.draft({ edits: [{ file: "a.txt", old: "one", new: "uno" }], author: "right" }, ["a0"]);
51 const storage = new SqlState();
52 const graph = new Graph({ storage });
53 for (const atom of oracle.graph.atoms()) graph.add(atom);
54 assert.equal(oracle.check(right).conflicts.length, 1);
55 assert.deepEqual(checkDraft(new Graph({ storage }), oracle.shared, right), oracle.check(right));
56 graph.add(right);
57 oracle.graph.add(right);
58 assert.deepEqual(new Graph({ storage }).writersOf("L:a0.0"), oracle.graph.writersOf("L:a0.0"));
59 assert.deepEqual(new Graph({ storage }).deletedLines(right.id), oracle.graph.deletedLines(right.id));
60 storage.db.close();
61});
63test("failed stored append rolls back all graph indexes and can be retried", () => {
64 const oracle = Repo.init({ "a.txt": lines("one", "two") });
65 const storage = new SqlState();
66 const graph = new Graph({ storage });
67 graph.add(oracle.graph.atom("a0"));
68 const before = JSON.stringify(graph.toJSON());
69 const draft = oracle.draft({ edits: [{ file: "a.txt", old: "one", new: "ONE" }] });
70 storage.failWrite = storage.writes + 10;
71 assert.throws(() => graph.add(draft), /injected storage failure/);
72 assert.equal(JSON.stringify(graph.toJSON()), before);
73 assert.equal(JSON.stringify(new Graph({ storage }).toJSON()), before);
74 storage.failWrite = Infinity;
75 graph.add(draft);
76 assert.equal(new Graph({ storage }).size, 2);
77 storage.db.close();
78});
80test("removing a stored label rolls back dependent rewrites on failure", () => {
81 const oracle = Repo.init({ "a.txt": lines("one") });
82 const storage = new SqlState();
83 const graph = new Graph({ storage });
84 graph.add(oracle.graph.atom("a0"));
85 graph.setLabel({ name: "base", head: "a0", title: "Base", message: "" });
86 graph.setLabel({ name: "child", head: "a0", base: "base", title: "Child", message: "" });
87 const before = graph.labels();
88 storage.failWrite = storage.writes + 1;
89 assert.throws(() => graph.removeLabel("base"), /injected storage failure/);
90 assert.deepEqual(new Graph({ storage }).labels(), before);
91 storage.failWrite = Infinity;
92 assert.equal(graph.removeLabel("base"), true);
93 assert.equal(new Graph({ storage }).label("base"), undefined);
94 assert.equal(new Graph({ storage }).label("child")?.base, "a0");
95 storage.db.close();
96});