59 lines
2.4 KiB
Go
59 lines
2.4 KiB
Go
package e2estack
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"github.com/tradarr/backend/internal/ai"
|
|
"github.com/tradarr/backend/internal/generation"
|
|
"github.com/tradarr/backend/internal/rankingcapability"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestBrowserFixturesDeclareRankingWithoutRelaxingProductionCapabilities(t *testing.T) {
|
|
raw, _ := json.Marshal(DefaultFixtures())
|
|
var fixture struct {
|
|
RankingModelID, RankingModelName string
|
|
RankingCapability rankingcapability.Capability
|
|
}
|
|
if json.Unmarshal(raw, &fixture) != nil || fixture.RankingModelID == "" || fixture.RankingModelName == "" || !fixture.RankingCapability.Selectable || fixture.RankingCapability.Mode != "json_schema" {
|
|
t.Fatalf("ranking metadata missing from browser manifest: %s", raw)
|
|
}
|
|
if rankingcapability.Lookup("ollama", "fake-summary", "http://127.0.0.1:1234").Selectable {
|
|
t.Fatal("fake summary leaked into production scoring registry")
|
|
}
|
|
}
|
|
func TestFakeProviderScoresEveryIndexedTitleSeparatelyFromLayaAndSummary(t *testing.T) {
|
|
f := NewFakes()
|
|
base, closeServer, err := Listen(f.Handler())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer closeServer()
|
|
request := generation.TitleScoreRequest{Watchlist: []generation.ScoringCompany{{ID: "fixture-company", Name: "Company"}}, Titles: []generation.ScoringTitle{{Index: 0, Title: "First"}, {Index: 1, Title: "Second"}}}
|
|
raw, _ := json.Marshal(request)
|
|
provider := FakeProvider{Model: "llama3", URL: base, Client: LoopbackClient()}
|
|
result, err := provider.Summarize(context.Background(), "Fixture instructions\n"+string(raw), ai.GenOptions{JSONMode: true, RequireComplete: true, JSONSchema: json.RawMessage(`{"type":"object"}`)})
|
|
if err != nil {
|
|
t.Fatalf("structured scoring fixture failed: %v", err)
|
|
}
|
|
var response struct {
|
|
Scores []struct {
|
|
Index int
|
|
Score float64
|
|
}
|
|
}
|
|
if json.Unmarshal([]byte(result), &response) != nil || len(response.Scores) != 2 || response.Scores[0].Index != 0 || response.Scores[1].Index != 1 {
|
|
t.Fatalf("missing indexed scoring results: %s", result)
|
|
}
|
|
f.mu.Lock()
|
|
defer f.mu.Unlock()
|
|
if f.counts["relevanceScoringCalls"] != 1 || f.counts["layaRankingCalls"] != 0 || f.counts["layaSummaryCalls"] != 0 || len(f.Events) != 1 || f.Events[0].Model != "llama3" {
|
|
t.Fatalf("scoring confused with downstream roles: %+v", f.Events)
|
|
}
|
|
event, _ := json.Marshal(f.Events)
|
|
if strings.Contains(string(event), "First") || strings.Contains(string(event), "Second") {
|
|
t.Fatal("scoring audit retained titles")
|
|
}
|
|
}
|