@@ -2,7 +2,7 @@ import { afterEach, describe, expect, spyOn, test } from "bun:test";
22import { existsSync , mkdtempSync , readFileSync , rmSync } from "node:fs" ;
33import { tmpdir } from "node:os" ;
44import { join } from "node:path" ;
5- import { augmentRoutedModelsWithJawcodeMetadata , augmentRoutedModelsWithRegistryOpenAiApiRows , buildCatalogEntries , clampCatalogModelsToCodexSupport , clampEntryToCodexSupportedEfforts , clampedDefaultEffort , deriveComboCatalogModel , exactComboCatalogSlugs , filterCatalogVisibleModels , filterSupportedNativeSlugs , gatherRoutedModels , isDatedVariantId , isMediaGenerationModelId , loadBundledCodexCatalog , materializeBundledCodexCatalog , mergeCatalogEntriesForSync , NATIVE_OPENAI_MODELS , normalizeRoutedCatalogEntry , resetCatalogRuntimeStateForTests , resetOpenAiApiCatalogWarningStateForTests } from "../src/codex/catalog" ;
5+ import { augmentRoutedModelsWithJawcodeMetadata , augmentRoutedModelsWithRegistryOpenAiApiRows , buildCatalogEntries , catalogModelSlug , clampCatalogModelsToCodexSupport , clampEntryToCodexSupportedEfforts , clampedDefaultEffort , deriveComboCatalogModel , exactComboCatalogSlugs , filterCatalogVisibleModels , filterSupportedNativeSlugs , gatherRoutedModels , isDatedVariantId , isMediaGenerationModelId , loadBundledCodexCatalog , materializeBundledCodexCatalog , mergeCatalogEntriesForSync , NATIVE_OPENAI_MODELS , normalizeRoutedCatalogEntry , resetCatalogRuntimeStateForTests , resetOpenAiApiCatalogWarningStateForTests } from "../src/codex/catalog" ;
66import {
77 CURSOR_STATIC_MODELS ,
88 filterCursorConfiguredModelsByLiveDiscovery ,
@@ -521,6 +521,129 @@ describe("Google Gemini catalog metadata", () => {
521521 } ) ;
522522} ) ;
523523
524+ describe ( "configured CatalogModel displayName -> catalog display_name" , ( ) => {
525+ test ( "a routed CatalogModel displayName becomes the catalog display_name" , ( ) => {
526+ const model = { provider : "deepseek" , id : "deepseek-v4" , displayName : "DeepSeek V4" , owned_by : "deepseek" } ;
527+ const entries = buildCatalogEntries ( nativeTemplate ( ) , [ ] , [ model ] ) ;
528+ const row = entries . find ( e => e . slug === "deepseek/deepseek-v4" ) ;
529+
530+ expect ( row ?. display_name ) . toBe ( "DeepSeek V4" ) ;
531+ // Routing slug is untouched — displayName is display-only.
532+ expect ( row ?. slug ) . toBe ( "deepseek/deepseek-v4" ) ;
533+ expect ( catalogModelSlug ( model ) ) . toBe ( "deepseek/deepseek-v4" ) ;
534+ } ) ;
535+
536+ test ( "absent displayName leaves display_name as the slug (unchanged behavior)" , ( ) => {
537+ const entries = buildCatalogEntries ( nativeTemplate ( ) , [ ] , [
538+ { provider : "anthropic" , id : "claude-sonnet-4-6" , owned_by : "anthropic" } ,
539+ ] ) ;
540+ const row = entries . find ( e => e . slug === "anthropic/claude-sonnet-4-6" ) ;
541+
542+ expect ( row ?. display_name ) . toBe ( "anthropic/claude-sonnet-4-6" ) ;
543+ expect ( row ?. slug ) . toBe ( "anthropic/claude-sonnet-4-6" ) ;
544+ } ) ;
545+
546+ test ( "empty/whitespace displayName is ignored and falls back to the slug" , ( ) => {
547+ const entries = buildCatalogEntries ( nativeTemplate ( ) , [ ] , [
548+ { provider : "deepseek" , id : "deepseek-v4" , displayName : " " , owned_by : "deepseek" } ,
549+ ] ) ;
550+ const row = entries . find ( e => e . slug === "deepseek/deepseek-v4" ) ;
551+ expect ( row ?. display_name ) . toBe ( "deepseek/deepseek-v4" ) ;
552+ } ) ;
553+
554+ test ( "displayName never affects the routing slug, alias, or provider" , ( ) => {
555+ const withAlias = { provider : "combo" , id : "x" , alias : "fast-chat" , displayName : "Fast Chat" , owned_by : "combo" } ;
556+ const entries = buildCatalogEntries ( nativeTemplate ( ) , [ ] , [ withAlias ] , undefined , false , "default" , new Set ( [ "fast-chat" ] ) ) ;
557+ const row = entries . find ( e => e . slug === "fast-chat" ) ! ;
558+
559+ // The public alias is still the slug; only the label changed.
560+ expect ( row . slug ) . toBe ( "fast-chat" ) ;
561+ expect ( catalogModelSlug ( withAlias ) ) . toBe ( "fast-chat" ) ;
562+ expect ( row . display_name ) . toBe ( "Fast Chat" ) ;
563+ expect ( row . owned_by ) . toBe ( "combo" ) ;
564+ } ) ;
565+
566+ test ( "displayName stays stable across repeated catalog sync (idempotent regeneration)" , ( ) => {
567+ const model = { provider : "deepseek" , id : "deepseek-v4" , displayName : "DeepSeek V4" , owned_by : "deepseek" } ;
568+ const rebuild = ( ) => buildCatalogEntries ( nativeTemplate ( ) , [ ] , [ model ] ) ;
569+
570+ // First sync: freshly built entries merged into an empty on-disk catalog.
571+ const firstSync = mergeCatalogEntriesForSync ( [ ] , rebuild ( ) , new Map ( ) , [ ] , false ) ;
572+ const firstRow = firstSync . find ( e => e . slug === "deepseek/deepseek-v4" ) ! ;
573+ expect ( firstRow . display_name ) . toBe ( "DeepSeek V4" ) ;
574+
575+ // Second sync: re-derive from the SAME config and merge against the now-populated catalog.
576+ // Routed entries are rebuilt from gatherRoutedModels each sync, so display_name must be
577+ // re-derived deterministically and never drift back to the bare slug.
578+ const secondSync = mergeCatalogEntriesForSync ( firstSync , rebuild ( ) , new Map ( ) , [ ] , false ) ;
579+ const secondRow = secondSync . find ( e => e . slug === "deepseek/deepseek-v4" ) ! ;
580+ expect ( secondRow . display_name ) . toBe ( "DeepSeek V4" ) ;
581+ expect ( secondRow . slug ) . toBe ( "deepseek/deepseek-v4" ) ;
582+ } ) ;
583+
584+ test ( "configured displayName does not override genuine native upstream marketing names" , ( ) => {
585+ // Native gpt-5.6-* entries come from the pinned upstream snapshot with their real display
586+ // names; they carry no CatalogModel (isRouted=false), so a configured displayName can never
587+ // reach them — and the fallback-quality discriminator (display_name === slug) still works.
588+ const entries = buildCatalogEntries ( nativeTemplate ( ) , [ "gpt-5.6-sol" ] , [ ] ) ;
589+ const sol = entries . find ( e => e . slug === "gpt-5.6-sol" ) ;
590+ expect ( sol ?. display_name ) . toBe ( "GPT-5.6-Sol" ) ;
591+
592+ // A fallback-quality native (display_name stamped with the bare slug) is still upgraded to
593+ // the upstream entry by sync — displayName on routed models does not interfere with that path.
594+ const synthesizedLuna = {
595+ ...nativeTemplate ( ) ,
596+ slug : "gpt-5.6-luna" ,
597+ display_name : "gpt-5.6-luna" ,
598+ priority : 9 ,
599+ } ;
600+ const merged = mergeCatalogEntriesForSync ( [ synthesizedLuna ] , [ ] , new Map ( ) , [ ] , false ) ;
601+ expect ( merged . find ( e => e . slug === "gpt-5.6-luna" ) ?. display_name ) . toBe ( "GPT-5.6-Luna" ) ;
602+ } ) ;
603+
604+ test ( "a configured customModel displayName propagates end-to-end through gatherRoutedModels" , async ( ) => {
605+ clearModelCache ( "custom-provider" ) ;
606+ const originalFetch = globalThis . fetch ;
607+ let fetchCalls = 0 ;
608+ globalThis . fetch = ( ( ) => {
609+ fetchCalls += 1 ;
610+ throw new Error ( "fetch should not be called" ) ;
611+ } ) as typeof fetch ;
612+ try {
613+ const models = await gatherRoutedModels ( {
614+ port : 10100 ,
615+ defaultProvider : "custom-provider" ,
616+ providers : {
617+ "custom-provider" : {
618+ baseUrl : "https://example.invalid/v1" ,
619+ adapter : "openai-chat" ,
620+ authMode : "key" ,
621+ liveModels : false ,
622+ models : [ "baseline-model" ] ,
623+ } ,
624+ } ,
625+ customModels : [
626+ { id : "cm-1" , provider : "custom-provider" , modelId : "renamed-model" , displayName : "Renamed Model" , addedAt : "2026-01-01T00:00:00.000Z" } ,
627+ ] ,
628+ } ) ;
629+
630+ expect ( fetchCalls ) . toBe ( 0 ) ;
631+ // The configured custom row is added alongside the provider's baseline model; displayName
632+ // rides only on the custom row.
633+ const custom = models . find ( m => m . provider === "custom-provider" && m . id === "renamed-model" ) ;
634+ expect ( custom ?. displayName ) . toBe ( "Renamed Model" ) ;
635+
636+ const entries = buildCatalogEntries ( nativeTemplate ( ) , [ ] , models ) ;
637+ const row = entries . find ( e => e . slug === "custom-provider/renamed-model" ) ;
638+ expect ( row ?. display_name ) . toBe ( "Renamed Model" ) ;
639+ expect ( row ?. slug ) . toBe ( "custom-provider/renamed-model" ) ;
640+ } finally {
641+ globalThis . fetch = originalFetch ;
642+ clearModelCache ( "custom-provider" ) ;
643+ }
644+ } ) ;
645+ } ) ;
646+
524647function openAiApiCatalogConfig ( overrides : Record < string , unknown > = { } ) : OcxConfig {
525648 return {
526649 port : 10100 ,
0 commit comments