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 116 to 318

Compare

+193 −0 in 1 place
new file, 193 lines
1+// Ask threads: replies from either side, whose turn it is, the
2+// asks someone sent, one ask with its thread, and asks going only to seats.
3+
4+import assert from "node:assert/strict";
5+import { DatabaseSync } from "node:sqlite";
6+import { describe, it } from "node:test";
7+import { issuesRoute } from "../../src/issues/routes.ts";
8+import { closestSeat, seatRefusal } from "../../src/issues/seats.ts";
9+import { IssuesStore, type Sql } from "../../src/issues/store.ts";
11+function sql(): Sql {
12+ const db = new DatabaseSync(":memory:");
13+ return {
14+ exec: (q, ...b) => {
15+ if (/^\s*CREATE\b/i.test(q)) {
16+ db.exec(q);
17+ return { toArray: () => [] };
18+ }
19+ const rows = db.prepare(q).all(...(b as (string | number | null)[]));
20+ return { toArray: () => rows };
21+ },
22+ };
23+}
25+function store(): { s: IssuesStore; db: Sql; tick: (ms?: number) => void } {
26+ let t = Date.parse("2026-10-10T05:00:00Z");
27+ const db = sql();
28+ IssuesStore.createTables(db);
29+ return { s: new IssuesStore(db, () => t), db, tick: (ms = 1000) => void (t += ms) };
30+}
32+const desk = { agent: "desk" };
33+const fay = { agent: "fay" };
35+describe("ask threads", () => {
36+ it("replies from both sides, oldest first; a question back waits on the asker until they reply", () => {
37+ const { s, tick } = store();
38+ const id = s.open(desk, { title: "Sync is slow" }).id;
39+ const ask = s.ask(desk, { issue: id, of: "fay", question: "Which way?" });
40+ assert.equal(s.askThread(ask.id).waitingOn, "fay");
42+ tick();
43+ s.ack(fay, ask.id, { note: "ok, let me check" });
44+ tick();
45+ const back = s.reply(fay, ask.id, { text: "staging or live?", question: true });
46+ assert.equal(back.ask.waitingOn, "desk");
47+ assert.deepEqual(back.news.to, ["desk"]);
48+ assert.equal(
49+ back.news.text,
50+ `fay replied on ask ${ask.id} (issue ${id}) with a question: "staging or live?" It waits on you. abso ask ${ask.id} shows the thread.`,
51+ );
52+ assert.deepEqual(
53+ back.ask.replies!.map((r) => [r.by, r.text, r.question === true]),
54+ [
55+ ["fay", "ok, let me check", false],
56+ ["fay", "staging or live?", true],
57+ ],
58+ );
59+ // It's in the asker's waiting list now, not the one asked's, and the issue waits on the asker.
60+ assert.deepEqual(
61+ s.waiting("desk").map((a) => a.id),
62+ [ask.id],
63+ );
64+ assert.deepEqual(s.waiting("fay"), []);
65+ assert.deepEqual(s.page(id).issue.waitingOn, ["desk"]);
67+ tick();
68+ const handed = s.reply(desk, ask.id, { text: "live" });
69+ assert.equal(handed.ask.waitingOn, "fay");
70+ assert.deepEqual(handed.news.to, ["fay"]);
71+ assert.match(handed.news.text, /^desk replied on ask \d+ \(issue \d+\): "live" It waits on you\./);
72+ assert.deepEqual(
73+ s.waiting("fay").map((a) => a.id),
74+ [ask.id],
75+ );
77+ // A plain reply from the one asked leaves the turn where it is.
78+ assert.equal(s.reply(fay, ask.id, { text: "deploying" }).ask.waitingOn, "fay");
80+ // Answering closes it; a reply after still lands, and waits on nobody.
81+ s.answer(fay, ask.id, { words: "done on live" });
82+ const after = s.reply(desk, ask.id, { text: "thanks" });
83+ assert.equal(after.ask.waitingOn, null);
84+ assert.equal(after.ask.answer!.words, "done on live");
85+ assert.equal(after.ask.replies!.length, 5);
86+ assert.equal(s.page(id).asks[0]!.replies!.length, 5);
87+ assert.deepEqual(s.waiting("fay"), []);
88+ assert.deepEqual(s.waiting("desk"), []);
89+ });
91+ it("only the two reply, with words, on an ask that exists", () => {
92+ const { s } = store();
93+ const ask = s.ask(desk, { of: "fay", question: "Pick one" });
94+ assert.throws(
95+ () => s.reply({ agent: "eve" }, ask.id, { text: "me too" }),
96+ (e: { status?: number; message: string }) =>
97+ e.status === 403 && /between desk and fay; only they reply on it/.test(e.message),
98+ );
99+ assert.throws(
100+ () => s.reply(fay, 99, { text: "x" }),
101+ (e: { status?: number }) => e.status === 404,
102+ );
103+ assert.throws(() => s.reply(fay, ask.id, { text: "" }));
104+ assert.throws(() => s.reply(fay, ask.id, {}));
105+ });
107+ it("an ack with no note adds no reply; ack's note is the thread's first", () => {
108+ const { s } = store();
109+ const ask = s.ask(desk, { of: "fay", question: "Pick one" });
110+ assert.deepEqual(s.ack(fay, ask.id, {}).ask.replies, []);
111+ assert.equal(s.ack(fay, ask.id, { note: "soon" }).ask.replies![0]!.text, "soon");
112+ });
114+ it("asked lists what someone sent: open oldest first, then the latest answered", () => {
115+ const { s, tick } = store();
116+ const a = s.ask(desk, { of: "fay", question: "One" });
117+ tick();
118+ const b = s.ask(desk, { of: "fay", question: "Two" });
119+ tick();
120+ const c = s.ask(desk, { of: "fay", question: "Three" });
121+ s.ask(fay, { of: "desk", question: "Not desk's" });
122+ s.answer(fay, b.id, { words: "yes" });
123+ assert.deepEqual(
124+ s.asked("desk").map((x) => x.id),
125+ [a.id, c.id, b.id],
126+ );
127+ });
128+});
130+describe("ask thread routes", () => {
131+ const call = (
132+ s: IssuesStore,
133+ method: string,
134+ path: string,
135+ body?: unknown,
136+ seatError?: (of: string) => Promise<string | null>,
137+ ) =>
138+ issuesRoute(
139+ s,
140+ new Request(`https://issues.internal${path}`, {
141+ method,
142+ ...(body !== undefined ? { body: JSON.stringify(body) } : {}),
143+ }),
144+ seatError,
145+ ).then(async (r) => ({ status: r.status, json: (await r.json()) as Record<string, any> }));
147+ it("POST a/<agent>/reply/N, GET ask/N, GET a/<agent>/asked and asked?by=", async () => {
148+ const { s } = store();
149+ const ask = s.ask(desk, { of: "fay", question: "Which way?" });
150+ const r = await call(s, "POST", `/p/web/a/fay/reply/${ask.id}`, { text: "live?", question: true });
151+ assert.equal(r.status, 200, JSON.stringify(r.json));
152+ assert.equal(r.json.ask.waitingOn, "desk");
153+ const one = await call(s, "GET", `/p/web/ask/${ask.id}`);
154+ assert.equal(one.json.ask.replies[0].text, "live?");
155+ assert.equal((await call(s, "GET", "/p/web/ask/99")).status, 404);
156+ const mine = await call(s, "GET", "/p/web/a/desk/asked");
157+ assert.deepEqual(
158+ mine.json.asks.map((a: { id: number }) => a.id),
159+ [ask.id],
160+ );
161+ assert.equal((await call(s, "GET", "/p/web/asked?by=desk")).json.asks.length, 1);
162+ assert.equal((await call(s, "GET", "/p/web/asked")).status, 400);
163+ });
165+ it("a new ask to a name that isn't a seat is refused, naming the closest seat", async () => {
166+ const { s } = store();
167+ const seats = ["cloud", "agentvcs", "pinch", "infra-ops"];
168+ const check = async (of: string) => (of.startsWith("person:") ? null : seatRefusal(of, "web", seats));
169+ const refused = await call(s, "POST", "/p/web/a/desk/ask", { of: "abso - Cloud Infra Lead", question: "Q" }, check);
170+ assert.equal(refused.status, 400);
171+ assert.equal(
172+ refused.json.error,
173+ '"abso - Cloud Infra Lead" isn\'t an agent in web, so nobody would hear the ask; did you mean cloud? abso status lists the agents.',
174+ );
175+ assert.deepEqual(s.asked("desk"), []);
176+ assert.equal((await call(s, "POST", "/p/web/a/desk/ask", { of: "cloud", question: "Q" }, check)).status, 200);
177+ });
179+ it("closestSeat: the same name written another way, a seat the name holds, then a near spelling", () => {
180+ const seats = ["cloud", "agentvcs", "pinch", "infra-ops", "security-2"];
181+ assert.equal(closestSeat("Agent VCS", seats), "agentvcs");
182+ assert.equal(closestSeat("abso - Cloud Infra Lead", seats), "cloud");
183+ assert.equal(closestSeat("Security 2", seats), "security-2");
184+ assert.equal(closestSeat("pnich", seats), "pinch");
185+ assert.equal(closestSeat("infraops", seats), "infra-ops");
186+ assert.equal(closestSeat("zzzzzz", seats), null);
187+ assert.equal(seatRefusal("pinch", "web", seats), null);
188+ assert.match(
189+ seatRefusal("nobody", "web", seats)!,
190+ /isn't an agent in web, so nobody would hear the ask\. abso status/,
191+ );
192+ });
193+});
MCP
compare on this site's /mcp
CLI
abso diff 116 318 server/test/issues/ask-threads.test.ts --json
JSON
/christopher/abso-core/compare/116..318?file=server%2Ftest%2Fissues%2Fask-threads.test.ts&format=json