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
116 linescapacity 100%Last change capacity in version 295, 1 version changed it

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

1// Owed news (abso Capacity, 2026-10-15): with owesDefinitionNews set (abso's disk route sets it), a publish leaves its
2// definition news for other agents for after its write. The same news, against the publish's version; told once; and
3// the publisher's own answer as before. abso's worker/test/owed-news.test.ts covers the disk route's marker and alarm.
4
5import assert from "node:assert/strict";
6import { test } from "node:test";
7import { MemoryStore, Project } from "../project.ts";
8
9// abso-core's changed-definition.test.ts scenario: parse.ts defines parsePattern, match.ts imports it.
10const START = {
11 "src/parse.ts": [
12 "export function parsePattern(text: string): Node {",
13 ' return { kind: "lit", text };',
14 "}",
15 "",
16 "export interface Node {",
17 " kind: string;",
18 " text: string;",
19 "}",
20 ].join("\n"),
21 "src/match.ts": ['import { parsePattern } from "./parse.ts";', "", "export function run(p: string) {", " return p;", "}"].join(
22 "\n",
23 ),
24 "README.md": "Uses parsePattern.\n",
25};
27/** bob's draft calls parsePattern; ann's draft changes its signature; cat's touches something else. Nothing published. */
28function drafts(project: Project): void {
29 project.init(START, 0);
30 project.sync("bob");
31 project.sync("ann");
32 project.sync("cat");
33 project.edit("bob", { file: "src/match.ts", old: " return p;\n", new: " const tree = parsePattern(p);\n return tree;\n" }, 1);
34 project.edit(
35 "ann",
36 { file: "src/parse.ts", old: "parsePattern(text: string): Node", new: "parsePattern(text: string, flags: string): Node" },
37 2,
38 );
39 project.edit("cat", { file: "README.md", old: "Uses parsePattern.", new: "Uses parsePattern, twice." }, 3);
42const definitionNews = (news: readonly string[]) => news.filter((n) => /definition of parsePattern/.test(n)).sort();
44test("the news owed is the news a publish would have told, and the publisher's own answer is the same", () => {
45 const told = new Project(new MemoryStore());
46 drafts(told);
47 const toldAnswer = told.publish("ann", "parsePattern takes flags", 4);
48 const expected = definitionNews(told.news("bob").news);
49 assert.equal(expected.length, 1, "the scenario has a definition collision");
51 const owing = new Project(new MemoryStore());
52 owing.owesDefinitionNews = true;
53 drafts(owing);
54 assert.deepEqual(owing.publish("ann", "parsePattern takes flags", 4), toldAnswer, "the publisher's answer");
55 const owed = owing.takeOwedDefinitionNews();
56 assert.deepEqual(owed, [{ version: owing.version, space: owed[0]!.space, publisher: "ann", names: ["parsePattern"] }]);
57 assert.deepEqual(owing.takeOwedDefinitionNews(), [], "handed over once");
58 // Not told yet: bob's news holds no definition news until it's delivered.
59 assert.deepEqual(definitionNews(owing.news("bob").news), []);
60 const found = owing.definitionNewsOwed(owed[0]!);
61 assert.deepEqual(
62 found.map((f) => f.agent),
63 ["bob"],
64 );
65 assert.ok(owing.deliverOwedNews(found) > 0);
66 assert.deepEqual(definitionNews(owing.news("bob").news), expected);
67 // Told twice adds nothing, and a run of the read after delivery finds nothing left.
68 assert.equal(owing.deliverOwedNews(found), 0);
69 assert.deepEqual(owing.definitionNewsOwed(owed[0]!), []);
70});
72test("worked out against the publish's version, though more was published before the news went out", () => {
73 const told = new Project(new MemoryStore());
74 drafts(told);
75 told.publish("ann", "parsePattern takes flags", 4);
76 const expected = definitionNews(told.news("bob").news);
78 const owing = new Project(new MemoryStore());
79 owing.owesDefinitionNews = true;
80 drafts(owing);
81 owing.publish("ann", "parsePattern takes flags", 4);
82 const [first] = owing.takeOwedDefinitionNews();
83 // Then parsePattern is removed, before the first publish's news is out: against the newest version the news
84 // would say "removes"; against the first publish's, it says "changes", as told at publish time.
85 owing.sync("ann");
86 owing.edit(
87 "ann",
88 {
89 file: "src/parse.ts",
90 old: 'export function parsePattern(text: string, flags: string): Node {\n return { kind: "lit", text };\n}\n',
91 new: "",
92 },
93 5,
94 );
95 owing.publish("ann", "parsePattern goes", 6);
96 assert.ok(owing.deliverOwedNews(owing.definitionNewsOwed(first!)) > 0);
97 assert.deepEqual(definitionNews(owing.news("bob").news), expected, "the first publish's news, as it was");
98});
100test("an agent that synced past the version since isn't told it", () => {
101 const owing = new Project(new MemoryStore());
102 owing.owesDefinitionNews = true;
103 drafts(owing);
104 owing.publish("ann", "parsePattern takes flags", 4);
105 const [owed] = owing.takeOwedDefinitionNews();
106 owing.sync("bob");
107 assert.deepEqual(owing.definitionNewsOwed(owed!), []);
108});
110test("the replay engine tells it at publish time, as before", () => {
111 const told = new Project(new MemoryStore());
112 drafts(told);
113 told.publish("ann", "parsePattern takes flags", 4);
114 assert.deepEqual(told.takeOwedDefinitionNews(), []);
115 assert.equal(definitionNews(told.news("bob").news).length, 1);
116});