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
MCP
blame on this site's /mcp
CLI
abso blame worker/project/test/known-paths.test.ts --json
JSON
/christopher/abso-core/blame/worker/project/test/known-paths.test.ts?format=json
124 linescapacity 100%Last change capacity in version 303,

124 lines from 3 changes in 2 versions.

capacity245Collisions step 1: whether a file exists, without laying it out (abso Capacity, issue 664). A published version's view on a writer answers hasFile from the kept path list (PathIndex.keptPathSet, the set pathsAt already answers from), and a draft's view asks its base for every file the draft doesn't touch. Resolving an import tried up to seven file names in collisions, and each check laid the whole file out. On the abso export (collisions, my machine): the first call lays out 130 files instead of 407, 13.4 s instead of 15.2 s; a warm call 7.7 s instead of 8.3 s (step 2 is most of what's left). Same answer as replay. Heap after a full warm run: 76.9 MB against 76.5 MB on 244. test/known-paths.test.ts: every name at versions 0 to 2 and in four drafts, against the in-memory project, before and after every file is read: a version that deletes a file and renames one with record, one that moves lines into a new file, and drafts that delete, rename, move lines and add.Compare1// Whether a file exists, answered without laying it out (abso Capacity, View.knowPaths): a published version's view
2// on a writer answers from the kept path list, and a draft's view asks its base for every file the draft doesn't
3// touch. Each must say what the in-memory project says, at every version and in every draft: files deleted or
4// renamed by a published version, and by a draft, by record and by moving lines.
5
6import assert from "node:assert/strict";
7import { test } from "node:test";
8import { storedArray } from "../../../src/engine/state-source.ts";
9import { SqlState } from "../../../src/engine/test/storage-helper.ts";
10import { MemoryStore, Project } from "../project.ts";
11import type { Entry, ProjectStore } from "../project-types.ts";
13function writer() {
14 const storage = new SqlState();
15 const entries = storedArray<Entry>(storage, "canonical-log");
16 const store: ProjectStore = {
17 append(batch) {
18 for (const entry of batch) entries.push(entry);
19 },
20 };
21 return new Project(store, { writerStorage: storage });
24const AREA = "export function area(r: number) {\n return 3.14 * r * r;\n}\n";
25const FILES = {
26 "src/shapes.ts": `// shapes\n${AREA}`,
27 "src/old-name.ts": "export const x = 1;\n",
28 "src/gone.ts": "export const y = 2;\n",
29 "src/keep.ts": 'import { x } from "./old-name";\n',
30 "notes.md": "notes\n",
31};
33/** Every name to ask about: each path any version or draft has had, and names that never existed. */
34const NAMES = [
35 ...Object.keys(FILES),
36 "src/new-name.ts",
37 "src/geometry.ts",
38 "src/draft-new.ts",
39 "src/draft-renamed.ts",
40 "src/never.ts",
41 "src/old-name",
42 "src/old-name.js",
43];
45function history(project: Project) {
46 let t = 0;
47 project.init(FILES, t);
48 project.sync("v0");
49 // Version 1: ann deletes a file and renames another with record.
50 project.record(
51 "ann",
52 { "src/gone.ts": null, "src/old-name.ts": null, "src/new-name.ts": FILES["src/old-name.ts"] },
53 ++t,
54 );
55 assert.equal(project.publish("ann", "Delete gone, rename old-name", ++t).ok, true);
56 project.sync("v1");
57 // Version 2: ann moves area() into a new file by moving its lines.
58 project.edit("ann", { file: "src/shapes.ts", old: AREA, new: "" }, ++t);
59 project.edit("ann", { file: "src/geometry.ts", content: AREA }, ++t);
60 assert.equal(project.publish("ann", "Move area", ++t).ok, true);
61 for (const agent of ["v2", "bob", "cy", "dee", "eve"]) project.sync(agent);
62 // Drafts over version 2: bob deletes a file, cy renames one with record, dee moves lines into a new file, eve adds one.
63 project.record("bob", { "src/keep.ts": null }, ++t);
64 project.record("cy", { "src/new-name.ts": null, "src/draft-renamed.ts": FILES["src/old-name.ts"] }, ++t);
65 project.edit("dee", { file: "src/geometry.ts", old: AREA, new: "" }, ++t);
66 project.edit("dee", { file: "src/draft-new.ts", content: AREA }, ++t);
67 project.record("eve", { "src/draft-new.ts": "new\n" }, ++t);
70const exists = (project: Project, agent: string) => {
71 const view = project.draftOf(agent)!.view;
72 return Object.fromEntries(NAMES.map((name) => [name, view.hasFile(name)]));
73};
75test("whether each file exists, at every version and in every draft, as the in-memory project says", () => {
76 const oracle = new Project(new MemoryStore());
77 const project = writer();
78 history(oracle);
79 history(project);
80 for (const agent of ["v0", "v1", "v2", "bob", "cy", "dee", "eve"]) {
81 // Before any layout, and again after every file has been read.
82 assert.deepEqual(exists(project, agent), exists(oracle, agent), agent);
83 const view = project.draftOf(agent)!.view;
84 for (const path of view.paths()) view.lines(path);
85 assert.deepEqual(exists(project, agent), exists(oracle, agent), `${agent} after reading`);
86 assert.deepEqual(view.paths(), oracle.draftOf(agent)!.view.paths(), `${agent} paths`);
87 }
88 // The cases the test is for, so a history change can't empty it.
89 const at = (agent: string) => exists(oracle, agent);
90 assert.equal(at("v0")["src/gone.ts"], true);
91 assert.equal(at("v1")["src/gone.ts"], false);
92 assert.equal(at("v1")["src/old-name.ts"], false);
93 assert.equal(at("v1")["src/new-name.ts"], true);
94 assert.equal(at("v2")["src/geometry.ts"], true);
95 assert.equal(at("bob")["src/keep.ts"], false);
96 assert.equal(at("cy")["src/new-name.ts"], false);
97 assert.equal(at("cy")["src/draft-renamed.ts"], true);
98 assert.equal(at("dee")["src/draft-new.ts"], true);
99 assert.equal(at("dee")["src/geometry.ts"], false);
100 assert.equal(at("eve")["src/draft-new.ts"], true);
101 for (const [version, agent] of [
102 [0, "v0"],
103 [1, "v1"],
104 [2, "v2"],
105 ] as const)
106 assert.deepEqual(project.pathsAt(version).files, oracle.draftOf(agent)!.view.paths(), `paths at ${version}`);
107});
capacity303Status for an agent behind shared lists its base version's kept paths, not a layout of every known file (abso 711, abso - Performance's fix; Capacity ships it) - agentPaths and pathsOf listed an agent's files with agentView(agent).paths(). For an agent behind shared on a stored writer, that lays out every known file's history: 21,939-28,410 statements the first time, 11,330-26,075 each repeat, nothing kept. On prod abso this afternoon, 28 status calls ran 29,000-40,000 statements each while the object reset (Observability). - An agent with nothing of its own (agent.mine empty) sees exactly its base version, so its paths are that version's kept file list (keptPaths, as pathsAt already uses: about 30 statements). An agent with a draft, or a store without kept paths, is laid out as before. - Performance's measurement on a copy of abso's tables, first status of 12 agents: median 26,040 statements before, 203 after (max 4,686, the three with drafts); 44.2 s in all before, 4.8 s after; every status body byte for byte the same. Checks: core tsc clean; Biome clean; node --test worker/project/test/known-paths (new: agentPaths and pathsOf on a writer match the in-memory project, for agents behind shared, at shared and with drafts), files-reads, project, reviewers: 33 of 33 pass.Compare108
109test("an agent's files on a writer, from its base version's kept list when it has nothing of its own, as the in-memory project says", () => {
110 // abso - Performance (abso 711): a status for an agent behind shared listed its files by laying out every known file.
111 const oracle = new Project(new MemoryStore());
112 const project = writer();
113 history(oracle);
114 history(project);
115 // v0 and v1 are behind shared with nothing of their own, v2 is at shared, and bob, cy, dee and eve have drafts.
116 for (const agent of ["v0", "v1", "v2", "bob", "cy", "dee", "eve"]) {
117 assert.deepEqual(project.agentPaths(agent), oracle.agentPaths(agent), agent);
118 assert.deepEqual(project.pathsOf(agent), oracle.pathsOf(agent), `${agent} for a reader`);
119 }
120 assert.deepEqual(project.agentPaths("v0").files, project.pathsAt(0).files);
121 assert.equal(project.agentPaths("v0").files.includes("src/gone.ts"), true);
122 assert.equal(project.agentPaths("v1").files.includes("src/gone.ts"), false);
123 assert.equal(project.agentPaths("eve").files.includes("src/draft-new.ts"), true);
124});