Files
writing-agent/tests/tts-cache.test.ts
chenmoranzhiandCursor 820397e578 接入边缘浏览器语音合成并做本地缓存,听书段落可直接朗读。
依赖随锁文件一并落下,避免环境缺包。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-07 23:48:43 +08:00

38 lines
1.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { ttsCacheKey } from "../src/tts/cache.js";
import { DEFAULT_TTS_PROVIDER, resolveTtsProvider } from "../src/tts/index.js";
describe("tts cache / provider", () => {
it("hashes stable keys", () => {
const a = ttsCacheKey({
provider: "edge",
voice: "zh-CN-XiaoxiaoNeural",
text: "你好",
extra: "s1",
});
const b = ttsCacheKey({
provider: "edge",
voice: "zh-CN-XiaoxiaoNeural",
text: "你好",
extra: "s1",
});
const c = ttsCacheKey({
provider: "edge",
voice: "zh-CN-XiaoxiaoNeural",
text: "你好啊",
extra: "s1",
});
expect(a).toBe(b);
expect(a).not.toBe(c);
expect(a.length).toBe(40);
});
it("defaults provider to edge", () => {
expect(DEFAULT_TTS_PROVIDER).toBe("edge");
const prev = process.env.WRITING_AGENT_TTS_PROVIDER;
delete process.env.WRITING_AGENT_TTS_PROVIDER;
expect(resolveTtsProvider()).toBe("edge");
process.env.WRITING_AGENT_TTS_PROVIDER = prev;
});
});