fix: precise item classification in catalog audit and repair
CI / check (push) Successful in 23s
CI / release (push) Skipped
CI / deploy (push) Successful in 1m3s

Detect badges by items_base.type='b' (authoritative, album gifs as
fallback), recognize pet/animals (a0 pet<N>, pet<N> interaction) and
system items (effects, bots, sticky notes), and resolve asset names for
dot/star classname variants so the audit no longer floods with false
missing nitro/icon errors and repair skips non-furni items.
This commit is contained in:
openhands committed 2026-08-04 11:07:04 +02:00
1 parent b1a1e5125c
commit d587749b50
5 files changed
+445 -36

No files matched your search

+188
View File
@@ -0,0 +1,188 @@
import { describe, expect, it } from "vitest";
import {
assetNameCandidates,
classifyCatalogItem,
isBadgeType,
isPetClassname,
isPetInteraction,
NO_ASSET_KINDS,
NO_CATALOG_KINDS,
} from "./item-kind";
describe("isBadgeType", () => {
it("returns true for badge type b (any case)", () => {
expect(isBadgeType("b")).toBe(true);
expect(isBadgeType("B")).toBe(true);
expect(isBadgeType(" b ")).toBe(true);
});
it("returns false for furni types", () => {
expect(isBadgeType("s")).toBe(false);
expect(isBadgeType("i")).toBe(false);
expect(isBadgeType("")).toBe(false);
});
});
describe("isPetClassname / isPetInteraction", () => {
it("recognises a0 pet<N> classnames", () => {
expect(isPetClassname("a0 pet0")).toBe(true);
expect(isPetClassname("a0 pet80")).toBe(true);
expect(isPetClassname(" a0 pet13 ")).toBe(true);
expect(isPetClassname("a0_pet0")).toBe(false);
expect(isPetClassname("bunny")).toBe(false);
});
it("recognises pet<N> interaction types", () => {
expect(isPetInteraction("pet0")).toBe(true);
expect(isPetInteraction(" pet13 ")).toBe(true);
expect(isPetInteraction("pet0 ")).toBe(true);
expect(isPetInteraction("postit")).toBe(false);
expect(isPetInteraction("default")).toBe(false);
expect(isPetInteraction(null)).toBe(false);
});
});
describe("classifyCatalogItem", () => {
it("classifies badges by type b", () => {
expect(
classifyCatalogItem({
type: "b",
item_name: "YZI68",
interaction_type: "default",
}),
).toBe("badge");
expect(
classifyCatalogItem({
type: "b",
item_name: "horse",
interaction_type: "default",
}),
).toBe("badge");
});
it("classifies pets by classname and interaction type", () => {
expect(
classifyCatalogItem({
type: "s",
item_name: "a0 pet0",
interaction_type: "pet0 ",
}),
).toBe("pet");
expect(
classifyCatalogItem({
type: "s",
item_name: "a0 pet37",
interaction_type: "pet13",
}),
).toBe("pet");
});
it("classifies effects, bots and sticky notes", () => {
expect(
classifyCatalogItem({
type: "s",
item_name: "avatar_effect158",
interaction_type: "default",
}),
).toBe("effect");
expect(
classifyCatalogItem({
type: "s",
item_name: "bot_generic",
interaction_type: "default",
}),
).toBe("bot");
expect(
classifyCatalogItem({
type: "s",
item_name: "rentable_bot_visitor_log",
interaction_type: "default",
}),
).toBe("bot");
expect(
classifyCatalogItem({
type: "s",
item_name: "post.it",
interaction_type: "postit",
}),
).toBe("sticky");
});
it("does not mistake furni classnames that share prefixes", () => {
expect(
classifyCatalogItem({
type: "s",
item_name: "botanical_garden",
interaction_type: "default",
}),
).toBe("furni");
// `effect_faketile` is a real purchasable furni item.
expect(
classifyCatalogItem({
type: "s",
item_name: "effect_faketile",
interaction_type: "default",
}),
).toBe("furni");
});
it("classifies normal furniture", () => {
expect(
classifyCatalogItem({
type: "s",
item_name: "table_silo_med",
interaction_type: "default",
}),
).toBe("furni");
expect(
classifyCatalogItem({
type: "i",
item_name: "wall_poster",
interaction_type: "default",
}),
).toBe("furni");
});
});
describe("kind sets", () => {
it("badges and pets never expect furni assets", () => {
expect(NO_ASSET_KINDS.has("badge")).toBe(true);
expect(NO_ASSET_KINDS.has("pet")).toBe(true);
expect(NO_ASSET_KINDS.has("effect")).toBe(true);
expect(NO_ASSET_KINDS.has("bot")).toBe(true);
expect(NO_ASSET_KINDS.has("sticky")).toBe(true);
expect(NO_ASSET_KINDS.has("furni")).toBe(false);
});
it("pets are catalog-purchasable, badges and system items are not", () => {
expect(NO_CATALOG_KINDS.has("badge")).toBe(true);
expect(NO_CATALOG_KINDS.has("effect")).toBe(true);
expect(NO_CATALOG_KINDS.has("bot")).toBe(true);
expect(NO_CATALOG_KINDS.has("sticky")).toBe(true);
expect(NO_CATALOG_KINDS.has("pet")).toBe(false);
expect(NO_CATALOG_KINDS.has("furni")).toBe(false);
});
});
describe("assetNameCandidates", () => {
it("returns the exact name first for plain classnames", () => {
expect(assetNameCandidates("table_silo_med")).toEqual({
nitro: ["table_silo_med.nitro"],
icon: ["table_silo_med_icon.png"],
});
});
it("adds the base classname for star variants", () => {
expect(assetNameCandidates("table_silo_med*10").nitro).toContain(
"table_silo_med.nitro",
);
expect(assetNameCandidates("table_silo_med*10").icon).toContain(
"table_silo_med_10_icon.png",
);
});
it("adds the underscore name for dotted classnames", () => {
expect(assetNameCandidates("post.it").nitro).toContain("post_it.nitro");
expect(assetNameCandidates("post.it").icon).toContain("post_it_icon.png");
});
});