From 7d299b31fe3832e492d676a910f5953c3e348067 Mon Sep 17 00:00:00 2001 From: Kosmos Date: Tue, 21 Apr 2026 13:03:08 +0000 Subject: [PATCH] Exclude derived scene thumbnails from orphan findings --- module.json | 2 +- scripts/core/finding-engine.js | 6 ++++++ tests/scene-thumbnail-orphan-test.mjs | 30 +++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/scene-thumbnail-orphan-test.mjs diff --git a/module.json b/module.json index ce008d9..c606702 100644 --- a/module.json +++ b/module.json @@ -2,7 +2,7 @@ "id": "kosmos-storage-audit", "title": "Kosmos Storage Audit", "description": "Analyzes media references and risky storage locations across Foundry data and public roots.", - "version": "0.0.19", + "version": "0.0.20", "compatibility": { "minimum": "13", "verified": "13" diff --git a/scripts/core/finding-engine.js b/scripts/core/finding-engine.js index dc7a773..a7fdae7 100644 --- a/scripts/core/finding-engine.js +++ b/scripts/core/finding-engine.js @@ -211,6 +211,7 @@ function wildcardToRegExp(pattern) { } function shouldReportOrphan(file, references) { + if (isDerivedSceneThumbnail(file)) return false; if (file.riskClass === "stable-world") { const worldId = file.ownerHint.ownerId; return references.some(reference => reference.sourceScope?.ownerType === "world" && reference.sourceScope.ownerId === worldId); @@ -224,6 +225,11 @@ function shouldReportOrphan(file, references) { return false; } +function isDerivedSceneThumbnail(file) { + const path = String(file.path ?? ""); + return /^worlds\/[^/]+\/assets\/scenes\/[^/]+-thumb\.(?:png|webp)$/u.test(path); +} + export function createFileRecord(locator, size = null) { return { ...locator, diff --git a/tests/scene-thumbnail-orphan-test.mjs b/tests/scene-thumbnail-orphan-test.mjs new file mode 100644 index 0000000..cfc6c67 --- /dev/null +++ b/tests/scene-thumbnail-orphan-test.mjs @@ -0,0 +1,30 @@ +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", "worlds/demo-world/assets/scenes/exampleScene-thumb.webp"), 1234) +]; + +const references = [ + { + sourceType: "world-document", + sourceScope: { ownerType: "world", ownerId: "demo-world", systemId: "demo-system", subtype: "actors" }, + sourceLabel: "Actor demo", + rawValue: "worlds/demo-world/assets/actors/portrait.webp", + normalized: { + ...createFileLocator("data", "worlds/demo-world/assets/actors/portrait.webp"), + targetKind: "local-file" + } + } +]; + +const findings = buildFindings({ files, references }); + +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 should not be reported as orphaned" +); + +console.log("scene-thumbnail-orphan-test: ok");