fix(scraper): verify complete article evidence (#40)
This commit is contained in:
36
backend/internal/generation/source_key_ticket40_test.go
Normal file
36
backend/internal/generation/source_key_ticket40_test.go
Normal file
@ -0,0 +1,36 @@
|
||||
package generation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/tradarr/backend/internal/models"
|
||||
"github.com/tradarr/backend/internal/scraper"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTicket40CanonicalSourceKeyAndReachabilitySeparateFromContent(t *testing.T) {
|
||||
for _, key := range []string{models.SourceYahooFinance, models.SourceBloomberg, models.SourceCNBCBusiness} {
|
||||
t.Run(key, func(t *testing.T) {
|
||||
feed := &ticket39ContentFeed{}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title_content", GlobalLimit: 3, Assets: []models.UserAsset{{Name: "Followed fixture"}}, Sources: []models.Source{{ID: "s", Type: "stocktwits", SourceKey: &key, Enabled: true, ArticleLimit: 3}}}}, saved: map[string][]GenerationRecord{}}
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Decider: &allYesMention{}, Summarizer: &contractSummarizer{}, Scrapers: map[string]scraper.Scraper{key: feed}}).Generate(context.Background(), "u")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
raw, _ := json.Marshal(r.Outcome)
|
||||
var outcome struct {
|
||||
SourceStats []map[string]any `json:"source_stats"`
|
||||
}
|
||||
json.Unmarshal(raw, &outcome)
|
||||
stat := outcome.SourceStats[0]
|
||||
if stat["source_key"] != key || stat["status"] != "ok" || stat["content_complete"] != float64(1) || stat["content_incomplete"] != float64(1) || stat["content_unavailable"] != float64(1) {
|
||||
t.Fatal("canonical key or distinct content states missing")
|
||||
}
|
||||
saved, _ := json.Marshal(repo.saved["u"][0].Outcome)
|
||||
if strings.Contains(string(saved), "fixture.invalid") || strings.Contains(string(saved), "Entire editorial") {
|
||||
t.Fatal("sensitive article persisted in diagnostics")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user