@@ -2,6 +2,7 @@ import { describe, expect, test } from "bun:test";
22import { createResponsesPassthroughAdapter as createResponsesPassthroughAdapterProduction , stripOpenAiOnlyWebSearchFields } from "../src/adapters/openai-responses" ;
33import { enrichProviderFromRegistry , providerConfigSeed } from "../src/providers/derive" ;
44import { getProviderRegistryEntry } from "../src/providers/registry" ;
5+ import { routedProviderConfig } from "../src/router" ;
56import type { OcxProviderConfig } from "../src/types" ;
67import { withTestTranslatorBudget } from "./helpers/translator-budget" ;
78
@@ -81,3 +82,52 @@ describe("Responses buildRequest web_search capability", () => {
8182 } ] ) ;
8283 } ) ;
8384} ) ;
85+
86+ // The request path resolves a saved provider row through routedProviderConfig(), NOT through
87+ // enrichProviderFromRegistry(). Until this backfill existed, a saved xai row reached the
88+ // Responses adapter with supportsOpenAiWebSearchToolFields === undefined, so the #2262
89+ // capability gate read "unclassified" and forwarded the fields; live xAI answered
90+ // `400 Argument not supported: external_web_access` and every routed Grok turn on the
91+ // Responses lane died before inference (verified against cli-chat-proxy.grok.com 2026-08-21).
92+ // Asserting on the adapter with a hand-built provider cannot catch this — the gap is upstream
93+ // of the adapter, in what the router hands it.
94+ describe ( "routedProviderConfig web_search capability backfill" , ( ) => {
95+ test ( "a saved xai row without the flag is classified by the registry" , ( ) => {
96+ const saved : OcxProviderConfig = {
97+ adapter : "openai-chat" ,
98+ baseUrl : "https://api.x.ai/v1" ,
99+ authMode : "oauth" ,
100+ // The GUI Responses opt-in writes only modelAdapters; it never writes the capability.
101+ modelAdapters : { "grok-4.6" : "openai-responses" } ,
102+ } ;
103+ expect ( saved . supportsOpenAiWebSearchToolFields ) . toBeUndefined ( ) ;
104+
105+ const routed = routedProviderConfig ( "xai" , saved ) ;
106+ expect ( routed . supportsOpenAiWebSearchToolFields ) . toBe ( false ) ;
107+ } ) ;
108+
109+ test ( "the routed row actually strips the fatal fields at the adapter" , ( ) => {
110+ const routed = routedProviderConfig ( "xai" , {
111+ adapter : "openai-chat" ,
112+ baseUrl : "https://api.x.ai/v1" ,
113+ authMode : "oauth" ,
114+ modelAdapters : { "grok-4.6" : "openai-responses" } ,
115+ } ) ;
116+
117+ const body = buildWebSearchBody ( { ...routed , adapter : "openai-responses" } ) ;
118+ expect ( body . tools ) . toEqual ( [ {
119+ type : "web_search" ,
120+ user_location : { type : "approximate" } ,
121+ } ] ) ;
122+ } ) ;
123+
124+ test ( "an explicit saved value still overrides the registry default" , ( ) => {
125+ const routed = routedProviderConfig ( "xai" , {
126+ adapter : "openai-responses" ,
127+ baseUrl : "https://api.x.ai/v1" ,
128+ authMode : "oauth" ,
129+ supportsOpenAiWebSearchToolFields : true ,
130+ } ) ;
131+ expect ( routed . supportsOpenAiWebSearchToolFields ) . toBe ( true ) ;
132+ } ) ;
133+ } ) ;
0 commit comments