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 150 to 151

Compare

+144 −0 in 1 place
new file, 144 lines
1+// A reader's news (a person's or an agent's): answers to their asks, replies on asks
2+// they're in, @name mentions, and comments, edits and closes on issues they
3+// watch, by others, newest first, each read or not.
4+
5+import assert from "node:assert/strict";
6+import { DatabaseSync } from "node:sqlite";
7+import { describe, it } from "node:test";
8+import { IssuesStore, NEWS_MAX, type Sql } from "../../src/issues/store.ts";
9+
10+function sql(): Sql {
11+ const db = new DatabaseSync(":memory:");
12+ return {
13+ exec: (q, ...b) => {
14+ if (/^\s*(CREATE|ALTER)\b/i.test(q)) {
15+ db.exec(q);
16+ return { toArray: () => [] };
17+ }
18+ const rows = db.prepare(q).all(...(b as (string | number | null)[]));
19+ return { toArray: () => rows };
20+ },
21+ };
22+}
24+function store(): { s: IssuesStore; db: Sql; tick: () => number } {
25+ const db = sql();
26+ IssuesStore.createTables(db);
27+ let at = Date.parse("2026-10-10T03:00:00Z");
28+ return { s: new IssuesStore(db, () => at), db, tick: () => (at += 1000) };
29+}
31+const ann = { person: "acct_ann" };
32+const fay = { agent: "fay" };
34+describe("a reader's news", () => {
35+ it("gathers answers, replies, mentions and watched changes by others, newest first", () => {
36+ const { s, tick } = store();
37+ const id = s.open(ann, { title: "Sync is slow" }).id;
38+ const other = s.open(fay, { title: "Not watched" }).id;
39+ tick();
40+ const ask = s.ask(ann, { issue: id, of: "fay", question: "Which way?" });
41+ tick();
42+ s.reply(fay, ask.id, { text: "staging or live?", question: true });
43+ tick();
44+ s.answer(fay, ask.id, { words: "live" });
45+ tick();
46+ s.comment(fay, id, { text: "a comment on a watched issue" });
47+ tick();
48+ s.comment(fay, other, { text: "cc @ann, have a look" });
49+ tick();
50+ s.comment(fay, other, { text: "no name here, and an email ann@x.dev isn't one" });
51+ tick();
52+ s.edit(fay, id, { title: "Sync is slow on big projects" });
53+ tick();
54+ s.markDone(fay, id, 12);
55+ tick();
56+ s.comment(ann, id, { text: "my own comment isn't news" });
58+ const news = s.newsFor({ person: "acct_ann" }, ["ann"]);
59+ assert.deepEqual(
60+ news.map((n) => [n.kind, n.issue]),
61+ [
62+ ["closed", id],
63+ ["edit", id],
64+ ["mention", other],
65+ ["comment", id],
66+ ["answer", id],
67+ ["reply", id],
68+ ],
69+ );
70+ assert.equal(news.find((n) => n.kind === "answer")!.text, "live");
71+ assert.equal(news.find((n) => n.kind === "answer")!.ask, ask.id);
72+ assert.equal(news.find((n) => n.kind === "edit")!.text, "title");
73+ assert.ok(news.every((n) => !n.read && n.by === "fay"));
74+ assert.deepEqual(
75+ s
76+ .newsFor({ person: "acct_ann" }, [])
77+ .map((n) => n.kind)
78+ .includes("mention"),
79+ false,
80+ "no names, no mentions",
81+ );
82+ });
84+ it("marks read up to a time, never back, per person", () => {
85+ const { s, tick } = store();
86+ const id = s.open(ann, { title: "One" }).id;
87+ tick();
88+ s.comment(fay, id, { text: "first" });
89+ const mark = tick();
90+ tick();
91+ s.comment(fay, id, { text: "second" });
92+ assert.equal(s.markNewsRead({ person: "acct_ann" }, mark).read, mark);
93+ assert.equal(s.markNewsRead({ person: "acct_ann" }, 0).read, mark, "a mark never goes back");
94+ assert.deepEqual(
95+ s.newsFor({ person: "acct_ann" }, []).map((n) => [n.text, n.read]),
96+ [
97+ ["second", false],
98+ ["first", true],
99+ ],
100+ );
101+ assert.ok(s.newsFor({ person: "acct_bo" }, []).every((n) => !n.read));
102+ });
104+ it("pages back with before, keeps at most NEWS_MAX and cuts long text", () => {
105+ const { s, tick } = store();
106+ const id = s.open(ann, { title: "Busy" }).id;
107+ for (let i = 0; i < NEWS_MAX + 5; i++) {
108+ tick();
109+ s.comment(fay, id, { text: i === 0 ? "x".repeat(400) : `comment ${i}` });
110+ }
111+ const first = s.newsFor({ person: "acct_ann" }, []);
112+ assert.equal(first.length, NEWS_MAX);
113+ const older = s.newsFor({ person: "acct_ann" }, [], first.at(-1)!.at);
114+ assert.equal(older.length, 5);
115+ assert.equal(older.at(-1)!.text.length, 280);
116+ });
118+ it("doesn't move the change count", () => {
119+ const { s } = store();
120+ s.open(ann, { title: "One" });
121+ const before = s.changes();
122+ s.markNewsRead({ person: "acct_ann" }, 5);
123+ assert.equal(s.changes(), before);
124+ });
126+ it("is an agent's too: answers to its asks and @mentions of its name", () => {
127+ const { s, tick } = store();
128+ const lead = { agent: "lead" };
129+ const id = s.open(fay, { title: "Sync is slow" }).id;
130+ tick();
131+ const ask = s.ask(lead, { issue: id, of: "fay", question: "Which way?" });
132+ tick();
133+ s.answer(fay, ask.id, { words: "live" });
134+ tick();
135+ s.comment(fay, id, { text: "@lead it's done" });
136+ assert.deepEqual(
137+ s.newsFor(lead, ["lead"]).map((n) => [n.kind, n.by, n.text]),
138+ [
139+ ["mention", "fay", "@lead it's done"],
140+ ["answer", "fay", "live"],
141+ ],
142+ );
143+ });
144+});
MCP
compare on this site's /mcp
CLI
abso diff 150 151 server/test/issues/news.test.ts --json
JSON
/christopher/abso-core/compare/150..151?file=server%2Ftest%2Fissues%2Fnews.test.ts&format=json