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 1 to 318

Compare

+72 −0 in 1 place
new file, 72 lines
1+// compare's summary (abso issue 680): every file a full compare lists, with its size in UTF-8 bytes and SHA-256 before
2+// and after instead of its texts, or its blob's hash for a binary file. The same on a writer-backed project as in
3+// memory.
4+
5+import assert from "node:assert/strict";
6+import { createHash } from "node:crypto";
7+import { test } from "node:test";
8+import { storedArray } from "../../../src/engine/state-source.ts";
9+import { SqlState } from "../../../src/engine/test/storage-helper.ts";
10+import { MemoryStore, Project } from "../project.ts";
11+import type { Entry, ProjectStore } from "../project-types.ts";
13+const A = "a".repeat(64);
14+const B = "b".repeat(64);
15+const held = (sha: string) => sha === A || sha === B;
17+function writer() {
18+ const storage = new SqlState();
19+ const entries = storedArray<Entry>(storage, "canonical-log");
20+ const store: ProjectStore = {
21+ append(batch) {
22+ for (const entry of batch) entries.push(entry);
23+ },
24+ };
25+ return new Project(store, { writerStorage: storage, hasBlob: held });
26+}
28+function history(project: Project) {
29+ project.init(
30+ { "keep.txt": "same\n", "edit.txt": "one\n", "gone.txt": "bye\n", "run.sh": "echo\n" },
31+ 0,
32+ {},
33+ { "logo.png": A },
34+ );
35+ project.record(
36+ "ann",
37+ { "edit.txt": "one\nzwei ü\n", "gone.txt": null, "new.txt": "hello\n" },
38+ 1,
39+ { "run.sh": { exec: true } },
40+ { "logo.png": B },
41+ );
42+ assert.equal(project.publish("ann", "Changes", 2).ok, true);
43+}
45+const sha = (text: string) => createHash("sha256").update(text, "utf8").digest("hex");
47+test("compare's summary lists what compare does, as sizes and SHA-256s", () => {
48+ for (const project of [new Project(new MemoryStore(), { hasBlob: held }), writer()]) {
49+ history(project);
50+ const full = project.compare(0, 1);
51+ const summary = project.compareSummary(0, 1);
52+ if ("summary" in full || !("summary" in summary)) throw Error("compare answered the wrong shape");
53+ assert.deepEqual(
54+ summary.files.map((f) => f.path),
55+ full.files.map((f) => f.path),
56+ );
57+ for (const f of full.files) {
58+ const s: (typeof summary.files)[number] = summary.files.find((x) => x.path === f.path)!;
59+ const sum = (text: string | null, blob: string | null | undefined) =>
60+ text === null ? null : blob ? { blob } : { size: Buffer.byteLength(text, "utf8"), sha256: sha(text) };
61+ assert.deepEqual(s.before, sum(f.before, f.blob?.before ?? null), `${f.path} before`);
62+ assert.deepEqual(s.after, sum(f.after, f.blob?.after ?? null), `${f.path} after`);
63+ assert.deepEqual(s.mode, f.mode);
64+ assert.deepEqual(s.blob, f.blob);
65+ }
66+ const edited = summary.files.find((f) => f.path === "edit.txt")!;
67+ assert.deepEqual(edited.after, { size: Buffer.byteLength("one\nzwei ü\n", "utf8"), sha256: sha("one\nzwei ü\n") });
68+ assert.equal(summary.files.find((f) => f.path === "gone.txt")!.after, null);
69+ assert.deepEqual(summary.files.find((f) => f.path === "logo.png")!.after, { blob: B });
70+ assert.ok(!JSON.stringify(summary).includes("zwei"), "no texts");
71+ }
72+});
MCP
compare on this site's /mcp
CLI
abso diff 1 318 worker/project/test/compare-summary.test.ts --json
JSON
/christopher/abso-core/compare/1..318?file=worker%2Fproject%2Ftest%2Fcompare-summary.test.ts&format=json