From 5b3c576045e79a529094403f1968f934ceb61f15 Mon Sep 17 00:00:00 2001 From: ytj-zuel <15623621570> Date: Mon, 6 Jul 2026 14:00:06 +0800 Subject: [PATCH] test: add unit tests for TTSConfigValidator Adds a small, focused, additive unit-test file (test/tts-config-validator.test.ts). No existing files are modified or removed. yarn test:ci passes locally. Co-Authored-By: Claude Opus 4.8 (1M context) --- test/tts-config-validator.test.ts | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/tts-config-validator.test.ts diff --git a/test/tts-config-validator.test.ts b/test/tts-config-validator.test.ts new file mode 100644 index 00000000000..4cdb9128c45 --- /dev/null +++ b/test/tts-config-validator.test.ts @@ -0,0 +1,35 @@ +// app/store/config.ts participates in an import cycle, so a static import can +// hit a temporal-dead-zone error. Load it dynamically in beforeAll instead. +let TTSConfigValidator: { + engine: (x: string) => string; + model: (x: string) => string; + voice: (x: string) => string; + speed: (x: number) => number; +}; + +beforeAll(async () => { + // Warm up the import cycle in a working order before loading the target. + await import("../app/client/api"); + ({ TTSConfigValidator } = await import("../app/store/config")); +}); + +describe("TTSConfigValidator", () => { + test("speed clamps to [0.25, 4.0] and defaults to 1.0 on NaN", () => { + expect(TTSConfigValidator.speed(0.1)).toBe(0.25); + expect(TTSConfigValidator.speed(10)).toBe(4.0); + expect(TTSConfigValidator.speed(2)).toBe(2); + expect(TTSConfigValidator.speed(NaN)).toBe(1.0); + }); + + test("engine passes the value through unchanged", () => { + expect(TTSConfigValidator.engine("OpenAI-TTS")).toBe("OpenAI-TTS"); + }); + + test("model passes the value through unchanged", () => { + expect(TTSConfigValidator.model("tts-1")).toBe("tts-1"); + }); + + test("voice passes the value through unchanged", () => { + expect(TTSConfigValidator.voice("alloy")).toBe("alloy"); + }); +});