// A ledger file beside the manifest (quartering-diet's ledger.draft.json, 30 Aug: 186 rows) is not the ledger the // build reads -- that is video.manifest.json's `ledger` (564 rows, 12 Nov) -- and nothing said so. `umtool lint` now // says which is live and that the other is stale, naming the file and the newer date. The file is never touched. import assert from "node:assert/strict"; import { mkdir, mkdtemp, readFile, rm, utimes, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; import { ledgerFileWarnings, lintCommand } from "./lintCli.mjs"; const row = (id) => ({ id, date: "2026-01-01", scope: "weight", population: "self", value: 300 }); async function project() { const root = await mkdtemp(path.join(tmpdir(), "umtool-ledger-files-")); const dir = path.join(root, "diet"); await mkdir(dir, { recursive: true }); const manifest = { schemaVersion: 1, slug: "diet", title: "T", render: { width: 640, height: 360, fps: 15 }, ledger: [row("d1"), row("d2"), row("d3")], timeline: [{ type: "clip", id: "c1", channel: "ch", video: "v", start: 0, end: 5 }] }; await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(manifest)); await writeFile(path.join(dir, "ledger.draft.json"), JSON.stringify([row("d1")])); // The draft from 30 Aug, the manifest from 12 Nov. await utimes(path.join(dir, "ledger.draft.json"), new Date("2026-08-30T13:18:00Z"), new Date("2026-08-30T13:18:00Z")); await utimes(path.join(dir, "video.manifest.json"), new Date("2026-11-12T16:51:00Z"), new Date("2026-11-12T16:51:00Z")); return { root, dir, manifest }; } test("a ledger file beside the manifest: lint says the manifest's ledger is live and the file stale, with both dates", async () => { const p = await project(); try { const before = await readFile(path.join(p.dir, "ledger.draft.json"), "utf8"); const w = await ledgerFileWarnings(p.dir, p.manifest); assert.equal(w.length, 1); assert.match(w[0], /ledger\.draft\.json/); assert.match(w[0], /live ledger is video\.manifest\.json's `ledger` \(3 rows, 2026-11-12\)/); assert.match(w[0], /ledger\.draft\.json \(1 row, 2026-08-30\) is stale/); // Through `umtool lint`: a warning, not an error -- the exit is the lint's own. const out = []; const code = await lintCommand(["diet"], { reportsRoot: p.root, log: (l) => out.push(l), err: (l) => out.push(l) }); assert.match(out.join("\n"), /ledger\.draft\.json \(1 row, 2026-08-30\) is stale/); assert.notEqual(code, 2); assert.equal(await readFile(path.join(p.dir, "ledger.draft.json"), "utf8"), before, "the operator's file is never touched"); // Written after the manifest but holding nothing the live ledger lacks: not "NEWER" (review 1, S8). await utimes(path.join(p.dir, "ledger.draft.json"), new Date("2026-11-13T15:00:00Z"), new Date("2026-11-13T15:00:00Z")); const later = await ledgerFileWarnings(p.dir, p.manifest); assert.doesNotMatch(later[0], /NEWER/); assert.match(later[0], /ledger\.draft\.json \(1 row, 2026-11-13\) is stale/); // Newer AND rows the manifest lacks: said so, naming them. await writeFile(path.join(p.dir, "ledger.draft.json"), JSON.stringify([row("d1"), row("d9")])); const newer = await ledgerFileWarnings(p.dir, p.manifest); assert.match(newer[0], /ledger\.draft\.json \(2 rows, \d{4}-\d\d-\d\d\) is NEWER than the manifest and holds 1 row the live ledger lacks \(d9\)/); // Not a ledger: a schema, an empty list, rows without ids, not JSON -- nothing said. await writeFile(path.join(p.dir, "ledgerSchema.json"), JSON.stringify({ kind: "measure", fields: [] })); await writeFile(path.join(p.dir, "ledger.empty.json"), "[]"); await writeFile(path.join(p.dir, "ledger.noids.json"), JSON.stringify([{ date: "2026-01-01" }])); await writeFile(path.join(p.dir, "ledger.bad.json"), "{not json"); await writeFile(path.join(p.dir, "ledger.rows.json"), JSON.stringify({ rows: [row("d1")] })); const names = (await ledgerFileWarnings(p.dir, p.manifest)).map((w) => w.split(" ")[0]); assert.deepEqual(names, ["ledger.draft.json", "ledger.rows.json"]); // Under --take the live count is the take's. const takeW = await ledgerFileWarnings(p.dir, { ...p.manifest, ledger: [row("d1"), row("d2")] }, { take: "t1" }); assert.match(takeW[0], /the live ledger is take t1's \(video\.manifest\.json's with its patch; 2 rows/); for (const f of ["ledgerSchema.json", "ledger.empty.json", "ledger.noids.json", "ledger.bad.json", "ledger.rows.json"]) await rm(path.join(p.dir, f)); // No ledger in the manifest, or no such file: nothing said. assert.deepEqual(await ledgerFileWarnings(p.dir, { ...p.manifest, ledger: undefined }), []); await rm(path.join(p.dir, "ledger.draft.json")); assert.deepEqual(await ledgerFileWarnings(p.dir, p.manifest), []); } finally { await rm(p.root, { recursive: true, force: true }); } });