Introduce support for per-command model defaults in config.toml, overriding global default if set. Update GetModel to accept command name and prioritize: flag > command default > global default. Add example config file and adjust all commands to pass their name. Update tests accordingly.
101 lines
2.0 KiB
Go
101 lines
2.0 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func TestGetModel(t *testing.T) {
|
|
// Reset viper for testing
|
|
viper.Reset()
|
|
viper.SetDefault("default_model", "grok-4")
|
|
|
|
tests := []struct {
|
|
name string
|
|
flagModel string
|
|
expected string
|
|
}{
|
|
{
|
|
name: "returns flag model when provided",
|
|
flagModel: "grok-beta",
|
|
expected: "grok-beta",
|
|
},
|
|
{
|
|
name: "returns default when flag empty",
|
|
flagModel: "",
|
|
expected: "grok-4",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := GetModel("", tt.flagModel)
|
|
if result != tt.expected {
|
|
t.Errorf("GetModel(%q) = %q, want %q", tt.flagModel, result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetModelWithAlias(t *testing.T) {
|
|
viper.Reset()
|
|
viper.Set("aliases.beta", "grok-beta-2")
|
|
viper.SetDefault("default_model", "grok-4")
|
|
|
|
result := GetModel("", "beta")
|
|
expected := "grok-beta-2"
|
|
if result != expected {
|
|
t.Errorf("GetModel('beta') = %q, want %q", result, expected)
|
|
|
|
}
|
|
}
|
|
|
|
func TestGetCommandModel(t *testing.T) {
|
|
viper.Reset()
|
|
viper.SetDefault("default_model", "grok-4")
|
|
viper.Set("commands.lint.model", "grok-4-1-fast-non-reasoning")
|
|
viper.Set("commands.other.model", "grok-other")
|
|
|
|
tests := []struct {
|
|
command string
|
|
flagModel string
|
|
expected string
|
|
}{
|
|
{
|
|
command: "lint",
|
|
flagModel: "",
|
|
expected: "grok-4-1-fast-non-reasoning",
|
|
},
|
|
{
|
|
command: "lint",
|
|
flagModel: "override",
|
|
expected: "override",
|
|
},
|
|
{
|
|
command: "other",
|
|
flagModel: "",
|
|
expected: "grok-other",
|
|
},
|
|
{
|
|
command: "unknown",
|
|
flagModel: "",
|
|
expected: "grok-4",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.command+"_"+tt.flagModel, func(t *testing.T) {
|
|
result := GetModel(tt.command, tt.flagModel)
|
|
if result != tt.expected {
|
|
t.Errorf("GetModel(%q, %q) = %q, want %q", tt.command, tt.flagModel, result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestLoad(t *testing.T) {
|
|
// Just ensure Load doesn't panic
|
|
Load()
|
|
}
|