- MCP
- blame on this site's /mcp
- CLI
- abso blame src/engine/test/reasons-to.test.ts --json
- JSON
- /christopher/abso-core/blame/src/engine/test/reasons-to.test.ts?format=json
56 linescapacity 100%Last change capacity in version 242,
56 lines from 1 change in 1 version.
capacity242why: reasons pointing at a change indexed, and a moved line looked for among its push (disk-first 2; abso Capacity).
why on abso, warm, one kept reader: 2.9 s a call with about 24,000 reads, 20,000 of them atoms.
- Reasons in: why listed the changes whose reasons point at the line's change by reading every atom in the project. The graph now keeps, for each atom, the atoms whose reasons point at it, in seq order, once each (reasons-in, Graph.reasonsTo), from a fresh stored graph on. A graph made before keeps none, reasonsTo says undefined, and why looks at every atom as before.
- Moved from: the trail looked for a deleted copy of a line's text among every atom within 5,000 of the change. Only atoms pushed with it can count, so where the change is published its version's atoms are the candidates (Project.versionAtoms, trail's pushmates). A change still in a draft goes with every other draft change, so it looks near by as before.
- trail takes atoms' numbers from their ids instead of reading each atom.
On abso adopted fresh: why 244 ms on the first call, then 86 and 46 ms (was 2.9 s); 1,091 reads, then 469 and 73. It matches replay, which takes 951 ms. Heap after: 22.6 MB.
New test reasons-to: the atoms pointing at an atom, in seq order, once each, whatever the kind and however many reasons one gives, in memory and stored. A stored graph without the index says undefined. Every engine test (292 of 292), every worker/project test (341 of 341); tsc and biome clean.Compare1// 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.
5import assert from "node:assert/strict";
6import { test } from "node:test";
7import { Graph } from "../index.ts";
8import { lines, Repo } from "./helpers.ts";
9import { SqlState } from "./storage-helper.ts";
11function 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. */
34const scanned = (graph: Graph, id: string) =>
35 [...graph.atoms()].filter((a) => a.reasons.some((r) => r.to === id)).map((a) => a.id);
37test("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});
49test("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});