167 lines
4.5 KiB
Go
167 lines
4.5 KiB
Go
package edgevalidate
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"iop/packages/go/config"
|
|
)
|
|
|
|
func TestValidateEdgeConfigProviderAdapterReferences(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
node config.NodeDefinition
|
|
wantErr string
|
|
}{
|
|
{
|
|
name: "valid exact openai compat instance",
|
|
node: config.NodeDefinition{
|
|
ID: "node-1",
|
|
Token: "tok",
|
|
Adapters: config.AdaptersConf{
|
|
OpenAICompatInstances: []config.OpenAICompatInstanceConf{
|
|
{Name: "vllm-gpu", Enabled: true, Endpoint: "http://127.0.0.1:8000/v1"},
|
|
},
|
|
},
|
|
Providers: []config.NodeProviderConf{
|
|
{ID: "prov-vllm", Type: "vllm", Category: config.CategoryAPI, Adapter: "vllm-gpu"},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "valid single type route",
|
|
node: config.NodeDefinition{
|
|
ID: "node-1",
|
|
Token: "tok",
|
|
Adapters: config.AdaptersConf{
|
|
OpenAICompatInstances: []config.OpenAICompatInstanceConf{
|
|
{Name: "vllm-gpu", Enabled: true, Endpoint: "http://127.0.0.1:8000/v1"},
|
|
},
|
|
},
|
|
Providers: []config.NodeProviderConf{
|
|
{ID: "prov-vllm", Type: "vllm", Category: config.CategoryAPI, Adapter: "openai_compat"},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "missing adapter rejected",
|
|
node: config.NodeDefinition{
|
|
ID: "node-1",
|
|
Token: "tok",
|
|
Adapters: config.AdaptersConf{
|
|
CLI: config.CLIConf{Enabled: true},
|
|
},
|
|
Providers: []config.NodeProviderConf{
|
|
{ID: "prov-vllm", Type: "vllm", Category: config.CategoryAPI, Adapter: "missing"},
|
|
},
|
|
},
|
|
wantErr: "does not resolve",
|
|
},
|
|
{
|
|
name: "disabled instance rejected",
|
|
node: config.NodeDefinition{
|
|
ID: "node-1",
|
|
Token: "tok",
|
|
Adapters: config.AdaptersConf{
|
|
CLI: config.CLIConf{Enabled: true},
|
|
OpenAICompatInstances: []config.OpenAICompatInstanceConf{
|
|
{Name: "vllm-gpu", Enabled: false, Endpoint: "http://127.0.0.1:8000/v1"},
|
|
},
|
|
},
|
|
Providers: []config.NodeProviderConf{
|
|
{ID: "prov-vllm", Type: "vllm", Category: config.CategoryAPI, Adapter: "vllm-gpu"},
|
|
},
|
|
},
|
|
wantErr: "does not resolve",
|
|
},
|
|
{
|
|
name: "ambiguous type route rejected",
|
|
node: config.NodeDefinition{
|
|
ID: "node-1",
|
|
Token: "tok",
|
|
Adapters: config.AdaptersConf{
|
|
OpenAICompatInstances: []config.OpenAICompatInstanceConf{
|
|
{Name: "vllm-a", Enabled: true, Endpoint: "http://127.0.0.1:8000/v1"},
|
|
{Name: "vllm-b", Enabled: true, Endpoint: "http://127.0.0.1:8001/v1"},
|
|
},
|
|
},
|
|
Providers: []config.NodeProviderConf{
|
|
{ID: "prov-vllm", Type: "vllm", Category: config.CategoryAPI, Adapter: "openai_compat"},
|
|
},
|
|
},
|
|
wantErr: "ambiguous",
|
|
},
|
|
{
|
|
name: "cli resource requires enabled cli",
|
|
node: config.NodeDefinition{
|
|
ID: "node-1",
|
|
Token: "tok",
|
|
Adapters: config.AdaptersConf{
|
|
OllamaInstances: []config.OllamaInstanceConf{
|
|
{Name: "ollama-local", Enabled: true, BaseURL: "http://127.0.0.1:11434"},
|
|
},
|
|
},
|
|
Providers: []config.NodeProviderConf{
|
|
{ID: "cli-codex", Type: "cli", Category: config.CategoryCLI, Adapter: "cli"},
|
|
},
|
|
},
|
|
wantErr: "category cli requires enabled cli adapter",
|
|
},
|
|
{
|
|
name: "valid cli resource",
|
|
node: config.NodeDefinition{
|
|
ID: "node-1",
|
|
Token: "tok",
|
|
Adapters: config.AdaptersConf{
|
|
CLI: config.CLIConf{Enabled: true},
|
|
},
|
|
Providers: []config.NodeProviderConf{
|
|
{ID: "cli-codex", Type: "cli", Category: config.CategoryCLI, Adapter: "cli"},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
err := ValidateEdgeConfig(&config.EdgeConfig{Nodes: []config.NodeDefinition{tc.node}})
|
|
if tc.wantErr == "" {
|
|
if err != nil {
|
|
t.Fatalf("ValidateEdgeConfig: %v", err)
|
|
}
|
|
return
|
|
}
|
|
if err == nil {
|
|
t.Fatalf("expected error containing %q", tc.wantErr)
|
|
}
|
|
if !strings.Contains(err.Error(), tc.wantErr) {
|
|
t.Fatalf("expected error containing %q, got %v", tc.wantErr, err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestValidateEdgeConfigProviderAdapterEmptyRejected(t *testing.T) {
|
|
cfg := &config.EdgeConfig{
|
|
Nodes: []config.NodeDefinition{
|
|
{
|
|
ID: "node-1",
|
|
Token: "tok",
|
|
Adapters: config.AdaptersConf{
|
|
CLI: config.CLIConf{Enabled: true},
|
|
},
|
|
Providers: []config.NodeProviderConf{
|
|
{ID: "prov-empty", Type: "cli", Category: config.CategoryCLI, Adapter: " "},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
err := ValidateEdgeConfig(cfg)
|
|
if err == nil {
|
|
t.Fatal("expected empty adapter error")
|
|
}
|
|
if !strings.Contains(err.Error(), "adapter must not be empty") {
|
|
t.Fatalf("expected adapter empty error, got %v", err)
|
|
}
|
|
}
|