package ingestionbench import ( "embed" "errors" "fmt" "io" "net/http" "strings" ) //go:embed testdata/body.html var fixtureFiles embed.FS // OfflineTransport serves synthetic responses only, rejecting every unlisted // destination. It never delegates to a real network transport. type OfflineTransport struct{} func (OfflineTransport) RoundTrip(r *http.Request) (*http.Response, error) { if r.Method != "GET" || r.URL.Scheme != "https" { return nil, errors.New("offline_request_rejected") } urls := []string{} root := "caas-body" switch r.URL.Host { case "feeds.finance.yahoo.com", "finance.yahoo.com": urls = []string{"https://finance.yahoo.com/news/bench-complete.html", "https://finance.yahoo.com/news/bench-partial.html", "https://finance.yahoo.com/news/bench-absent.html"} case "www.cnbc.com": root = "ArticleBody-articleBody" urls = []string{"https://www.cnbc.com/2026/01/02/bench-complete.html", "https://www.cnbc.com/2026/01/02/bench-partial.html", "https://www.cnbc.com/2026/01/02/bench-absent.html"} default: return nil, errors.New("offline_request_rejected") } body := "" if r.URL.Host == "feeds.finance.yahoo.com" && r.URL.Path == "/rss/2.0/headline" || r.URL.Host == "www.cnbc.com" && r.URL.Path == "/id/10001147/device/rss/rss.html" { body = "" for i, url := range urls { date := "" if i > 0 { date = "Fri, 02 Jan 2026 03:04:05 +0000" } body += fmt.Sprintf("Synthetic benchmark headline %d%sSynthetic RSS teaser.%s", i, url, date) } body += "" } else { index := -1 for i, url := range urls { if strings.Replace(url, "http://", "https://", 1) == r.URL.String() { index = i } } if index < 0 { return nil, errors.New("offline_request_rejected") } raw, _ := fixtureFiles.ReadFile("testdata/body.html") body = strings.ReplaceAll(strings.ReplaceAll(string(raw), "{{URL}}", r.URL.String()), "{{ROOT}}", root) if index == 1 { // Restriction belongs to the synthetic editorial body, not site chrome. body = strings.Replace(body, "", `
`, 1) body += `` } if index == 2 { body = `
` } } return &http.Response{StatusCode: 200, Header: make(http.Header), Body: io.NopCloser(strings.NewReader(body)), Request: r}, nil }