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 162 to 163

Compare

+182 −0 in 1 place
new file, 182 lines
1+import assert from "node:assert/strict";
2+import { test } from "node:test";
3+import { answer } from "../../worker/project/http.ts";
4+import type { Project } from "../../worker/project/project.ts";
5+import { DiskFirstRuntime } from "../src/disk-first-runtime.ts";
6+import { memoryStorage } from "./helpers.ts";
7+
8+test("disk queue preserves a dropped base without restoring dropped changes", (t) => {
9+ const storage = memoryStorage();
10+ t.after(() => storage.db.close());
11+ const runtime = () => new DiskFirstRuntime(storage, "queue-drop", "queue-drop");
12+ runtime().initialize(
13+ (c) => answer(c, "init", undefined, { files: { "avcs.json": '{"queue":true}', "a.txt": "before\n" } }),
14+ () => {},
15+ );
16+ while (!runtime().preparePage(() => {}).ready) {}
17+ runtime().write(
18+ (c) => {
19+ assert.equal(answer(c, "record", "alice", { files: { "a.txt": "temporary\n" } }).status, 200);
20+ assert.equal(answer(c, "publish", "alice", { message: "Temporary" }).status, 200);
21+ c.sync("old");
22+ assert.equal(c.drop("alice", [1], "Undo temporary").ok, true);
23+ },
24+ () => {},
25+ );
26+ for (const [agent, file] of [
27+ ["ahead", "ahead.txt"],
28+ ["old", "old.txt"],
29+ ] as const) {
30+ runtime().write(
31+ (c) => {
32+ c.setCheckerReady(true);
33+ assert.equal(answer(c, "record", agent, { files: { [file]: `${agent}\n` } }).status, 200);
34+ const result = answer(c, "publish", agent, { message: agent });
35+ assert.equal(result.status, 200, JSON.stringify(result));
36+ assert.equal((result.body as { queued: number }).queued, agent === "ahead" ? 1 : 2);
37+ },
38+ () => {},
39+ );
40+ }
41+ const candidate = runtime().read(
42+ (c) => (c as unknown as { project: Project }).project.queueCandidate(2),
43+ () => {},
44+ );
45+ assert.equal(candidate.files["a.txt"], "before\n");
46+ assert.equal(candidate.files["ahead.txt"], "ahead\n");
47+ assert.equal(candidate.files["old.txt"], "old\n");
48+});
50+test("disk runtime builds and lands a queued candidate", (t) => {
51+ const storage = memoryStorage();
52+ t.after(() => storage.db.close());
53+ const runtime = () => new DiskFirstRuntime(storage, "queue", "queue");
54+ runtime().initialize(
55+ (c) => answer(c, "init", undefined, { files: { "avcs.json": '{"queue":true}', "a.txt": "before\n" } }),
56+ () => {},
57+ );
58+ while (!runtime().preparePage(() => {}).ready) {}
59+ runtime().write(
60+ (c) => {
61+ c.setCheckerReady(true);
62+ assert.equal(answer(c, "record", "alice", { files: { "a.txt": "after\n" } }).status, 200);
63+ const result = answer(c, "publish", "alice", { message: "Queued" });
64+ assert.equal((result.body as { queued: number }).queued, 1);
65+ },
66+ () => {},
67+ );
68+ // Queue-driver methods are internal to the Project adapter, not public HTTP commands.
69+ const candidate = runtime().read(
70+ (c) => (c as unknown as { project: Project }).project.queueCandidate(1),
71+ () => {},
72+ );
73+ assert.equal(candidate.files["a.txt"], "after\n");
74+ const landed = runtime().write(
75+ (c) => (c as unknown as { project: Project }).project.queueLand(1, 10),
76+ () => {},
77+ );
78+ assert.deepEqual(landed.versions, [{ id: 1, version: 1 }]);
79+ assert.equal(
80+ runtime().read(
81+ (c) => c.shared().files["a.txt"],
82+ () => {},
83+ ),
84+ "after\n",
85+ );
86+});
88+test("disk runtime builds and lands two queued candidates in order", (t) => {
89+ const storage = memoryStorage();
90+ t.after(() => storage.db.close());
91+ const runtime = () => new DiskFirstRuntime(storage, "queue", "queue");
92+ runtime().initialize(
93+ (c) => answer(c, "init", undefined, { files: { "avcs.json": '{"queue":true}', "a.txt": "before\n" } }),
94+ () => {},
95+ );
96+ while (!runtime().preparePage(() => {}).ready) {}
97+ runtime().write(
98+ (c) => {
99+ c.setCheckerReady(true);
100+ assert.equal(answer(c, "record", "alice", { files: { "a.txt": "after\n" } }).status, 200);
101+ const result = answer(c, "publish", "alice", { message: "Queued" });
102+ assert.equal((result.body as { queued: number }).queued, 1);
103+ },
104+ () => {},
105+ );
106+ runtime().write(
107+ (c) => {
108+ c.setCheckerReady(true);
109+ assert.equal(answer(c, "record", "bob", { files: { "b.txt": "second\n" } }).status, 200);
110+ const result = answer(c, "publish", "bob", { message: "Second" });
111+ assert.equal(result.status, 200, JSON.stringify(result));
112+ assert.equal((result.body as { queued: number }).queued, 2);
113+ },
114+ () => {},
115+ );
116+ // Queue-driver methods are internal to the Project adapter, not public HTTP commands.
117+ const candidate = runtime().read(
118+ (c) => (c as unknown as { project: Project }).project.queueCandidate(2),
119+ () => {},
120+ );
121+ assert.equal(candidate.files["a.txt"], "after\n");
122+ assert.equal(candidate.files["b.txt"], "second\n");
123+ const landed = runtime().write(
124+ (c) => (c as unknown as { project: Project }).project.queueLand(2, 10),
125+ () => {},
126+ );
127+ assert.deepEqual(landed.versions, [
128+ { id: 1, version: 1 },
129+ { id: 2, version: 2 },
130+ ]);
131+ assert.equal(
132+ runtime().read(
133+ (c) => c.shared().files["a.txt"],
134+ () => {},
135+ ),
136+ "after\n",
137+ );
138+});
140+test("disk queue refuses overlapping edits and accepts an older nonconflicting base", (t) => {
141+ const storage = memoryStorage();
142+ t.after(() => storage.db.close());
143+ const runtime = () => new DiskFirstRuntime(storage, "queue-edge", "queue-edge");
144+ runtime().initialize(
145+ (c) => answer(c, "init", undefined, { files: { "avcs.json": '{"queue":true}', "a.txt": "before\n" } }),
146+ () => {},
147+ );
148+ while (!runtime().preparePage(() => {}).ready) {}
149+ const call = (op: string, agent: string, body: unknown) =>
150+ runtime().write(
151+ (c) => {
152+ c.setCheckerReady(true);
153+ return answer(c, op, agent, body);
154+ },
155+ () => {},
156+ );
157+ for (const agent of ["alice", "bob", "old"]) assert.equal(call("sync", agent, {}).status, 200);
158+ assert.equal(call("record", "alice", { files: { "a.txt": "alice\n" } }).status, 200);
159+ assert.equal((call("publish", "alice", { message: "Alice" }).body as { queued: number }).queued, 1);
160+ assert.equal(call("record", "bob", { files: { "a.txt": "bob\n" } }).status, 200);
161+ const refused = call("publish", "bob", { message: "Bob conflict" });
162+ assert.equal(refused.status, 200, JSON.stringify(refused));
163+ assert.equal((refused.body as { ok: boolean }).ok, false);
164+ assert.ok((refused.body as { collisions: unknown[] }).collisions.length > 0);
165+ runtime().write(
166+ (c) => (c as unknown as { project: Project }).project.queueLand(1, 20),
167+ () => {},
168+ );
169+ assert.equal(call("record", "alice", { files: { "next.txt": "next\n" } }).status, 200);
170+ assert.equal((call("publish", "alice", { message: "Next" }).body as { queued: number }).queued, 2);
171+ assert.equal(call("record", "old", { files: { "old.txt": "old base\n" } }).status, 200);
172+ const queued = call("publish", "old", { message: "Old base" });
173+ assert.equal(queued.status, 200, JSON.stringify(queued));
174+ assert.equal((queued.body as { queued: number }).queued, 3);
175+ const candidate = runtime().read(
176+ (c) => (c as unknown as { project: Project }).project.queueCandidate(2),
177+ () => {},
178+ );
179+ assert.equal(candidate.files["a.txt"], "alice\n");
180+ assert.equal(candidate.files["next.txt"], "next\n");
181+ assert.equal(candidate.files["old.txt"], "old base\n");
182+});
MCP
compare on this site's /mcp
CLI
abso diff 162 163 server/test/projected-queue.test.ts --json
JSON
/christopher/abso-core/compare/162..163?file=server%2Ftest%2Fprojected-queue.test.ts&format=json