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 192 to 193

Compare

+144 −0 in 1 place
new file, 144 lines
1+// abso why past formatting to the reason (abso-core issue 20), and lines
2+// imported from git naming their commit and their tracker (issue 21), from
3+// the command line: a line imported from git, then reformatted.
4+
5+import assert from "node:assert/strict";
6+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
7+import { tmpdir } from "node:os";
8+import { join } from "node:path";
9+import { after, before, describe, it } from "node:test";
10+import { gitOrigin, issueLinks, issueNumbers, issuesOf } from "../src/git-origin.ts";
11+import { main } from "../src/main.ts";
12+import { type Fake, startFake } from "./fake-server.ts";
14+const TOKEN = "test-token-not-secret";
15+const ENV = { AVCS_TOKEN: TOKEN, AVCS_HOOK_FORCE: "1", AVCS_SERVERS_FILE: "no-servers.json" };
16+const IMPORTED =
17+ "Merge queue: check publishes in batches (#39)\n\nCap the batch at 8.\n\ngit 4e1a7c2b9f03, Ada Lovelace, 2026-10-06T20:36:43-05:00";
19+let fake: Fake;
20+const dirs: string[] = [];
21+before(async () => {
22+ fake = await startFake(0, TOKEN);
23+});
24+after(async () => {
25+ await fake.close();
26+ for (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });
27+});
29+async function run(cwd: string, ...argv: string[]): Promise<{ exit: number; out: string }> {
30+ const r = await main(argv, { cwd, env: ENV, write: () => {} });
31+ return { exit: r.exit, out: r.stdout + r.stderr };
32+}
34+let projects = 0;
35+/** v0 init; v1 a git import changes the cap line; v2 a reformat. */
36+async function history(config = '{ "check": "true" }\n', message = IMPORTED): Promise<string> {
37+ const dir = mkdtempSync(join(tmpdir(), "abso-why-"));
38+ dirs.push(dir);
39+ writeFileSync(join(dir, "abso.json"), config);
40+ writeFileSync(join(dir, "queue.ts"), "export function take(w) {\n\tconst n = Math.min(4, w);\n\treturn n;\n}\n");
41+ const made = await run(
42+ dir,
43+ "init",
44+ "--server",
45+ fake.url,
46+ "--project",
47+ `why${++projects}`,
48+ "--agent",
49+ "imp",
50+ "--as-is",
51+ );
52+ assert.equal(made.exit, 0, made.out);
53+ const edit = (from: string, to: string) =>
54+ writeFileSync(join(dir, "queue.ts"), readFileSync(join(dir, "queue.ts"), "utf8").replace(from, to));
55+ edit("Math.min(4, w); ", "Math.min(4, w);");
56+ edit("Math.min(4, w);", "Math.min(8, w); // #39");
57+ let r = await run(dir, "push", "-m", message);
58+ assert.equal(r.exit, 0, r.out);
59+ edit("\tconst n = Math.min(8, w); // #39", " const n = Math.min(8, w) // #39");
60+ r = await run(dir, "push", "-m", "Format the code");
61+ assert.equal(r.exit, 0, r.out);
62+ return dir;
63+}
65+describe("abso why", () => {
66+ it("leads with the change that said what the line does, and says which formatting change it skipped", async () => {
67+ const dir = await history('{ "gitIssues": "https://github.com/owner/repo/issues/" }\n');
68+ const r = await run(dir, "why", "queue.ts:2");
69+ assert.equal(r.exit, 0, r.out);
70+ assert.match(r.out, /^queue\.ts line 2: {3}const n = Math\.min\(8, w\) \/\/ #39$/m);
71+ assert.match(r.out, /^Written by imp \(.*\), pushed in version 1 by imp \(.*\): "Merge queue: check publishes/m);
72+ assert.doesNotMatch(r.out, /pushed in version 1 [^\n]*git d9cf/, "the git line is said once, below");
73+ assert.match(r.out, /^ {2}From git: commit 4e1a7c2b9f03 by Ada Lovelace, 2026-10-06T20:36:43-05:00\.$/m);
74+ assert.match(r.out, /^ {2}#39 is https:\/\/github\.com\/owner\/repo\/issues\/39$/m);
75+ assert.match(r.out, /^Skipped 1 formatting change since: version 2 \(imp, "Format the code"\)\./m);
76+ assert.match(
77+ r.out,
78+ /^Earlier changes, newest first:\n {2}version 0 by init .*"Start the project"\n {4}It read: const n = Math\.min\(4, w\);$/m,
79+ );
80+ });
82+ it("--all leads with the newest change, formatting or not; --at reads an older version", async () => {
83+ const dir = await history();
84+ const all = await run(dir, "why", "queue.ts:2", "--all");
85+ assert.equal(all.exit, 0, all.out);
86+ assert.match(all.out, /^Written by imp .*pushed in version 2 .*"Format the code"/m);
87+ assert.match(
88+ all.out,
89+ /^ {2}version 1 by imp .*"Merge queue: check publishes in batches \(#39\)", from git commit 4e1a7c2b9f03 by Ada Lovelace$/m,
90+ );
91+ assert.doesNotMatch(all.out, /#39 is/, "no tracker: abso.json doesn't say where");
92+ const at = await run(dir, "why", "queue.ts:2", "--at", "0", "--json");
93+ assert.equal(at.exit, 0, at.out);
94+ assert.equal(JSON.parse(at.out).text, "\tconst n = Math.min(4, w);");
95+ });
97+ it("blame names an imported push's commit", async () => {
98+ const dir = await history();
99+ const r = await run(dir, "blame", "queue.ts", "--version", "1");
100+ assert.equal(r.exit, 0, r.out);
101+ assert.match(
102+ r.out,
103+ /^ {2}v1 by imp, .*: Merge queue: check publishes in batches \(#39\) \(from git commit 4e1a7c2b9f03 by Ada Lovelace\)$/m,
104+ );
105+ });
106+});
108+describe("git origins", () => {
109+ it("reads import-git's lines, a git push's, or the host's commit", () => {
110+ assert.deepEqual(gitOrigin({ message: `${IMPORTED}\nIssues: https://github.com/o/r/issues` }), {
111+ commit: "4e1a7c2b9f03",
112+ author: "Ada Lovelace",
113+ time: "2026-10-06T20:36:43-05:00",
114+ issues: "https://github.com/o/r/issues",
115+ message: "Merge queue: check publishes in batches (#39)\n\nCap the batch at 8.",
116+ });
117+ assert.deepEqual(gitOrigin({ message: "Fix\n\nGit-Commit: abcdef1234\nAuthor: Bo" }), {
118+ commit: "abcdef1234",
119+ author: "Bo",
120+ message: "Fix",
121+ });
122+ assert.deepEqual(gitOrigin({ message: "Plain", commit: "abc1234", author: "Cy" }, "https://x/issues"), {
123+ commit: "abc1234",
124+ author: "Cy",
125+ issues: "https://x/issues",
126+ message: "Plain",
127+ });
128+ assert.equal(gitOrigin({ message: "Written in abso (#39)" }), undefined);
129+ });
131+ it("names each #N once, and leaves owner/repo#N alone", () => {
132+ assert.deepEqual(issueNumbers("see #39 and #4, again #39; other/repo#7, a#5"), [39, 4]);
133+ assert.deepEqual(issueLinks("(#39)", "https://g/o/r/issues"), ["#39 is https://g/o/r/issues/39"]);
134+ assert.deepEqual(issueLinks("(#39)", undefined), []);
135+ });
137+ it("finds a remote's issues on GitHub or GitLab, by https or ssh", () => {
138+ assert.equal(issuesOf("https://github.com/o/r.git"), "https://github.com/o/r/issues");
139+ assert.equal(issuesOf("git@github.com:o/r.git"), "https://github.com/o/r/issues");
140+ assert.equal(issuesOf("https://gitlab.com/g/sub/r"), "https://gitlab.com/g/sub/r/-/issues");
141+ assert.equal(issuesOf("https://example.com/o/r.git"), undefined);
142+ assert.equal(issuesOf(""), undefined);
143+ });
144+});
MCP
compare on this site's /mcp
CLI
abso diff 192 193 client/test/why-trail.test.ts --json
JSON
/christopher/abso-core/compare/192..193?file=client%2Ftest%2Fwhy-trail.test.ts&format=json