feat(laya): integrate HTTP ranking service
Add the pinned Laya HTTP ranker and production composition, configure the CPU Compose service and cache, and document operations. Cover protocol validation, generation orchestration, sanitized logging, and Compose wiring. Refs #17 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
40
backend/cmd/server/laya_composition_test.go
Normal file
40
backend/cmd/server/laya_composition_test.go
Normal file
@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Keep the executable's production composition wired through server.Dependencies,
|
||||
// rather than relying only on unit tests that inject a fake ranker.
|
||||
func TestProductionCompositionSuppliesLayaRankerToServerDependencies(t *testing.T) {
|
||||
file, err := parser.ParseFile(token.NewFileSet(), "main.go", nil, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
found := false
|
||||
ast.Inspect(file, func(node ast.Node) bool {
|
||||
literal, ok := node.(*ast.CompositeLit)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
selector, ok := literal.Type.(*ast.SelectorExpr)
|
||||
if !ok || selector.Sel.Name != "Dependencies" {
|
||||
return true
|
||||
}
|
||||
for _, element := range literal.Elts {
|
||||
kv, ok := element.(*ast.KeyValueExpr)
|
||||
if ok {
|
||||
if key, ok := kv.Key.(*ast.Ident); ok && key.Name == "LayaRanker" {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
if !found {
|
||||
t.Fatal("cmd/server main does not pass a LayaRanker through server.Dependencies")
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/tradarr/backend/internal/ai"
|
||||
"github.com/tradarr/backend/internal/config"
|
||||
"github.com/tradarr/backend/internal/crypto"
|
||||
"github.com/tradarr/backend/internal/database"
|
||||
@ -22,6 +23,10 @@ func main() {
|
||||
log.Fatalf("config: %v", err)
|
||||
}
|
||||
|
||||
laya, err := ai.NewLayaHTTPRanker(ai.LayaHTTPConfig{BaseURL: cfg.LayaURL, Timeout: cfg.LayaTimeout, APIKey: cfg.LayaAPIKey})
|
||||
if err != nil {
|
||||
log.Fatalf("config: %v", err)
|
||||
}
|
||||
db, err := database.Connect(cfg.DatabaseURL)
|
||||
if err != nil {
|
||||
log.Fatalf("database: %v", err)
|
||||
@ -45,7 +50,7 @@ func main() {
|
||||
models.SourceWatcherGuru: watcherguru.New(),
|
||||
}
|
||||
|
||||
app := server.New(repo, cfg, server.Dependencies{Feeds: feeds, IndexSearcher: openfigi.New(openfigi.Config{APIKey: cfg.OpenFIGIAPIKey, Timeout: cfg.OpenFIGITimeout}, nil), EnableScheduler: true})
|
||||
app := server.New(repo, cfg, server.Dependencies{LayaRanker: laya, Feeds: feeds, IndexSearcher: openfigi.New(openfigi.Config{APIKey: cfg.OpenFIGIAPIKey, Timeout: cfg.OpenFIGITimeout}, nil), EnableScheduler: true})
|
||||
defer app.Close()
|
||||
|
||||
addr := fmt.Sprintf(":%s", cfg.Port)
|
||||
|
||||
Reference in New Issue
Block a user