@@ -11,10 +11,107 @@ const createResponsesPassthroughAdapter = (...args: Parameters<typeof createResp
1111
1212const provider = {
1313 adapter : "openai-responses" ,
14- baseUrl : "https://chatgpt.example /backend-api/codex" ,
14+ baseUrl : "https://chatgpt.com /backend-api/codex" ,
1515 authMode : "forward" as const ,
1616} ;
1717
18+ test ( "noncanonical forward providers cannot receive caller or runtime credentials" , ( ) => {
19+ const userInfoUrl = new URL ( "https://chatgpt.com/backend-api/codex" ) ;
20+ userInfoUrl . username = "user" ;
21+ userInfoUrl . password = "secret" ;
22+ for ( const baseUrl of [
23+ "https://provider.example/v1/" ,
24+ "https://chatgpt.com/backend-api/not-codex" ,
25+ "https://chatgpt.example/backend-api/codex" ,
26+ "https://chatgpt.com/backend-api/codex?target=custom" ,
27+ "https://chatgpt.com/backend-api/codex#custom" ,
28+ userInfoUrl . toString ( ) ,
29+ ] ) {
30+ const adapter = createResponsesPassthroughAdapter ( {
31+ adapter : "openai-responses" ,
32+ baseUrl,
33+ authMode : "forward" ,
34+ headers : { "x-provider-option" : "enabled" } ,
35+ _codexAccountRequired : true ,
36+ _codexAccountOverride : {
37+ accessToken : "runtime-secret" ,
38+ chatgptAccountId : "runtime-account" ,
39+ } ,
40+ } as Parameters < typeof createResponsesPassthroughAdapter > [ 0 ] ) ;
41+ const request = adapter . buildRequest ( {
42+ modelId : "test-model" ,
43+ context : { messages : [ ] } ,
44+ stream : true ,
45+ options : { } ,
46+ _rawBody : { model : "test-model" , input : "ping" } ,
47+ } , {
48+ headers : new Headers ( {
49+ authorization : "Bearer caller-secret" ,
50+ "chatgpt-account-id" : "caller-account" ,
51+ session_id : "caller-session" ,
52+ } ) ,
53+ } ) ;
54+
55+ expect ( request . url ) . toBe ( `${ baseUrl . replace ( / \/ + $ / , "" ) } /responses` ) ;
56+ expect ( request . headers [ "x-provider-option" ] ) . toBe ( "enabled" ) ;
57+ expect ( request . headers . authorization ) . toBeUndefined ( ) ;
58+ expect ( request . headers [ "chatgpt-account-id" ] ) . toBeUndefined ( ) ;
59+ expect ( request . headers . session_id ) . toBeUndefined ( ) ;
60+ }
61+ } ) ;
62+
63+ test ( "canonical forward providers normalize trailing slashes and let the pool override win" , ( ) => {
64+ const adapter = createResponsesPassthroughAdapter ( {
65+ ...provider ,
66+ baseUrl : "https://chatgpt.com/backend-api/codex///" ,
67+ _codexAccountRequired : true ,
68+ _codexAccountOverride : {
69+ accessToken : "runtime-secret" ,
70+ chatgptAccountId : "runtime-account" ,
71+ } ,
72+ } as Parameters < typeof createResponsesPassthroughAdapter > [ 0 ] ) ;
73+ const request = adapter . buildRequest ( {
74+ modelId : "test-model" ,
75+ context : { messages : [ ] } ,
76+ stream : true ,
77+ options : { } ,
78+ _rawBody : { model : "test-model" , input : "ping" } ,
79+ } , { headers : new Headers ( { authorization : "Bearer caller-secret" } ) } ) ;
80+
81+ expect ( request . url ) . toBe ( "https://chatgpt.com/backend-api/codex/responses" ) ;
82+ expect ( request . headers . authorization ) . toBe ( "Bearer runtime-secret" ) ;
83+ expect ( request . headers [ "chatgpt-account-id" ] ) . toBe ( "runtime-account" ) ;
84+ } ) ;
85+
86+ test ( "noncanonical pool-required providers use only their configured static credentials" , ( ) => {
87+ const adapter = createResponsesPassthroughAdapter ( {
88+ adapter : "openai-responses" ,
89+ baseUrl : "https://provider.example/v1/" ,
90+ authMode : "forward" ,
91+ headers : { authorization : "Bearer provider-static" , "x-provider-option" : "enabled" } ,
92+ _codexAccountRequired : true ,
93+ } as Parameters < typeof createResponsesPassthroughAdapter > [ 0 ] ) ;
94+ const request = adapter . buildRequest ( {
95+ modelId : "test-model" ,
96+ context : { messages : [ ] } ,
97+ stream : true ,
98+ options : { } ,
99+ _rawBody : { model : "test-model" , input : "ping" } ,
100+ } , {
101+ headers : new Headers ( {
102+ authorization : "Bearer caller-secret" ,
103+ "chatgpt-account-id" : "caller-account" ,
104+ session_id : "caller-session" ,
105+ } ) ,
106+ } ) ;
107+
108+ expect ( request . url ) . toBe ( "https://provider.example/v1/responses" ) ;
109+ expect ( request . headers [ "x-provider-option" ] ) . toBe ( "enabled" ) ;
110+ expect ( request . headers . authorization ) . toBe ( "Bearer provider-static" ) ;
111+ expect ( request . headers [ "chatgpt-account-id" ] ) . toBeUndefined ( ) ;
112+ expect ( request . headers . session_id ) . toBeUndefined ( ) ;
113+ } ) ;
114+
18115test ( "passthrough serialized-body observation releases after the request settles" , ( ) => {
19116 const budget = createTranslatorBudget ( ) ;
20117 const request = createResponsesPassthroughAdapter ( provider ) . buildRequest ( {
0 commit comments