11import { waitForNativeMainStartupGate } from "../src/codex/native-profile-startup" ;
2- import { afterEach , beforeEach , expect , test } from "bun:test" ;
2+ import { afterEach , beforeEach , describe , expect , test } from "bun:test" ;
33import { mkdtempSync , rmSync , writeFileSync } from "node:fs" ;
44import { tmpdir } from "node:os" ;
55import { join } from "node:path" ;
@@ -10,6 +10,7 @@ import type { OcxConfig, OcxProviderConfig } from "../src/types";
1010import { installIsolatedCodexHome , type IsolatedCodexHome } from "./helpers/isolated-codex-home" ;
1111import { chatCompletionsToResponsesBody , ChatCompletionsRequestError } from "../src/chat/inbound" ;
1212import { chatCompletionsUsage } from "../src/chat/outbound" ;
13+ import { parseRequest } from "../src/responses/parser" ;
1314import { createTestTranslatorBudget } from "./helpers/translator-budget" ;
1415import type { TranslatorBudget } from "../src/lib/translator-budget" ;
1516import {
@@ -218,7 +219,7 @@ test("chatCompletionsToResponsesBody maps messages/tools/system", () => {
218219 expect ( body . stream ) . toBe ( true ) ;
219220 expect ( body . instructions ) . toBe ( "be brief" ) ;
220221 expect ( body . max_output_tokens ) . toBe ( 64 ) ;
221- expect ( body . reasoning ) . toEqual ( { effort : "high" } ) ;
222+ expect ( body . reasoning ) . toEqual ( { effort : "high" , summary : "auto" } ) ;
222223 expect ( body . tool_choice ) . toBe ( "auto" ) ;
223224 expect ( Array . isArray ( body . tools ) ) . toBe ( true ) ;
224225 expect ( ( body . tools as Array < Record < string , unknown > > ) [ 0 ] ) . toMatchObject ( { type : "function" , name : "lookup" } ) ;
@@ -228,6 +229,59 @@ test("chatCompletionsToResponsesBody maps messages/tools/system", () => {
228229 expect ( input . some ( i => i . type === "function_call_output" && i . call_id === "call_1" ) ) . toBe ( true ) ;
229230} ) ;
230231
232+ describe ( "chatCompletionsToResponsesBody reasoning summary" , ( ) => {
233+ test ( "defaults summary to auto when the client only sent reasoning_effort" , ( ) => {
234+ const body = chatCompletionsToResponsesBody ( {
235+ model : "opencode-go/deepseek-v4-flash" ,
236+ messages : [ { role : "user" , content : "What is 17*19?" } ] ,
237+ reasoning_effort : "max" ,
238+ } ) ;
239+ expect ( body . reasoning ) . toEqual ( { effort : "max" , summary : "auto" } ) ;
240+ const parsed = parseRequest ( body ) ;
241+ expect ( parsed . options . hideThinkingSummary ) . not . toBe ( true ) ;
242+ expect ( parsed . options . reasoning ) . toBe ( "max" ) ;
243+ } ) ;
244+
245+ test ( "preserves an explicit reasoning.summary" , ( ) => {
246+ const body = chatCompletionsToResponsesBody ( {
247+ model : "mock/test-model" ,
248+ messages : [ { role : "user" , content : "hi" } ] ,
249+ reasoning : { effort : "high" , summary : "concise" } ,
250+ } ) ;
251+ expect ( body . reasoning ) . toEqual ( { effort : "high" , summary : "concise" } ) ;
252+ } ) ;
253+
254+ test ( "include_reasoning false hides thinking even when effort is set" , ( ) => {
255+ const body = chatCompletionsToResponsesBody ( {
256+ model : "mock/test-model" ,
257+ messages : [ { role : "user" , content : "hi" } ] ,
258+ reasoning_effort : "high" ,
259+ include_reasoning : false ,
260+ } ) ;
261+ expect ( body . reasoning ) . toEqual ( { effort : "high" , summary : "none" } ) ;
262+ expect ( parseRequest ( body ) . options . hideThinkingSummary ) . toBe ( true ) ;
263+ } ) ;
264+
265+ test ( "include_reasoning true requests a visible summary without an effort" , ( ) => {
266+ const body = chatCompletionsToResponsesBody ( {
267+ model : "mock/test-model" ,
268+ messages : [ { role : "user" , content : "hi" } ] ,
269+ include_reasoning : true ,
270+ } ) ;
271+ expect ( body . reasoning ) . toEqual ( { summary : "auto" } ) ;
272+ expect ( parseRequest ( body ) . options . hideThinkingSummary ) . not . toBe ( true ) ;
273+ } ) ;
274+
275+ test ( "omits reasoning when the client sent no reasoning knobs" , ( ) => {
276+ const body = chatCompletionsToResponsesBody ( {
277+ model : "mock/test-model" ,
278+ messages : [ { role : "user" , content : "hi" } ] ,
279+ } ) ;
280+ expect ( body . reasoning ) . toBeUndefined ( ) ;
281+ expect ( parseRequest ( body ) . options . hideThinkingSummary ) . toBe ( true ) ;
282+ } ) ;
283+ } ) ;
284+
231285test ( "chatCompletionsToResponsesBody rejects missing model" , ( ) => {
232286 expect ( ( ) => chatCompletionsToResponsesBody ( { messages : [ { role : "user" , content : "x" } ] } ) )
233287 . toThrow ( ChatCompletionsRequestError ) ;
0 commit comments