diff --git a/pkg/config/migration.go b/pkg/config/migration.go index c7fc214d5..a9fc86874 100644 --- a/pkg/config/migration.go +++ b/pkg/config/migration.go @@ -453,6 +453,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 1b6e5b032..3ecf57941 100644 --- a/pkg/config/migration_test.go +++ b/pkg/config/migration_test.go @@ -283,6 +283,10 @@ func TestConvertProvidersToModelList_PreservesUserModel_OpenAI(t *testing.T) { t.Fatalf("len(result) = %d, want 1", len(result)) } + if result[0].ModelName != "gpt-4-turbo" { + t.Errorf("ModelName = %q, want %q", result[0].ModelName, "gpt-4-turbo") + } + if result[0].Model != "openai/gpt-4-turbo" { t.Errorf("Model = %q, want %q", result[0].Model, "openai/gpt-4-turbo") } @@ -331,11 +335,43 @@ func TestConvertProvidersToModelList_PreservesUserModel_Qwen(t *testing.T) { t.Fatalf("len(result) = %d, want 1", len(result)) } + if result[0].ModelName != "qwen-plus" { + t.Errorf("ModelName = %q, want %q", result[0].ModelName, "qwen-plus") + } + if result[0].Model != "qwen/qwen-plus" { t.Errorf("Model = %q, want %q", result[0].Model, "qwen/qwen-plus") } } +func TestConvertProvidersToModelList_PreservesUserModelName_Ollama(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) + + if len(result) != 1 { + t.Fatalf("len(result) = %d, want 1", len(result)) + } + if result[0].ModelName != "llama3.2" { + t.Fatalf("ModelName = %q, want %q", result[0].ModelName, "llama3.2") + } + if result[0].Model != "ollama/llama3.2" { + t.Fatalf("Model = %q, want %q", result[0].Model, "ollama/llama3.2") + } +} + func TestConvertProvidersToModelList_UsesDefaultWhenNoUserModel(t *testing.T) { cfg := &Config{ Agents: AgentsConfig{ diff --git a/pkg/providers/factory_test.go b/pkg/providers/factory_test.go index 91469f25b..fb5fc4fec 100644 --- a/pkg/providers/factory_test.go +++ b/pkg/providers/factory_test.go @@ -344,6 +344,24 @@ func TestCreateProviderReturnsClaudeProviderForAnthropicOAuth(t *testing.T) { // TODO: Test custom APIBase when createClaudeAuthProvider supports it } +func TestCreateProvider_LegacyOllamaProviderUsesUserModelAlias(t *testing.T) { + cfg := config.DefaultConfig() + cfg.Agents.Defaults.Provider = "ollama" + cfg.Agents.Defaults.Model = "llama3.2" + cfg.Providers.Ollama.APIBase = "http://localhost:11434/v1" + + provider, modelID, err := CreateProvider(cfg) + if err != nil { + t.Fatalf("CreateProvider() error = %v", err) + } + if provider == nil { + t.Fatal("CreateProvider() returned nil provider") + } + if modelID != "llama3.2" { + t.Fatalf("modelID = %q, want %q", modelID, "llama3.2") + } +} + func TestCreateProviderReturnsCodexProviderForOpenAIOAuth(t *testing.T) { // TODO: This test requires openai protocol to support auth_method: "oauth" // which is not yet implemented in the new factory_provider.go