From 827a41241cbf77ec8501ae19f9e3ec6b8d33148f Mon Sep 17 00:00:00 2001 From: Aditya Vikram Singh <247195684+avs-io@users.noreply.github.com> Date: Wed, 19 Aug 2026 21:27:13 +0530 Subject: [PATCH] fix(models): keep getShortModelName unary for Array.map CI typecheck failed: sessions-report maps getShortModelName, and the Extra High cycle Set was a second parameter. Array.map fed the index as `seen`. Cycle tracking stays on an internal helper. Display and alias behavior unchanged. No second Extra High. --- src/models.ts | 13 +++++++++---- tests/models.test.ts | 8 ++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/models.ts b/src/models.ts index 907c2327..d429ab47 100644 --- a/src/models.ts +++ b/src/models.ts @@ -994,7 +994,12 @@ function lookupShortName(id: string): string | undefined { return undefined } -export function getShortModelName(model: string, seen: Set = new Set()): string { +// Public API stays unary so Array.map/forEach cannot feed index as cycle state. +export function getShortModelName(model: string): string { + return shortModelName(model, new Set()) +} + +function shortModelName(model: string, seen: Set): string { if (autoModelNames[model]) return autoModelNames[model] if (seen.has(model)) { const leaf = model.includes('/') ? model.slice(model.lastIndexOf('/') + 1) : model @@ -1005,13 +1010,13 @@ export function getShortModelName(model: string, seen: Set = new Set()): // User aliases win over built-in display names. A remap of gpt-4o must // show the target, not "GPT-4o". if (Object.hasOwn(userAliases, model)) { - return getShortModelName(userAliases[model]!, seen) + return shortModelName(userAliases[model]!, seen) } const stripped = getCanonicalName(model) if (stripped !== model) { if (Object.hasOwn(userAliases, stripped)) { - return getShortModelName(userAliases[stripped]!, seen) + return shortModelName(userAliases[stripped]!, seen) } const knownStripped = lookupShortName(stripped) if (knownStripped && !Object.hasOwn(BUILTIN_ALIASES, stripped) && !Object.hasOwn(BUILTIN_ALIASES, stripped.toLowerCase())) { @@ -1028,7 +1033,7 @@ export function getShortModelName(model: string, seen: Set = new Set()): if (!segment || seen.has(segment) || segment === stripped) { return lookupShortName(segment) ?? segment } - return getShortModelName(segment, seen) + return shortModelName(segment, seen) } return lookupShortName(canonical) ?? canonical } diff --git a/tests/models.test.ts b/tests/models.test.ts index 2c81f74f..44461252 100644 --- a/tests/models.test.ts +++ b/tests/models.test.ts @@ -776,6 +776,14 @@ describe('observed provider model aliases', () => { expect(getShortModelName('cline-pass/mimo-v2.5-pro')).toBe('MiMo v2.5 Pro') }) + it('stays unary so Array.map cannot feed the index as cycle state', () => { + expect(['mimo-v2.5', 'gpt-4o', 'cline-pass/mimo-v2.5-pro'].map(getShortModelName)).toEqual([ + 'mimo-v2.5', + 'GPT-4o', + 'MiMo v2.5 Pro', + ]) + }) + it('does not map dated Qwen3 Max to a reseller price without provider context', () => { expect(getModelCosts('qwen3-max-2026-01-23')).toBeNull() expect(calculateCost('qwen3-max-2026-01-23', 1_000_000, 1_000_000, 0, 0, 0)).toBe(0)