Files
TradarrV2/backend/internal/e2estack/safety_test.go
Blomios 4459a81206 test(e2e): add isolated browser journey and cleanup supervision
Add a fake-only end-to-end stack, Firefox journey, and bounded process cleanup for normal, failed, and interrupted runs.

Refs #12

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-20 23:39:02 +01:00

51 lines
1.7 KiB
Go

package e2estack
import (
"context"
"net/http"
"strings"
"testing"
"github.com/tradarr/backend/internal/ai"
"github.com/tradarr/backend/internal/models"
)
func TestRejectNonLoopbackDestinationsWithoutEgress(t *testing.T) {
for _, destination := range []string{"https://api.openfigi.com:443", "http://203.0.113.10:80", "http://localhost:8080", "http://127.0.0.1.evil.test:80", "file:///tmp/fixture"} {
if ValidateURL(destination, false) == nil {
t.Fatalf("unsafe base URL accepted: %s", destination)
}
request, err := http.NewRequest("GET", destination, nil)
if err == nil {
if _, err = LoopbackClient().Do(request); err == nil {
t.Fatal("external request accepted")
}
}
}
if ValidateURL("postgres://127.0.0.1:5432/tradarr_e2e", true) != nil {
t.Fatal("loopback DB rejected")
}
}
func TestFakesRankActualCandidateIDAndJournalCalls(t *testing.T) {
fake := NewFakes()
base, closeServer, err := Listen(fake.Handler())
if err != nil {
t.Fatal(err)
}
defer closeServer()
provider := FakeProvider{URL: base, Client: LoopbackClient()}
articles := []models.Article{{ID: "runtime-candidate-uuid", Title: fake.Fixture.ArticleTitle, Content: fake.Fixture.ArticleContent}}
ranked, err := ai.RankArticles(context.Background(), provider, []string{"Index (IDX)"}, articles, 20, "title_content")
if err != nil || len(ranked) != 1 || ranked[0].ID != articles[0].ID {
t.Fatalf("ranking=%v err=%v", ranked, err)
}
fake.mu.Lock()
defer fake.mu.Unlock()
if fake.counts["layaRankingCalls"] != 1 || fake.Events[0].CandidateID != "runtime-candidate-uuid" {
t.Fatal("ranking call not journaled")
}
if strings.Contains(fake.Fixture.SummarySentinel, fake.Fixture.ArticleTitle) {
t.Fatal("unsafe summary fixture")
}
}