73 lines
2.1 KiB
Go
73 lines
2.1 KiB
Go
|
|
package secutools
|
||
|
|
|
||
|
|
import "testing"
|
||
|
|
|
||
|
|
// TestDecideProvider_TableDriven exercises the full decision matrix for
|
||
|
|
// the map-input adapter used by the bash-side ccl-delegate CLI. The
|
||
|
|
// richer Task-struct variant lives in internal/router.
|
||
|
|
func TestDecideProvider_TableDriven(t *testing.T) {
|
||
|
|
cases := []struct {
|
||
|
|
name string
|
||
|
|
fm map[string]any
|
||
|
|
want string
|
||
|
|
}{
|
||
|
|
{"nil map falls back to local", nil, "local"},
|
||
|
|
{"empty map → local (allow_delegation default false)", map[string]any{}, "local"},
|
||
|
|
{"needs_claude_code wins", map[string]any{
|
||
|
|
"needs_claude_code": true,
|
||
|
|
"allow_delegation": true,
|
||
|
|
"preferred_ai": "gpu",
|
||
|
|
}, "local"},
|
||
|
|
{"explicit claude-code stays local", map[string]any{
|
||
|
|
"preferred_ai": "claude-code",
|
||
|
|
"allow_delegation": true,
|
||
|
|
}, "local"},
|
||
|
|
{"allow_delegation=false blocks even with preferred_ai=gpu", map[string]any{
|
||
|
|
"preferred_ai": "gpu",
|
||
|
|
"allow_delegation": false,
|
||
|
|
}, "local"},
|
||
|
|
{"gpu", map[string]any{
|
||
|
|
"preferred_ai": "gpu",
|
||
|
|
"allow_delegation": true,
|
||
|
|
}, "gpu"},
|
||
|
|
{"GPU (case-insensitive)", map[string]any{
|
||
|
|
"preferred_ai": "GPU",
|
||
|
|
"allow_delegation": true,
|
||
|
|
}, "gpu"},
|
||
|
|
{"gemini", map[string]any{
|
||
|
|
"preferred_ai": "gemini",
|
||
|
|
"allow_delegation": true,
|
||
|
|
}, "gemini"},
|
||
|
|
{"claude-api", map[string]any{
|
||
|
|
"preferred_ai": "claude-api",
|
||
|
|
"allow_delegation": true,
|
||
|
|
}, "claude-api"},
|
||
|
|
{"auto", map[string]any{
|
||
|
|
"preferred_ai": "auto",
|
||
|
|
"allow_delegation": true,
|
||
|
|
}, "auto"},
|
||
|
|
{"empty preferred_ai + allow_delegation → auto", map[string]any{
|
||
|
|
"allow_delegation": true,
|
||
|
|
}, "auto"},
|
||
|
|
{"unknown provider → fail-safe local", map[string]any{
|
||
|
|
"preferred_ai": "claude-3-mystery",
|
||
|
|
"allow_delegation": true,
|
||
|
|
}, "local"},
|
||
|
|
{"allow_delegation as string 'true'", map[string]any{
|
||
|
|
"preferred_ai": "gpu",
|
||
|
|
"allow_delegation": "true",
|
||
|
|
}, "gpu"},
|
||
|
|
{"allow_delegation as int 1", map[string]any{
|
||
|
|
"preferred_ai": "gemini",
|
||
|
|
"allow_delegation": 1,
|
||
|
|
}, "gemini"},
|
||
|
|
}
|
||
|
|
for _, c := range cases {
|
||
|
|
t.Run(c.name, func(t *testing.T) {
|
||
|
|
if got := DecideProvider(c.fm); got != c.want {
|
||
|
|
t.Errorf("DecideProvider(%v) = %q, want %q", c.fm, got, c.want)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|