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 276 to 277

Compare

+90 −0 in 1 place
new file, 90 lines
1+// Who is calling a seat: one header with the chat's session, the computer and the folder, read back exactly or not at all.
2+import assert from "node:assert/strict";
3+import { test } from "node:test";
4+import { CALLER_HEADER, CALLER_MAX, callerHeader, callerPlace, parseCaller } from "../../src/caller.ts";
5+import { Api } from "../src/api.ts";
6+
7+const session = "0da5c2b7-ab07-4249-b868-e8f09b6ec7b6";
8+
9+test("a caller goes out and comes back as it was", () => {
10+ const header = callerHeader({ session, machine: "DESKTOP-1", folder: "C:\\Users\\sam\\repos\\abso\\groups" })!;
11+ assert.match(header, /^[A-Za-z0-9_-]+$/);
12+ assert.deepEqual(parseCaller(header), {
13+ session,
14+ machine: "DESKTOP-1",
15+ folder: "C:\\Users\\sam\\repos\\abso\\groups",
16+ });
17+ assert.equal(callerPlace(parseCaller(header)!), "groups on DESKTOP-1");
18+ // Outside a chat there's no session, and that's still a caller.
19+ assert.deepEqual(parseCaller(callerHeader({ machine: "box", folder: "/work/über" })), {
20+ machine: "box",
21+ folder: "/work/über",
22+ });
23+});
25+test("a session that isn't an id is left out, and a long folder keeps its end", () => {
26+ assert.deepEqual(parseCaller(callerHeader({ session: "not a session!", machine: "m", folder: "/a" })), {
27+ machine: "m",
28+ folder: "/a",
29+ });
30+ const deep = `/${"very-long-folder-name/".repeat(40)}groups`;
31+ const header = callerHeader({ session, machine: "m", folder: deep })!;
32+ assert.ok(header.length <= CALLER_MAX);
33+ assert.ok(parseCaller(header)!.folder.endsWith("/groups"));
34+});
36+test("a header that isn't a caller is refused, never guessed at", () => {
37+ const enc = (v: unknown) => Buffer.from(JSON.stringify(v)).toString("base64url");
38+ for (const bad of [
39+ undefined,
40+ "",
41+ "not base64!",
42+ enc("text"),
43+ enc([1]),
44+ enc({ machine: "m" }),
45+ enc({ machine: "has space", folder: "/a" }),
46+ enc({ machine: "m", folder: "/a", session: "bad id!" }),
47+ enc({ machine: "m", folder: "/a", token: "x" }),
48+ enc({ machine: "m", folder: "/a\nb" }),
49+ "A".repeat(CALLER_MAX + 1),
50+ ])
51+ assert.equal(parseCaller(bad), null, String(bad));
52+});
54+test("the Api sends the caller with its calls, except from a visitor folder", () => {
55+ const config = {
56+ server: "https://abso.test",
57+ project: "p",
58+ agent: "ann",
59+ token: "abso_sk_x",
60+ } as ConstructorParameters<typeof Api>[0];
61+ const api = new Api(config);
62+ assert.equal(api.headers()[CALLER_HEADER], undefined);
63+ api.caller = callerHeader({ session, machine: "m", folder: "/a" });
64+ assert.equal(api.headers()[CALLER_HEADER], api.caller);
65+ const visitor = new Api({ ...config, visitor: true } as ConstructorParameters<typeof Api>[0]);
66+ visitor.caller = api.caller;
67+ assert.equal(visitor.headers()[CALLER_HEADER], undefined);
68+});
70+test("a seat notice on any answer is printed once with the news", async () => {
71+ const { takeNews } = await import("../src/command-env.ts");
72+ takeNews();
73+ const real = globalThis.fetch;
74+ const line = "ann was used from another chat (groups on DESKTOP-2) in the last 30 minutes";
75+ globalThis.fetch = (async () => Response.json({ ok: true, seatNotice: line })) as typeof fetch;
76+ try {
77+ const api = new Api({
78+ server: "https://abso.test",
79+ project: "p",
80+ agent: "ann",
81+ token: "abso_sk_x",
82+ } as ConstructorParameters<typeof Api>[0]);
83+ await api.json("GET", "/status");
84+ await api.json("GET", "/status");
85+ assert.deepEqual(takeNews(), [line]);
86+ assert.deepEqual(takeNews(), []);
87+ } finally {
88+ globalThis.fetch = real;
89+ }
90+});
MCP
compare on this site's /mcp
CLI
abso diff 276 277 client/test/caller.test.ts --json
JSON
/christopher/abso-core/compare/276..277?file=client%2Ftest%2Fcaller.test.ts&format=json