CI ran typecheck/lint/locales/test/build. Everything else the repo owned was
configured but never executed — `knip` was installed and configured yet ran
nowhere, Prettier had a config and no gate, and the six version fields the
release ritual bumps by hand had nothing watching them. This wires all of it
into the pipeline.
Correctness gaps this immediately caught:
- `tsconfig.json` covers only `src`, so tests/ and scripts/ were NEVER
type-checked. Adding `tsconfig.check.json` (+ `typecheck:all`) surfaced 53
errors, including three fields silently missing from the editor→engine
parity fixture: `videoStyleEra` (v0.22.0), `adEmail` + `gameKeyEmail`
(v0.34.0), and the four `endings*` fields (v0.16.0/v0.17.1). The fixture is
the guard against exactly that class of drift, and it had drifted itself.
- `vitest.config.ts` `include` matched only `*.test.ts`, so any `.test.tsx`
would have been collected by nobody and "passed" silently. Now `{ts,tsx}`.
New gates in ci.yml: `typecheck:all`, `format:check`, `knip`, `check:version`,
and an advisory `npm audit --audit-level=high` (advisory so a fresh transitive
advisory cannot redden every unrelated PR before Dependabot opens its fix).
Plus least-privilege `permissions: contents: read` — which also clears the
`actions/missing-workflow-permissions` code-scanning alert — and a
concurrency group that cancels superseded runs everywhere except `main`.
New scripts:
- `scripts/check-version-sync.ts` — asserts all SIX version fields agree
(package.json, package-lock root AND packages[""], tauri.conf.json,
Cargo.toml, Cargo.lock self-entry). Nothing else notices a missed one, and a
stale tauri.conf.json ships an installer that disagrees with its tag.
- `scripts/generate-locale-template.ts` — `npm run generate:locale` has been
advertised in package.json and docs/I18N.md step 1 since v0.1, but the file
was never committed, so the documented first step of adding a language
failed outright. Blocks the planned pt-BR + id work.
Dead code removed: the Rust `ensure_dir` command and its two scoped `opener:`
capabilities. Its documented caller, `openSettingsFolder()`, no longer exists
in `src/` — `opener:default` (all `openExternal` needs) is untouched. Also
`@tauri-apps/plugin-opener` left knip's ignore list now that it is genuinely
imported, and `DroppedReasonId` went from unused export to typing
PlaylistPage's dropped-reason state.
Security: the `js/incomplete-url-substring-sanitization` alert in
description-builder.test.ts was a real (if low-stakes) weak assertion —
`includes("itch.io")` also matches `https://itch.io.example.com/`, so the
test could pass on the wrong line. Now matches the full URL.
CHANGELOG: v0.31.0, v0.32.0 and v0.32.1 shipped as tagged releases but were
never logged, leaving the file jumping v0.33.0 → v0.30.0. Reconstructed from
the release commits in the file's existing house style.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
182 lines
6.7 KiB
TypeScript
182 lines
6.7 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { parseTimeline, renderTimeline } from "@engine/timeline-parser";
|
|
import type { TranslationFn } from "@engine/types";
|
|
|
|
// Minimal translation lookup keyed by (language, keyword id).
|
|
// Mirrors the shape of the real templates.json entries.
|
|
const DICT: Record<string, Record<string, string>> = {
|
|
en: {
|
|
chapter: "Chapter {{n}}",
|
|
part: "Part {{n}}",
|
|
boss: "Boss {{n}}",
|
|
final_boss: "Final Boss",
|
|
intro: "Intro",
|
|
// v0.16.0: ending keyword now interpolates {{n}} like chapter/part/boss
|
|
// so "Ending 1" / "Ending 2" survive the parse → render round-trip.
|
|
ending: "Ending {{n}}",
|
|
tutorial: "Tutorial",
|
|
credits: "Credits",
|
|
},
|
|
vi: {
|
|
chapter: "Chương {{n}}",
|
|
part: "Phần {{n}}",
|
|
boss: "Boss {{n}}",
|
|
final_boss: "Boss cuối",
|
|
intro: "Mở đầu",
|
|
ending: "Kết thúc {{n}}",
|
|
tutorial: "Hướng dẫn",
|
|
credits: "Credits",
|
|
},
|
|
ja: {
|
|
chapter: "第{{n}}章",
|
|
part: "パート{{n}}",
|
|
boss: "ボス{{n}}",
|
|
final_boss: "ラスボス",
|
|
intro: "オープニング",
|
|
ending: "エンディング{{n}}",
|
|
tutorial: "チュートリアル",
|
|
credits: "クレジット",
|
|
},
|
|
};
|
|
|
|
function makeT(lang: "en" | "vi" | "ja"): TranslationFn {
|
|
return (key, opts) => {
|
|
const id = key.replace("timeline.keywords.", "");
|
|
const template = DICT[lang]?.[id] ?? id;
|
|
if (!opts) return template;
|
|
return template.replace(/\{\{(\w+)\}\}/g, (_, k) => opts[k] ?? "");
|
|
};
|
|
}
|
|
|
|
describe("parseTimeline", () => {
|
|
it("parses time + label into entries", () => {
|
|
const entries = parseTimeline("0:00 Intro\n5:30 Chapter 1\n15:00 Boss 2");
|
|
expect(entries).toHaveLength(3);
|
|
expect(entries[0]!.time).toBe("0:00");
|
|
expect(entries[0]!.keyword).toBe("intro");
|
|
expect(entries[1]!.keyword).toBe("chapter");
|
|
expect(entries[1]!.number).toBe(1);
|
|
expect(entries[2]!.keyword).toBe("boss");
|
|
expect(entries[2]!.number).toBe(2);
|
|
});
|
|
|
|
it("supports HH:MM:SS timecodes", () => {
|
|
const entries = parseTimeline("1:23:45 Chapter 7");
|
|
expect(entries[0]!.time).toBe("1:23:45");
|
|
expect(entries[0]!.keyword).toBe("chapter");
|
|
expect(entries[0]!.number).toBe(7);
|
|
});
|
|
|
|
it("recognizes final boss before boss", () => {
|
|
const entries = parseTimeline("10:00 Final Boss");
|
|
expect(entries[0]!.keyword).toBe("final_boss");
|
|
});
|
|
|
|
it("recognizes Vietnamese keywords", () => {
|
|
const entries = parseTimeline("0:00 Mở đầu\n5:00 Chương 3\n20:00 Boss cuối");
|
|
expect(entries[0]!.keyword).toBe("intro");
|
|
expect(entries[1]!.keyword).toBe("chapter");
|
|
expect(entries[1]!.number).toBe(3);
|
|
expect(entries[2]!.keyword).toBe("final_boss");
|
|
});
|
|
|
|
it("recognizes Japanese keywords", () => {
|
|
const entries = parseTimeline("0:00 オープニング\n5:00 パート 2\n20:00 ラスボス");
|
|
expect(entries[0]!.keyword).toBe("intro");
|
|
expect(entries[1]!.keyword).toBe("part");
|
|
expect(entries[1]!.number).toBe(2);
|
|
expect(entries[2]!.keyword).toBe("final_boss");
|
|
});
|
|
|
|
it("preserves lines that don't match a known keyword", () => {
|
|
const entries = parseTimeline("0:00 Random Stuff");
|
|
expect(entries[0]!.time).toBe("0:00");
|
|
expect(entries[0]!.keyword).toBeUndefined();
|
|
expect(entries[0]!.rawLabel).toBe("Random Stuff");
|
|
});
|
|
|
|
it("preserves lines without a time prefix", () => {
|
|
const entries = parseTimeline("Just a note");
|
|
expect(entries[0]!.time).toBe("");
|
|
expect(entries[0]!.rawLabel).toBe("Just a note");
|
|
});
|
|
|
|
it("skips blank lines", () => {
|
|
const entries = parseTimeline("\n0:00 Intro\n\n5:00 Chapter 1\n");
|
|
expect(entries).toHaveLength(2);
|
|
});
|
|
|
|
// v0.16.0: ending keyword now captures an optional ordinal so
|
|
// structured `endings[]` rows can be matched to timeline markers.
|
|
it("captures the ending ordinal when present", () => {
|
|
const entries = parseTimeline("1:00:00 Ending 1\n2:00:00 Ending 3");
|
|
expect(entries[0]!.keyword).toBe("ending");
|
|
expect(entries[0]!.number).toBe(1);
|
|
expect(entries[1]!.keyword).toBe("ending");
|
|
expect(entries[1]!.number).toBe(3);
|
|
});
|
|
|
|
it("recognises a bare 'Ending' line as ending without a number", () => {
|
|
const entries = parseTimeline("1:00:00 Ending");
|
|
expect(entries[0]!.keyword).toBe("ending");
|
|
expect(entries[0]!.number).toBeUndefined();
|
|
});
|
|
|
|
it("captures the trailing label after 'Ending N: ...' as `rest`", () => {
|
|
const entries = parseTimeline("1:00:00 Ending 3: Best End");
|
|
expect(entries[0]!.keyword).toBe("ending");
|
|
expect(entries[0]!.number).toBe(3);
|
|
expect(entries[0]!.rest).toBe(": Best End");
|
|
});
|
|
|
|
it("recognises Vietnamese 'Kết thúc 2'", () => {
|
|
const entries = parseTimeline("1:30:00 Kết thúc 2");
|
|
expect(entries[0]!.keyword).toBe("ending");
|
|
expect(entries[0]!.number).toBe(2);
|
|
});
|
|
});
|
|
|
|
describe("renderTimeline", () => {
|
|
it("translates English input to Vietnamese", () => {
|
|
const entries = parseTimeline("0:00 Intro\n5:30 Chapter 1\n10:00 Boss 2\n20:00 Final Boss");
|
|
const out = renderTimeline(entries, "vi", makeT("vi"));
|
|
expect(out).toBe("0:00 Mở đầu\n5:30 Chương 1\n10:00 Boss 2\n20:00 Boss cuối");
|
|
});
|
|
|
|
it("translates English input to Japanese", () => {
|
|
const entries = parseTimeline("0:00 Intro\n5:30 Chapter 1");
|
|
const out = renderTimeline(entries, "ja", makeT("ja"));
|
|
expect(out).toBe("0:00 オープニング\n5:30 第1章");
|
|
});
|
|
|
|
it("keeps unrecognized labels verbatim", () => {
|
|
const entries = parseTimeline("0:00 Intro\n7:00 Random Stuff");
|
|
const out = renderTimeline(entries, "vi", makeT("vi"));
|
|
expect(out).toBe("0:00 Mở đầu\n7:00 Random Stuff");
|
|
});
|
|
|
|
it("renders English (identity) correctly", () => {
|
|
const entries = parseTimeline("0:00 Intro\n5:30 Chapter 1\n10:00 Boss 2");
|
|
const out = renderTimeline(entries, "en", makeT("en"));
|
|
expect(out).toBe("0:00 Intro\n5:30 Chapter 1\n10:00 Boss 2");
|
|
});
|
|
|
|
// v0.16.0: when a numbered keyword has no captured ordinal (rare —
|
|
// e.g. a "boss" line without an N), the renderer used to emit a
|
|
// trailing space ("Boss "). Now it collapses internal/trailing
|
|
// whitespace so output stays clean.
|
|
it("collapses trailing space when a numbered keyword has no ordinal", () => {
|
|
const entries = parseTimeline("0:00 Boss");
|
|
const out = renderTimeline(entries, "en", makeT("en"));
|
|
expect(out).toBe("0:00 Boss");
|
|
});
|
|
|
|
it("renders 'Ending N' bilingually when the ordinal is present", () => {
|
|
const entries = parseTimeline("1:00:00 Ending 2");
|
|
const enOut = renderTimeline(entries, "en", makeT("en"));
|
|
expect(enOut).toBe("1:00:00 Ending 2");
|
|
const viOut = renderTimeline(entries, "vi", makeT("vi"));
|
|
expect(viOut).toBe("1:00:00 Kết thúc 2");
|
|
});
|
|
});
|