import { test } from "node:test"; import assert from "node:assert/strict"; import { citationOriginFor, projectsRootOf, resolveCorpus } from "./reportDraft"; import { defaultProjectsRoot } from "../lib/projectsRoot.mjs"; import { defaults } from "../lib/settingsSchema"; import { PROJECT_URL } from "../lib/project"; // demo epic D1 item 3: a sweep over a published archive cites that archive. const gen = (over: Record = {}) => ({ ...defaults().generation, ...over }); const paths = { exportBuildsDir: "/nonexistent/builds", sitesDir: "/nonexistent/sites" }; test("a remote source's citations are on its own origin; citationOrigin overrides only when set", () => { assert.equal(citationOriginFor("remote:https://stub.test/", gen()), "https://stub.test"); assert.equal(citationOriginFor("remote:https://stub.test", gen({ citationOrigin: "https://mirror.test" })), "https://mirror.test"); // A hub's members each have their own origin; a local dir has none: as before. assert.equal(citationOriginFor("hub:https://hub.test", gen()), PROJECT_URL); assert.equal(citationOriginFor("local:/x", gen()), PROJECT_URL); }); test("the corpus: the body's source, else the lineage's, before any local build", async () => { assert.deepEqual(await resolveCorpus({ source: "remote:https://stub.test" }, ["alpha"], paths, gen()), { source: "remote:https://stub.test", origin: "https://stub.test" }); // A revision with no source of its own reads (and cites) what its sweep read. assert.deepEqual(await resolveCorpus({}, ["alpha"], paths, gen(), "remote:https://stub.test"), { source: "remote:https://stub.test", origin: "https://stub.test" }); // A named build wins over the inherited source; with none on disk it is refused as before. await assert.rejects(resolveCorpus({ build: "mine" }, ["alpha"], paths, gen(), "remote:https://stub.test")); await assert.rejects(resolveCorpus({}, ["alpha"], paths, gen(), null)); }); test("projectsRoot blank: /articles when set (a container's volume), else ~/reports/articles", () => { assert.equal(defaultProjectsRoot({ REPORTS_DIR: "/data/reports" }), "/data/reports/articles"); assert.match(defaultProjectsRoot({}), /\/reports\/articles$/); const saved = process.env.REPORTS_DIR; process.env.REPORTS_DIR = "/data/reports"; try { assert.equal(projectsRootOf(gen()), "/data/reports/articles"); assert.equal(projectsRootOf(gen({ projectsRoot: "/elsewhere" })), "/elsewhere"); } finally { if (saved === undefined) delete process.env.REPORTS_DIR; else process.env.REPORTS_DIR = saved; } });