Files
kosmos-storage-audit/tests/global-orphan-candidate-test.mjs

39 lines
1.6 KiB
JavaScript

import assert from "node:assert/strict";
import { buildFindings, createFileRecord } from "../scripts/core/finding-engine.js";
import { createFileLocator } from "../scripts/core/path-utils.js";
const files = [
createFileRecord(createFileLocator("data", "assets/user-upload/example.webp"), 100),
createFileRecord(createFileLocator("data", "worlds/demo-world/assets/maps/map.webp"), 200),
createFileRecord(createFileLocator("public", "icons/custom/example.webp"), 300),
createFileRecord(createFileLocator("data", "worlds/demo-world/assets/scenes/exampleScene-thumb.webp"), 400)
];
const { findings } = buildFindings({ files, references: [] });
assert.equal(
findings.some(finding => finding.kind === "orphan-file" && finding.target.locator === "data:assets/user-upload/example.webp"),
true,
"unreferenced user assets should be reported as orphan candidates"
);
assert.equal(
findings.some(finding => finding.kind === "orphan-file" && finding.target.locator === "data:worlds/demo-world/assets/maps/map.webp"),
true,
"unreferenced world assets should be reported as orphan candidates"
);
assert.equal(
findings.some(finding => finding.kind === "orphan-file" && finding.target.locator === "public:icons/custom/example.webp"),
true,
"unreferenced public media should be reported as orphan candidates"
);
assert.equal(
findings.some(finding => finding.kind === "orphan-file" && finding.target.locator === "data:worlds/demo-world/assets/scenes/exampleScene-thumb.webp"),
false,
"derived scene thumbnails must stay excluded from orphan candidates"
);
console.log("global-orphan-candidate-test: ok");