import assert from "node:assert/strict"; import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import test from "node:test"; import { contentPackForPath, createContentManifest, publishContent, scanContentSources, } from "./publish-content.mjs"; test("assigns stable player-facing packs from logical asset paths", () => { assert.equal(contentPackForPath("assets/game/dungeons/wailing-caverns/visual.glb"), "dungeon:wailing-caverns"); assert.equal(contentPackForPath("assets/creatures/wailing-caverns/mutanus.glb"), "dungeon:wailing-caverns"); assert.equal(contentPackForPath("assets/characters/wow335a-v1/manifest.json"), "characters:wow335a-v1"); assert.equal(contentPackForPath("assets/game/manastorm/stage-1/visual.glb"), "manastorm:stage-1"); }); test("publishes objects before a deterministic latest manifest", async () => { const directory = await mkdtemp(path.join(os.tmpdir(), "healer-man-content-test-")); const sourceDirectory = path.join(directory, "source"); const contentDirectory = path.join(directory, "content"); await mkdir(path.join(sourceDirectory, "wailing-caverns"), { recursive: true }); await writeFile(path.join(sourceDirectory, "wailing-caverns", "visual.glb"), Buffer.from("glb-one")); const sources = [{ directory: sourceDirectory, logicalPrefix: "assets/game/dungeons" }]; try { const scanned = await scanContentSources(sources); const firstManifest = createContentManifest(scanned, { createdAt: "2026-08-14T00:00:00.000Z" }); assert.equal(Object.keys(firstManifest.files).length, 1); assert.equal(firstManifest.packs[0].id, "dungeon:wailing-caverns"); const first = await publishContent({ contentDirectory, sources, createdAt: "2026-08-14T00:00:00.000Z" }); assert.equal(first.copiedObjects, 1); const latest = JSON.parse(await readFile(path.join(contentDirectory, "manifest.json"), "utf8")); assert.equal(latest.version, first.manifest.version); const entry = latest.files["/assets/game/dungeons/wailing-caverns/visual.glb"]; assert.match(entry.url, /^\/content\/objects\/[a-f0-9]{64}\.glb$/); assert.equal(await readFile(path.join(contentDirectory, "objects", path.basename(entry.url)), "utf8"), "glb-one"); const second = await publishContent({ contentDirectory, sources, createdAt: "2026-08-14T00:00:00.000Z" }); assert.equal(second.copiedObjects, 0); assert.equal(second.manifest.version, first.manifest.version); } finally { await rm(directory, { recursive: true, force: true }); } });