@@ -208,6 +208,72 @@ describe("OpenAiNativeHandler", () => {
208208 } )
209209
210210 describe ( "GPT-5 models" , ( ) => {
211+ it ( "should map gpt-5-codex to gpt-5-2025-08-07" , ( ) => {
212+ const handler = new OpenAiNativeHandler ( {
213+ ...mockOptions ,
214+ apiModelId : "gpt-5-codex" ,
215+ } )
216+
217+ const model = handler . getModel ( )
218+ // Verify that gpt-5-codex is mapped to gpt-5-2025-08-07
219+ expect ( model . id ) . toBe ( "gpt-5-2025-08-07" )
220+ // Verify it has the correct model info from gpt-5-codex
221+ expect ( model . info . description ) . toBe ( "GPT-5-Codex: A version of GPT-5 optimized for agentic coding in Codex" )
222+ expect ( model . info . supportsVerbosity ) . toBe ( true )
223+ expect ( model . info . supportsTemperature ) . toBe ( false )
224+ } )
225+
226+ it ( "should handle gpt-5-codex streaming with Responses API" , async ( ) => {
227+ // Mock fetch for Responses API
228+ const mockFetch = vitest . fn ( ) . mockResolvedValue ( {
229+ ok : true ,
230+ body : new ReadableStream ( {
231+ start ( controller ) {
232+ controller . enqueue (
233+ new TextEncoder ( ) . encode (
234+ 'data: {"type":"response.output_item.added","item":{"type":"text","text":"Codex response"}}\n\n' ,
235+ ) ,
236+ )
237+ controller . enqueue (
238+ new TextEncoder ( ) . encode (
239+ 'data: {"type":"response.done","response":{"usage":{"prompt_tokens":10,"completion_tokens":2}}}\n\n' ,
240+ ) ,
241+ )
242+ controller . enqueue ( new TextEncoder ( ) . encode ( "data: [DONE]\n\n" ) )
243+ controller . close ( )
244+ } ,
245+ } ) ,
246+ } )
247+ global . fetch = mockFetch as any
248+
249+ // Mock SDK to fail so it uses fetch
250+ mockResponsesCreate . mockRejectedValue ( new Error ( "SDK not available" ) )
251+
252+ handler = new OpenAiNativeHandler ( {
253+ ...mockOptions ,
254+ apiModelId : "gpt-5-codex" ,
255+ } )
256+
257+ const stream = handler . createMessage ( systemPrompt , messages )
258+ const chunks : any [ ] = [ ]
259+ for await ( const chunk of stream ) {
260+ chunks . push ( chunk )
261+ }
262+
263+ // Verify the request uses the mapped model ID
264+ expect ( mockFetch ) . toHaveBeenCalledWith (
265+ "https://api.openai.com/v1/responses" ,
266+ expect . objectContaining ( {
267+ body : expect . stringContaining ( '"model":"gpt-5-2025-08-07"' ) ,
268+ } ) ,
269+ )
270+
271+ // Verify the response content
272+ const textChunks = chunks . filter ( ( c ) => c . type === "text" )
273+ expect ( textChunks ) . toHaveLength ( 1 )
274+ expect ( textChunks [ 0 ] . text ) . toBe ( "Codex response" )
275+ } )
276+
211277 it ( "should handle GPT-5 model with Responses API" , async ( ) => {
212278 // Mock fetch for Responses API
213279 const mockFetch = vitest . fn ( ) . mockResolvedValue ( {
0 commit comments