Files
healer-man/scripts/runewaker-pipeline/lib/native-water-audit-cache.test.mjs
2026-10-06 22:25:34 -04:00

34 lines
1.6 KiB
JavaScript

import assert from "node:assert/strict";
import { mkdtemp, rm } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import test from "node:test";
import { writeNativeWaterAuditCacheAliases } from "./native-water-audit-cache.mjs";
test("water audit-cache aliases preserve exact DDS/PNG bytes under a unique texture basename", async () => {
const projectRoot = await mkdtemp(path.join(os.tmpdir(), "native-water-audit-cache-"));
const auditCacheRoot = path.join(projectRoot, "water-audit-cache");
const ddsBytes = Buffer.from("source-dds-frame");
const pngBytes = Buffer.from("prepared-lossless-png-frame");
const options = { projectRoot, auditCacheRoot, variantName: "rom-water-normal-1234-00", ddsBytes, pngBytes };
try {
const first = await writeNativeWaterAuditCacheAliases(options);
const second = await writeNativeWaterAuditCacheAliases(options);
assert.deepEqual(second, first, "existing exact aliases are safe to reuse");
assert.match(first.rawDds.path, /raw\/textures\/rom-water-normal-1234-00\.dds$/);
assert.match(first.preparedPng.path, /prepared\/textures\/rom-water-normal-1234-00\.png$/);
assert.equal(first.rawDds.bytes, ddsBytes.length);
assert.equal(first.preparedPng.bytes, pngBytes.length);
await assert.rejects(writeNativeWaterAuditCacheAliases({
...options,
ddsBytes: Buffer.from("different source frame"),
}), /non-identical/);
await assert.rejects(writeNativeWaterAuditCacheAliases({
...options,
variantName: "../escape",
}), /safe texture basename/);
} finally {
await rm(projectRoot, { recursive: true, force: true });
}
});