fix(cli): read explicit TTS file input before synthesis (#5306)

This commit is contained in:
Abdullah M. Nazif
2026-10-24 07:31:57 +00:00
committed by GitHub
parent f937076b26
commit d63ff907aa
2 changed files with 23 additions and 1 deletions
+22
View File
@@ -45,6 +45,28 @@ describe("tts command", () => {
);
});
it("refuses a missing --text-file before passing its path to synthesis", async () => {
const input = join(dir, "missing.txt");
await expect(
runCommand(ttsCommand, { rawArgs: ["--text-file", input, "--json"] }),
).rejects.toMatchObject({ code: "ENOENT" });
expect(synthesizeMock).not.toHaveBeenCalled();
});
it("keeps positional text that resembles a missing filename as spoken text", async () => {
const input = join(dir, "missing.txt");
await runCommand(ttsCommand, { rawArgs: [input, "--json"] });
expect(synthesizeMock).toHaveBeenCalledWith(
input,
expect.any(String),
expect.objectContaining({ lang: "en-us" }),
);
});
it.each(["0.05", "1x", "1.5junk", "1 2", "", " ", "NaN", "Infinity", "0", "-1", "3.01"])(
"rejects invalid speed %j before synthesis",
async (speed) => {
+1 -1
View File
@@ -103,7 +103,7 @@ export default defineCommand({
}
let text: string;
if (isTextFile(input)) {
if (args["text-file"] !== undefined || isTextFile(input)) {
text = readFileSync(resolve(input), "utf-8").trim();
if (!text) {
console.error(c.error("File is empty."));