Files
youtube-generator/tests/engine/limits.test.ts
T
poli0981andClaude Opus 5.5 7e6c12152f fix(data): hardware names, YouTube's tag count, chapters, history duplicates, validation
Hardware
- GPU catalog rewritten with stable ids and official names: descriptions
  read "NVIDIA GeForce RTX 5080", "AMD Radeon RX 9070 XT", "Apple M4 Pro"
  instead of "NVIDIA RTX 5080" / "AMD RX 9070 XT" / "Apple Silicon M4 Pro".
  Cards that never shipped (RX 9080, RX 9090 XT, Arc B380) are gone;
  RTX 50/40/30 laptop GPUs, RX 9070 GRE, VRAM variants, Radeon/Intel
  integrated graphics, handheld APUs and Apple M5 (Pro/Max/Ultra) added.
  One searchable picker ("5080", "rog ally") replaces Brand › Series ›
  Model, with free text for anything else.
- Old `brand|series|model` values are migrated (editor v19, profiles v3,
  templates v2, and on load/import); unknown cards keep their full name.
- RAM: 24/48/192 GB, LPDDR4/4X/5/5X, optional speed ("32 GB DDR5-6000");
  no DDR6/DDR7; plain "DDR"; "48GB GB" fixed; changing the size no longer
  clears the type. OS: SteamOS, Bazzite, CachyOS, Nobara, openSUSE,
  Fedora 43/44; Linux reads "Ubuntu 24.04 LTS". CPU: suggestions, and
  Windows' "Intel(R) Core(TM) … CPU @ 3.60GHz" is tidied on blur.
- The rig block uses translated labels in a fixed order (CPU, GPU, RAM…)
  in both the description and the social captions.

Tags
- Measured the way YouTube counts (quotes around multi-word tags, one
  comma between): 15 of 51 real tag sets were over 500 by YouTube's count
  while showing under. Counters and the limit warning use the same count.
- Trimming keeps trying shorter tags after one that doesn't fit.
- "Elden Ring Steam", "itch.io gameplay" (was STEAM / ITCHIO); no platform
  tags for a publisher site; "best open world games" (was "openworld");
  RPG/simulation/card pools no longer carry other genres' tags.

Timestamps
- Keywords need a word boundary: "Final Fantasy VII" stays a title (was
  "Ending Fantasy VII"), "Introduction" stays whole.
- Accepts [0:00], 0:00 - label and editor frame counts; pt-BR and
  Indonesian keywords; a Tidy up button; a live check of YouTube's
  chapter rules (0:00 first, 3+, 10 s apart, in order).

Output and data
- History keeps one entry per video (updated in place) instead of one per
  Output visit; existing duplicates are folded (history v3). The History
  Limit is healed on every load.
- A field over its limit blocks only its own copy button (Copy All: title
  or description); a warning when YouTube would reject "<" or ">".
- Validation: Steam /sub/, /bundle/ and s.team links, GOG/Humble/xbox.com
  without www, regional Nintendo sites, Microsoft Store, Luna; social
  links with www./m./twitter.com; phone, YouTube Music and
  video-in-playlist links (normalised); email domains need a TLD; the live
  URL is validated; no bare "#" hashtag.
- The engine takes the year from the caller; "Ending N" follows the output
  language.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 21:11:58 +07:00

165 lines
5.6 KiB
TypeScript

