Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 3 to 318

Compare

+56 −0 in 1 place
new file, 56 lines
1+// The atoms whose reasons point at an atom (abso Capacity, Graph.reasonsTo): why's "reasons in" reads them instead of
2+// every atom. In seq order, once each, whatever the kind and however many reasons one atom gives; kept from a fresh
3+// stored graph on, and undefined on a stored graph made before, where the caller looks at every atom.
4+
5+import assert from "node:assert/strict";
6+import { test } from "node:test";
7+import { Graph } from "../index.ts";
8+import { lines, Repo } from "./helpers.ts";
9+import { SqlState } from "./storage-helper.ts";
11+function history() {
12+ const repo = Repo.init({ "f.txt": lines("one", "two", "three") });
13+ const x = repo.edit({ author: "ann", message: "x", edits: [{ file: "f.txt", old: "one", new: "ONE" }] });
14+ repo.edit({
15+ author: "bob",
16+ message: "y",
17+ edits: [{ file: "f.txt", old: "two", new: "TWO" }],
18+ reasons: [
19+ { to: x.id, kind: "together", text: "same idea" },
20+ { to: x.id, kind: "because-of", text: "and because of it" },
21+ ],
22+ });
23+ repo.edit({ author: "cy", message: "unrelated", edits: [{ file: "f.txt", old: "three", new: "3" }] });
24+ repo.edit({
25+ author: "dee",
26+ message: "z",
27+ edits: [{ file: "f.txt", old: "3", new: "THREE" }],
28+ reasons: [{ to: x.id, kind: "supersedes", text: "replaces it" }],
29+ });
30+ return { repo, x };
31+}
33+/** Every atom whose reasons point at id, by looking at each one: what reasonsTo must give. */
34+const scanned = (graph: Graph, id: string) =>
35+ [...graph.atoms()].filter((a) => a.reasons.some((r) => r.to === id)).map((a) => a.id);
37+test("reasonsTo lists the atoms pointing at an atom, in seq order, once each", () => {
38+ const { repo, x } = history();
39+ const want = scanned(repo.graph, x.id);
40+ assert.equal(want.length, 2, "bob's two reasons and dee's");
41+ assert.deepEqual(repo.graph.reasonsTo(x.id), want);
42+ const storage = new SqlState();
43+ const stored = new Graph({ storage });
44+ for (const atom of repo.graph.atoms()) stored.add(atom);
45+ assert.deepEqual(new Graph({ storage }).reasonsTo(x.id), want);
46+ assert.deepEqual(new Graph({ storage }).reasonsTo("a0"), []);
47+});
49+test("a stored graph made before the index keeps none, and says so", () => {
50+ const { repo, x } = history();
51+ const storage = new SqlState();
52+ const stored = new Graph({ storage });
53+ for (const atom of repo.graph.atoms()) stored.add(atom);
54+ storage.remove("reasons-in:meta", "kept");
55+ assert.equal(new Graph({ storage }).reasonsTo(x.id), undefined);
56+});
MCP
compare on this site's /mcp
CLI
abso diff 3 318 src/engine/test/reasons-to.test.ts --json
JSON
/christopher/abso-core/compare/3..318?file=src%2Fengine%2Ftest%2Freasons-to.test.ts&format=json