@@ -3,6 +3,7 @@ import * as os from "node:os";
33import * as path from "node:path" ;
44import type { AgentSideConnection } from "@agentclientprotocol/sdk" ;
55import { afterAll , beforeEach , describe , expect , it , vi } from "vitest" ;
6+ import { DEFAULT_GATEWAY_MODEL } from "../../gateway-models" ;
67
78type SdkQueryHandle = {
89 interrupt : ReturnType < typeof vi . fn > ;
@@ -153,18 +154,43 @@ describe("ClaudeAcpAgent session model on resume", () => {
153154 } ,
154155 ) ;
155156
156- it ( "does not call setModel for a new session on the default model" , async ( ) => {
157+ // New sessions pass the model to the SDK at spawn, never via setModel. The
158+ // Codex-model row guards the desync that surfaced as "picked gpt-5.5, session
159+ // ran Opus": a non-Anthropic id on the Claude adapter must fall back to the
160+ // default AND warn rather than silently masquerade as a deliberate Opus run.
161+ it . each ( [
162+ {
163+ name : "uses the gateway default and never calls setModel without a requested model" ,
164+ model : undefined ,
165+ expectsWarn : false ,
166+ } ,
167+ {
168+ name : "warns and falls back to the default when a Codex model reaches the Claude adapter" ,
169+ model : "gpt-5.5" ,
170+ expectsWarn : true ,
171+ } ,
172+ ] ) ( "newSession $name" , async ( { model, expectsWarn } ) => {
157173 const agent = makeAgent ( ) ;
174+ const warnSpy = vi . spyOn ( agent . logger , "warn" ) ;
158175
159- await agent . newSession ( {
176+ const response = await agent . newSession ( {
160177 cwd,
161178 mcpServers : [ ] ,
162- _meta : { taskRunId : "run-3" } ,
179+ _meta : { taskRunId : "run-new" , ... ( model ? { model } : { } ) } ,
163180 } ) ;
164181
165- // New sessions already pass options.model to the SDK at spawn.
166- expect ( createdQueries ) . toHaveLength ( 1 ) ;
167182 expect ( createdQueries [ 0 ] . setModel ) . not . toHaveBeenCalled ( ) ;
183+ expect ( getModelConfigOption ( response ) ?. currentValue ) . toBe (
184+ DEFAULT_GATEWAY_MODEL ,
185+ ) ;
186+ if ( expectsWarn ) {
187+ expect ( warnSpy ) . toHaveBeenCalledWith (
188+ expect . stringContaining ( "Non-Anthropic model" ) ,
189+ expect . objectContaining ( { requestedModel : model } ) ,
190+ ) ;
191+ } else {
192+ expect ( warnSpy ) . not . toHaveBeenCalled ( ) ;
193+ }
168194 } ) ;
169195
170196 // The timeout *message* (RequestError "... timed out after ...") is covered
0 commit comments