48 lines
2.3 KiB
Go
48 lines
2.3 KiB
Go
package configuration
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
"go.maximumdirect.net/configkit"
|
|
)
|
|
|
|
func TestBundledOpenRouterUnderlay(t *testing.T) {
|
|
state, err := Load(configkit.Input{Source: configkit.NoSource()}, []configkit.Underlay{BundledOpenRouterUnderlay()})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
backend, err := state.GetBackend("openrouter")
|
|
if err != nil || backend.Endpoint != "https://openrouter.ai/api/v1" || backend.APIKeyEnv != "OPENROUTER_API_KEY" || backend.SmokeTests == nil || backend.SmokeTests.DefaultProfile == nil || *backend.SmokeTests.DefaultProfile != "gpt-luna-latest" || backend.SmokeTests.Authentication == nil || *backend.SmokeTests.Authentication.Kind != "openrouter_key" {
|
|
t.Fatalf("backend = %+v, %v", backend, err)
|
|
}
|
|
models := map[string]string{
|
|
"gpt-astra-latest": "~openai/gpt-astra-latest", "gpt-sol-latest": "~openai/gpt-sol-latest", "gpt-terra-latest": "~openai/gpt-terra-latest", "gpt-luna-latest": "~openai/gpt-luna-latest",
|
|
"claude-fable-latest": "~anthropic/claude-fable-latest", "claude-opus-latest": "~anthropic/claude-opus-latest", "claude-sonnet-latest": "~anthropic/claude-sonnet-latest", "claude-haiku-latest": "~anthropic/claude-haiku-latest",
|
|
"gemini-pro-latest": "~google/gemini-pro-latest", "gemini-flash-latest": "~google/gemini-flash-latest", "auto": "openrouter/auto", "free": "openrouter/free",
|
|
}
|
|
for _, tier := range []string{"low", "medium", "high", "xhigh", "max"} {
|
|
models["auto-"+tier] = "openrouter/auto"
|
|
}
|
|
if len(state.profileIDs) != len(models) {
|
|
t.Fatalf("profiles = %v", state.profileIDs)
|
|
}
|
|
for id, model := range models {
|
|
profile, err := state.GetProfile(context.Background(), id)
|
|
if err != nil || profile.ResolvedTarget.Model != model || profile.ResolvedTarget.BackendID != "openrouter" {
|
|
t.Fatalf("profile %s = %+v, %v", id, profile, err)
|
|
}
|
|
if tier, ok := strings.CutPrefix(id, "auto-"); ok {
|
|
plugins := fmt.Sprint(profile.ResolvedTarget.ExtraParams)
|
|
if !strings.Contains(plugins, "cost_tier:"+tier) || !strings.Contains(plugins, "id:auto-router") {
|
|
t.Fatalf("profile %s plugins = %+v", id, profile.ResolvedTarget.ExtraParams)
|
|
}
|
|
}
|
|
}
|
|
if !strings.Contains(fmt.Sprint(state.result.Sources()), "Promptkit bundled OpenRouter") {
|
|
t.Fatalf("source evidence = %+v", state.result.Sources())
|
|
}
|
|
}
|