79 lines
2.5 KiB
Go
79 lines
2.5 KiB
Go
package engine
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/promptkit/internal/backend"
|
|
"gitea.maximumdirect.net/eric/promptkit/internal/domain"
|
|
"gitea.maximumdirect.net/eric/promptkit/internal/profile"
|
|
)
|
|
|
|
func TestNewMaintainedProfileRepository(t *testing.T) {
|
|
newCatalogProfiles := func(t *testing.T, definitions []domain.ExecutionProfile) profile.Repository {
|
|
t.Helper()
|
|
repository, err := profile.NewMemoryRepository(definitions)
|
|
if err != nil {
|
|
t.Fatalf("create catalog profiles: %v", err)
|
|
}
|
|
return repository
|
|
}
|
|
newBackend := func(id string) domain.Backend {
|
|
return domain.Backend{ID: id, Endpoint: "https://" + id + ".example/v1", APIKeyEnv: "TEST_API_KEY"}
|
|
}
|
|
|
|
t.Run("resolves inherited and direct definitions", func(t *testing.T) {
|
|
repository, err := newMaintainedProfileRepository(
|
|
newCatalogProfiles(t, []domain.ExecutionProfile{{
|
|
ID: "gemini-flash-latest",
|
|
BackendID: backend.OpenRouterID,
|
|
Model: "catalog-selected-model",
|
|
}}),
|
|
[]domain.Backend{newBackend(backend.OpenRouterID)},
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("create maintained profiles: %v", err)
|
|
}
|
|
|
|
resolved := profile.NewResolvingRepository(repository)
|
|
standard, err := resolved.GetProfile(context.Background(), "promptkit-openrouter-standard")
|
|
if err != nil {
|
|
t.Fatalf("resolve inherited profile: %v", err)
|
|
}
|
|
if standard.BackendID != backend.OpenRouterID || standard.Model != "catalog-selected-model" {
|
|
t.Fatalf("unexpected inherited profile: %#v", standard)
|
|
}
|
|
|
|
auto, err := resolved.GetProfile(context.Background(), "promptkit-openrouter-auto")
|
|
if err != nil {
|
|
t.Fatalf("resolve direct profile: %v", err)
|
|
}
|
|
definitions := maintainedProfileDefinitions()
|
|
if auto.BackendID != definitions[1].BackendID || auto.Model != definitions[1].Model {
|
|
t.Fatalf("unexpected direct profile: %#v", auto)
|
|
}
|
|
})
|
|
|
|
t.Run("rejects a missing inherited base", func(t *testing.T) {
|
|
if _, err := newMaintainedProfileRepository(
|
|
newCatalogProfiles(t, nil),
|
|
[]domain.Backend{newBackend(backend.OpenRouterID)},
|
|
); err == nil {
|
|
t.Fatal("expected missing base error")
|
|
}
|
|
})
|
|
|
|
t.Run("rejects an unavailable effective backend", func(t *testing.T) {
|
|
if _, err := newMaintainedProfileRepository(
|
|
newCatalogProfiles(t, []domain.ExecutionProfile{{
|
|
ID: "gemini-flash-latest",
|
|
BackendID: "other",
|
|
Model: "catalog-selected-model",
|
|
}}),
|
|
[]domain.Backend{newBackend("other")},
|
|
); err == nil {
|
|
t.Fatal("expected unavailable backend error")
|
|
}
|
|
})
|
|
}
|