From 3b76824665ff3a3c75c929b63395ef95b912986a Mon Sep 17 00:00:00 2001 From: Rahul Bansal Date: Sun, 1 Mar 2026 22:11:36 +0530 Subject: [PATCH] fix: set ModelName in legacy migration when user specifies provider+model (#958) --- pkg/config/migration.go | 1 + pkg/config/migration_test.go | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/pkg/config/migration.go b/pkg/config/migration.go index 5deb09270..526242ebb 100644 --- a/pkg/config/migration.go +++ b/pkg/config/migration.go @@ -368,6 +368,7 @@ func ConvertProvidersToModelList(cfg *Config) []ModelConfig { // Check if this is the user's configured provider if slices.Contains(m.providerNames, userProvider) && userModel != "" { // Use the user's configured model instead of default + mc.ModelName = userModel mc.Model = buildModelWithProtocol(m.protocol, userModel) } else if userProvider == "" && userModel != "" && !legacyModelNameApplied { // Legacy config: no explicit provider field but model is specified diff --git a/pkg/config/migration_test.go b/pkg/config/migration_test.go index db8f4657d..192747625 100644 --- a/pkg/config/migration_test.go +++ b/pkg/config/migration_test.go @@ -581,3 +581,42 @@ func TestConvertProvidersToModelList_LegacyModelWithProtocolPrefix(t *testing.T) t.Errorf("Model = %q, want %q (should not duplicate prefix)", result[0].Model, "openrouter/auto") } } + +func TestConvertProvidersToModelList_UserModelWithProvider(t *testing.T) { + cfg := &Config{ + Agents: AgentsConfig{ + Defaults: AgentDefaults{ + Provider: "ollama", + Model: "llama3.2", + }, + }, + Providers: ProvidersConfig{ + Ollama: ProviderConfig{ + APIBase: "http://localhost:11434/v1", + }, + }, + } + + result := ConvertProvidersToModelList(cfg) + + // Find the ollama entry + var found *ModelConfig + for i := range result { + if strings.Contains(result[i].Model, "ollama/") { + found = &result[i] + break + } + } + + if found == nil { + t.Fatalf("expected an ollama entry in result, got %d entries: %+v", len(result), result) + } + + if found.ModelName != "llama3.2" { + t.Errorf("ModelName = %q, want %q", found.ModelName, "llama3.2") + } + + if found.Model != "ollama/llama3.2" { + t.Errorf("Model = %q, want %q", found.Model, "ollama/llama3.2") + } +}