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:
2026-11-22 00:55:18 +01:00
parent 89503c52fc
commit 1123360914
15 changed files with 1023 additions and 9 deletions

View File

@ -8,6 +8,9 @@ import (
)
type Config struct {
LayaURL string
LayaTimeout time.Duration
LayaAPIKey string
OpenFIGIAPIKey string
OpenFIGITimeout time.Duration
DatabaseURL string
@ -57,7 +60,20 @@ func Load() (*Config, error) {
}
timeout = parsed
}
layaURL := os.Getenv("LAYA_URL")
if layaURL == "" {
layaURL = "http://laya:8000"
}
layaTimeout := 120 * time.Second
if value := os.Getenv("LAYA_TIMEOUT"); value != "" {
parsed, err := time.ParseDuration(value)
if err != nil || parsed <= 0 || parsed > 10*time.Minute {
return nil, fmt.Errorf("LAYA_TIMEOUT must be a duration greater than 0 and at most 10m")
}
layaTimeout = parsed
}
return &Config{
LayaURL: layaURL, LayaTimeout: layaTimeout, LayaAPIKey: os.Getenv("LAYA_API_KEY"),
OpenFIGIAPIKey: os.Getenv("OPENFIGI_API_KEY"),
OpenFIGITimeout: timeout,
DatabaseURL: dbURL,

View File

@ -0,0 +1,36 @@
package config
import (
"strings"
"testing"
"time"
)
func TestLayaEnvironment(t *testing.T) {
t.Setenv("DATABASE_URL", "unused")
t.Setenv("JWT_SECRET", "unused")
t.Setenv("ENCRYPTION_KEY", strings.Repeat("ab", 32))
t.Setenv("LAYA_URL", "")
t.Setenv("LAYA_TIMEOUT", "")
t.Setenv("LAYA_API_KEY", "")
cfg, err := Load()
if err != nil {
t.Fatal(err)
}
if cfg.LayaURL != "http://laya:8000" || cfg.LayaTimeout != 120*time.Second {
t.Fatal("incorrect Laya defaults")
}
t.Setenv("LAYA_URL", "http://127.0.0.1:8001")
t.Setenv("LAYA_TIMEOUT", "45s")
t.Setenv("LAYA_API_KEY", "test-secret")
cfg, err = Load()
if err != nil || cfg.LayaURL != "http://127.0.0.1:8001" || cfg.LayaTimeout != 45*time.Second || cfg.LayaAPIKey != "test-secret" {
t.Fatalf("environment not loaded: %v", err)
}
for _, value := range []string{"invalid", "0s", "-1s", "11m"} {
t.Setenv("LAYA_TIMEOUT", value)
if _, err := Load(); err == nil {
t.Errorf("accepted timeout %s", value)
}
}
}