vibe-proxy/backend/sdk/cliproxy/service_models_config_index_test.go
2026-08-24 00:10:41 +02:00

41 lines
1.6 KiB
Go

package cliproxy
import (
"testing"
"github.com/router-for-me/CLIProxyAPI/v7/internal/config"
coreauth "github.com/router-for-me/CLIProxyAPI/v7/sdk/cliproxy/auth"
)
func TestOpenAICompatibilityRegistrationCacheUsesConfigIndex(t *testing.T) {
service := &Service{cfg: &config.Config{OpenAICompatibility: []config.OpenAICompatibility{
{Name: "shared", Models: []config.OpenAICompatibilityModel{{Name: "first"}}},
{Name: "shared", Models: []config.OpenAICompatibilityModel{{Name: "second"}}},
}}}
cache := service.newOpenAICompatibilityRegistrationCache()
auth := &coreauth.Auth{Attributes: map[string]string{
coreauth.AttributeSource: "config:shared[token-1]",
coreauth.AttributeConfigIndex: "1",
}}
entry, ok := cache.lookup(auth, "shared")
if !ok || entry == nil || len(entry.models) != 1 || entry.models[0].ID != "second" {
t.Fatalf("cached config entry = %+v, want second model", entry)
}
}
func TestResolveConfigClaudeKeyUsesConfigIndex(t *testing.T) {
service := &Service{cfg: &config.Config{ClaudeKey: []config.ClaudeKey{
{APIKey: "shared-key", Models: []config.ClaudeModel{{Name: "first"}}},
{APIKey: "shared-key", Models: []config.ClaudeModel{{Name: "second"}}},
}}}
auth := &coreauth.Auth{Attributes: map[string]string{
coreauth.AttributeAPIKey: "shared-key",
coreauth.AttributeSource: "config:claude[token-1]",
coreauth.AttributeConfigIndex: "1",
}}
entry := service.resolveConfigClaudeKey(auth)
if entry == nil || len(entry.Models) != 1 || entry.Models[0].Name != "second" {
t.Fatalf("resolved config entry = %+v, want second entry", entry)
}
}