@@ -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 , 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 , 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 ,
@@ -1712,3 +1712,75 @@ describe("media-generation model filtering", () => {
17121712 }
17131713 } ) ;
17141714} ) ;
1715+
1716+ describe ( "Codex reasoning-effort capability clamp" , ( ) => {
1717+ function bundledCatalogDeps ( efforts : string [ ] ) {
1718+ return {
1719+ commandCandidates : ( ) => [ "codex" ] ,
1720+ execFileSync : ( ) => JSON . stringify ( {
1721+ models : [ {
1722+ slug : "gpt-5.5" ,
1723+ base_instructions : "test" ,
1724+ supported_reasoning_levels : efforts . map ( effort => ( { effort, description : effort } ) ) ,
1725+ default_reasoning_level : "medium" ,
1726+ } ] ,
1727+ } ) ,
1728+ } ;
1729+ }
1730+
1731+ function routedEntry ( ) {
1732+ return {
1733+ slug : "openrouter/example" ,
1734+ supported_reasoning_levels : [ "low" , "medium" , "high" , "xhigh" , "max" , "ultra" ]
1735+ . map ( effort => ( { effort, description : effort } ) ) ,
1736+ default_reasoning_level : "max" ,
1737+ } ;
1738+ }
1739+
1740+ test ( "strips max and ultra when the installed Codex ladder stops at xhigh" , ( ) => {
1741+ const models = [ routedEntry ( ) ] ;
1742+
1743+ clampCatalogModelsToCodexSupport ( models , bundledCatalogDeps ( [ "low" , "medium" , "high" , "xhigh" ] ) ) ;
1744+
1745+ expect ( models [ 0 ] ! . supported_reasoning_levels . map ( level => level . effort ) )
1746+ . toEqual ( [ "low" , "medium" , "high" , "xhigh" ] ) ;
1747+ } ) ;
1748+
1749+ test ( "preserves max and ultra when the installed Codex ladder includes them" , ( ) => {
1750+ const models = [ routedEntry ( ) ] ;
1751+
1752+ clampCatalogModelsToCodexSupport ( models , bundledCatalogDeps ( [ "low" , "medium" , "high" , "xhigh" , "max" , "ultra" ] ) ) ;
1753+
1754+ expect ( models [ 0 ] ! . supported_reasoning_levels . map ( level => level . effort ) )
1755+ . toEqual ( [ "low" , "medium" , "high" , "xhigh" , "max" , "ultra" ] ) ;
1756+ } ) ;
1757+
1758+ test ( "falls back to the conservative universal ladder when every advertised effort is unsupported" , ( ) => {
1759+ const entry = {
1760+ supported_reasoning_levels : [ { effort : "max" } , { effort : "ultra" } ] ,
1761+ default_reasoning_level : "ultra" ,
1762+ } ;
1763+
1764+ clampEntryToCodexSupportedEfforts ( entry , new Set ( [ "low" , "medium" , "high" , "xhigh" ] ) ) ;
1765+
1766+ expect ( entry . supported_reasoning_levels . map ( level => level . effort ) ) . toEqual ( [ "low" , "medium" , "high" ] ) ;
1767+ expect ( clampedDefaultEffort ( "max" , [ ] ) ) . toBe ( "medium" ) ;
1768+ } ) ;
1769+
1770+ test ( "repairs an unsupported max default to the highest surviving xhigh rung" , ( ) => {
1771+ const entry = routedEntry ( ) ;
1772+
1773+ clampEntryToCodexSupportedEfforts ( entry , new Set ( [ "low" , "medium" , "high" , "xhigh" ] ) ) ;
1774+
1775+ expect ( entry . default_reasoning_level ) . toBe ( "xhigh" ) ;
1776+ } ) ;
1777+
1778+ test ( "is a no-op when the installed Codex binary cannot be probed" , ( ) => {
1779+ const models = [ routedEntry ( ) ] ;
1780+ const before = structuredClone ( models ) ;
1781+
1782+ clampCatalogModelsToCodexSupport ( models , { commandCandidates : ( ) => [ ] } ) ;
1783+
1784+ expect ( models ) . toEqual ( before ) ;
1785+ } ) ;
1786+ } ) ;
0 commit comments