fix(cli): a model name that every object carries is an unknown model (#8319)

* fix(cli): a model name that every object carries is an unknown model

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* chore(cli): name the own-key lookup instead of commenting it

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
James Russo
2026-11-20 23:18:35 +00:00
committed by GitHub
co-authored by Claude Fable 5.2
parent 0012c1cb88
commit 2ed4a141eb
4 changed files with 23 additions and 4 deletions
+5
View File
@@ -1027,6 +1027,11 @@ describe("generate", () => {
expect(check("nano-banana-2")).toThrow("nano-banana-2 is no longer offered here");
expect(check("gpt-image-2.5", "16:9")).toThrow("gpt-image-2.5 is no longer offered here");
expect(check("some-new-model", "7:5")).not.toThrow();
// A name every object carries is a model this build has no entry for, like any other.
for (const model of ["constructor", "toString", "__proto__", "hasOwnProperty"]) {
expect(check(model, "7:5")).not.toThrow();
expect(check(model, undefined, 20)).toThrow("no file at");
}
});
it("prices only a request the real call would accept", () => {
+5 -2
View File
@@ -202,11 +202,14 @@ const need = <T>(value: T | undefined, flag: string, example: string): T => {
return value;
};
const ownEntry = <T>(table: Record<string, T>, name: string): T | undefined =>
Object.hasOwn(table, name) ? table[name] : undefined;
function imageModel(r: GenerateRequest): string {
const model = r.model ?? DEFAULTS.image;
const replacement = RETIRED_IMAGE_MODELS[model];
const replacement = ownEntry(RETIRED_IMAGE_MODELS, model);
if (replacement) throw new Fix(`${model} is no longer offered here`, `--model ${replacement}`);
const spec = IMAGE_MODELS[model];
const spec = ownEntry(IMAGE_MODELS, model);
if (!spec) return model;
if (r.aspect && !spec.aspects.includes(r.aspect))
throw new Fix(`${model} does not make ${r.aspect}`, `--aspect ${spec.aspects.join("|")}`);
+10
View File
@@ -2,10 +2,20 @@ import { describe, expect, it } from "vitest";
import {
BUNDLED_VOICES,
SUPPORTED_LANGS,
ensureModel,
inferLangFromVoiceId,
isSupportedLang,
} from "./manager.js";
describe("ensureModel", () => {
it.each(["no-such-model", "constructor", "toString", "__proto__"])(
"names %s as an unknown model",
async (model) => {
await expect(ensureModel(model)).rejects.toThrow(`Unknown TTS model: ${model}.`);
},
);
});
describe("inferLangFromVoiceId", () => {
it.each([
["af_heart", "en-us"],
+3 -2
View File
@@ -117,8 +117,9 @@ export async function ensureModel(
model: string = DEFAULT_MODEL,
options?: { onProgress?: (message: string) => void },
): Promise<string> {
const url = MODEL_URLS[model];
const pin = MODEL_PINS[model];
const known = Object.hasOwn(MODEL_URLS, model) && Object.hasOwn(MODEL_PINS, model);
const url = known ? MODEL_URLS[model] : undefined;
const pin = known ? MODEL_PINS[model] : undefined;
if (!url || !pin) {
throw new Error(
`Unknown TTS model: ${model}. Available: ${Object.keys(MODEL_URLS).join(", ")}`,