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
blame on this site's /mcp
CLI
abso blame src/engine/test/sets.test.ts --json
JSON
/christopher/abso-core/blame/src/engine/test/sets.test.ts?format=json
86 linesFirst import 100%Last change First import in version 0,

86 lines from 1 change in 1 version.

init0Start the project1// Sets and labels: closure, closedness, history, drop, refs.
2
3import assert from "node:assert/strict";
4import { describe, it } from "node:test";
5import {
6 closure,
7 dependentsIn,
8 drop,
9 history,
10 isClosed,
11 labelContents,
12 labelsContaining,
13 missingDeps,
14 resolveRef,
15 stateOf,
16} from "../index.ts";
17import { lines, Repo } from "./helpers.ts";
19function chain() {
20 const repo = Repo.init({ "f.txt": lines("one", "two", "three") });
21 const a = repo.edit({ edits: [{ file: "f.txt", old: "one", new: "ONE" }] });
22 const b = repo.edit({ edits: [{ file: "f.txt", old: "ONE", new: "uno" }] });
23 const c = repo.edit({ edits: [{ file: "f.txt", old: "three", new: "THREE" }] });
24 const d = repo.edit({ message: "tie", needs: [b.id, c.id] });
25 return { repo, a, b, c, d };
28describe("sets", () => {
29 it("closure and closedness", () => {
30 const { repo, a, b, c, d } = chain();
31 assert.deepEqual([...closure(repo.graph, [b.id])].sort(), ["a0", a.id, b.id].sort());
32 assert.deepEqual([...closure(repo.graph, [b.id, c.id])].sort(), ["a0", a.id, b.id, c.id].sort());
33 assert.equal(isClosed(repo.graph, repo.shared), true);
34 const open = new Set(["a0", b.id, d.id]);
35 assert.equal(isClosed(repo.graph, open), false);
36 assert.deepEqual(missingDeps(repo.graph, open), [
37 { atom: b.id, missing: [a.id] },
38 { atom: d.id, missing: [c.id] },
39 ]);
40 });
42 it("history is ascending (lamport, seq)", () => {
43 const { repo, a, b, c, d } = chain();
44 assert.deepEqual(
45 history(repo.graph, repo.shared).map((x) => x.id),
46 ["a0", a.id, c.id, b.id, d.id],
47 );
48 });
50 it("drop removes dependents transitively, only within the set", () => {
51 const { repo, a, b, c, d } = chain();
52 assert.deepEqual([...dependentsIn(repo.graph, repo.shared, a.id)].sort(), [b.id, d.id].sort());
53 const out = drop(repo.graph, repo.shared, a.id);
54 assert.deepEqual(out.removed, [a.id, b.id, d.id]);
55 assert.deepEqual([...out.set].sort(), ["a0", c.id].sort());
56 assert.equal(isClosed(repo.graph, out.set), true);
57 assert.deepEqual(repo.files(out.set), { "f.txt": lines("one", "two", "THREE") });
58 assert.throws(() => drop(repo.graph, out.set, a.id), { code: "not-in-set" });
59 // The original set is untouched.
60 assert.ok(repo.shared.has(a.id));
61 });
62});
64describe("labels", () => {
65 it("resolve refs, compute contents with label or atom bases, and find labels holding an atom", () => {
66 const { repo, a, b, c, d } = chain();
67 const g = repo.graph;
68 g.setLabel({ name: "first", head: b.id, title: "First", message: "" });
69 g.setLabel({ name: "all", head: d.id, base: "first", title: "All", message: "" });
70 assert.equal(resolveRef(g, "first"), b.id);
71 assert.equal(resolveRef(g, c.id), c.id);
72 assert.throws(() => resolveRef(g, "nope"), { code: "unknown-ref" });
73 assert.deepEqual([...stateOf(g, "first")].sort(), ["a0", a.id, b.id].sort());
74 assert.deepEqual(labelContents(g, g.label("first")!), [a.id, b.id]);
75 assert.deepEqual(labelContents(g, g.label("all")!), [c.id, d.id]);
76 assert.deepEqual(labelContents(g, { head: d.id, base: a.id }), [c.id, b.id, d.id]);
77 assert.deepEqual(
78 labelsContaining(g, a.id).map((l) => l.name),
79 ["first"],
80 );
81 assert.deepEqual(
82 labelsContaining(g, c.id).map((l) => l.name),
83 ["all"],
84 );
85 });
86});