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 worker/project/test/changes.test.ts --json
JSON
/christopher/abso-core/blame/worker/project/test/changes.test.ts?format=json
191 linesFirst import 98% · rename 2%Last change rename in version 100,

191 lines from 2 changes in 2 versions.

init0Start the project1// Changes (#44, the ruling on questions 1-3): a change is one start
2// note's work, a named draft's, or a lone publish. Start notes last through
3// publishes until the next start, a take-back (publish --done), or 2 hours
4// idle. The change page reads one change; "since you last looked" lists the
5// changes with anything new after a log position.
6
7import assert from "node:assert/strict";
8import { test } from "node:test";
9import { type EditBody, type Entry, MemoryStore, Project } from "../project.ts";
11const HOUR = 60 * 60 * 1000;
13function edit(project: Project, agent: string, body: EditBody, time: number): void {
14 const a = project.edit(agent, body, time);
15 if (!a.ok) throw new Error(`edit by ${agent} was out of step`);
18function setup() {
19 const store = new MemoryStore();
20 let now = 0;
21 const project = new Project(store, { now: () => now });
22 project.init(
23 { "a.ts": "export const a = 1;\n", "b.ts": "export const b = 1;\n", "c.ts": "export const c = 1;\n" },
24 0,
25 );
26 for (const a of ["ann", "bob"]) project.sync(a);
27 return { project, store, at: (t: number) => (now = t) };
30const publishOf = (store: MemoryStore, version: number) =>
31 store.entries.find(
32 (e): e is Extract<Entry, { type: "publish" }> => e.type === "publish" && e.version === version && !e.space,
33 )!;
rename100abso publish is now abso push, abso sync is now abso pull (abso 427) Commands, help, flags, messages, MCP tool names and descriptions, hook text, README, SKILL.md and tests say push and pull; "shared" stays the noun ("Pushed version N"). No aliases, no notices. A queued push that was "pulled" is now "turned back", so pull means one thing. push -f/--force/-u/--all/--tags and pull --rebase/--ff-only/--squash refuse with one plain line naming the abso way; push and pull take no remote or branch. Kept as stored: log entry kinds (publish, sync, pulled), HTTP route paths, the pipeline trigger on: publish, the yours (unpublished) marker, npm-publish.Compare35test("a start note's pushes are one change, with its versions, files and title", () => {
init0Start the project36 const { project, store, at } = setup();
37 at(1);
38 project.starting("ann", "Bigger numbers", ["a.ts", "b.ts"], 1);
39 const noteAt = store.entries.findIndex((e) => e.type === "starting");
40 edit(project, "ann", { file: "a.ts", old: "1", new: "2" }, 2);
41 project.publish("ann", "a is 2", 3);
42 edit(project, "bob", { file: "c.ts", old: "1", new: "5" }, 4);
43 project.publish("bob", "c is 5", 5);
44 project.sync("ann");
45 edit(project, "ann", { file: "b.ts", old: "1", new: "2" }, 6);
46 project.publish("ann", "b is 2", 7);
47 at(8);
48 assert.equal(publishOf(store, 1).change, noteAt);
49 assert.equal(publishOf(store, 3).change, noteAt);
50 const c = project.change(noteAt);
51 assert.deepEqual(
52 [c.kind, c.agent, c.title, c.open, c.note],
53 ["note", "ann", "Bigger numbers", true, { text: "Bigger numbers", files: ["a.ts", "b.ts"] }],
54 );
55 assert.deepEqual(
56 c.versions.map((v) => [v.version, v.message, v.files]),
57 [
58 [1, "a is 2", ["a.ts"]],
59 [3, "b is 2", ["b.ts"]],
60 ],
61 );
62 assert.deepEqual(c.files, ["a.ts", "b.ts"]);
63 // bob's publish, with no start note, is a change of its own, named by its publish's log position.
64 const bobs = publishOf(store, 2).change!;
65 assert.deepEqual(
66 [project.change(bobs).kind, project.change(bobs).title, project.change(bobs).open],
67 ["publish", "c is 5", false],
68 );
69 assert.throws(() => project.change(9999), /there is no change 9999/);
70});
72test("a start note ends at the next start, a take-back, or 2 hours idle, and so does its change", () => {
73 const { project, store, at } = setup();
74 project.starting("ann", "One", undefined, 1);
75 edit(project, "ann", { file: "a.ts", old: "1", new: "2" }, 2);
76 project.publish("ann", "first", 3);
77 const one = publishOf(store, 1).change!;
78 project.starting("ann", "Two", undefined, 4);
79 edit(project, "ann", { file: "a.ts", old: "2", new: "3" }, 5);
80 project.publish("ann", "second", 6);
81 const two = publishOf(store, 2).change!;
82 assert.notEqual(one, two);
83 at(6);
84 assert.equal(project.change(one).open, false);
85 assert.equal(project.change(two).open, true);
86 // Taken back (what publish --done sends).
87 project.starting("ann", null, undefined, 7);
88 assert.equal(project.change(two).open, false);
89 // Idle: a note, then nothing for over 2 hours, then a publish is a change of its own.
90 project.starting("ann", "Three", undefined, 10);
91 at(10 + 2 * HOUR + 1);
92 assert.equal(project.startingNotes().length, 0, "the note has ended");
93 edit(project, "ann", { file: "a.ts", old: "3", new: "4" }, 10 + 2 * HOUR + 1);
94 project.publish("ann", "after a break", 10 + 2 * HOUR + 2);
95 const after = publishOf(store, 3);
96 assert.equal(project.change(after.change!).kind, "publish");
97});
99test("a named draft's work is one change, its land included", () => {
100 const { project, store } = setup();
101 project.switchTo("ann", "feature", 1);
102 const startedAt = store.entries.findIndex((e) => e.type === "space");
103 edit(project, "ann", { file: "a.ts", old: "1", new: "2" }, 2);
104 project.publish("ann", "in the draft", 3);
105 project.land("ann", "Land feature", 4);
106 const c = project.change(startedAt);
107 assert.deepEqual([c.kind, c.draft, c.title], ["draft", "feature", "Draft feature"]);
108 assert.deepEqual(
109 c.versions.map((v) => [v.draft, v.message]),
110 [
111 ["feature", "in the draft"],
112 [null, "Land feature"],
113 ],
114 );
115});
117test("since you last looked: the changes with anything new after a log position, newest first", () => {
118 const { project, store } = setup();
119 edit(project, "ann", { file: "a.ts", old: "1", new: "2" }, 1);
120 project.publish("ann", "a is 2", 2);
121 const mark = store.entries.length;
122 edit(project, "bob", { file: "b.ts", old: "1", new: "2" }, 3);
123 project.publish("bob", "b is 2", 4);
124 // A refusal lands on the refused agent's change only when it has one: a start note here.
125 project.starting("ann", "Clash", undefined, 5);
126 edit(project, "ann", { file: "b.ts", old: "export const b = 1;", new: "export const b = 9;" }, 6);
127 assert.equal(project.publish("ann", "b is 9", 7).ok, false);
128 const since = project.changes(mark);
129 assert.deepEqual(
130 since.changes.map((c) => [c.agent, c.title]),
131 [
132 ["ann", "Clash"],
133 ["bob", "b is 2"],
134 ],
135 );
136 assert.deepEqual(
137 since.changes[0]!.refusals.map((r) => [r.kinds, r.files]),
138 [[["lines"], ["b.ts"]]],
139 );
140 assert.equal(since.next, store.entries.length);
141 assert.equal(project.changes(0).changes.length, 3);
142});
rename100abso publish is now abso push, abso sync is now abso pull (abso 427) Commands, help, flags, messages, MCP tool names and descriptions, hook text, README, SKILL.md and tests say push and pull; "shared" stays the noun ("Pushed version N"). No aliases, no notices. A queued push that was "pulled" is now "turned back", so pull means one thing. push -f/--force/-u/--all/--tags and pull --rebase/--ff-only/--squash refuse with one plain line naming the abso way; push and pull take no remote or branch. Kept as stored: log entry kinds (publish, sync, pulled), HTTP route paths, the pipeline trigger on: publish, the yours (unpublished) marker, npm-publish.Compare144test("changes come back the same from the log, and old pushes without a change still group and end the note", () => {
init0Start the project145 const { project, store } = setup();
146 project.starting("ann", "Note", undefined, 1);
147 edit(project, "ann", { file: "a.ts", old: "1", new: "2" }, 2);
148 project.publish("ann", "one", 3);
149 const again = Project.load(store.entries, new MemoryStore(), { now: () => 3 });
150 assert.deepEqual(again.changes(0), project.changes(0));
151 // The same log as written before changes: no `change` on the publish.
152 const old = store.entries.map((e) => (e.type === "publish" ? (({ change: _, ...rest }) => rest)(e) : e)) as Entry[];
153 const replayed = Project.load(old, new MemoryStore(), { now: () => 3 });
rename100abso publish is now abso push, abso sync is now abso pull (abso 427) Commands, help, flags, messages, MCP tool names and descriptions, hook text, README, SKILL.md and tests say push and pull; "shared" stays the noun ("Pushed version N"). No aliases, no notices. A queued push that was "pulled" is now "turned back", so pull means one thing. push -f/--force/-u/--all/--tags and pull --rebase/--ff-only/--squash refuse with one plain line naming the abso way; push and pull take no remote or branch. Kept as stored: log entry kinds (publish, sync, pulled), HTTP route paths, the pipeline trigger on: publish, the yours (unpublished) marker, npm-publish.Compare154 assert.equal(replayed.startingNotes().length, 0, "an old push ended the note");
init0Start the project155 const noteAt = store.entries.findIndex((e) => e.type === "starting");
156 assert.deepEqual(
157 replayed.change(noteAt).versions.map((v) => v.message),
158 ["one"],
159 );
160});
162test("log and show name each version's change", () => {
163 const { project, store } = setup();
164 project.starting("ann", "Note", undefined, 1);
165 const noteAt = store.entries.findIndex((e) => e.type === "starting");
166 edit(project, "ann", { file: "a.ts", old: "1", new: "2" }, 2);
167 project.publish("ann", "one", 3);
168 assert.equal(project.log().versions[0]!.change, noteAt);
169 assert.equal(project.show(1).change, noteAt);
170 assert.equal(project.log().versions.at(-1)!.change, undefined, "init belongs to no change");
171});
173test("changes pages back with before, and says where the next older page starts", () => {
174 const { project } = setup();
175 for (let i = 2; i <= 6; i++) {
176 edit(project, "ann", { file: "a.ts", old: `a = ${i - 1}`, new: `a = ${i}` }, i);
177 project.publish("ann", `a is ${i}`, i);
178 }
179 const first = project.changes(0, 2);
180 assert.deepEqual(
181 first.changes.map((c) => c.title),
182 ["a is 6", "a is 5"],
183 );
184 const second = project.changes(0, 2, first.older);
185 assert.deepEqual(
186 second.changes.map((c) => c.title),
187 ["a is 4", "a is 3"],
188 );
189 const last = project.changes(0, 2, second.older);
190 assert.deepEqual([last.changes.map((c) => c.title), last.older], [["a is 2"], undefined]);
191});