forked from phenom/healer-man
63 lines
2.6 KiB
TypeScript
63 lines
2.6 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { readFile } from "node:fs/promises";
|
|
import { gunzipSync, strFromU8 } from "fflate";
|
|
import { describe, expect, it } from "vitest";
|
|
import { validateDungeonEncounterDefinition } from "./dungeonEncounterRuntime";
|
|
import type { DungeonDefinition } from "./dungeonTypes";
|
|
import compressedCampaign from "./generated/dungeonCampaignCatalog.compressed";
|
|
import {
|
|
WOW_VERIFIED_NO_OP_INSTANCE_REVIEWS,
|
|
withWowVerifiedNoOpInstanceContent,
|
|
} from "./wowVerifiedNoOpInstanceCatalog";
|
|
|
|
function decodeBase64(value: string): Uint8Array {
|
|
const decoded = atob(value);
|
|
const bytes = new Uint8Array(decoded.length);
|
|
for (let index = 0; index < decoded.length; index += 1) bytes[index] = decoded.charCodeAt(index);
|
|
return bytes;
|
|
}
|
|
|
|
const generatedDefinitions = (
|
|
JSON.parse(strFromU8(gunzipSync(decodeBase64(compressedCampaign)))) as {
|
|
readonly definitions: readonly DungeonDefinition[];
|
|
}
|
|
).definitions;
|
|
|
|
describe("verified no-op WoW instance scripts", () => {
|
|
it("matches every pinned source file by SHA-256", async () => {
|
|
for (const review of WOW_VERIFIED_NO_OP_INSTANCE_REVIEWS) {
|
|
const source = await readFile(new URL(`../../${review.sourceFile}`, import.meta.url));
|
|
expect(createHash("sha256").update(source).digest("hex"), review.dungeonId).toBe(review.sha256);
|
|
}
|
|
});
|
|
|
|
it("adds a source-exact empty orchestration review without altering population", () => {
|
|
expect(WOW_VERIFIED_NO_OP_INSTANCE_REVIEWS.map((review) => review.dungeonId)).toEqual([
|
|
"stormwind-stockade",
|
|
"razorfen-kraul",
|
|
"ragefire-chasm",
|
|
]);
|
|
for (const review of WOW_VERIFIED_NO_OP_INSTANCE_REVIEWS) {
|
|
const source = generatedDefinitions.find((definition) => definition.id === review.dungeonId);
|
|
if (!source) throw new Error(`Missing generated dungeon ${review.dungeonId}`);
|
|
const adapted = withWowVerifiedNoOpInstanceContent(source);
|
|
const encounter = adapted.encounters?.find(
|
|
(candidate) => candidate.id === `${review.dungeonId}:source-reviewed-instance`,
|
|
);
|
|
expect(encounter).toBeDefined();
|
|
validateDungeonEncounterDefinition(encounter!);
|
|
expect(encounter?.source).toMatchObject({
|
|
fidelity: "source-exact",
|
|
scope: "instance-orchestration",
|
|
adaptations: [],
|
|
remainingGaps: [],
|
|
});
|
|
expect(encounter?.rules).toEqual([]);
|
|
expect(adapted.entities).toBe(source.entities);
|
|
expect(adapted.staticSpawns).toBe(source.staticSpawns);
|
|
expect(adapted.roamingPacks).toBe(source.roamingPacks);
|
|
expect(withWowVerifiedNoOpInstanceContent(adapted)).toBe(adapted);
|
|
}
|
|
});
|
|
});
|