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/without.test.ts?format=json
206 linescandidates 100%Last change candidates in version 186, 1 version changed it
1// A version without others: the files of one version of shared with some earlier versions left out. A read:
2// shared and its log never change. Refused, naming the chain, when a version kept builds on one left out.
3
4import assert from "node:assert/strict";
5import { test } from "node:test";
6import { MemoryStore, Project, ProjectError } from "../project.ts";
7import { treeHash } from "../tree.ts";
8
9const START = { "a.ts": "one\ntwo\nthree\n", "b.ts": "alpha\nbeta\n" };
11function setup() {
12 const store = new MemoryStore();
13 const project = new Project(store, { hasBlob: () => true });
14 project.init(START, 0);
15 for (const a of ["ann", "bob", "cat"]) project.sync(a);
16 return { project, store };
19/** ann publishes v1 (a.ts), bob v2 (b.ts), cat v3 (a new c.ts): three versions that don't build on each other. */
20function threeVersions(project: Project): void {
21 project.edit("ann", { file: "a.ts", old: "two", new: "TWO" }, 1);
22 project.publish("ann", "Shout two", 2);
23 project.edit("bob", { file: "b.ts", old: "beta", new: "BETA" }, 3);
24 project.publish("bob", "Shout beta", 4);
25 project.record("cat", { "c.ts": "gamma\n" }, 5);
26 project.publish("cat", "Add c", 6);
29const badRequest = (f: () => unknown): string => {
30 try {
31 f();
32 } catch (e) {
33 if (e instanceof ProjectError && e.code === "bad-request") return e.message;
34 throw e;
35 }
36 return "no error";
37};
39test("leaving out an independent version takes only its change out; the others stay as they are", () => {
40 const { project, store } = setup();
41 threeVersions(project);
42 const entries = store.entries.length;
43 const answer = project.without(3, [1]);
44 assert.equal(answer.ok, true);
45 assert.ok(answer.ok);
46 assert.deepEqual(answer.without, [{ version: 1, agent: "ann", message: "Shout two" }]);
47 assert.deepEqual(answer.files, [{ path: "a.ts", before: "one\nTWO\nthree\n", after: "one\ntwo\nthree\n" }]);
48 assert.equal(
49 answer.tree,
50 treeHash({ files: { "a.ts": "one\ntwo\nthree\n", "b.ts": "alpha\nBETA\n", "c.ts": "gamma\n" } }),
51 );
52 // Shared is unchanged: same version, same files, nothing written to the log.
53 assert.equal(project.version, 3);
54 assert.deepEqual(project.files(), { "a.ts": "one\nTWO\nthree\n", "b.ts": "alpha\nBETA\n", "c.ts": "gamma\n" });
55 assert.equal(store.entries.length, entries);
56 // Two left out at once.
57 const two = project.without(3, [3, 1]);
58 assert.ok(two.ok);
59 assert.deepEqual(
60 two.without.map((w) => w.version),
61 [1, 3],
62 );
63 assert.deepEqual(
64 two.files.map((f) => [f.path, f.after]),
65 [
66 ["a.ts", "one\ntwo\nthree\n"],
67 ["c.ts", null],
68 ],
69 );
70});
72test("the same ask gives the same answer, and shared moving on doesn't change it", () => {
73 const { project } = setup();
74 threeVersions(project);
75 const first = project.without(3, [2]);
76 assert.deepEqual(project.without(3, [2]), first);
77 project.sync("ann");
78 project.edit("ann", { file: "c.ts", old: "gamma", new: "GAMMA" }, 7);
79 project.publish("ann", "Shout gamma", 8);
80 assert.deepEqual(project.without(3, [2]), first);
81 // Asked of the newer version, the newer change is in it.
82 const later = project.without(4, [2]);
83 assert.ok(later.ok && first.ok);
84 assert.notEqual(later.tree, first.tree);
85});
87test("leaving out a version a kept one builds on is refused, with the chain, the files and the wider set", () => {
88 const { project, store } = setup();
89 threeVersions(project);
90 project.sync("cat");
91 project.edit("cat", { file: "a.ts", old: "TWO", new: "TWO!" }, 7);
92 project.publish("cat", "Louder", 8); // v4 builds on v1
93 project.sync("bob");
94 project.edit("bob", { file: "a.ts", old: "TWO!", new: "TWO!!" }, 9);
95 project.publish("bob", "Louder still", 10); // v5 builds on v4
96 const entries = store.entries.length;
97 const refused = project.without(5, [1]);
98 assert.deepEqual(refused, {
99 ok: false,
100 version: 5,
101 without: [{ version: 1, agent: "ann", message: "Shout two" }],
102 dependents: [
103 { version: 4, agent: "cat", message: "Louder", needs: [{ version: 1, files: ["a.ts"] }] },
104 { version: 5, agent: "bob", message: "Louder still", needs: [{ version: 4, files: ["a.ts"] }] },
105 ],
106 suggestion: [1, 4, 5],
107 });
108 assert.equal(store.entries.length, entries);
109 assert.equal(project.version, 5);
110 // The suggestion, asked for, works; it's never applied without being asked.
111 const wider = project.without(5, refused.ok ? [] : refused.suggestion);
112 assert.ok(wider.ok);
113 assert.deepEqual(wider.files, [{ path: "a.ts", before: "one\nTWO!!\nthree\n", after: "one\ntwo\nthree\n" }]);
114 // Before the dependent version, leaving it out is fine.
115 assert.equal(project.without(3, [1]).ok, true);
116});
118test("a deletion left out brings the lines back; a rename left out keeps the old name; a move left out puts lines back", () => {
119 const { project } = setup();
120 project.edit("ann", { file: "a.ts", old: "two\n", new: "" }, 1);
121 project.publish("ann", "No two", 2);
122 project.record("bob", { "b.ts": null, "c.ts": START["b.ts"] }, 3);
123 project.publish("bob", "Rename b to c", 4);
124 project.sync("cat");
125 project.move("cat", "a.ts", "src/a.ts", 5);
126 project.publish("cat", "Move a into src", 6);
127 assert.deepEqual(project.files(), { "src/a.ts": "one\nthree\n", "c.ts": "alpha\nbeta\n" });
129 const noDelete = project.without(3, [1]);
130 assert.ok(noDelete.ok);
131 assert.deepEqual(
132 noDelete.files.map((f) => [f.path, f.after]),
133 [["src/a.ts", "one\ntwo\nthree\n"]],
134 );
135 const noRename = project.without(3, [2]);
136 assert.ok(noRename.ok);
137 assert.deepEqual(
138 noRename.files.map((f) => [f.path, f.before, f.after]),
139 [
140 ["b.ts", null, "alpha\nbeta\n"],
141 ["c.ts", "alpha\nbeta\n", null],
142 ],
143 );
144 const noMove = project.without(3, [3]);
145 assert.ok(noMove.ok);
146 assert.deepEqual(
147 noMove.files.map((f) => [f.path, f.after]),
148 [
149 ["a.ts", "one\nthree\n"],
150 ["src/a.ts", null],
151 ],
152 );
153});
155test("a binary file's change and an executable bit left out go back to what they were", () => {
156 const A = "a".repeat(64);
157 const B = "b".repeat(64);
158 const store = new MemoryStore();
159 const project = new Project(store, { hasBlob: () => true });
160 project.init({ "run.sh": "echo hi\n" }, 0, {}, { "logo.png": A });
161 project.sync("ann");
162 project.record("ann", {}, 1, {}, { "logo.png": B });
163 project.publish("ann", "New logo", 2);
164 project.record("ann", {}, 3, { "run.sh": { exec: true } });
165 project.publish("ann", "Make run.sh runnable", 4);
166 const noLogo = project.without(2, [1]);
167 assert.ok(noLogo.ok);
168 assert.deepEqual(
169 noLogo.files.map((f) => [f.path, f.blob]),
170 [["logo.png", { before: B, after: A }]],
171 );
172 const noExec = project.without(2, [2]);
173 assert.ok(noExec.ok);
174 assert.deepEqual(
175 noExec.files.map((f) => [f.path, f.mode?.after.exec ?? false]),
176 [["run.sh", false]],
177 );
178});
180test("versions it can't leave out are refused plainly", () => {
181 const { project } = setup();
182 threeVersions(project);
183 assert.equal(project.drop("cat", [2], "Undo beta", 7).ok, true); // v4 drops v2
184 assert.match(
185 badRequest(() => project.without(3, [4])),
186 /comes after version 3/,
187 );
188 assert.match(
189 badRequest(() => project.without(4, [0])),
190 /version 0 is the start/,
191 );
192 assert.match(
193 badRequest(() => project.without(4, [4])),
194 /is a drop/,
195 );
196 assert.match(
197 badRequest(() => project.without(4, [2])),
198 /isn't in version 4: version 4 dropped it/,
199 );
200 assert.match(
201 badRequest(() => project.without(4, [])),
202 /versions to leave out/,
203 );
204 // Before the drop, it's there to leave out.
205 assert.equal(project.without(3, [2]).ok, true);
206});