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
72 linesengine 89% · rename 11%Last change rename in version 100, 2 versions changed it

You're reading version 309. The newest is 318, and no version since then changed this file. Go to the newestCompare with 318

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
5import assert from "node:assert/strict";
6import { test } from "node:test";
7import { MemoryStore, Project } from "../project.ts";
8
9const 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};
14function 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 };
24/** Status from the warm project, checked against the same log loaded cold. */
25function 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;
31const filesOf = (status: ReturnType<Project["status"]>, agent: string) =>
32 status.agents.find((a) => a.agent === agent)!.files;
34test("status answers the same warm and cold through records, pushes and pulls 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 push"), "ann"), []);
44 project.sync("bob");
45 assert.deepEqual(filesOf(same(project, store, "bob's pull"), "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 push");
50});
52test("two agents in one named draft: one pushes, 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 pushes into rw");
63 assert.deepEqual(filesOf(after, "ann"), []);
64 project.sync("bob");
65 assert.deepEqual(filesOf(same(project, store, "bob pulls in rw"), "bob"), ["notes.md"]);
66 project.publish("bob", "Note", 6);
67 assert.deepEqual(filesOf(same(project, store, "bob pushes 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});