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
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/worker/project/test/whole.test.ts?format=json
104 linesFirst import 95% · pinch 4% · rename 1%Last change rename in version 100, 3 versions changed it
1// Files kept whole (#46, ruled on #43): paths matching
2// avcs.json's "whole", and any text over 1 MB, are stored like binary files:
3// whole versions in the blob store, no line ids, so a large generated file
4// can't fill the project's memory. Once whole, a file stays whole while it
5// exists, so it never flips back and forth.
6
7import assert from "node:assert/strict";
8import { createHash } from "node:crypto";
9import { test } from "node:test";
10import { MemoryStore, Project } from "../project.ts";
12function setup(config: object = { whole: ["test/recordings/**"] }) {
13 const store = new Map<string, string>();
14 const whole = {
15 keep: (text: string) => {
16 const sha = createHash("sha256").update(text, "utf8").digest("hex");
17 store.set(sha, text);
18 return sha;
19 },
20 read: (sha: string) => store.get(sha) ?? null,
21 };
22 const log = new MemoryStore();
23 const project = new Project(log, { hasBlob: (sha) => store.has(sha), whole });
24 project.init({ "avcs.json": `${JSON.stringify(config)}\n`, "src/a.ts": "export const a = 1;\n" }, 0);
25 for (const a of ["ann", "bob"]) project.sync(a);
26 return { project, store, log, whole };
29const recording = (n: number) =>
30 `${JSON.stringify({ frames: Array.from({ length: 50 }, (_, i) => i * n) }, null, 2)}\n`;
32test("a path the project marks whole is stored as a blob, and pushes and pulls like one", () => {
33 const { project, store } = setup();
34 const r = project.record("ann", { "test/recordings/one.json": recording(1) }, 1);
35 assert.deepEqual(r.changed, ["test/recordings/one.json"]);
36 const p = project.publish("ann", "a recording", 2);
37 assert.ok(p.ok);
38 const blob = project.blobs()["test/recordings/one.json"];
39 assert.equal(typeof blob, "string");
40 assert.equal(store.get(blob as string), recording(1));
41 // The graph holds no lines for it: blame has nothing to say, the file text in views is empty.
42 assert.equal(project.files()["test/recordings/one.json"] ?? "", "");
43});
45test("text over 1 MB is kept whole whatever its path; smaller text is tracked by line", () => {
46 const { project } = setup({});
47 const big = `${"x".repeat(80)}\n`;
48 project.record("ann", { "gen/big.txt": big.repeat(13_000), "src/small.txt": "small\n" }, 1);
49 project.publish("ann", "two files", 2);
50 assert.ok(project.blobs()["gen/big.txt"], "the big one is a blob");
51 assert.equal(project.blobs()["src/small.txt"], undefined);
52 assert.equal(project.files()["src/small.txt"], "small\n");
53});
55test("once whole, a file stays whole even when it shrinks; an Edit of it is out of step so the client sends the file", () => {
56 const { project, store } = setup({});
57 project.record("ann", { "gen/big.txt": `${"y".repeat(80)}\n`.repeat(13_000) }, 1);
58 project.publish("ann", "big", 2);
59 project.sync("bob");
60 project.record("bob", { "gen/big.txt": "tiny now\n" }, 3);
61 project.publish("bob", "shrink", 4);
62 const sha = project.blobs()["gen/big.txt"]!;
63 assert.equal(store.get(sha), "tiny now\n");
64 assert.deepEqual(project.edit("bob", { file: "gen/big.txt", old: "tiny", new: "small" }, 5), {
65 ok: false,
66 reason: "out of step",
67 });
68 // A Write is recorded whole.
69 assert.equal(project.edit("bob", { file: "gen/big.txt", content: "written\n" }, 6).ok, true);
70 project.publish("bob", "write", 7);
71 assert.equal(store.get(project.blobs()["gen/big.txt"]!), "written\n");
72});
74test("init keeps whole the paths its own avcs.json names; without a store nothing is kept whole", () => {
75 const store = new Map<string, string>();
76 const whole = {
77 keep: (t: string) => {
78 const sha = createHash("sha256").update(t, "utf8").digest("hex");
79 store.set(sha, t);
80 return sha;
81 },
82 read: (s: string) => store.get(s) ?? null,
83 };
84 const project = new Project(new MemoryStore(), { hasBlob: (s) => store.has(s), whole });
85 project.init({ "avcs.json": '{"whole": ["rec/**"]}\n', "rec/a.json": "{}\n", "b.ts": "b\n" }, 0);
86 assert.ok(project.blobs()["rec/a.json"]);
87 const plain = new Project(new MemoryStore());
88 plain.init({ "avcs.json": '{"whole": ["rec/**"]}\n', "rec/a.json": "{}\n" }, 0);
89 assert.equal(plain.files()["rec/a.json"], "{}\n", "no store: tracked by line as before");
90});
92test("a whole project's memory stays small: 20 re-recordings of a 60,000-line file add no lines to the graph", () => {
93 const { project, log } = setup();
94 const big = (n: number) =>
95 JSON.stringify({ frames: Array.from({ length: 20_000 }, (_, i) => ({ i, v: i % 50 === 0 ? n : 0 })) }, null, 2) +
96 "\n";
97 for (let n = 0; n < 20; n++) {
98 project.record(n % 2 ? "ann" : "bob", { "test/recordings/big.json": big(n) }, n + 1);
99 project.publish(n % 2 ? "ann" : "bob", `rec ${n}`, n + 1);
100 project.sync(n % 2 ? "bob" : "ann");
101 }
102 const size = JSON.stringify(log.entries).length;
103 assert.ok(size < 200_000, `log is ${size} characters: only hashes, no lines`);
104});