Files
stack/packages/queue/tests/migration.test.mjs
T
jason.woltjeandClaude Opus 5.5 6ca116b7ba feat(queue): queue as data A2, migration, render and dispatch (#1508)
Filbert approved round 1 (f167b85e). Manifest 782bcb62, 21 files, plus
the QUEUE.md markers and the TOOLS.md section. Lead decision 35.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-26 20:14:09 -05:00

78 lines
4.5 KiB
JavaScript

// The real migration (A2): the reviewed map renders the golden genesis
// table, and the marked QUEUE.md keeps every row between its markers for
// genesis's legacyView. map-check.mjs, the pre-genesis drift check, is
// tested on the frozen fixture here; no test reads the live QUEUE.md.
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { test } from "node:test";
import { genesisRows, parseMigrationMap, render, splitView, validateRows } from "../src/queue.mjs";
import { check, tableLines } from "../../../agents/darkwing/work/queue-a2/map-check.mjs";
const HERE = new URL(".", import.meta.url).pathname;
const MAP = readFileSync(`${HERE}../../../agents/darkwing/work/queue-migration-map.md`, "utf8");
const MARKED = readFileSync(`${HERE}fixtures/queue-marked.md`, "utf8");
const GOLDEN = readFileSync(`${HERE}fixtures/genesis-render.md`, "utf8");
test("the migration map validates and renders the golden genesis table", () => {
const map = parseMigrationMap(MAP);
assert.deepEqual(map.rows.map((r) => r.id), Array.from({ length: 30 }, (_, i) => i + 1));
assert.equal(map.highWater, 30);
assert.deepEqual(map.retired, []);
const blobs = new Map(map.rows.filter((r) => r.brief).map((r) => [r.id, "a".repeat(40)]));
const rows = genesisRows(map, blobs, "genesis-2026-09-27", "2026-09-27T00:00:00.000Z", "sage");
validateRows(rows);
assert.equal(render(rows, 0), GOLDEN);
assert.deepEqual(rows.filter((r) => r.claim).map((r) => [r.id, r.claim.seat]), [[5, "dewey"], [7, "sage"], [9, "darkwing"], [11, "darkwing"], [16, "darkwing"]]);
assert.deepEqual(rows.filter((r) => r.state === "parked").map((r) => r.id), [8, 26, 27, 28, 29, 30]);
assert.deepEqual(rows.filter((r) => r.required).map((r) => r.id), [9, 10, 11, 12, 13]);
});
test("the marked QUEUE.md holds every row and parked item between its markers", () => {
const parts = splitView(MARKED);
assert.notEqual(parts, null);
const inside = tableLines(parts.body);
assert.deepEqual([...inside.keys()], Array.from({ length: 30 }, (_, i) => i + 1));
assert.deepEqual(tableLines(MARKED), inside);
assert.equal(tableLines(parts.head).size, 0);
assert.match(parts.head, /^## Pieces \(in order\)\n\n<!-- mosaic-queue:begin -->\n$/m);
assert.match(parts.tail, /^<!-- mosaic-queue:end -->\n\n## Log of table changes\n/);
assert.deepEqual(check(MARKED, MAP, MARKED), []);
});
test("map-check reports each kind of drift", () => {
const line = (id) => tableLines(MARKED).get(id);
const edit = (id, to) => MARKED.replace(line(id), to);
const cellsOf = (id) => line(id).slice(2, -2).split(" | ");
const row = (c) => `| ${c.join(" | ")} |`;
const c9 = cellsOf(9);
const piece = edit(9, row([c9[0], "Queue as data, renamed", ...c9.slice(2)]));
assert.deepEqual(check(piece, MAP, MARKED), ["row 9: changed since the map's QUEUE.md blob", "row 9: piece differs from the map"]);
const c10 = cellsOf(10);
const owner = edit(10, row([c10[0], c10[1], "sage", ...c10.slice(3)]));
assert.deepEqual(check(owner, MAP, MARKED), ["row 10: changed since the map's QUEUE.md blob", "row 10: owner sage in QUEUE.md, coordinator in the map"]);
const c16 = cellsOf(16);
const issue = edit(16, row([...c16.slice(0, 3), "#1510, #1520", ...c16.slice(4)]));
assert.deepEqual(check(issue, MAP, MARKED), ["row 16: changed since the map's QUEUE.md blob", "row 16: issues 1510,1520 in QUEUE.md, 1510 in the map"]);
const state = edit(5, line(5).replace("Gate E blocked", "Gate E rescoped"));
assert.deepEqual(check(state, MAP, MARKED), ["row 5: changed since the map's QUEUE.md blob"]);
const parked = edit(27, line(27).replace("Auth/provider/harness registry review", "Registry review"));
assert.deepEqual(check(parked, MAP, MARKED), ["row 27: changed since the map's QUEUE.md blob", 'row 27: parked item "Registry review" is not the map\'s piece']);
const gone = MARKED.replace(`${line(12)}\n`, "");
assert.deepEqual(check(gone, MAP, MARKED), ["row 12: removed since the map's QUEUE.md blob", "row 12: in the map, not in QUEUE.md"]);
// A new row 26 moves the parked items to 27..31, so the map's ids no
// longer line up and every shifted row reports.
const added = MARKED.replace(`${line(25)}\n`, `${line(25)}\n| 26 | New piece | darkwing | — | queued | g | b |\n`);
const found = check(added, MAP, MARKED);
assert.ok(found.includes("row 26: changed since the map's QUEUE.md blob"));
assert.ok(found.includes("row 26: piece differs from the map"));
assert.ok(found.includes("row 31: in QUEUE.md, not in the map"));
assert.equal(found.filter((d) => / parked item /.test(d)).length, 4);
});