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
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/server/test/issues/changes.test.ts?version=261&format=json
121 linestrials 100%Last change trials in version 151, 1 version changed it

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

1// The change count: one number per project's issues that every write an issue read can
2// show moves forward, kept by SQLite triggers, so a reader can cache issue reads under it.
3
4import assert from "node:assert/strict";
5import { DatabaseSync } from "node:sqlite";
6import { describe, it } from "node:test";
7import { issuesRoute } from "../../src/issues/routes.ts";
8import { IssuesStore, type Sql } from "../../src/issues/store.ts";
9
10function sql(): { sql: Sql; db: DatabaseSync } {
11 const db = new DatabaseSync(":memory:");
12 return {
13 db,
14 sql: {
15 exec: (q, ...b) => {
16 if (/^\s*CREATE\b/i.test(q)) {
17 db.exec(q);
18 return { toArray: () => [] };
19 }
20 const rows = db.prepare(q).all(...(b as (string | number | null)[]));
21 return { toArray: () => rows };
22 },
23 },
24 };
27function store(): { s: IssuesStore; db: DatabaseSync; tick: () => void } {
28 let t = Date.parse("2026-10-09T10:00:00Z");
29 const { sql: q, db } = sql();
30 IssuesStore.createTables(q);
31 return { s: new IssuesStore(q, () => t), db, tick: () => void (t += 1000) };
34const builder = { agent: "builder3" };
35const christopher = { person: "u1" };
37describe("issues: the change count", () => {
38 it("is kept by a trigger on each counted table, for insert, update and delete", () => {
39 const { db, s } = store();
40 const triggers = db
41 .prepare("SELECT name FROM sqlite_master WHERE type = 'trigger' AND name LIKE 'changed_%'")
42 .all();
43 assert.equal(triggers.length, 30, "three for each of the ten tables an issue read shows");
44 assert.equal(s.changes(), 0);
45 });
47 it("moves forward on every write an issue read shows, and not on reads, drafts or a repeated waiting", () => {
48 const { s, tick } = store();
49 let last = s.changes();
50 const moved = (what: string) => {
51 const n = s.changes();
52 assert.ok(n > last, `${what} moved the count (${last} to ${n})`);
53 last = n;
54 };
55 const still = (what: string) => assert.equal(s.changes(), last, `${what} left the count alone`);
57 const a = s.open(builder, { title: "Sign-in" }).id;
58 moved("opening an issue");
59 const b = s.open(builder, { title: "Logo", parent: a }).id;
60 moved("opening a child");
61 tick();
62 s.comment(christopher, a, { text: "Looks right." });
63 moved("a comment");
64 const q = s.ask(builder, { issue: a, of: "security", question: "Is the cookie set right?", review: true });
65 moved("an ask");
66 s.waiting("security", "security");
67 moved("waiting marking an ask seen");
68 s.waiting("security", "security");
69 still("a second waiting with nothing new");
70 s.answer({ agent: "security" }, q.id, { words: "Yes." });
71 moved("an answer");
72 s.claim("builder3", b, 12);
73 moved("a start note's claim");
74 s.edit(christopher, b, { labels: ["design"] });
75 moved("a label");
76 s.edit(christopher, a, { blockedBy: [b] });
77 moved("Blocked by");
78 s.markDone(builder, b, 381);
79 moved("done in a version");
80 const c = s.open(builder, { title: "Footer" }).id;
81 s.claim("builder3", c, 13);
82 last = s.changes();
83 s.unclaim("builder3", c);
84 moved("an unclaim");
85 s.drop(builder, c);
86 moved("a drop");
87 s.reopen(builder, c);
88 moved("a reopen");
90 s.page(a);
91 s.list({});
92 s.search("sign", 10);
93 s.waiting();
94 still("reads");
95 s.saveDraft(builder, { title: "Mine for now" });
96 s.wrote(builder);
97 still("a draft and the rate log");
98 });
100 it("is a route, and every write answers the count it made", async () => {
101 const { s } = store();
102 const call = async (method: string, path: string, body?: unknown) => {
103 const r = await issuesRoute(
104 s,
105 new Request(`https://issues.internal${path}`, {
106 method,
107 ...(body !== undefined ? { body: JSON.stringify(body) } : {}),
108 }),
109 );
110 return { status: r.status, json: (await r.json()) as Record<string, unknown> };
111 };
112 assert.deepEqual((await call("GET", "/p/web/changes")).json, { changes: 0 });
113 const opened = await call("POST", "/p/web/a/builder3/issue", { title: "Sign-in" });
114 assert.equal(opened.status, 200);
115 const after = (await call("GET", "/p/web/changes")).json.changes as number;
116 assert.ok(after > 0);
117 assert.equal(opened.json.changes, after, "the write's answer is the count a read after it sees");
118 const commented = await call("POST", "/p/web/a/builder3/issue/1/comment", { text: "More." });
119 assert.ok((commented.json.changes as number) > after);
120 });
121});