feat(sources): enforce supported source allowlist
Assign stable keys to the three supported sources, preserve excluded historical rows, and expose history read-only in admin. Add migration, coverage, and responsive browser spec. Refs #13 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -52,11 +52,12 @@ func TestLegacyNullFIGIAssetStillContributesToGenerationPostgres(t *testing.T) {
|
||||
for _, statement := range []string{
|
||||
`CREATE TABLE users (id UUID PRIMARY KEY, language TEXT NOT NULL DEFAULT 'fr', ranking_mode TEXT NOT NULL DEFAULT 'title')`,
|
||||
`CREATE TABLE user_assets (id UUID PRIMARY KEY, user_id UUID NOT NULL, symbol VARCHAR(20) NOT NULL, name TEXT NOT NULL DEFAULT '', figi TEXT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW())`,
|
||||
`CREATE TABLE sources (id UUID PRIMARY KEY, name TEXT NOT NULL, type TEXT NOT NULL, enabled BOOLEAN NOT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), article_limit INT NOT NULL DEFAULT 20)`,
|
||||
`CREATE TABLE sources (id UUID PRIMARY KEY, name TEXT NOT NULL, type TEXT NOT NULL, enabled BOOLEAN NOT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), article_limit INT NOT NULL DEFAULT 20, source_key TEXT)`,
|
||||
`CREATE TABLE settings (key TEXT PRIMARY KEY, value TEXT NOT NULL)`,
|
||||
`INSERT INTO users(id,language,ranking_mode) VALUES ('` + userID + `','fr','title')`,
|
||||
`INSERT INTO user_assets(id,user_id,symbol,name,figi) VALUES ('00000000-0000-0000-0000-000000000411','` + userID + `','LEGACY','Historic asset',NULL)`,
|
||||
`INSERT INTO sources(id,name,type,enabled,article_limit) VALUES ('00000000-0000-0000-0000-000000000421','test source','ticket4',TRUE,20)`,
|
||||
`INSERT INTO sources(id,name,type,enabled,article_limit,source_key) VALUES ('00000000-0000-0000-0000-000000000421','test source','ticket4',TRUE,20,'yahoo_finance')`,
|
||||
`INSERT INTO sources(id,name,type,enabled,article_limit,source_key) VALUES ('00000000-0000-0000-0000-000000000422','Historic enabled','reuters',TRUE,42,NULL),('00000000-0000-0000-0000-000000000423','Disabled target','bloomberg',FALSE,77,'bloomberg')`,
|
||||
`INSERT INTO settings(key,value) VALUES ('summary_max_articles','50')`,
|
||||
} {
|
||||
if _, err := db.Exec(statement); err != nil {
|
||||
@ -68,6 +69,9 @@ func TestLegacyNullFIGIAssetStillContributesToGenerationPostgres(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("load legacy generation input from PostgreSQL: %v", err)
|
||||
}
|
||||
if len(input.Sources) != 1 || input.Sources[0].SourceKey == nil || *input.Sources[0].SourceKey != models.SourceYahooFinance || input.Sources[0].ArticleLimit != 20 {
|
||||
t.Fatalf("LoadUserInput must exclude unsupported/disabled sources, preserving target caps: %+v", input.Sources)
|
||||
}
|
||||
if len(input.Assets) != 1 || input.Assets[0].Symbol != "LEGACY" || input.Assets[0].Name != "Historic asset" {
|
||||
t.Fatalf("loaded legacy asset=%+v, want symbol/name preserved", input.Assets)
|
||||
}
|
||||
@ -84,7 +88,7 @@ func TestLegacyNullFIGIAssetStillContributesToGenerationPostgres(t *testing.T) {
|
||||
fakeRepository := &contractRepository{inputs: map[string]UserInput{userID: input}, saved: map[string][]GenerationRecord{}}
|
||||
uc := NewUseCase(Dependencies{
|
||||
Repository: fakeRepository,
|
||||
Scrapers: map[string]scraper.Scraper{"ticket4": feed},
|
||||
Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: feed},
|
||||
Ranker: ranker,
|
||||
Summarizer: summarizer,
|
||||
Clock: func() time.Time { return time.Unix(1, 0).UTC() },
|
||||
|
||||
Reference in New Issue
Block a user