fix(scraper): verify complete article evidence (#40)

This commit is contained in:
2026-11-24 19:24:29 +01:00
parent 70ffe41cfb
commit a55dc2e189
27 changed files with 833 additions and 132 deletions

View File

@ -0,0 +1,29 @@
package yahoofinance
import (
"context"
"github.com/tradarr/backend/internal/scraper"
"io"
"net/http"
"strings"
"testing"
)
func TestTicket40FailedRSSIsNotReportedAsReachableEmptySource(t *testing.T) {
y := &YahooFinance{client: &http.Client{Transport: ticket20RoundTrip(func(r *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: 503, Body: io.NopCloser(strings.NewReader("PRIVATE unavailable")), Header: make(http.Header), Request: r}, nil
})}}
a, err := y.Scrape(context.Background(), []string{"FIX"})
if err == nil || len(a) != 0 || strings.Contains(err.Error(), "PRIVATE") {
t.Fatal("failed RSS must produce a sanitized source failure")
}
}
func TestTicket40RSSDescriptionNeverClaimsComplete(t *testing.T) {
y := &YahooFinance{client: &http.Client{Transport: ticket20RoundTrip(func(r *http.Request) (*http.Response, error) {
return &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(`<rss><channel><item><title>Fixture</title><link>https://finance.yahoo.com/news/fixture.html</link><description>Synthetic RSS teaser.</description></item></channel></rss>`)), Header: make(http.Header), Request: r}, nil
})}}
a, err := y.Scrape(context.Background(), []string{"FIX"})
if err != nil || len(a) != 1 || scraper.ContentStatus(a[0]) == scraper.ContentComplete {
t.Fatal("RSS description claimed full article")
}
}