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 54 to 55

Compare

+72 −0 in 1 place
new file, 72 lines
1+// Each agent's draft files are kept between calls (abso-core issue 6). Status
2+// must answer as a project that works them out cold does, after every kind of
3+// step, in shared and in a named draft.
4+
5+import assert from "node:assert/strict";
6+import { test } from "node:test";
7+import { MemoryStore, Project } from "../project.ts";
8+
9+const START = {
10+ "core.ts": "export function step(x: number) {\n return x + 1;\n}\n\nexport const version = 1;\n",
11+ "notes.md": "one\ntwo\nthree\n",
12+};
14+function setup() {
15+ const store = new MemoryStore();
16+ const project = new Project(store);
17+ project.init(START, 0);
18+ for (const a of ["ann", "bob", "cat"]) project.sync(a);
19+ // Warm: every agent's draft files are kept from here on.
20+ project.status();
21+ return { project, store };
22+}
24+/** Status from the warm project, checked against the same log loaded cold. */
25+function same(project: Project, store: MemoryStore, step: string) {
26+ const warm = project.status();
27+ assert.deepEqual(warm, Project.load(store.entries, new MemoryStore()).status(), `after ${step}`);
28+ return warm;
29+}
31+const filesOf = (status: ReturnType<Project["status"]>, agent: string) =>
32+ status.agents.find((a) => a.agent === agent)!.files;
34+test("status answers the same warm and cold through records, publishes and syncs in shared", () => {
35+ const { project, store } = setup();
36+ project.edit("ann", { file: "core.ts", old: " return x + 1;", new: " return x + 2;" }, 1);
37+ assert.deepEqual(filesOf(same(project, store, "ann's edit"), "ann"), ["core.ts"]);
38+ project.edit("ann", { file: "notes.md", old: "two\n", new: "two!\n" }, 2);
39+ assert.deepEqual(filesOf(same(project, store, "ann's second edit"), "ann"), ["core.ts", "notes.md"]);
40+ project.edit("bob", { file: "notes.md", old: "three\n", new: "three!\n" }, 3);
41+ same(project, store, "bob's edit");
42+ project.publish("ann", "Ann's two", 4);
43+ assert.deepEqual(filesOf(same(project, store, "ann's publish"), "ann"), []);
44+ project.sync("bob");
45+ assert.deepEqual(filesOf(same(project, store, "bob's sync"), "bob"), ["notes.md"]);
46+ project.record("cat", { "new.ts": "export {};\n" }, 5);
47+ assert.deepEqual(filesOf(same(project, store, "cat's new file"), "cat"), ["new.ts"]);
48+ project.publish("cat", "Cat's file", 6);
49+ same(project, store, "cat's publish");
50+});
52+test("two agents in one named draft: one publishes, and the other's status still matches a cold load", () => {
53+ const { project, store } = setup();
54+ project.switchTo("ann", "rw", 1);
55+ project.switchTo("bob", "rw", 2);
56+ same(project, store, "both switch");
57+ project.edit("ann", { file: "core.ts", old: " return x + 1;", new: " return x * 2;" }, 3);
58+ project.edit("bob", { file: "notes.md", old: "one\n", new: "one (rw)\n" }, 4);
59+ const before = same(project, store, "both edit in rw");
60+ assert.deepEqual(filesOf(before, "bob"), ["notes.md"]);
61+ project.publish("ann", "Double", 5);
62+ const after = same(project, store, "ann publishes into rw");
63+ assert.deepEqual(filesOf(after, "ann"), []);
64+ project.sync("bob");
65+ assert.deepEqual(filesOf(same(project, store, "bob syncs in rw"), "bob"), ["notes.md"]);
66+ project.publish("bob", "Note", 6);
67+ assert.deepEqual(filesOf(same(project, store, "bob publishes into rw"), "bob"), []);
68+ project.land("ann", "Land rw", 7);
69+ same(project, store, "rw lands");
70+ project.switchTo("ann", "shared", 8);
71+ same(project, store, "ann back in shared");
72+});
MCP
compare on this site's /mcp
CLI
abso diff 54 55 worker/project/test/draft-files-kept.test.ts --json
JSON
/christopher/abso-core/compare/54..55?file=worker%2Fproject%2Ftest%2Fdraft-files-kept.test.ts&format=json