@@ -77,12 +77,14 @@ func TestSwitchSessionKeepsCurrentStateOnModelRestoreFailure(t *testing.T) {
7777 Store : current ,
7878 Manager : mgr ,
7979 Settings : config.Resolved {
80- DefaultProvider : "openai" ,
81- DefaultModel : "good-model" ,
82- APIKey : "k" ,
83- ContextWindow : 128000 ,
84- AutoCompaction : false ,
85- MaxTurns : 30 ,
80+ Provider : "openai" ,
81+ Model : "good-model" ,
82+ Providers : map [string ]config.ProviderConfig {
83+ "openai" : {APIKey : "k" },
84+ },
85+ ContextWindow : 128000 ,
86+ AutoCompaction : false ,
87+ MaxTurns : 30 ,
8688 },
8789 Cwd : dir ,
8890 CreateModel : func (_ string , model string , _ string , _ string ) (agentcore.ChatModel , error ) {
@@ -140,12 +142,14 @@ func TestSetModelKeepsStateWhenPersistFails(t *testing.T) {
140142 Store : store ,
141143 Manager : mgr ,
142144 Settings : config.Resolved {
143- DefaultProvider : "openai" ,
144- DefaultModel : "good-model" ,
145- APIKey : "k" ,
146- ContextWindow : 128000 ,
147- AutoCompaction : false ,
148- MaxTurns : 30 ,
145+ Provider : "openai" ,
146+ Model : "good-model" ,
147+ Providers : map [string ]config.ProviderConfig {
148+ "openai" : {APIKey : "k" },
149+ },
150+ ContextWindow : 128000 ,
151+ AutoCompaction : false ,
152+ MaxTurns : 30 ,
149153 },
150154 Cwd : dir ,
151155 CreateModel : func (_ string , _ string , _ string , _ string ) (agentcore.ChatModel , error ) {
@@ -165,7 +169,7 @@ func TestSetModelKeepsStateWhenPersistFails(t *testing.T) {
165169 oldProvider := s .Provider ()
166170 oldModel := s .ModelName ()
167171
168- err = s .SetModel ("openai" , "new-model" , "k" )
172+ err = s .SetModel ("openai" , "new-model" )
169173 if err == nil {
170174 t .Fatalf ("expected set model failure" )
171175 }
@@ -280,49 +284,45 @@ func TestRestoreAllToolsRebuildsPrompt(t *testing.T) {
280284 }
281285}
282286
283- func TestResolveCredentialsDefaultProvider (t * testing.T ) {
287+ func TestResolveCredentialsPerProvider (t * testing.T ) {
284288 t .Parallel ()
285289 ag := agentcore .NewAgent (agentcore .WithModel (& stubChatModel {}))
286290 s := NewSession (SessionConfig {
287291 Agent : ag ,
288292 Settings : config.Resolved {
289- DefaultProvider : "openai" ,
290- APIKey : "openai-key" ,
291- BaseURL : "https://openai.example.com" ,
293+ Provider : "openai" ,
294+ Model : "gpt-5" ,
295+ Providers : map [string ]config.ProviderConfig {
296+ "openai" : {APIKey : "openai-key" , BaseURL : "https://openai.example.com" },
297+ "anthropic" : {APIKey : "ant-key" },
298+ },
292299 },
293300 Cwd : t .TempDir (),
294301 })
295302 t .Cleanup (s .Close )
296303
304+ // Default provider
297305 apiKey , baseURL := s .resolveCredentials ("openai" )
298306 if apiKey != "openai-key" {
299307 t .Fatalf ("expected openai-key, got %s" , apiKey )
300308 }
301309 if baseURL != "https://openai.example.com" {
302310 t .Fatalf ("expected https://openai.example.com, got %s" , baseURL )
303311 }
304- }
305312
306- func TestResolveCredentialsCrossProviderUsesMainCredentials (t * testing.T ) {
307- t .Parallel ()
308- ag := agentcore .NewAgent (agentcore .WithModel (& stubChatModel {}))
309- s := NewSession (SessionConfig {
310- Agent : ag ,
311- Settings : config.Resolved {
312- DefaultProvider : "openai" ,
313- APIKey : "openai-key" ,
314- BaseURL : "https://openai.example.com" ,
315- },
316- Cwd : t .TempDir (),
317- })
318- t .Cleanup (s .Close )
319-
320- apiKey , baseURL := s .resolveCredentials ("anthropic" )
321- if apiKey != "openai-key" {
322- t .Fatalf ("expected openai-key, got %s" , apiKey )
313+ // Cross-provider resolves its own credentials
314+ apiKey , baseURL = s .resolveCredentials ("anthropic" )
315+ if apiKey != "ant-key" {
316+ t .Fatalf ("expected ant-key, got %s" , apiKey )
323317 }
324- if baseURL != "https://openai.example.com" {
325- t .Fatalf ("expected https://openai.example.com, got %s" , baseURL )
318+ if baseURL != "" {
319+ t .Fatalf ("expected empty baseURL for anthropic, got %s" , baseURL )
320+ }
321+
322+ // Unknown provider returns empty
323+ apiKey , baseURL = s .resolveCredentials ("unknown" )
324+ if apiKey != "" || baseURL != "" {
325+ t .Fatalf ("expected empty for unknown provider, got %s/%s" , apiKey , baseURL )
326326 }
327327}
328328
@@ -355,12 +355,14 @@ func TestSwitchSessionCrossProviderCredentials(t *testing.T) {
355355 Store : current ,
356356 Manager : mgr ,
357357 Settings : config.Resolved {
358- DefaultProvider : "openai" ,
359- DefaultModel : "gpt-5" ,
360- APIKey : "openai-key" ,
361- BaseURL : "https://openai.example.com" ,
362- ContextWindow : 128000 ,
363- MaxTurns : 30 ,
358+ Provider : "openai" ,
359+ Model : "gpt-5" ,
360+ Providers : map [string ]config.ProviderConfig {
361+ "openai" : {APIKey : "openai-key" , BaseURL : "https://openai.example.com" },
362+ "anthropic" : {APIKey : "ant-key" },
363+ },
364+ ContextWindow : 128000 ,
365+ MaxTurns : 30 ,
364366 },
365367 Cwd : dir ,
366368 CreateModel : func (_ , _ string , apiKey , baseURL string ) (agentcore.ChatModel , error ) {
@@ -375,18 +377,12 @@ func TestSwitchSessionCrossProviderCredentials(t *testing.T) {
375377 t .Fatalf ("switch session: %v" , err )
376378 }
377379
378- // Cross-provider uses the same credentials from settings.
379- if capturedKey != "openai-key" {
380- t .Fatalf ("expected CreateModel to receive openai-key, got %s" , capturedKey )
381- }
382- if capturedBase != "https://openai.example.com" {
383- t .Fatalf ("expected https://openai.example.com, got %s" , capturedBase )
384- }
385- if s .APIKey () != "openai-key" {
386- t .Fatalf ("expected session apiKey=openai-key, got %s" , s .APIKey ())
380+ // Cross-provider uses anthropic's own credentials.
381+ if capturedKey != "ant-key" {
382+ t .Fatalf ("expected CreateModel to receive ant-key, got %s" , capturedKey )
387383 }
388- if s . BaseURL () != "https://openai.example.com " {
389- t .Fatalf ("expected session baseURL=https://openai.example.com , got %s" , s . BaseURL () )
384+ if capturedBase != "" {
385+ t .Fatalf ("expected empty baseURL for anthropic , got %s" , capturedBase )
390386 }
391387}
392388
0 commit comments