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

143 lines from 2 changes in 2 versions.

init0Start the project1// Drop (#10): take published versions back out of shared. Shared is a set of
2// changes, so a drop is a new version whose set leaves them out, with
3// whatever built on them; later work that didn't build on them stays, and
4// history keeps everything.
5
6import assert from "node:assert/strict";
7import { test } from "node:test";
8import { MemoryStore, Project, ProjectError } from "../project.ts";
9
10const START = { "a.ts": "one\ntwo\nthree\n", "b.ts": "alpha\nbeta\n" };
12function setup() {
13 const store = new MemoryStore();
14 const project = new Project(store);
15 project.init(START, 0);
16 for (const a of ["ann", "bob", "cat"]) project.sync(a);
17 return { project, store };
20/** ann publishes v1 (a.ts), bob publishes v2 (b.ts, unrelated). */
21function twoVersions(project: Project): void {
22 project.edit("ann", { file: "a.ts", old: "two", new: "TWO" }, 1);
23 project.publish("ann", "Shout two", 2);
24 project.edit("bob", { file: "b.ts", old: "beta", new: "BETA" }, 3);
25 project.publish("bob", "Shout beta", 4);
28const conflictMessage = (f: () => unknown): string => {
29 try {
30 f();
31 } catch (e) {
32 if (e instanceof ProjectError && e.code === "conflict") return e.message;
33 throw e;
34 }
35 return "no conflict";
36};
38test("dropping a version takes its change out; later unrelated work stays; history keeps both", () => {
39 const { project } = setup();
40 twoVersions(project);
41 const answer = project.drop("cat", [1], "TWO broke the parser", 5);
42 assert.deepEqual(answer, { ok: true, version: 3, dropped: [{ version: 1, agent: "ann", message: "Shout two" }] });
43 assert.deepEqual(project.files(), { "a.ts": "one\ntwo\nthree\n", "b.ts": "alpha\nBETA\n" });
44 const log = project.log().versions;
45 assert.deepEqual(log[0]!.drops, [1]);
46 assert.deepEqual(log[0]!.files, ["a.ts"]);
47 assert.equal(log.find((v) => v.version === 1)!.droppedIn, 3);
48 assert.equal(project.fileAt("a.ts", 1).text, "one\nTWO\nthree\n");
49 assert.deepEqual(project.show(3).diff, [{ path: "a.ts", before: "one\nTWO\nthree\n", after: "one\ntwo\nthree\n" }]);
50 // Everyone hears it, and their next sync takes it out of their folder.
51 assert.deepEqual(project.news("bob").news, [
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.Compare52 'cat dropped version 1 from shared (version 3): "TWO broke the parser". Run abso pull to take it out of your folder.',
init0Start the project53 ]);
54 assert.deepEqual(project.sync("ann").files, { "a.ts": "one\ntwo\nthree\n", "b.ts": "alpha\nBETA\n" });
55});
57test("work that built on a dropped version is listed and refused, unless it goes too", () => {
58 const { project } = setup();
59 twoVersions(project);
60 project.sync("cat");
61 project.edit("cat", { file: "a.ts", old: "TWO", new: "TWO!" }, 5);
62 project.publish("cat", "Louder", 6);
63 const refused = project.drop("bob", [1], "Undo the shouting", 7);
64 assert.deepEqual(refused, { ok: false, dependents: [{ version: 3, agent: "cat", message: "Louder" }], blocked: [] });
65 assert.equal(project.version, 3);
66 const both = project.drop("bob", [1], "Undo the shouting", 7, { withDependents: true });
67 assert.equal(both.ok, true);
68 assert.deepEqual(both.ok && both.dropped.map((d) => d.version), [1, 3]);
69 assert.deepEqual(project.files(), { "a.ts": "one\ntwo\nthree\n", "b.ts": "alpha\nBETA\n" });
70});
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.Compare72test("unpushed work that builds on it blocks a drop; drop never touches a draft", () => {
init0Start the project73 const { project } = setup();
74 twoVersions(project);
75 project.sync("cat");
76 project.edit("cat", { file: "a.ts", old: "TWO", new: "Two" }, 5);
77 const refused = project.drop("bob", [1], "Undo", 6);
78 assert.deepEqual(refused, { ok: false, dependents: [], blocked: [{ agent: "cat", files: ["a.ts"] }] });
79 // An agent with an unrelated draft doesn't block it.
80 project.restore("cat", null, 7);
81 project.edit("cat", { file: "b.ts", old: "alpha", new: "ALPHA" }, 7);
82 assert.equal(project.drop("bob", [1], "Undo", 8).ok, true);
83 assert.equal(project.publish("cat", "Shout alpha", 9).ok, true);
84 assert.deepEqual(project.files(), { "a.ts": "one\ntwo\nthree\n", "b.ts": "ALPHA\nBETA\n" });
85});
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.Compare87test("an agent that edits dropped lines without pulling is told to restore, not broken", () => {
init0Start the project88 const { project } = setup();
89 twoVersions(project);
90 project.sync("cat"); // cat sees TWO
91 assert.equal(project.drop("bob", [1], "Undo", 5).ok, true);
92 project.edit("cat", { file: "a.ts", old: "TWO", new: "Two" }, 6); // against its old base
93 assert.match(
94 conflictMessage(() => project.publish("cat", "Soften", 7)),
95 /a\.ts build on lines a drop took out/,
96 );
97 assert.match(
98 conflictMessage(() => project.sync("cat")),
99 /abso restore a\.ts/,
100 );
101 project.restore("cat", ["a.ts"], 8);
102 assert.deepEqual(project.sync("cat").files, { "a.ts": "one\ntwo\nthree\n" });
103});
105test("dropping a deletion brings the lines back; dropping a move puts the lines back where they were", () => {
106 const { project } = setup();
107 project.edit("ann", { file: "a.ts", old: "two\n", new: "" }, 1);
108 project.publish("ann", "No two", 2);
109 project.record("bob", { "b.ts": null, "c.ts": START["b.ts"] }, 3);
110 project.publish("bob", "Rename b to c", 4); // bob's base is old; publish still lands
111 assert.deepEqual(project.files(), { "a.ts": "one\nthree\n", "c.ts": "alpha\nbeta\n" });
112 assert.equal(project.drop("cat", [1], "Two is needed", 5).ok, true);
113 assert.equal(project.drop("cat", [2], "Keep the old name", 6).ok, true);
114 assert.deepEqual(project.files(), START);
115});
117test("a dropped land is never landed again by its draft", () => {
118 const { project } = setup();
119 project.switchTo("ann", "feature", 1);
120 project.edit("ann", { file: "a.ts", old: "one", new: "ONE" }, 1);
121 project.publish("ann", "One loud", 2);
122 assert.equal(project.land("ann", "Feature", 3).ok, true);
123 assert.equal(project.files()["a.ts"], "ONE\ntwo\nthree\n");
124 assert.equal(project.drop("bob", [1], "Not yet", 4).ok, true);
125 assert.equal(project.files()["a.ts"], "one\ntwo\nthree\n");
126 const again = project.land("ann", "Feature again", 5);
127 assert.deepEqual(again, { ok: true, version: 2, changes: 0 });
128 assert.equal(project.files()["a.ts"], "one\ntwo\nthree\n");
129});
131test("bad drops are plain errors; a log with drops loads back the same", () => {
132 const { project, store } = setup();
133 twoVersions(project);
134 assert.throws(() => project.drop("cat", [0], "x", 5), /version 0 is the start/);
135 assert.throws(() => project.drop("cat", [9], "x", 5), /no version 9/);
136 assert.throws(() => project.drop("cat", [1], "", 5), /message/);
137 project.drop("cat", [1], "x", 5);
138 assert.throws(() => project.drop("cat", [1], "x", 6), /already dropped in version 3/);
139 assert.throws(() => project.drop("cat", [3], "x", 6), /added nothing/);
140 const again = Project.load(store.entries, new MemoryStore());
141 assert.deepEqual(again.files(), project.files());
142 assert.deepEqual(again.log(), project.log());
143});