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/worker/project/test/notes.test.ts?format=json
133 linesFirst import 99% · rename 1%Last change rename in version 100, 2 versions changed it
1// Notes on lines (#44, step 2): a note is anchored to line ids, so it stays
2// on the code it's about while others change the file around it. The lines'
3// authors, the change's agent and the thread hear it as news. An objection
4// whose lines are all changed or taken out is "addressed", and its writer
5// hears so; only the writer closes a note.
6
7import assert from "node:assert/strict";
8import { test } from "node:test";
9import { type EditBody, MemoryStore, Project } from "../project.ts";
11function edit(project: Project, agent: string, body: EditBody, time: number): void {
12 const a = project.edit(agent, body, time);
13 if (!a.ok) throw new Error(`edit by ${agent} was out of step`);
16const AUTH = "export function login(user) {\n return check(user);\n}\n";
18function setup() {
19 const store = new MemoryStore();
20 const project = new Project(store, { now: () => 100 });
21 project.init({ "auth.ts": "// auth\n", "notes.md": "# notes\n" }, 0);
22 for (const a of ["builder", "security", "writer"]) project.sync(a);
23 project.starting("builder", "Sign-in", ["auth.ts"], 1);
24 edit(project, "builder", { file: "auth.ts", content: `// auth\n${AUTH}` }, 2);
25 project.publish("builder", "Add login", 3);
26 for (const a of ["security", "writer"]) project.sync(a);
27 return { project, store };
30test("a note follows its lines as the file changes around them, and reaches the author as news", () => {
31 const { project, store } = setup();
32 const noteAt = store.entries.findIndex((e) => e.type === "starting");
33 const n = project.note(
34 "security",
35 { file: "auth.ts", from: 3, to: 3, text: "check doesn't verify the state", kind: "objection" },
36 4,
37 );
38 assert.deepEqual(n, { id: 1, change: noteAt, lines: [3, 3] });
39 const news = project.news("builder").news;
40 assert.ok(
41 news.some((x) =>
42 x.startsWith('security objects on auth.ts line 3 (change "Sign-in"): "check doesn\'t verify the state". Fix it'),
43 ),
44 JSON.stringify(news),
45 );
46 // writer adds lines above: the note moves down with its line.
47 edit(project, "writer", { file: "auth.ts", old: "// auth\n", new: "// auth\n// sign-in, see notes.md\n\n" }, 5);
48 project.publish("writer", "Header", 6);
49 assert.deepEqual(
50 project.notes({ file: "auth.ts" }).notes.map((x) => [x.id, x.lines, x.state]),
51 [[1, [5, 5], "open"]],
52 );
53 // On the change page.
54 assert.deepEqual(
55 project.change(noteAt).notes.map((x) => [x.agent, x.kind, x.text]),
56 [["security", "objection", "check doesn't verify the state"]],
57 );
58});
60test("replies make a thread whose writers hear each other; read marks are quiet", () => {
61 const { project } = setup();
62 project.note("security", { file: "auth.ts", from: 2, to: 4, text: "Why no rate limit?" }, 4);
63 project.news("builder");
64 const r = project.note("builder", { reply: 1, text: "The Worker limits it before this." }, 5);
65 assert.deepEqual(r.lines, [2, 4]);
66 assert.ok(project.news("security").news.some((x) => x.startsWith("builder replies on auth.ts lines 2-4")));
67 project.note("writer", { file: "auth.ts", from: 2, to: 2, text: "read", kind: "read" }, 6);
68 assert.equal(project.news("builder").news.length, 0, "a read mark sends no news");
69 assert.deepEqual(
70 project.notes().notes.map((x) => [x.id, x.reply, x.kind]),
71 [
72 [1, null, "comment"],
73 [2, 1, "comment"],
74 [3, null, "read"],
75 ],
76 );
77});
79test("fixing every line an objection is on marks it addressed and tells its writer; only the writer closes it", () => {
80 const { project } = setup();
81 project.note("security", { file: "auth.ts", from: 3, to: 3, text: "verify the state", kind: "objection" }, 4);
82 edit(
83 project,
84 "builder",
85 { file: "auth.ts", old: " return check(user);\n", new: " return check(user, state);\n" },
86 5,
87 );
88 project.publish("builder", "Check the state", 6);
89 assert.equal(project.notes().notes[0]!.state, "addressed");
90 assert.ok(
91 project
92 .news("security")
93 .news.some((x) => x.startsWith("builder's version 2 changed every line your objection 1 on auth.ts was on")),
94 );
95 assert.throws(() => project.closeNote("builder", 1, "resolved", 7), /only security, who wrote note 1, can close it/);
96 assert.equal(project.closeNote("security", 1, "resolved", 7).state, "resolved");
97 assert.ok(project.news("builder").news.some((x) => x.includes("security resolved its objection on auth.ts")));
98});
100test("a note on someone's unpushed draft sits on their lines and belongs to their change", () => {
101 const { project, store } = setup();
102 project.starting("builder", "Logout", undefined, 4);
103 const logout = store.entries.length - 1;
104 edit(project, "builder", { file: "auth.ts", old: "}\n", new: "}\nexport function logout() {}\n" }, 5);
105 const n = project.note(
106 "security",
107 { file: "auth.ts", from: 5, to: 5, text: "clear the session too", of: "builder" },
108 6,
109 );
110 assert.deepEqual([n.change, n.lines], [logout, [5, 5]]);
111 assert.throws(
112 () => project.note("security", { file: "auth.ts", from: 1, to: 1, text: "x", of: "nobody" }, 7),
113 /there is no agent "nobody"/,
114 );
115});
117test("notes check their input, and come back the same from the log", () => {
118 const { project, store } = setup();
119 assert.throws(
120 () => project.note("security", { file: "auth.ts", from: 9, to: 9, text: "x" }, 4),
121 /from and to are line numbers in auth.ts, 1 to 4/,
122 );
123 assert.throws(() => project.note("security", { file: "auth.ts", from: 1, text: "" }, 4), /a note needs \{text\}/);
124 assert.throws(
125 () => project.note("security", { file: "auth.ts", from: 1, text: "x", kind: "approve" }, 4),
126 /kind is comment, objection or read/,
127 );
128 assert.throws(() => project.note("security", { reply: 7, text: "x" }, 4), /there is no note 7/);
129 project.note("security", { file: "auth.ts", from: 2, to: 3, text: "hm" }, 4);
130 project.closeNote("security", 1, "withdrawn", 5);
131 const again = Project.load(store.entries, new MemoryStore(), { now: () => 100 });
132 assert.deepEqual(again.notes(), project.notes());
133});