fix(tiny): guard unsupportedReason access on const model-spec union (#3133 integration typecheck)
This commit is contained in:
@@ -38,7 +38,10 @@ export function resolveModels(model: string | undefined): TinyLocalModelKey[] {
|
||||
if (!model) return [DEFAULT_TINY_TITLE_LOCAL_MODEL_KEY];
|
||||
// `all` is a prefetch convenience: skip models that fail before load (unsupported
|
||||
// runtime), so the bulk download stays green when every *usable* model succeeds.
|
||||
if (model === "all") return TINY_LOCAL_MODELS.filter(spec => !spec.unsupportedReason).map(spec => spec.key);
|
||||
if (model === "all")
|
||||
return TINY_LOCAL_MODELS.filter(spec => !("unsupportedReason" in spec) || !spec.unsupportedReason).map(
|
||||
spec => spec.key,
|
||||
);
|
||||
if (!isTinyLocalModelKey(model)) {
|
||||
const values = TINY_LOCAL_MODELS.map(spec => spec.key).join(", ");
|
||||
throw new Error(`Unknown tiny local model: ${model}. Expected one of: ${values}, all`);
|
||||
|
||||
@@ -4,19 +4,23 @@ import { TINY_LOCAL_MODELS } from "@oh-my-pi/pi-coding-agent/tiny/models";
|
||||
|
||||
describe("tiny-models download model resolution", () => {
|
||||
it("excludes load-blocked models from `all` so the bulk prefetch stays green", () => {
|
||||
const unsupported = TINY_LOCAL_MODELS.filter(spec => spec.unsupportedReason).map(spec => spec.key);
|
||||
const unsupported = TINY_LOCAL_MODELS.filter(spec => "unsupportedReason" in spec && spec.unsupportedReason).map(
|
||||
spec => spec.key,
|
||||
);
|
||||
// Guard: keep this regression meaningful — at least one registry entry must be load-blocked.
|
||||
expect(unsupported.length).toBeGreaterThan(0);
|
||||
|
||||
const all = resolveModels("all");
|
||||
for (const key of unsupported) expect(all).not.toContain(key);
|
||||
|
||||
const usable = TINY_LOCAL_MODELS.filter(spec => !spec.unsupportedReason).map(spec => spec.key);
|
||||
const usable = TINY_LOCAL_MODELS.filter(spec => !("unsupportedReason" in spec) || !spec.unsupportedReason).map(
|
||||
spec => spec.key,
|
||||
);
|
||||
for (const key of usable) expect(all).toContain(key);
|
||||
});
|
||||
|
||||
it("still resolves an explicitly requested unsupported model (only `all` is filtered)", () => {
|
||||
const blocked = TINY_LOCAL_MODELS.find(spec => spec.unsupportedReason);
|
||||
const blocked = TINY_LOCAL_MODELS.find(spec => "unsupportedReason" in spec && spec.unsupportedReason);
|
||||
expect(blocked).toBeDefined();
|
||||
if (!blocked) return;
|
||||
expect(resolveModels(blocked.key)).toEqual([blocked.key]);
|
||||
|
||||
Reference in New Issue
Block a user