Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| The artifacts service is services/artifacts, the Worker g1t-artifacts, bound as ARTIFACTS by the API, the site and the agents; its live rooms move to it with a Durable Object transfer from g1t-docs-service, and its database, bucket, indexes and queue keep their names. The git store's binding and settings are GITSTORE, its ops scripts gitstore-*, and workflow run artifacts keep their compatible API under run_artifacts modules. The deploy tool puts a Worker that has never deployed before the Workers in its stage that bind to it, and the deploy guide gives the cutover runbook. | 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; | |
| 3 | ||
| 4 | import { STEP, ancestors, childrenOf, descendants, exportPaths, fileName, lastPosition, placeBefore, wouldCycle } from "./tree.ts"; | |
| 5 | ||
| 6 | const rows = [ | |
| 7 | { id: "a", parent_id: null, position: 1024, title: "Alpha" }, | |
| 8 | { id: "b", parent_id: null, position: 2048, title: "Beta" }, | |
| 9 | { id: "c", parent_id: "a", position: 1024, title: "Child" }, | |
| 10 | { id: "d", parent_id: "c", position: 1024, title: "Deep" }, | |
| 11 | ]; | |
| 12 | ||
| 13 | test("children come in position order", () => { | |
| 14 | assert.deepEqual( | |
| 15 | childrenOf(rows, null).map((r) => r.id), | |
| 16 | ["a", "b"], | |
| 17 | ); | |
| 18 | assert.equal(lastPosition(rows, null), 2048 + STEP); | |
| 19 | assert.equal(lastPosition(rows, "b"), STEP); | |
| 20 | }); | |
| 21 | ||
| 22 | test("placing before a sibling takes the midpoint", () => { | |
| 23 | const placed = placeBefore(rows, "x", null, "b"); | |
| 24 | assert.equal(placed.position, 1536); | |
| 25 | assert.equal(placed.renumber.size, 0); | |
| 26 | assert.ok(placeBefore(rows, "x", null, "a").position < 1024); | |
| 27 | assert.equal(placeBefore(rows, "x", null, null).position, 2048 + STEP); | |
| 28 | }); | |
| 29 | ||
| 30 | test("moving a page among its own siblings ignores where it was", () => { | |
| 31 | // b before a: b is not its own neighbour. | |
| 32 | const placed = placeBefore(rows, "b", null, "a"); | |
| 33 | assert.ok(placed.position < 1024); | |
| 34 | }); | |
| 35 | ||
| 36 | test("siblings too close together are renumbered", () => { | |
| 37 | const tight = [ | |
| 38 | { id: "p", parent_id: null, position: 1 }, | |
| 39 | { id: "q", parent_id: null, position: 1 + 1e-7 }, | |
| 40 | ]; | |
| 41 | const placed = placeBefore(tight, "x", null, "q"); | |
| 42 | assert.equal(placed.renumber.size, 2); | |
| 43 | assert.ok(placed.position > placed.renumber.get("p")! && placed.position < placed.renumber.get("q")!); | |
| 44 | }); | |
| 45 | ||
| 46 | test("a page can't move under itself or its own descendants", () => { | |
| 47 | assert.equal(wouldCycle(rows, "a", "d"), true); | |
| 48 | assert.equal(wouldCycle(rows, "a", "a"), true); | |
| 49 | assert.equal(wouldCycle(rows, "d", "b"), false); | |
| 50 | assert.equal(wouldCycle(rows, "c", null), false); | |
| 51 | }); | |
| 52 | ||
| 53 | test("descendants and ancestors", () => { | |
| 54 | assert.deepEqual(descendants(rows, "a").sort(), ["a", "c", "d"]); | |
| 55 | assert.deepEqual( | |
| 56 | ancestors(rows, "d").map((r) => r.id), | |
| 57 | ["a", "c"], | |
| 58 | ); | |
| 59 | assert.deepEqual(ancestors(rows, "a"), []); | |
| 60 | }); | |
| 61 | ||
| 62 | test("export paths follow the tree and stay unique", () => { | |
| 63 | const paths = exportPaths([...rows, { id: "e", parent_id: null, position: 4000, title: "alpha" }, { id: "f", parent_id: null, position: 5000, title: "a/b: c?" }]); | |
| 64 | assert.equal(paths.get("a"), "Alpha.md"); | |
| 65 | assert.equal(paths.get("c"), "Alpha/Child.md"); | |
| 66 | assert.equal(paths.get("d"), "Alpha/Child/Deep.md"); | |
| 67 | assert.equal(paths.get("e"), "alpha (2).md"); | |
| 68 | assert.equal(paths.get("f"), "a b c.md"); | |
| 69 | assert.equal(fileName("..."), "Untitled"); | |
| 70 | }); |