import { describe, it, expect } from "vitest";
import {
getOutputLimitStatus,
mergeLimitStatus,
EMPTY_LIMIT_STATUS,
fieldsWithForbiddenChars,
isFieldOver,
isCopyAllBlocked,
type OutputLimitStatus,
} from "@engine/limits";
import { renderAll } from "@engine/template-renderer";
import { YT_LIMITS, type CharLimitWarning, type GeneratorInput } from "@engine/types";
import { DEFAULTS } from "@config/defaults";
import { createMockT } from "../helpers/mock-t";
function warning(
field: CharLimitWarning["field"],
current: number,
limit: number,
): CharLimitWarning {
return { field, current, limit, message: `${field} over` };
}
function status(...warnings: CharLimitWarning[]): OutputLimitStatus {
return getOutputLimitStatus({ warnings });
}
describe("getOutputLimitStatus", () => {
it("is not blocked when there are no warnings", () => {
expect(status()).toEqual(EMPTY_LIMIT_STATUS);
expect(status().blocked).toBe(false);
});
it("blocks on a single over-limit field and reports it", () => {
const result = status(warning("title", 130, 100));
expect(result.blocked).toBe(true);
expect(result.overflows).toEqual([{ field: "title", current: 130, limit: 100 }]);
});
it("reports every offending field in title → description → tags order", () => {
// Pushed out of order on purpose — display order must not depend on it.
const result = status(
warning("tags", 600, 500),
warning("title", 130, 100),
warning("description", 5200, 5000),
);
expect(result.overflows.map((o) => o.field)).toEqual(["title", "description", "tags"]);
});
it("drops the engine's hardcoded English message", () => {
// It exists on CharLimitWarning but is unusable in a localized UI, so the
// status must not carry it through to the components.
const result = status(warning("title", 130, 100));
expect(result.overflows[0]).not.toHaveProperty("message");
});
});
describe("mergeLimitStatus", () => {
it("returns the empty status for no inputs", () => {
expect(mergeLimitStatus([])).toEqual(EMPTY_LIMIT_STATUS);
});
it("stays unblocked when every input is clean", () => {
expect(mergeLimitStatus([status(), status()]).blocked).toBe(false);
});
it("blocks when any single input is over", () => {
const merged = mergeLimitStatus([status(), status(warning("title", 130, 100))]);
expect(merged.blocked).toBe(true);
});
it("dedupes by field and keeps the worst offender", () => {
// Five Batch rows all over on description must yield ONE banner line.
const merged = mergeLimitStatus([
status(warning("description", 5100, 5000)),
status(warning("description", 6400, 5000)),
status(warning("description", 5300, 5000)),
]);
expect(merged.overflows).toHaveLength(1);
expect(merged.overflows[0]?.current).toBe(6400);
});
it("keeps distinct fields separate and ordered", () => {
const merged = mergeLimitStatus([
status(warning("tags", 600, 500)),
status(warning("title", 130, 100)),
]);
expect(merged.overflows.map((o) => o.field)).toEqual(["title", "tags"]);
});
});
describe("integration with renderAll", () => {
function makeInput(overrides: Partial<GeneratorInput> = {}): GeneratorInput {
return {
...(DEFAULTS.editor as unknown as GeneratorInput),
videoType: "full",
language: "en",
genres: ["horror"],
gameName: "Test Game",
...overrides,
};
}
it("does not block an ordinary output", () => {
const output = renderAll(makeInput(), createMockT("en"));
expect(getOutputLimitStatus(output).blocked).toBe(false);
});
it("blocks a title pushed past the YouTube limit", () => {
const output = renderAll(
makeInput({ gameName: "G".repeat(YT_LIMITS.TITLE_MAX + 50) }),
createMockT("en"),
);
const result = getOutputLimitStatus(output);
expect(result.blocked).toBe(true);
expect(result.overflows.some((o) => o.field === "title")).toBe(true);
});
it("blocks a description pushed past the YouTube limit", () => {
const output = renderAll(
makeInput({ timestamps: "0:00 Intro\n".repeat(600) }),
createMockT("en"),
);
const result = getOutputLimitStatus(output);
expect(result.blocked).toBe(true);
expect(result.overflows.some((o) => o.field === "description")).toBe(true);
});
it("treats an empty output (locale still loading) as unblocked", () => {
// EMPTY_GENERATOR_OUTPUT has no warnings. Copy buttons must be disabled by
// the empty-text check, not by this one claiming a false overflow.
expect(getOutputLimitStatus({ warnings: [] }).blocked).toBe(false);
});
});
describe("fieldsWithForbiddenChars", () => {
it("names the fields YouTube would refuse", () => {
expect(fieldsWithForbiddenChars({ title: "A <3 B", description: "ok" })).toEqual(["title"]);
expect(fieldsWithForbiddenChars({ title: "ok", description: "x > y" })).toEqual([
"description",
]);
expect(fieldsWithForbiddenChars({ title: "ok", description: "ok" })).toEqual([]);
});
});
describe("per-field copy gating (v1.0.0)", () => {
const status: OutputLimitStatus = {
blocked: true,
overflows: [{ field: "tags", current: 520, limit: 500 }],
};
it("blocks only the field that is over", () => {
expect(isFieldOver(status, "tags")).toBe(true);
expect(isFieldOver(status, "title")).toBe(false);
});
it("doesn't block Copy All for tags it doesn't contain", () => {
expect(isCopyAllBlocked(status)).toBe(false);
expect(
isCopyAllBlocked({
blocked: true,
overflows: [{ field: "description", current: 5100, limit: 5000 }],
}),
).toBe(true);
});
});