feat(sources): retire Yahoo and CNBC feeds (#42)

This commit is contained in:
2026-11-25 02:00:25 +01:00
parent 7a342f240d
commit 0503c2653f
41 changed files with 603 additions and 173 deletions

View File

@ -42,7 +42,7 @@ func TestArticleCapsMigrationAndInvalidAdminUpdatesAreAtomicPostgres(t *testing.
`CREATE TABLE sources (id UUID PRIMARY KEY, name TEXT NOT NULL, type TEXT NOT NULL, source_key TEXT, enabled BOOLEAN NOT NULL DEFAULT TRUE, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW())`,
`CREATE TABLE scrape_schedules (id UUID PRIMARY KEY, day_of_week INT NOT NULL, hour INT NOT NULL, minute INT NOT NULL)`,
`INSERT INTO settings (key,value) VALUES ('summary_max_articles','733')`,
`INSERT INTO sources (id,name,type,source_key) VALUES ('00000000-0000-0000-0000-000000000001','Yahoo Finance','stocktwits','yahoo_finance')`,
`INSERT INTO sources (id,name,type,source_key) VALUES ('00000000-0000-0000-0000-000000000001','Bloomberg','bloomberg','bloomberg')`,
} {
if _, err = db.Exec(statement); err != nil {
t.Fatal(err)

View File

@ -36,7 +36,12 @@ func TestAdminSourcesExposeSupportStateAndRejectHistoricalUpdateAtomicallyPostgr
t.Fatal(err)
}
t.Cleanup(func() { _, _ = db.Exec(`DROP SCHEMA ` + pq.QuoteIdentifier(schema) + ` CASCADE`); _ = db.Close() })
for _, q := range []string{`CREATE TABLE users(id TEXT PRIMARY KEY,email TEXT,role TEXT,password_hash TEXT,created_at TIMESTAMPTZ DEFAULT NOW(),updated_at TIMESTAMPTZ DEFAULT NOW())`, `INSERT INTO users(id,email,role,password_hash) VALUES('admin-id','admin@example.test','admin','hash')`, `CREATE TABLE sources(id TEXT PRIMARY KEY,name TEXT,type TEXT,enabled BOOLEAN,article_limit INTEGER DEFAULT 20,source_key TEXT,created_at TIMESTAMPTZ DEFAULT NOW())`, `INSERT INTO sources(id,name,type,enabled,article_limit,source_key) VALUES('old-id','Reuters','reuters',true,42,NULL),('y-id','Yahoo Finance','stocktwits',true,83,'yahoo_finance')`} {
for _, q := range []string{`CREATE TABLE users(id TEXT PRIMARY KEY,email TEXT,role TEXT,password_hash TEXT,created_at TIMESTAMPTZ DEFAULT NOW(),updated_at TIMESTAMPTZ DEFAULT NOW())`, `INSERT INTO users(id,email,role,password_hash) VALUES('admin-id','admin@example.test','admin','hash')`, `CREATE TABLE sources(id TEXT PRIMARY KEY,name TEXT,type TEXT,enabled BOOLEAN,article_limit INTEGER DEFAULT 20,source_key TEXT,created_at TIMESTAMPTZ DEFAULT NOW())`, `INSERT INTO sources(id,name,type,enabled,article_limit,source_key) VALUES('old-id','Reuters','reuters',true,42,NULL),('b-id','Bloomberg','bloomberg',true,83,'bloomberg')`} {
if _, err = db.Exec(q); err != nil {
t.Fatal(err)
}
}
for _, q := range []string{`CREATE TABLE source_feeds(source_id TEXT,position INT,url TEXT)`, `INSERT INTO source_feeds VALUES('b-id',0,'https://feed.quanwenrss.com/feed/bloomberg-latest.xml')`} {
if _, err = db.Exec(q); err != nil {
t.Fatal(err)
}
@ -67,7 +72,7 @@ func TestAdminSourcesExposeSupportStateAndRejectHistoricalUpdateAtomicallyPostgr
if row["id"] == "old-id" {
old = row
}
if row["id"] == "y-id" {
if row["id"] == "b-id" {
supported = row
}
}
@ -90,7 +95,7 @@ func TestAdminSourcesExposeSupportStateAndRejectHistoricalUpdateAtomicallyPostgr
if supported == nil {
t.Fatalf("GET omitted supported source: %s", get.Body.String())
}
for field, want := range map[string]any{"source_key": "yahoo_finance", "supported": true, "operational": true} {
for field, want := range map[string]any{"source_key": "bloomberg", "supported": true, "operational": true} {
if supported[field] != want {
t.Errorf("supported source %s=%v, want %v; row=%v", field, supported[field], want, supported)
}

View File

@ -40,7 +40,7 @@ func TestGenerationSucceedsWithoutArticleTablesAndRollsBackSummaryPostgres(t *te
`CREATE TABLE settings(key TEXT PRIMARY KEY,value TEXT)`,
`CREATE TABLE summaries(id UUID PRIMARY KEY,user_id UUID REFERENCES users(id),content TEXT,ai_provider_id UUID,generated_at TIMESTAMPTZ,summary_model_id UUID NULL,provider_name TEXT NULL,model_name TEXT NULL)`,
`INSERT INTO users(id) VALUES('00000000-0000-0000-0000-000000000001')`,
`INSERT INTO sources(id,name,type,enabled,source_key) VALUES('00000000-0000-0000-0000-000000000002','Fixture','fixture',true,'yahoo_finance')`,
`INSERT INTO sources(id,name,type,enabled,source_key) VALUES('00000000-0000-0000-0000-000000000002','Fixture','fixture',true,'bloomberg')`,
`CREATE TABLE summary_generations(id UUID PRIMARY KEY,user_id UUID,summary_id UUID REFERENCES summaries(id),outcome JSONB NOT NULL,created_at TIMESTAMPTZ)`,
} {
if _, err := db.Exec(statement); err != nil {
@ -48,7 +48,7 @@ func TestGenerationSucceedsWithoutArticleTablesAndRollsBackSummaryPostgres(t *te
}
}
repo := models.NewRepository(db)
uc := generation.NewUseCase(generation.Dependencies{Repository: generation.RepositoryAdapter{Repo: repo}, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: memoryFeed{}}, Ranker: passRanker{}, Summarizer: safeSummarizer{}})
uc := generation.NewUseCase(generation.Dependencies{Repository: generation.RepositoryAdapter{Repo: repo}, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: memoryFeed{}}, Ranker: passRanker{}, Summarizer: safeSummarizer{}})
result, err := uc.Generate(context.Background(), "00000000-0000-0000-0000-000000000001")
if err != nil || result.Summary == nil || result.Outcome.Status != "succeeded" {
t.Fatalf("result=%+v err=%v", result, err)

View File

@ -0,0 +1,86 @@
package api_test
import (
"bytes"
"database/sql"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/lib/pq"
"github.com/tradarr/backend/internal/api"
"github.com/tradarr/backend/internal/api/handlers"
"github.com/tradarr/backend/internal/auth"
"github.com/tradarr/backend/internal/config"
"github.com/tradarr/backend/internal/models"
)
func TestTicket42AdminCannotReactivateOrModifyRetiredSourcesPostgres(t *testing.T) {
db, err := sql.Open("postgres", postgresTestURL(t))
if err != nil {
t.Fatal(err)
}
defer db.Close()
db.SetMaxOpenConns(1)
schema := fmt.Sprintf("retired42_%d", time.Now().UnixNano())
if _, err = db.Exec(`CREATE SCHEMA ` + pq.QuoteIdentifier(schema)); err != nil {
t.Fatal(err)
}
defer db.Exec(`DROP SCHEMA ` + pq.QuoteIdentifier(schema) + ` CASCADE`)
if _, err = db.Exec(`SET search_path TO ` + pq.QuoteIdentifier(schema)); err != nil {
t.Fatal(err)
}
for _, q := range []string{
`CREATE TABLE users(id TEXT PRIMARY KEY,email TEXT,role TEXT,password_hash TEXT,created_at TIMESTAMPTZ DEFAULT NOW(),updated_at TIMESTAMPTZ DEFAULT NOW())`,
`INSERT INTO users(id,email,role,password_hash) VALUES('admin','admin@example.test','admin','hash')`,
`CREATE TABLE sources(id TEXT PRIMARY KEY,name TEXT,type TEXT,source_key TEXT,enabled BOOLEAN,article_limit INT,created_at TIMESTAMPTZ DEFAULT NOW())`,
`INSERT INTO sources(id,name,type,source_key,enabled,article_limit) VALUES('y','Yahoo Finance','stocktwits','yahoo_finance',false,83),('c','CNBC Business','cnbc_business','cnbc_business',false,31)`,
} {
if _, err = db.Exec(q); err != nil {
t.Fatal(err)
}
}
const secret = "retired42-fixture"
token, _ := auth.GenerateToken("admin", "admin@example.test", "admin", secret)
router := api.SetupRouter(handlers.New(models.NewRepository(db), &config.Config{JWTSecret: secret}, nil, nil, nil, nil), secret)
request := func(method, path, body string) *httptest.ResponseRecorder {
r := httptest.NewRequest(method, path, bytes.NewBufferString(body))
r.Header.Set("Authorization", "Bearer "+token)
r.Header.Set("Content-Type", "application/json")
w := httptest.NewRecorder()
router.ServeHTTP(w, r)
return w
}
for _, id := range []string{"y", "c"} {
for _, body := range []string{`{"enabled":true}`, `{"enabled":false,"article_limit":1}`, `{"enabled":true,"feed_urls":["https://feed.quanwenrss.com/feed/bloomberg-latest.xml"]}`} {
w := request(http.MethodPut, "/api/admin/sources/"+id, body)
if w.Code != 409 || w.Body.String() != `{"error":"source_not_supported"}` {
t.Error("retired source modification/re-activation not explicitly rejected")
}
}
}
// Even a direct SQL reactivation must not make a legacy row operational.
if _, err = db.Exec(`UPDATE sources SET enabled=true`); err != nil {
t.Fatal(err)
}
w := request(http.MethodGet, "/api/admin/sources", "")
var result struct {
Data []struct {
ID, Name string
SourceKey *string `json:"source_key"`
Enabled, Supported, Operational bool
Limit int `json:"article_limit"`
}
}
if w.Code != 200 || json.Unmarshal(w.Body.Bytes(), &result) != nil || len(result.Data) != 2 {
t.Fatal("retired admin rows were removed")
}
for _, s := range result.Data {
if !s.Enabled || s.Supported || s.Operational || s.SourceKey == nil || (s.ID == "y" && (s.Limit != 83 || s.Name != "Yahoo Finance" || *s.SourceKey != "yahoo_finance")) || (s.ID == "c" && (s.Limit != 31 || s.Name != "CNBC Business" || *s.SourceKey != "cnbc_business")) {
t.Fatal("historical metadata was changed or source still operational")
}
}
}

View File

@ -58,7 +58,7 @@ func TestManualGenerationResolvesAccountModelsAndSnapshotsWithoutGlobalFallbackP
`CREATE TABLE settings(key TEXT PRIMARY KEY,value TEXT)`,
`INSERT INTO settings VALUES('summary_max_articles','50'),('ai_role_summary_provider','legacy-must-not-resolve'),('ai_role_summary_model','legacy-must-not-resolve'),('ai_role_filter_provider','legacy-must-not-resolve')`,
`CREATE TABLE sources(id UUID PRIMARY KEY,name TEXT,type TEXT,enabled BOOLEAN,created_at TIMESTAMPTZ DEFAULT NOW(),article_limit INT,source_key TEXT)`,
`INSERT INTO sources VALUES('00000000-0000-0000-0000-000000001599','Yahoo Finance','stocktwits',true,NOW(),20,'yahoo_finance')`,
`INSERT INTO sources VALUES('00000000-0000-0000-0000-000000001599','Bloomberg','bloomberg',true,NOW(),20,'bloomberg')`,
`CREATE TABLE user_assets(id UUID PRIMARY KEY,user_id UUID,symbol TEXT,name TEXT,figi TEXT,created_at TIMESTAMPTZ DEFAULT NOW())`,
`CREATE TABLE summaries(id UUID PRIMARY KEY,user_id UUID,content TEXT,ai_provider_id UUID,generated_at TIMESTAMPTZ,summary_model_id UUID,provider_name TEXT,model_name TEXT)`,
`CREATE TABLE summary_generations(id UUID PRIMARY KEY,user_id UUID,summary_id UUID,outcome JSONB,created_at TIMESTAMPTZ)`,
@ -81,7 +81,7 @@ func TestManualGenerationResolvesAccountModelsAndSnapshotsWithoutGlobalFallbackP
return &selectionProvider{model: m.Model, calls: providerCalls}, nil
}
pipeline := ai.NewPipeline(repo, nil)
feeds := map[string]scraper.Scraper{models.SourceYahooFinance: feed}
feeds := map[string]scraper.Scraper{models.SourceBloomberg: feed}
useCase := pipeline.NewGenerationUseCaseWithFactory(feeds, laya, factory)
h := handlers.New(repo, &config.Config{}, nil, nil, pipeline, nil)
h.SetGenerationUseCase(useCase)