Files
EpicNext-Cms/src/lib/furni/classname.test.ts
T
openhands 3c8abb6fbf
CI / check (push) Successful in 39s
CI / tests-imaging-browsers (push) Successful in 2m9s
CI / tests-integration (push) Successful in 2m47s
CI / tests-unit (push) Failing after 3m22s
CI / tests-ui (push) Failing after 4m14s
CI / preflight (push) Skipped
CI / deploy (push) Skipped
feat(assets): choose furniture bundle ext via FURNI_BUNDLE_EXT
Bundle the remaining imaging hardening and the host/CI fixes from the
"Doe alles" pass into one release.

Furniture:
- Resolve the local bundle extension from FURNI_BUNDLE_EXT (".hab" default,
  ".nitro" for a stock Nitro client). The configured extension is written by
  imports/repairs and preferred on lookup; the other stays a legacy fallback.

Imaging:
- Avatar proxy sends s-maxage=86400 + stale-while-revalidate (300/3600 for the
  fallback path) so the edge can hold a render a day.
- Cloudflare cache rule now covers /api/imaging/ (verified MISS->HIT live).
- Document that bare /imaging is shadowed by the edge proxy to the renderer.

Ops/CI:
- docker-update.sh skips a CI-managed host (exit 0) instead of failing cron.
- ci-deploy.sh runs the cross-browser imaging gate (chromium+firefox+webkit)
  against the candidate before cutover; DEPLOY_SKIP_CROSS_BROWSER=1 as escape.
- scripts/imager-health-alert.sh alerts (Discord) on imager up/down transitions;
  runs from cron every 5 minutes.

Tests:
- Furniture bundle-ext resolver + FURNI_BUNDLE_EXT wiring.
- Imaging performance budget (bytes + warm latency).
- classifyDdos: /api/imaging/* stays in the api bucket.
2026-10-14 21:46:56 +02:00

132 lines
4.0 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "vitest";
import {
getBaseClassname,
getBundleFileName,
getHabboCdnIconUrl,
getIconFileName,
getLocalBundleFileNames,
getLocalIconUrl,
getNitroFileName,
getSafeClassnameStem,
getSwfFileName,
isValidClassname,
normalizeClassname,
resolveLocalBundleExt,
SOURCE_BUNDLE_EXT,
} from "./classname";
describe("getBaseClassname", () => {
it("strips the * suffix", () => {
expect(getBaseClassname("chair_basic*")).toBe("chair_basic");
});
it("returns the classname unchanged when no * is present", () => {
expect(getBaseClassname("chair_basic")).toBe("chair_basic");
});
});
describe("getSafeClassnameStem", () => {
it("replaces * with underscore", () => {
expect(getSafeClassnameStem("wall_plant*")).toBe("wall_plant_");
});
it("leaves plain classnames untouched", () => {
expect(getSafeClassnameStem("lamp_floor")).toBe("lamp_floor");
});
});
describe("file name helpers", () => {
it("builds icon file names from the safe stem", () => {
expect(getIconFileName("sofa_blue*")).toBe("sofa_blue__icon.png");
});
it("builds swf file names from the base classname", () => {
expect(getSwfFileName("sofa_blue*")).toBe("sofa_blue.swf");
});
it("builds the primary (`.hab`) bundle name from the base classname", () => {
expect(getNitroFileName("sofa_blue*")).toBe("sofa_blue.hab");
});
it("offers `.hab` first and keeps legacy `.nitro` resolvable", () => {
expect(getLocalBundleFileNames("sofa_blue*")).toEqual([
"sofa_blue.hab",
"sofa_blue.nitro",
]);
});
it("builds a bundle name for an explicit extension", () => {
expect(getBundleFileName("sofa_blue*", SOURCE_BUNDLE_EXT)).toBe(
"sofa_blue.nitro",
);
});
});
describe("normalizeClassname", () => {
it("trims and lowercases", () => {
expect(normalizeClassname(" Chair_Basic ")).toBe("chair_basic");
});
});
describe("resolveLocalBundleExt", () => {
it("defaults to .hab", () => {
expect(resolveLocalBundleExt(undefined)).toBe(".hab");
expect(resolveLocalBundleExt("")).toBe(".hab");
});
it("accepts .nitro and the bare form", () => {
expect(resolveLocalBundleExt(".nitro")).toBe(".nitro");
expect(resolveLocalBundleExt("nitro")).toBe(".nitro");
expect(resolveLocalBundleExt("NITRO")).toBe(".nitro");
});
it("accepts .hab and the bare form", () => {
expect(resolveLocalBundleExt(".hab")).toBe(".hab");
expect(resolveLocalBundleExt("HAB")).toBe(".hab");
});
it("falls back to .hab for unknown values", () => {
expect(resolveLocalBundleExt("swf")).toBe(".hab");
});
});
describe("FURNI_BUNDLE_EXT wiring", () => {
afterEach(() => {
vi.unstubAllEnvs();
vi.resetModules();
});
it("prefers the configured extension and keeps the other as fallback", async () => {
vi.stubEnv("FURNI_BUNDLE_EXT", ".nitro");
vi.resetModules();
const mod = await import("./classname");
expect(mod.LOCAL_BUNDLE_EXT).toBe(".nitro");
expect(mod.getNitroFileName("sofa_blue")).toBe("sofa_blue.nitro");
expect(mod.getLocalBundleFileNames("sofa_blue")).toEqual([
"sofa_blue.nitro",
"sofa_blue.hab",
]);
});
});
describe("isValidClassname", () => {
it("accepts lowercase letters, digits and allowed symbols", () => {
expect(isValidClassname("chair_basic")).toBe(true);
expect(isValidClassname("sofa*")).toBe(true);
expect(isValidClassname("wall.part-1")).toBe(true);
});
it("rejects uppercase, spaces and invalid characters", () => {
expect(isValidClassname("Chair")).toBe(false);
expect(isValidClassname("sofa basic")).toBe(false);
expect(isValidClassname("sofa/basic")).toBe(false);
expect(isValidClassname("")).toBe(false);
});
});
describe("icon URLs", () => {
it("builds a local icon URL with encoding", () => {
expect(getLocalIconUrl("sofa_blue")).toBe(
"/swf/dcr/hof_furni/icons/sofa_blue_icon.png",
);
expect(getLocalIconUrl("wall*")).toBe(
"/swf/dcr/hof_furni/icons/wall__icon.png",
);
});
it("builds a Habbo CDN icon URL with revision and base classname", () => {
expect(getHabboCdnIconUrl("sofa_blue*", 567)).toBe(
"https://images.habbo.com/dcr/hof_furni/567/sofa_blue_icon.png",
);
});
});