{"file":"worker/project/test/changes.test.ts","version":318,"total":191,"from":1,"to":191,"lines":[{"n":1,"text":"// Changes (#44, the ruling on questions 1-3): a change is one start","atom":"a0","author":"init","version":0},{"n":2,"text":"// note's work, a named draft's, or a lone publish. Start notes last through","atom":"a0","author":"init","version":0},{"n":3,"text":"// publishes until the next start, a take-back (publish --done), or 2 hours","atom":"a0","author":"init","version":0},{"n":4,"text":"// idle. The change page reads one change; \"since you last looked\" lists the","atom":"a0","author":"init","version":0},{"n":5,"text":"// changes with anything new after a log position.","atom":"a0","author":"init","version":0},{"n":6,"text":"","atom":"a0","author":"init","version":0},{"n":7,"text":"import assert from \"node:assert/strict\";","atom":"a0","author":"init","version":0},{"n":8,"text":"import { test } from \"node:test\";","atom":"a0","author":"init","version":0},{"n":9,"text":"import { type EditBody, type Entry, MemoryStore, Project } from \"../project.ts\";","atom":"a0","author":"init","version":0},{"n":10,"text":"","atom":"a0","author":"init","version":0},{"n":11,"text":"const HOUR = 60 * 60 * 1000;","atom":"a0","author":"init","version":0},{"n":12,"text":"","atom":"a0","author":"init","version":0},{"n":13,"text":"function edit(project: Project, agent: string, body: EditBody, time: number): void {","atom":"a0","author":"init","version":0},{"n":14,"text":"\tconst a = project.edit(agent, body, time);","atom":"a0","author":"init","version":0},{"n":15,"text":"\tif (!a.ok) throw new Error(`edit by ${agent} was out of step`);","atom":"a0","author":"init","version":0},{"n":16,"text":"}","atom":"a0","author":"init","version":0},{"n":17,"text":"","atom":"a0","author":"init","version":0},{"n":18,"text":"function setup() {","atom":"a0","author":"init","version":0},{"n":19,"text":"\tconst store = new MemoryStore();","atom":"a0","author":"init","version":0},{"n":20,"text":"\tlet now = 0;","atom":"a0","author":"init","version":0},{"n":21,"text":"\tconst project = new Project(store, { now: () => now });","atom":"a0","author":"init","version":0},{"n":22,"text":"\tproject.init(","atom":"a0","author":"init","version":0},{"n":23,"text":"\t\t{ \"a.ts\": \"export const a = 1;\\n\", \"b.ts\": \"export const b = 1;\\n\", \"c.ts\": \"export const c = 1;\\n\" },","atom":"a0","author":"init","version":0},{"n":24,"text":"\t\t0,","atom":"a0","author":"init","version":0},{"n":25,"text":"\t);","atom":"a0","author":"init","version":0},{"n":26,"text":"\tfor (const a of [\"ann\", \"bob\"]) project.sync(a);","atom":"a0","author":"init","version":0},{"n":27,"text":"\treturn { project, store, at: (t: number) => (now = t) };","atom":"a0","author":"init","version":0},{"n":28,"text":"}","atom":"a0","author":"init","version":0},{"n":29,"text":"","atom":"a0","author":"init","version":0},{"n":30,"text":"const publishOf = (store: MemoryStore, version: number) =>","atom":"a0","author":"init","version":0},{"n":31,"text":"\tstore.entries.find(","atom":"a0","author":"init","version":0},{"n":32,"text":"\t\t(e): e is Extract<Entry, { type: \"publish\" }> => e.type === \"publish\" && e.version === version && !e.space,","atom":"a0","author":"init","version":0},{"n":33,"text":"\t)!;","atom":"a0","author":"init","version":0},{"n":34,"text":"","atom":"a0","author":"init","version":0},{"n":35,"text":"test(\"a start note's pushes are one change, with its versions, files and title\", () => {","atom":"a884","author":"rename","version":100},{"n":36,"text":"\tconst { project, store, at } = setup();","atom":"a0","author":"init","version":0},{"n":37,"text":"\tat(1);","atom":"a0","author":"init","version":0},{"n":38,"text":"\tproject.starting(\"ann\", \"Bigger numbers\", [\"a.ts\", \"b.ts\"], 1);","atom":"a0","author":"init","version":0},{"n":39,"text":"\tconst noteAt = store.entries.findIndex((e) => e.type === \"starting\");","atom":"a0","author":"init","version":0},{"n":40,"text":"\tedit(project, \"ann\", { file: \"a.ts\", old: \"1\", new: \"2\" }, 2);","atom":"a0","author":"init","version":0},{"n":41,"text":"\tproject.publish(\"ann\", \"a is 2\", 3);","atom":"a0","author":"init","version":0},{"n":42,"text":"\tedit(project, \"bob\", { file: \"c.ts\", old: \"1\", new: \"5\" }, 4);","atom":"a0","author":"init","version":0},{"n":43,"text":"\tproject.publish(\"bob\", \"c is 5\", 5);","atom":"a0","author":"init","version":0},{"n":44,"text":"\tproject.sync(\"ann\");","atom":"a0","author":"init","version":0},{"n":45,"text":"\tedit(project, \"ann\", { file: \"b.ts\", old: \"1\", new: \"2\" }, 6);","atom":"a0","author":"init","version":0},{"n":46,"text":"\tproject.publish(\"ann\", \"b is 2\", 7);","atom":"a0","author":"init","version":0},{"n":47,"text":"\tat(8);","atom":"a0","author":"init","version":0},{"n":48,"text":"\tassert.equal(publishOf(store, 1).change, noteAt);","atom":"a0","author":"init","version":0},{"n":49,"text":"\tassert.equal(publishOf(store, 3).change, noteAt);","atom":"a0","author":"init","version":0},{"n":50,"text":"\tconst c = project.change(noteAt);","atom":"a0","author":"init","version":0},{"n":51,"text":"\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":52,"text":"\t\t[c.kind, c.agent, c.title, c.open, c.note],","atom":"a0","author":"init","version":0},{"n":53,"text":"\t\t[\"note\", \"ann\", \"Bigger numbers\", true, { text: \"Bigger numbers\", files: [\"a.ts\", \"b.ts\"] }],","atom":"a0","author":"init","version":0},{"n":54,"text":"\t);","atom":"a0","author":"init","version":0},{"n":55,"text":"\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":56,"text":"\t\tc.versions.map((v) => [v.version, v.message, v.files]),","atom":"a0","author":"init","version":0},{"n":57,"text":"\t\t[","atom":"a0","author":"init","version":0},{"n":58,"text":"\t\t\t[1, \"a is 2\", [\"a.ts\"]],","atom":"a0","author":"init","version":0},{"n":59,"text":"\t\t\t[3, \"b is 2\", [\"b.ts\"]],","atom":"a0","author":"init","version":0},{"n":60,"text":"\t\t],","atom":"a0","author":"init","version":0},{"n":61,"text":"\t);","atom":"a0","author":"init","version":0},{"n":62,"text":"\tassert.deepEqual(c.files, [\"a.ts\", \"b.ts\"]);","atom":"a0","author":"init","version":0},{"n":63,"text":"\t// bob's publish, with no start note, is a change of its own, named by its publish's log position.","atom":"a0","author":"init","version":0},{"n":64,"text":"\tconst bobs = publishOf(store, 2).change!;","atom":"a0","author":"init","version":0},{"n":65,"text":"\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":66,"text":"\t\t[project.change(bobs).kind, project.change(bobs).title, project.change(bobs).open],","atom":"a0","author":"init","version":0},{"n":67,"text":"\t\t[\"publish\", \"c is 5\", false],","atom":"a0","author":"init","version":0},{"n":68,"text":"\t);","atom":"a0","author":"init","version":0},{"n":69,"text":"\tassert.throws(() => project.change(9999), /there is no change 9999/);","atom":"a0","author":"init","version":0},{"n":70,"text":"});","atom":"a0","author":"init","version":0},{"n":71,"text":"","atom":"a0","author":"init","version":0},{"n":72,"text":"test(\"a start note ends at the next start, a take-back, or 2 hours idle, and so does its change\", () => {","atom":"a0","author":"init","version":0},{"n":73,"text":"\tconst { project, store, at } = setup();","atom":"a0","author":"init","version":0},{"n":74,"text":"\tproject.starting(\"ann\", \"One\", undefined, 1);","atom":"a0","author":"init","version":0},{"n":75,"text":"\tedit(project, \"ann\", { file: \"a.ts\", old: \"1\", new: \"2\" }, 2);","atom":"a0","author":"init","version":0},{"n":76,"text":"\tproject.publish(\"ann\", \"first\", 3);","atom":"a0","author":"init","version":0},{"n":77,"text":"\tconst one = publishOf(store, 1).change!;","atom":"a0","author":"init","version":0},{"n":78,"text":"\tproject.starting(\"ann\", \"Two\", undefined, 4);","atom":"a0","author":"init","version":0},{"n":79,"text":"\tedit(project, \"ann\", { file: \"a.ts\", old: \"2\", new: \"3\" }, 5);","atom":"a0","author":"init","version":0},{"n":80,"text":"\tproject.publish(\"ann\", \"second\", 6);","atom":"a0","author":"init","version":0},{"n":81,"text":"\tconst two = publishOf(store, 2).change!;","atom":"a0","author":"init","version":0},{"n":82,"text":"\tassert.notEqual(one, two);","atom":"a0","author":"init","version":0},{"n":83,"text":"\tat(6);","atom":"a0","author":"init","version":0},{"n":84,"text":"\tassert.equal(project.change(one).open, false);","atom":"a0","author":"init","version":0},{"n":85,"text":"\tassert.equal(project.change(two).open, true);","atom":"a0","author":"init","version":0},{"n":86,"text":"\t// Taken back (what publish --done sends).","atom":"a0","author":"init","version":0},{"n":87,"text":"\tproject.starting(\"ann\", null, undefined, 7);","atom":"a0","author":"init","version":0},{"n":88,"text":"\tassert.equal(project.change(two).open, false);","atom":"a0","author":"init","version":0},{"n":89,"text":"\t// Idle: a note, then nothing for over 2 hours, then a publish is a change of its own.","atom":"a0","author":"init","version":0},{"n":90,"text":"\tproject.starting(\"ann\", \"Three\", undefined, 10);","atom":"a0","author":"init","version":0},{"n":91,"text":"\tat(10 + 2 * HOUR + 1);","atom":"a0","author":"init","version":0},{"n":92,"text":"\tassert.equal(project.startingNotes().length, 0, \"the note has ended\");","atom":"a0","author":"init","version":0},{"n":93,"text":"\tedit(project, \"ann\", { file: \"a.ts\", old: \"3\", new: \"4\" }, 10 + 2 * HOUR + 1);","atom":"a0","author":"init","version":0},{"n":94,"text":"\tproject.publish(\"ann\", \"after a break\", 10 + 2 * HOUR + 2);","atom":"a0","author":"init","version":0},{"n":95,"text":"\tconst after = publishOf(store, 3);","atom":"a0","author":"init","version":0},{"n":96,"text":"\tassert.equal(project.change(after.change!).kind, \"publish\");","atom":"a0","author":"init","version":0},{"n":97,"text":"});","atom":"a0","author":"init","version":0},{"n":98,"text":"","atom":"a0","author":"init","version":0},{"n":99,"text":"test(\"a named draft's work is one change, its land included\", () => {","atom":"a0","author":"init","version":0},{"n":100,"text":"\tconst { project, store } = setup();","atom":"a0","author":"init","version":0},{"n":101,"text":"\tproject.switchTo(\"ann\", \"feature\", 1);","atom":"a0","author":"init","version":0},{"n":102,"text":"\tconst startedAt = store.entries.findIndex((e) => e.type === \"space\");","atom":"a0","author":"init","version":0},{"n":103,"text":"\tedit(project, \"ann\", { file: \"a.ts\", old: \"1\", new: \"2\" }, 2);","atom":"a0","author":"init","version":0},{"n":104,"text":"\tproject.publish(\"ann\", \"in the draft\", 3);","atom":"a0","author":"init","version":0},{"n":105,"text":"\tproject.land(\"ann\", \"Land feature\", 4);","atom":"a0","author":"init","version":0},{"n":106,"text":"\tconst c = project.change(startedAt);","atom":"a0","author":"init","version":0},{"n":107,"text":"\tassert.deepEqual([c.kind, c.draft, c.title], [\"draft\", \"feature\", \"Draft feature\"]);","atom":"a0","author":"init","version":0},{"n":108,"text":"\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":109,"text":"\t\tc.versions.map((v) => [v.draft, v.message]),","atom":"a0","author":"init","version":0},{"n":110,"text":"\t\t[","atom":"a0","author":"init","version":0},{"n":111,"text":"\t\t\t[\"feature\", \"in the draft\"],","atom":"a0","author":"init","version":0},{"n":112,"text":"\t\t\t[null, \"Land feature\"],","atom":"a0","author":"init","version":0},{"n":113,"text":"\t\t],","atom":"a0","author":"init","version":0},{"n":114,"text":"\t);","atom":"a0","author":"init","version":0},{"n":115,"text":"});","atom":"a0","author":"init","version":0},{"n":116,"text":"","atom":"a0","author":"init","version":0},{"n":117,"text":"test(\"since you last looked: the changes with anything new after a log position, newest first\", () => {","atom":"a0","author":"init","version":0},{"n":118,"text":"\tconst { project, store } = setup();","atom":"a0","author":"init","version":0},{"n":119,"text":"\tedit(project, \"ann\", { file: \"a.ts\", old: \"1\", new: \"2\" }, 1);","atom":"a0","author":"init","version":0},{"n":120,"text":"\tproject.publish(\"ann\", \"a is 2\", 2);","atom":"a0","author":"init","version":0},{"n":121,"text":"\tconst mark = store.entries.length;","atom":"a0","author":"init","version":0},{"n":122,"text":"\tedit(project, \"bob\", { file: \"b.ts\", old: \"1\", new: \"2\" }, 3);","atom":"a0","author":"init","version":0},{"n":123,"text":"\tproject.publish(\"bob\", \"b is 2\", 4);","atom":"a0","author":"init","version":0},{"n":124,"text":"\t// A refusal lands on the refused agent's change only when it has one: a start note here.","atom":"a0","author":"init","version":0},{"n":125,"text":"\tproject.starting(\"ann\", \"Clash\", undefined, 5);","atom":"a0","author":"init","version":0},{"n":126,"text":"\tedit(project, \"ann\", { file: \"b.ts\", old: \"export const b = 1;\", new: \"export const b = 9;\" }, 6);","atom":"a0","author":"init","version":0},{"n":127,"text":"\tassert.equal(project.publish(\"ann\", \"b is 9\", 7).ok, false);","atom":"a0","author":"init","version":0},{"n":128,"text":"\tconst since = project.changes(mark);","atom":"a0","author":"init","version":0},{"n":129,"text":"\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":130,"text":"\t\tsince.changes.map((c) => [c.agent, c.title]),","atom":"a0","author":"init","version":0},{"n":131,"text":"\t\t[","atom":"a0","author":"init","version":0},{"n":132,"text":"\t\t\t[\"ann\", \"Clash\"],","atom":"a0","author":"init","version":0},{"n":133,"text":"\t\t\t[\"bob\", \"b is 2\"],","atom":"a0","author":"init","version":0},{"n":134,"text":"\t\t],","atom":"a0","author":"init","version":0},{"n":135,"text":"\t);","atom":"a0","author":"init","version":0},{"n":136,"text":"\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":137,"text":"\t\tsince.changes[0]!.refusals.map((r) => [r.kinds, r.files]),","atom":"a0","author":"init","version":0},{"n":138,"text":"\t\t[[[\"lines\"], [\"b.ts\"]]],","atom":"a0","author":"init","version":0},{"n":139,"text":"\t);","atom":"a0","author":"init","version":0},{"n":140,"text":"\tassert.equal(since.next, store.entries.length);","atom":"a0","author":"init","version":0},{"n":141,"text":"\tassert.equal(project.changes(0).changes.length, 3);","atom":"a0","author":"init","version":0},{"n":142,"text":"});","atom":"a0","author":"init","version":0},{"n":143,"text":"","atom":"a0","author":"init","version":0},{"n":144,"text":"test(\"changes come back the same from the log, and old pushes without a change still group and end the note\", () => {","atom":"a884","author":"rename","version":100},{"n":145,"text":"\tconst { project, store } = setup();","atom":"a0","author":"init","version":0},{"n":146,"text":"\tproject.starting(\"ann\", \"Note\", undefined, 1);","atom":"a0","author":"init","version":0},{"n":147,"text":"\tedit(project, \"ann\", { file: \"a.ts\", old: \"1\", new: \"2\" }, 2);","atom":"a0","author":"init","version":0},{"n":148,"text":"\tproject.publish(\"ann\", \"one\", 3);","atom":"a0","author":"init","version":0},{"n":149,"text":"\tconst again = Project.load(store.entries, new MemoryStore(), { now: () => 3 });","atom":"a0","author":"init","version":0},{"n":150,"text":"\tassert.deepEqual(again.changes(0), project.changes(0));","atom":"a0","author":"init","version":0},{"n":151,"text":"\t// The same log as written before changes: no `change` on the publish.","atom":"a0","author":"init","version":0},{"n":152,"text":"\tconst old = store.entries.map((e) => (e.type === \"publish\" ? (({ change: _, ...rest }) => rest)(e) : e)) as Entry[];","atom":"a0","author":"init","version":0},{"n":153,"text":"\tconst replayed = Project.load(old, new MemoryStore(), { now: () => 3 });","atom":"a0","author":"init","version":0},{"n":154,"text":"\tassert.equal(replayed.startingNotes().length, 0, \"an old push ended the note\");","atom":"a884","author":"rename","version":100},{"n":155,"text":"\tconst noteAt = store.entries.findIndex((e) => e.type === \"starting\");","atom":"a0","author":"init","version":0},{"n":156,"text":"\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":157,"text":"\t\treplayed.change(noteAt).versions.map((v) => v.message),","atom":"a0","author":"init","version":0},{"n":158,"text":"\t\t[\"one\"],","atom":"a0","author":"init","version":0},{"n":159,"text":"\t);","atom":"a0","author":"init","version":0},{"n":160,"text":"});","atom":"a0","author":"init","version":0},{"n":161,"text":"","atom":"a0","author":"init","version":0},{"n":162,"text":"test(\"log and show name each version's change\", () => {","atom":"a0","author":"init","version":0},{"n":163,"text":"\tconst { project, store } = setup();","atom":"a0","author":"init","version":0},{"n":164,"text":"\tproject.starting(\"ann\", \"Note\", undefined, 1);","atom":"a0","author":"init","version":0},{"n":165,"text":"\tconst noteAt = store.entries.findIndex((e) => e.type === \"starting\");","atom":"a0","author":"init","version":0},{"n":166,"text":"\tedit(project, \"ann\", { file: \"a.ts\", old: \"1\", new: \"2\" }, 2);","atom":"a0","author":"init","version":0},{"n":167,"text":"\tproject.publish(\"ann\", \"one\", 3);","atom":"a0","author":"init","version":0},{"n":168,"text":"\tassert.equal(project.log().versions[0]!.change, noteAt);","atom":"a0","author":"init","version":0},{"n":169,"text":"\tassert.equal(project.show(1).change, noteAt);","atom":"a0","author":"init","version":0},{"n":170,"text":"\tassert.equal(project.log().versions.at(-1)!.change, undefined, \"init belongs to no change\");","atom":"a0","author":"init","version":0},{"n":171,"text":"});","atom":"a0","author":"init","version":0},{"n":172,"text":"","atom":"a0","author":"init","version":0},{"n":173,"text":"test(\"changes pages back with before, and says where the next older page starts\", () => {","atom":"a0","author":"init","version":0},{"n":174,"text":"\tconst { project } = setup();","atom":"a0","author":"init","version":0},{"n":175,"text":"\tfor (let i = 2; i <= 6; i++) {","atom":"a0","author":"init","version":0},{"n":176,"text":"\t\tedit(project, \"ann\", { file: \"a.ts\", old: `a = ${i - 1}`, new: `a = ${i}` }, i);","atom":"a0","author":"init","version":0},{"n":177,"text":"\t\tproject.publish(\"ann\", `a is ${i}`, i);","atom":"a0","author":"init","version":0},{"n":178,"text":"\t}","atom":"a0","author":"init","version":0},{"n":179,"text":"\tconst first = project.changes(0, 2);","atom":"a0","author":"init","version":0},{"n":180,"text":"\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":181,"text":"\t\tfirst.changes.map((c) => c.title),","atom":"a0","author":"init","version":0},{"n":182,"text":"\t\t[\"a is 6\", \"a is 5\"],","atom":"a0","author":"init","version":0},{"n":183,"text":"\t);","atom":"a0","author":"init","version":0},{"n":184,"text":"\tconst second = project.changes(0, 2, first.older);","atom":"a0","author":"init","version":0},{"n":185,"text":"\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":186,"text":"\t\tsecond.changes.map((c) => c.title),","atom":"a0","author":"init","version":0},{"n":187,"text":"\t\t[\"a is 4\", \"a is 3\"],","atom":"a0","author":"init","version":0},{"n":188,"text":"\t);","atom":"a0","author":"init","version":0},{"n":189,"text":"\tconst last = project.changes(0, 2, second.older);","atom":"a0","author":"init","version":0},{"n":190,"text":"\tassert.deepEqual([last.changes.map((c) => c.title), last.older], [[\"a is 2\"], undefined]);","atom":"a0","author":"init","version":0},{"n":191,"text":"});","atom":"a0","author":"init","version":0}],"atoms":[{"atom":"a0","author":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z","publish":{"draft":null,"version":0,"agent":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z"}},{"atom":"a884","author":"rename","message":"","time":1791659799126,"timeIso":"2026-10-10T19:16:39.126Z","publish":{"draft":null,"version":100,"agent":"rename","message":"abso publish is now abso push, abso sync is now abso pull (abso 427)\n\nCommands, 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.\n\npush -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.\n\nKept as stored: log entry kinds (publish, sync, pulled), HTTP route paths, the pipeline trigger on: publish, the yours (unpublished) marker, npm-publish.","time":1791659833853,"timeIso":"2026-10-10T19:17:13.853Z"}}]}