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 291 to 292

Compare

+56 −0 in 1 place
new file, 56 lines
1+// A host learns each write's news as the write appends it (newsWritten), and can read an agent's waiting news without
2+// taking it (peekNews), so a listener can be woken for exactly the agents that got news and caught up on connect.
3+
4+import assert from "node:assert/strict";
5+import { test } from "node:test";
6+import { MemoryStore, type NewsWritten, Project } from "../project.ts";
7+
8+function setup() {
9+ const store = new MemoryStore();
10+ const written: NewsWritten[][] = [];
11+ const project = new Project(store, { newsWritten: (items) => written.push([...items]) });
12+ project.init({ "a.txt": "a\n" }, 0);
13+ for (const a of ["builder1", "builder2", "builder3"]) project.sync(a);
14+ written.length = 0;
15+ return { project, store, written };
16+}
18+test("a write's news is told once, per item, with its agent, text and place in the log", () => {
19+ const { project, store, written } = setup();
20+ project.announce("builder1", "Ship it", ["builder2", "builder3"], 1);
21+ assert.equal(written.length, 1, "one call for the write");
22+ const items = written[0]!;
23+ assert.deepEqual(
24+ items.map((i) => i.agent),
25+ ["builder2", "builder3"],
26+ );
27+ for (const item of items) {
28+ assert.match(item.text, /Announcement from builder1.*Ship it/);
29+ assert.equal(store.entries[item.seq]?.type, "news", "seq is the entry's place in the log");
30+ }
31+ assert.ok(items[1]!.seq > items[0]!.seq);
32+});
34+test("writes with no news, and taking news (heard), tell nothing", () => {
35+ const { project, written } = setup();
36+ project.announce("builder1", "Ship it", ["builder2"], 1);
37+ written.length = 0;
38+ project.news("builder2");
39+ project.sync("builder3");
40+ assert.deepEqual(written, []);
41+});
43+test("peekNews reads waiting news and takes nothing; hasAgent reads only", () => {
44+ const { project, store } = setup();
45+ project.announce("builder1", "Ship it", ["builder2"], 1);
46+ const length = store.entries.length;
47+ const peeked = project.peekNews("builder2");
48+ assert.equal(peeked.length, 1);
49+ assert.match(peeked[0]!.text, /Ship it/);
50+ assert.deepEqual(project.peekNews("builder2"), peeked, "still there");
51+ assert.deepEqual(project.peekNews("nobody"), [], "no agent: none, and none made");
52+ assert.equal(project.hasAgent("builder2"), true);
53+ assert.equal(project.hasAgent("nobody"), false);
54+ assert.equal(store.entries.length, length, "nothing written");
55+ assert.equal(project.news("builder2").news.length, 1, "the take still finds it");
56+});
MCP
compare on this site's /mcp
CLI
abso diff 291 292 worker/project/test/news-written.test.ts --json
JSON
/christopher/abso-core/compare/291..292?file=worker%2Fproject%2Ftest%2Fnews-written.test.ts&format=json