fix: set ModelName in legacy migration when user specifies provider+model (#958)

This commit is contained in:
Rahul Bansal 2026-03-01 22:11:36 +05:30
parent 3926585786
commit 3b76824665
2 changed files with 40 additions and 0 deletions

View file

@ -368,6 +368,7 @@ func ConvertProvidersToModelList(cfg *Config) []ModelConfig {
// Check if this is the user's configured provider // Check if this is the user's configured provider
if slices.Contains(m.providerNames, userProvider) && userModel != "" { if slices.Contains(m.providerNames, userProvider) && userModel != "" {
// Use the user's configured model instead of default // Use the user's configured model instead of default
mc.ModelName = userModel
mc.Model = buildModelWithProtocol(m.protocol, userModel) mc.Model = buildModelWithProtocol(m.protocol, userModel)
} else if userProvider == "" && userModel != "" && !legacyModelNameApplied { } else if userProvider == "" && userModel != "" && !legacyModelNameApplied {
// Legacy config: no explicit provider field but model is specified // Legacy config: no explicit provider field but model is specified

View file

@ -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") 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")
}
}