diff --git a/backend/internal/scraper/watcherguru/host_ticket21_test.go b/backend/internal/scraper/watcherguru/host_ticket21_test.go new file mode 100644 index 0000000..11b8a7a --- /dev/null +++ b/backend/internal/scraper/watcherguru/host_ticket21_test.go @@ -0,0 +1,86 @@ +package watcherguru + +import ( + "context" + "io" + "net/http" + "reflect" + "strings" + "testing" +) + +func TestTicket21UsesAuthorizedHostAndPreservesFallbackPaths(t *testing.T) { + var paths []string + watcher := &WatcherGuru{client: &http.Client{Transport: ticket20RoundTrip(func(r *http.Request) (*http.Response, error) { + if r.URL.Scheme != "https" || r.URL.Host != "watcherguru.com" { + t.Errorf("request origin=%s://%s; want https://watcherguru.com", r.URL.Scheme, r.URL.Host) + } + if r.Method != http.MethodGet { + t.Errorf("method=%s; want GET", r.Method) + } + paths = append(paths, r.URL.Path) + body := "" + if r.URL.Path == "/news/" { + body = `Synthetic market headline for host contract` + } + return &http.Response{StatusCode: 200, Header: make(http.Header), Body: io.NopCloser(strings.NewReader(body)), Request: r}, nil + })}} + articles, err := watcher.Scrape(context.Background(), nil) + if err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(paths, []string{"/feed/", "/news/feed/", "/news/"}) { + t.Fatalf("paths=%v", paths) + } + if len(articles) != 1 || articles[0].URL != "https://watcherguru.com/news/synthetic-market" { + t.Fatalf("relative link resolution changed: %+v", articles) + } +} + +func TestTicket21RSSSuccessStillStopsBeforeFallback(t *testing.T) { + calls := 0 + watcher := &WatcherGuru{client: &http.Client{Transport: ticket20RoundTrip(func(r *http.Request) (*http.Response, error) { + calls++ + if r.URL.String() != "https://watcherguru.com/feed/" { + t.Errorf("request=%s", r.URL) + } + return &http.Response{StatusCode: 200, Header: make(http.Header), Body: io.NopCloser(strings.NewReader(`Synthetic RSS headlinehttps://fixture.invalid/articleSynthetic evidence`)), Request: r}, nil + })}} + articles, err := watcher.Scrape(context.Background(), nil) + if err != nil || calls != 1 || len(articles) != 1 { + t.Fatalf("calls=%d articles=%d err=%v", calls, len(articles), err) + } + if articles[0].Title != "Synthetic RSS headline" || articles[0].Content != "Synthetic evidence" || articles[0].URL != "https://fixture.invalid/article" { + t.Fatalf("RSS contract changed: %+v", articles[0]) + } +} + +func TestTicket21ExtractsAbsoluteNewDomainLinkWithoutNewsPath(t *testing.T) { + const articleURL = "https://watcherguru.com/synthetic-market-update" + const title = "Synthetic absolute headline for new domain" + var paths []string + watcher := &WatcherGuru{client: &http.Client{Transport: ticket20RoundTrip(func(r *http.Request) (*http.Response, error) { + if r.URL.Scheme != "https" || r.URL.Host != "watcherguru.com" { + t.Fatalf("unexpected request origin: %s", r.URL) + } + paths = append(paths, r.URL.Path) + body := "" + if r.URL.Path == "/news/" { + body = `` + title + `` + } + return &http.Response{StatusCode: http.StatusOK, Header: make(http.Header), Body: io.NopCloser(strings.NewReader(body)), Request: r}, nil + })}} + articles, err := watcher.Scrape(context.Background(), nil) + if err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(paths, []string{"/feed/", "/news/feed/", "/news/"}) { + t.Fatalf("paths=%v", paths) + } + if len(articles) != 1 { + t.Fatalf("articles=%d; want absolute new-domain link without /news/", len(articles)) + } + if articles[0].URL != articleURL || articles[0].Title != title || articles[0].Content != title { + t.Fatalf("unexpected article: %+v", articles[0]) + } +} diff --git a/backend/internal/scraper/watcherguru/watcherguru.go b/backend/internal/scraper/watcherguru/watcherguru.go index 7097bcf..6fb8ab5 100644 --- a/backend/internal/scraper/watcherguru/watcherguru.go +++ b/backend/internal/scraper/watcherguru/watcherguru.go @@ -13,7 +13,7 @@ import ( "github.com/tradarr/backend/internal/scraper" ) -const baseURL = "https://watcher.guru" +const baseURL = "https://watcherguru.com" type WatcherGuru struct { client *http.Client @@ -165,7 +165,7 @@ func (w *WatcherGuru) scrapeHTML(ctx context.Context) (articles []scraper.Articl return } // Collect links that look like news articles - if strings.Contains(href, "/news/") || strings.Contains(href, "watcher.guru") { + if strings.Contains(href, "/news/") || strings.Contains(href, "watcherguru.com") { text := strings.TrimSpace(nodeText(n)) if len(text) > 20 { url := href