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 102 to 103

Compare

+127 −0 in 1 place
new file, 127 lines
1+// A small live graph and a graph rebuilt from its serialized history must
2+// answer the same one-file record query.
3+
4+import assert from "node:assert/strict";
5+import { describe, it } from "node:test";
6+import { buildAtom, Graph, View } from "../index.ts";
7+import { lines, Repo } from "./helpers.ts";
8+
9+describe("record-query replay contract", () => {
10+ it("matches a one-file record query after repeated writers, readers, and delete/recreate history", () => {
11+ const repo = Repo.init({ "src.txt": lines("top", "bottom"), "recreated.txt": lines("old") });
12+ const base = ["a0"];
13+ const insertAtTopGap = (text: string) =>
14+ repo.edit({ edits: [{ file: "src.txt", start: 1, end: 1, lines: [text], mode: "after" }] }, base);
15+ const writerOne = insertAtTopGap("writer one");
16+ const writerTwo = insertAtTopGap("writer two");
17+ const readerOne = insertAtTopGap("reader one");
18+ const readerTwo = insertAtTopGap("reader two");
19+ const attrOne = repo.edit({ attrs: [{ file: "src.txt", name: "exec", value: "1" }] }, base);
20+ const attrTwo = repo.edit({ attrs: [{ file: "src.txt", name: "exec", value: null }] }, base);
21+ const deletion = repo.edit({ edits: [{ file: "recreated.txt", old: lines("old"), new: "" }] });
22+ const recreation = repo.edit({ edits: [{ file: "recreated.txt", old: "", new: lines("fresh") }] });
24+ // Nine existing atoms make a finite, repeatable history. The last query
25+ // both replaces a line and inserts at the repeatedly written gap.
26+ assert.equal(repo.graph.size, 9);
27+ assert.deepEqual(recreation.deps, ["a0", deletion.id]);
28+ assert.deepEqual(repo.view().attrs("src.txt"), {
29+ exists: false,
30+ exec: false,
31+ link: null,
32+ blob: null,
33+ });
35+ const input = {
36+ author: "record-query-test",
37+ message: "record one file",
38+ time: 100,
39+ edits: [
40+ { file: "src.txt", start: 0, end: 1, lines: ["TOP"] },
41+ { file: "src.txt", start: 1, end: 1, lines: ["recorded"] },
42+ ],
43+ attrs: [{ file: "src.txt", name: "exec" as const, value: "1" }],
44+ };
45+ const liveAtom = buildAtom(repo.view(), input);
46+ const expectedDeps = ["a0", writerOne.id, writerTwo.id, readerOne.id, readerTwo.id, attrOne.id, attrTwo.id];
47+ assert.deepEqual(liveAtom.deps, expectedDeps);
48+ assert.equal(liveAtom.deps.length, 7);
49+ assert.equal(liveAtom.writes.length, 3);
50+ assert.equal(liveAtom.reads.length, 2);
51+ assert.equal(liveAtom.holds.length, 0);
52+ assert.equal(liveAtom.seq, 9);
53+ assert.deepEqual(liveAtom.deletes, ["a0.1"]);
54+ assert.deepEqual(liveAtom.inserts, [
55+ { file: "src.txt", parent: "a0.1", lines: ["TOP"] },
56+ { file: "src.txt", parent: "a0.1", lines: ["recorded"] },
57+ ]);
58+ assert.deepEqual(liveAtom.attrs, [{ file: "src.txt", name: "exec", value: "1" }]);
60+ const coldGraph = Graph.fromJSON(JSON.parse(JSON.stringify(repo.graph.toJSON())));
61+ const coldSet = new Set(repo.shared);
62+ const coldAtom = buildAtom(new View(coldGraph, coldSet), input);
63+ assert.deepEqual(coldAtom, liveAtom);
64+ assert.equal(JSON.stringify(coldAtom), JSON.stringify(liveAtom));
65+ const perturbedInput = {
66+ ...input,
67+ edits: input.edits.map((edit, index) => (index === 1 ? { ...edit, lines: ["different"] } : edit)),
68+ };
69+ const perturbedAtom = buildAtom(new View(coldGraph, coldSet), perturbedInput);
70+ assert.notDeepEqual(perturbedAtom, liveAtom);
71+ assert.notEqual(JSON.stringify(perturbedAtom), JSON.stringify(liveAtom));
73+ repo.graph.add(liveAtom);
74+ repo.shared.add(liveAtom.id);
75+ coldGraph.add(coldAtom);
76+ coldSet.add(coldAtom.id);
77+ const liveView = new View(repo.graph, repo.shared);
78+ const coldView = new View(coldGraph, coldSet);
79+ const visible = (view: View, path: string) => view.lines(path).map((line) => [line.id, line.text, line.atom]);
80+ assert.deepEqual(visible(liveView, "src.txt"), visible(coldView, "src.txt"));
81+ assert.deepEqual(
82+ visible(liveView, "src.txt").map((line) => line[1]),
83+ ["TOP", "recorded", "reader two", "reader one", "writer two", "writer one", "bottom"],
84+ );
85+ assert.deepEqual(liveView.attrs("src.txt"), coldView.attrs("src.txt"));
86+ assert.equal(liveView.attrs("src.txt").exec, true);
87+ assert.deepEqual(visible(liveView, "recreated.txt"), visible(coldView, "recreated.txt"));
88+ assert.deepEqual(
89+ visible(liveView, "recreated.txt").map((line) => line[1]),
90+ ["fresh"],
91+ );
92+ assert.deepEqual(
93+ liveView.sequence("recreated.txt").map((line) => [line.id, line.text, line.visible, line.deletedBy]),
94+ [
95+ [`${recreation.id}.0`, "fresh", true, []],
96+ ["a0.0", "old", false, [deletion.id]],
97+ ],
98+ );
100+ const recreatedFileInput = {
101+ author: "record-query-test",
102+ message: "record the recreated file",
103+ time: 101,
104+ edits: [{ file: "recreated.txt", old: lines("fresh"), new: lines("FRESH") }],
105+ };
106+ const liveRecreatedFileAtom = buildAtom(liveView, recreatedFileInput);
107+ const coldRecreatedFileAtom = buildAtom(coldView, recreatedFileInput);
108+ assert.deepEqual(liveRecreatedFileAtom.deps, [recreation.id]);
109+ assert.deepEqual(coldRecreatedFileAtom, liveRecreatedFileAtom);
110+ assert.equal(JSON.stringify(coldRecreatedFileAtom), JSON.stringify(liveRecreatedFileAtom));
111+ repo.graph.add(liveRecreatedFileAtom);
112+ repo.shared.add(liveRecreatedFileAtom.id);
113+ coldGraph.add(coldRecreatedFileAtom);
114+ coldSet.add(coldRecreatedFileAtom.id);
115+ assert.deepEqual(
116+ visible(new View(repo.graph, repo.shared), "recreated.txt"),
117+ visible(new View(coldGraph, coldSet), "recreated.txt"),
118+ );
119+ assert.deepEqual(
120+ visible(new View(repo.graph, repo.shared), "recreated.txt").map((line) => line[1]),
121+ ["FRESH"],
122+ );
123+ assert.equal(repo.graph.size, 11);
124+ assert.equal(coldGraph.size, 11);
125+ assert.equal(JSON.stringify(coldGraph.toJSON()), JSON.stringify(repo.graph.toJSON()));
126+ });
127+});
MCP
compare on this site's /mcp
CLI
abso diff 102 103 src/engine/test/record-query-contract.test.ts --json
JSON
/christopher/abso-core/compare/102..103?file=src%2Fengine%2Ftest%2Frecord-query-contract.test.ts&format=json