11import { describe , expect , test } from "bun:test" ;
22import { createAnthropicAdapter as createAnthropicAdapterProduction } from "../src/adapters/anthropic" ;
33import { parseRequest } from "../src/responses/parser" ;
4+ import { anthropicToResponsesBody } from "../src/claude/inbound" ;
45import type { OcxParsedRequest , OcxProviderConfig } from "../src/types" ;
56import { withTestTranslatorBudget } from "./helpers/translator-budget" ;
67
@@ -136,13 +137,74 @@ describe("anthropic extended-thinking gate", () => {
136137 expect ( b . output_config ) . toBeUndefined ( ) ;
137138 } ) ;
138139
140+ // The adaptive-wire predicate shares the id parse with the #545 disable gate, so a
141+ // slash-carrying id must still pick the ADAPTIVE shape. Getting this wrong sends obsolete
142+ // manual `thinking.enabled` to a model that rejects it — a 400, not a silent truncation.
143+ test . each ( [
144+ "anthropic/claude-sonnet-5" ,
145+ "claude-sonnet-5/variant" ,
146+ "claude-opus-4-8/vendor-suffix" ,
147+ ] ) ( "adaptive-thinking model %s keeps the adaptive wire shape" , async ( modelId ) => {
148+ const b = await bodyOf ( parsed ( "high" , { } , modelId ) ) ;
149+ expect ( b . thinking ) . toEqual ( { type : "adaptive" } ) ;
150+ expect ( b . output_config ) . toEqual ( { effort : "high" } ) ;
151+ } ) ;
152+
139153 test ( "adaptive-thinking model with reasoning 'none' sends no thinking config" , async ( ) => {
140154 const b = await bodyOf ( parsed ( "none" , { temperature : 0.3 } , "claude-fable-5" ) ) ;
141155 expect ( b . thinking ) . toBeUndefined ( ) ;
142156 expect ( b . output_config ) . toBeUndefined ( ) ;
143157 expect ( b . temperature ) . toBe ( 0.3 ) ;
144158 } ) ;
145159
160+ // #545: Claude Desktop's Auto Mode classifier sends thinking:{type:"disabled"} with
161+ // max_tokens:64. Omitting the field lets a default-on model think anyway, and thinking
162+ // shares that 64-token budget — so generation stopped before the stop sequence and the
163+ // client retried. Say "disabled" out loud, but only where the vendor accepts it.
164+ test . each ( [
165+ "claude-sonnet-5" ,
166+ "claude-sonnet-5-20260101" ,
167+ "claude-sonnet-5[1m]" ,
168+ // A modelMap entry can point at a routed destination, which custom-provider routing
169+ // decodes back into a slash-carrying native id. An id-shape miss here is silent: the
170+ // request simply goes out without the disable and the model thinks anyway.
171+ "anthropic/claude-sonnet-5" ,
172+ "openrouter/anthropic/claude-sonnet-5" ,
173+ // The slash can also carry a vendor SUFFIX rather than a routing prefix, so the family
174+ // segment is not reliably first or last. Both directions are real routed shapes.
175+ "claude-sonnet-5/variant" ,
176+ ] ) ( "%s + reasoning 'none' sends an explicit thinking disable (#545)" , async ( modelId ) => {
177+ const b = await bodyOf ( parsed ( "none" , { maxOutputTokens : 64 , stopSequences : [ "</block>" ] } , modelId ) ) ;
178+ expect ( b . thinking ) . toEqual ( { type : "disabled" } ) ;
179+ expect ( b . output_config ) . toBeUndefined ( ) ;
180+ // The caller's own limits must survive untouched — they were never the defect.
181+ expect ( b . max_tokens ) . toBe ( 64 ) ;
182+ expect ( b . stop_sequences ) . toEqual ( [ "</block>" ] ) ;
183+ } ) ;
184+
185+ test ( "Sonnet 5 with reasoning OMITTED still omits thinking (#545)" , async ( ) => {
186+ // Absence is not a disable instruction: only an explicit "none" earns the explicit field.
187+ const b = await bodyOf ( parsed ( undefined , { } , "claude-sonnet-5" ) ) ;
188+ expect ( b . thinking ) . toBeUndefined ( ) ;
189+ } ) ;
190+
191+ test . each ( [
192+ "claude-fable-5" ,
193+ "claude-opus-4-7" ,
194+ "claude-opus-4-8" ,
195+ "claude-haiku-4-5" ,
196+ "claude-sonnet-4-6" ,
197+ "anthropic/claude-fable-5" ,
198+ "claude-fable-5/foo" ,
199+ "not-a-claude-model" ,
200+ ] ) ( "%s + 'none' sends NO explicit disable (#545 gate stays narrow)" , async ( modelId ) => {
201+ // Fable always thinks and rejects an explicit disable; the Opus 4.7/4.8 adaptive wire
202+ // leaves thinking off when omitted. Widening the gate to every adaptive family would
203+ // trade a silent truncation for a 400.
204+ const b = await bodyOf ( parsed ( "none" , { } , modelId ) ) ;
205+ expect ( b . thinking ) . toBeUndefined ( ) ;
206+ } ) ;
207+
146208 test ( "drops reconstructed Responses reasoning signatures when switching into Anthropic" , async ( ) => {
147209 const b = await bodyOf ( parseRequest ( {
148210 model : "anthropic/claude-sonnet-4.5" ,
@@ -169,3 +231,26 @@ describe("anthropic extended-thinking gate", () => {
169231 expect ( messages ) . toEqual ( [ { role : "user" , content : "continue on anthropic" } ] ) ;
170232 } ) ;
171233} ) ;
234+
235+ describe ( "Claude Desktop classifier round trip (#545)" , ( ) => {
236+ test ( "thinking:disabled survives inbound translation to the outbound Anthropic body" , async ( ) => {
237+ // The reporter's exact shape: a permission classifier with a 64-token budget that must
238+ // close its XML tag. Before the fix, "disabled" was dropped at the inbound hop and the
239+ // outbound request omitted `thinking` entirely, so Sonnet 5 thought anyway and spent the
240+ // budget before emitting </block>. Claude Code then retried, up to five times.
241+ const inbound = anthropicToResponsesBody ( {
242+ model : "claude-sonnet-5" ,
243+ max_tokens : 64 ,
244+ stop_sequences : [ "</block>" ] ,
245+ thinking : { type : "disabled" } ,
246+ system : "decide whether this tool call is allowed" ,
247+ messages : [ { role : "user" , content : "<request>ls</request>" } ] ,
248+ } ) ;
249+
250+ const body = await bodyOf ( parseRequest ( inbound ) ) ;
251+
252+ expect ( body . thinking ) . toEqual ( { type : "disabled" } ) ;
253+ expect ( body . max_tokens ) . toBe ( 64 ) ;
254+ expect ( body . stop_sequences ) . toEqual ( [ "</block>" ] ) ;
255+ } ) ;
256+ } ) ;
0 commit comments