feat(sources): retire Yahoo and CNBC feeds (#42)
This commit is contained in:
@ -29,18 +29,18 @@ func (f *symbolFeed) Scrape(_ context.Context, s []string) ([]scraper.Article, e
|
||||
}
|
||||
|
||||
func TestPerSourceCompanyHintsDoNotChangeOtherFeeds(t *testing.T) {
|
||||
yahoo, bloomberg, cnbc, watcher := &symbolFeed{}, &symbolFeed{}, &symbolFeed{}, &symbolFeed{}
|
||||
yahoo, bloomberg, cnbc, watcher, investing := &symbolFeed{}, &symbolFeed{}, &symbolFeed{}, &symbolFeed{}, &symbolFeed{}
|
||||
input := UserInput{Language: "fr", RankingMode: "title", GlobalLimit: 20, Assets: []models.UserAsset{{CompanyID: pointer("isin:company"), Name: "Company", Symbol: "HISTORIC INDEX", YahooSymbol: pointer("9888.HK")}}}
|
||||
for _, key := range []string{models.SourceYahooFinance, models.SourceBloomberg, models.SourceCNBCBusiness, models.SourceWatcherGuru} {
|
||||
for _, key := range []string{models.SourceYahooFinance, models.SourceBloomberg, models.SourceCNBCBusiness, models.SourceWatcherGuru, models.SourceInvesting} {
|
||||
key := key
|
||||
input.Sources = append(input.Sources, models.Source{ID: key, SourceKey: &key, Enabled: true, ArticleLimit: 20})
|
||||
}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"owner": input}, saved: map[string][]GenerationRecord{}}
|
||||
uc := NewUseCase(Dependencies{Repository: repo, LayaRanker: &contractRanker{}, Summarizer: &contractSummarizer{}, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: yahoo, models.SourceBloomberg: bloomberg, models.SourceCNBCBusiness: cnbc, models.SourceWatcherGuru: watcher}})
|
||||
uc := NewUseCase(Dependencies{Repository: repo, LayaRanker: &contractRanker{}, Summarizer: &contractSummarizer{}, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: yahoo, models.SourceBloomberg: bloomberg, models.SourceCNBCBusiness: cnbc, models.SourceWatcherGuru: watcher, models.SourceInvesting: investing}})
|
||||
if _, err := uc.Generate(context.Background(), "owner"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(yahoo.symbols, []string{"9888.HK"}) || !reflect.DeepEqual(bloomberg.symbols, []string{"HISTORIC INDEX"}) || !reflect.DeepEqual(cnbc.symbols, bloomberg.symbols) || watcher.symbols != nil {
|
||||
if yahoo.symbols != nil || cnbc.symbols != nil || !reflect.DeepEqual(bloomberg.symbols, []string{"HISTORIC INDEX"}) || !reflect.DeepEqual(investing.symbols, bloomberg.symbols) || watcher.symbols != nil {
|
||||
t.Fatalf("Yahoo=%v Bloomberg=%v Watcher=%v", yahoo.symbols, bloomberg.symbols, watcher.symbols)
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,13 +34,13 @@ func (f *contentFeed) Enrich(_ context.Context, a []scraper.Article) ([]scraper.
|
||||
func TestTicket36EnrichmentAfterPoolAndNoReordering(t *testing.T) {
|
||||
for _, mode := range []string{"title_content", "title", "failure", "other_source"} {
|
||||
t.Run(mode, func(t *testing.T) {
|
||||
source := models.SourceBloomberg
|
||||
source := models.SourceInvesting
|
||||
rankingMode := mode
|
||||
if mode == "failure" || mode == "other_source" {
|
||||
rankingMode = "title_content"
|
||||
}
|
||||
if mode == "other_source" {
|
||||
source = models.SourceYahooFinance
|
||||
source = models.SourceBloomberg
|
||||
}
|
||||
feed := &contentFeed{fail: mode == "failure", contractScraper: contractScraper{articles: []scraper.Article{{Title: "Fixture first"}, {Title: "Fixture second"}, {Title: "excluded"}}}}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: rankingMode, GlobalLimit: 2, Assets: []models.UserAsset{{Name: "Fixture"}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(source), Enabled: true, ArticleLimit: 2}}}}, saved: map[string][]GenerationRecord{}}
|
||||
@ -74,7 +74,7 @@ func TestTicket36EnrichmentAfterPoolAndNoReordering(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTicket36EnrichedDateDoesNotChangeCrossSourceOrder(t *testing.T) {
|
||||
keyB, keyY := models.SourceBloomberg, models.SourceYahooFinance
|
||||
keyB, keyY := models.SourceInvesting, models.SourceBloomberg
|
||||
feed := &contentFeed{contractScraper: contractScraper{articles: []scraper.Article{{Title: "Fixture Bloomberg"}}}}
|
||||
old := time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
other := &contractScraper{articles: []scraper.Article{{Title: "Fixture Yahoo", ContentState: scraper.ContentComplete, Content: "synthetic full Yahoo body", PublishedAt: &old}}}
|
||||
|
||||
@ -20,6 +20,7 @@ type ticket40Transport func(*http.Request) (*http.Response, error)
|
||||
func (f ticket40Transport) RoundTrip(r *http.Request) (*http.Response, error) { return f(r) }
|
||||
|
||||
type ticket40EvidenceFeed struct {
|
||||
calls *int
|
||||
source string
|
||||
articles []scraper.Article
|
||||
client *http.Client
|
||||
@ -28,6 +29,9 @@ type ticket40EvidenceFeed struct {
|
||||
|
||||
func (f ticket40EvidenceFeed) Name() string { return f.source }
|
||||
func (f ticket40EvidenceFeed) Scrape(context.Context, []string) ([]scraper.Article, error) {
|
||||
if f.calls != nil {
|
||||
*f.calls++
|
||||
}
|
||||
return append([]scraper.Article(nil), f.articles...), nil
|
||||
}
|
||||
func (f ticket40EvidenceFeed) Enrich(ctx context.Context, a []scraper.Article) ([]scraper.Article, error) {
|
||||
@ -36,8 +40,8 @@ func (f ticket40EvidenceFeed) Enrich(ctx context.Context, a []scraper.Article) (
|
||||
}
|
||||
return articlecontent.Enrich(ctx, f.client, f.source, a)
|
||||
}
|
||||
func TestTicket40RealEnrichmentPortsOnlyPropagateCompleteBodiesToSummary(t *testing.T) {
|
||||
for _, key := range []string{models.SourceBloomberg, models.SourceYahooFinance, models.SourceCNBCBusiness} {
|
||||
func TestTicket40LegacyEnrichmentPreservedAndRetiredSourcesCannotGenerate(t *testing.T) {
|
||||
for _, key := range []string{models.SourceYahooFinance, models.SourceBloomberg, models.SourceCNBCBusiness} {
|
||||
t.Run(key, func(t *testing.T) {
|
||||
const full = "Synthetic full editorial body."
|
||||
base, root := "https://finance.yahoo.com/news/", "caas-body"
|
||||
@ -48,7 +52,8 @@ func TestTicket40RealEnrichmentPortsOnlyPropagateCompleteBodiesToSummary(t *test
|
||||
if key == models.SourceBloomberg {
|
||||
base = "https://www.bloomberg.com/news/articles/"
|
||||
}
|
||||
feed := ticket40EvidenceFeed{source: key}
|
||||
calls := 0
|
||||
feed := ticket40EvidenceFeed{source: key, calls: &calls}
|
||||
for _, kind := range []string{"complete", "partial", "absent"} {
|
||||
feed.articles = append(feed.articles, scraper.Article{Title: "Followed fixture " + kind, URL: base + kind + ".html", Content: "RSS teaser", ContentState: scraper.ContentIncomplete})
|
||||
}
|
||||
@ -91,10 +96,21 @@ func TestTicket40RealEnrichmentPortsOnlyPropagateCompleteBodiesToSummary(t *test
|
||||
return &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(body)), Header: make(http.Header), Request: r}, nil
|
||||
})}
|
||||
}
|
||||
// The legacy adapters remain intact for historical/diagnostic tooling.
|
||||
enriched, err := feed.Enrich(context.Background(), feed.articles)
|
||||
if err != nil || len(enriched) != 3 || scraper.ContentStatus(enriched[0]) != scraper.ContentComplete || scraper.ContentStatus(enriched[1]) != scraper.ContentIncomplete || scraper.ContentStatus(enriched[2]) != scraper.ContentUnavailable {
|
||||
t.Fatal("legacy enrichment port was changed")
|
||||
}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title_content", GlobalLimit: 3, Assets: []models.UserAsset{{Name: "Followed fixture"}}, Sources: []models.Source{{ID: "s", SourceKey: &key, Enabled: true, ArticleLimit: 3}}}}, saved: map[string][]GenerationRecord{}}
|
||||
sum := &contractSummarizer{}
|
||||
result, err := NewUseCase(Dependencies{Repository: repo, Decider: &allYesMention{}, Summarizer: sum, Scrapers: map[string]scraper.Scraper{key: feed}}).Generate(context.Background(), "u")
|
||||
o := result.Outcome
|
||||
if key == models.SourceYahooFinance || key == models.SourceCNBCBusiness {
|
||||
if err != nil || result.Summary != nil || calls != 0 || len(sum.articles) != 0 || o.TotalCandidates != 0 || len(o.SourceStats) != 0 {
|
||||
t.Fatal("retired source entered new generation")
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil || result.Summary == nil || o.Status != "partial" || o.ContentComplete != 1 || o.ContentIncomplete != 1 || o.ContentUnavailable != 1 || o.Selected != 1 || len(sum.articles) != 1 || sum.articles[0][0].Article.Content != full || o.SourceStats[0].Status != "ok" || o.SourceStats[0].SourceKey != key {
|
||||
t.Fatal("enrichment status lost before summary", o, err)
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestTicket39NoContentIsExplicit(t *testing.T) {
|
||||
key := models.SourceYahooFinance
|
||||
key := models.SourceBloomberg
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title_content", GlobalLimit: 2, Assets: []models.UserAsset{{Name: "Fixture"}}, Sources: []models.Source{{ID: "s", SourceKey: &key, Enabled: true, ArticleLimit: 2}}}}, saved: map[string][]GenerationRecord{}}
|
||||
sum := &contractSummarizer{}
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Decider: &allYesMention{}, Summarizer: sum, Scrapers: map[string]scraper.Scraper{key: &contractScraper{articles: []scraper.Article{{Title: "Fixture", Content: "RSS teaser", ContentTruncated: true}}}}}).Generate(context.Background(), "u")
|
||||
@ -42,7 +42,7 @@ func (f *ticket39ContentFeed) Enrich(_ context.Context, a []scraper.Article) ([]
|
||||
return out, nil
|
||||
}
|
||||
func TestTicket39AllRuntimeSourcesEnrichAfterLimitAndOnlyCompleteSelectable(t *testing.T) {
|
||||
for _, key := range []string{models.SourceBloomberg, models.SourceYahooFinance, models.SourceCNBCBusiness} {
|
||||
for _, key := range []string{models.SourceBloomberg, models.SourceInvesting} {
|
||||
t.Run(key, func(t *testing.T) {
|
||||
feed := &ticket39ContentFeed{}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title_content", GlobalLimit: 3, Assets: []models.UserAsset{{Name: "Followed fixture"}}, Sources: []models.Source{{ID: "s", SourceKey: &key, Enabled: true, ArticleLimit: 3}}}}, saved: map[string][]GenerationRecord{}}
|
||||
|
||||
@ -92,8 +92,8 @@ func (s *contractSummarizer) Summarize(_ context.Context, language string, _ []m
|
||||
|
||||
func TestUseCaseIsolatesTwoUsersAndUsesOnlyEnabledSourcesAndUserInputs(t *testing.T) {
|
||||
alphaID, betaID := "user-alpha", "user-beta"
|
||||
alphaSource := models.Source{ID: "alpha-feed", Type: "alpha", SourceKey: testSourceKey(models.SourceYahooFinance), Enabled: true, ArticleLimit: 5}
|
||||
betaSource := models.Source{ID: "beta-feed", Type: "beta", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 5}
|
||||
alphaSource := models.Source{ID: "alpha-feed", Type: "alpha", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 5}
|
||||
betaSource := models.Source{ID: "beta-feed", Type: "beta", SourceKey: testSourceKey(models.SourceInvesting), Enabled: true, ArticleLimit: 5}
|
||||
disabled := models.Source{ID: "disabled-feed", Type: "disabled", SourceKey: testSourceKey(models.SourceWatcherGuru), Enabled: false, ArticleLimit: 5}
|
||||
alphaScraper := &contractScraper{name: "alpha", articles: []scraper.Article{{Title: "alpha-only", URL: "https://private.test/alpha", ContentState: scraper.ContentComplete, Content: "alpha-secret"}}}
|
||||
betaScraper := &contractScraper{name: "beta", articles: []scraper.Article{{Title: "beta-only", URL: "https://private.test/beta", ContentState: scraper.ContentComplete, Content: "beta-secret"}}}
|
||||
@ -107,7 +107,7 @@ func TestUseCaseIsolatesTwoUsersAndUsesOnlyEnabledSourcesAndUserInputs(t *testin
|
||||
},
|
||||
saved: map[string][]GenerationRecord{},
|
||||
}
|
||||
useCase := NewUseCase(Dependencies{Repository: repo, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: alphaScraper, models.SourceBloomberg: betaScraper, models.SourceWatcherGuru: disabledScraper}, Ranker: ranker, Summarizer: summarizer, Clock: func() time.Time { return time.Date(2026, 11, 20, 12, 0, 0, 0, time.UTC) }})
|
||||
useCase := NewUseCase(Dependencies{Repository: repo, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: alphaScraper, models.SourceInvesting: betaScraper, models.SourceWatcherGuru: disabledScraper}, Ranker: ranker, Summarizer: summarizer, Clock: func() time.Time { return time.Date(2026, 11, 20, 12, 0, 0, 0, time.UTC) }})
|
||||
|
||||
alpha, err := useCase.Generate(context.Background(), alphaID)
|
||||
if err != nil || alpha.Summary == nil {
|
||||
@ -148,8 +148,8 @@ func TestUseCasePreservesRecentInputOrderWithSourcePoolsAndGlobalOutputCap(t *te
|
||||
feedB := &contractScraper{name: "b", articles: articles[2:]}
|
||||
ranker := &contractRanker{order: []string{"a2", "b1", "a1", "b2", "a3"}}
|
||||
summarizer := &contractSummarizer{}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 3, Assets: []models.UserAsset{{Symbol: "IDX"}}, Sources: []models.Source{{ID: "a", Type: "a", SourceKey: testSourceKey(models.SourceYahooFinance), Enabled: true, ArticleLimit: 1}, {ID: "b", Type: "b", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 2}}}}, saved: map[string][]GenerationRecord{}}
|
||||
uc := NewUseCase(Dependencies{Repository: repo, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: feedA, models.SourceBloomberg: feedB}, Ranker: ranker, Summarizer: summarizer, Clock: func() time.Time { return time.Unix(1, 0) }})
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 3, Assets: []models.UserAsset{{Symbol: "IDX"}}, Sources: []models.Source{{ID: "a", Type: "a", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 1}, {ID: "b", Type: "b", SourceKey: testSourceKey(models.SourceInvesting), Enabled: true, ArticleLimit: 2}}}}, saved: map[string][]GenerationRecord{}}
|
||||
uc := NewUseCase(Dependencies{Repository: repo, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: feedA, models.SourceInvesting: feedB}, Ranker: ranker, Summarizer: summarizer, Clock: func() time.Time { return time.Unix(1, 0) }})
|
||||
if _, err := uc.Generate(context.Background(), "u"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -176,10 +176,10 @@ func TestUseCaseNoResultsInvalidLayaAndSummaryFailurePersistNoSummary(t *testing
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 10, Sources: []models.Source{{ID: "s", Type: "s", SourceKey: testSourceKey(models.SourceYahooFinance), Enabled: true, ArticleLimit: 10}}}}, saved: map[string][]GenerationRecord{}}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 10, Sources: []models.Source{{ID: "s", Type: "s", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 10}}}}, saved: map[string][]GenerationRecord{}}
|
||||
ranker := &contractRanker{err: tt.rankErr}
|
||||
summarizer := &contractSummarizer{err: tt.summaryErr}
|
||||
uc := NewUseCase(Dependencies{Repository: repo, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: &contractScraper{name: "s", articles: tt.articles}}, Ranker: ranker, Summarizer: summarizer, Clock: func() time.Time { return time.Unix(1, 0) }})
|
||||
uc := NewUseCase(Dependencies{Repository: repo, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: &contractScraper{name: "s", articles: tt.articles}}, Ranker: ranker, Summarizer: summarizer, Clock: func() time.Time { return time.Unix(1, 0) }})
|
||||
result, err := uc.Generate(context.Background(), "u")
|
||||
if err != nil {
|
||||
t.Fatalf("expected aggregate failure outcome, got error: %v", err)
|
||||
@ -199,8 +199,8 @@ func TestUseCasePartialSourceFailureCanSummarizeRemainingSources(t *testing.T) {
|
||||
bad := &contractScraper{name: "bad", err: errors.New("private error with URL https://private.test/article")}
|
||||
ranker := &contractRanker{order: []string{"good-result"}}
|
||||
summarizer := &contractSummarizer{}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title_content", GlobalLimit: 10, Sources: []models.Source{{ID: "good", Type: "good", SourceKey: testSourceKey(models.SourceYahooFinance), Enabled: true, ArticleLimit: 5}, {ID: "bad", Type: "bad", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 5}}}}, saved: map[string][]GenerationRecord{}}
|
||||
uc := NewUseCase(Dependencies{Repository: repo, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: good, models.SourceBloomberg: bad}, Ranker: ranker, Summarizer: summarizer, Clock: func() time.Time { return time.Unix(1, 0) }})
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title_content", GlobalLimit: 10, Sources: []models.Source{{ID: "good", Type: "good", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 5}, {ID: "bad", Type: "bad", SourceKey: testSourceKey(models.SourceInvesting), Enabled: true, ArticleLimit: 5}}}}, saved: map[string][]GenerationRecord{}}
|
||||
uc := NewUseCase(Dependencies{Repository: repo, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: good, models.SourceInvesting: bad}, Ranker: ranker, Summarizer: summarizer, Clock: func() time.Time { return time.Unix(1, 0) }})
|
||||
result, err := uc.Generate(context.Background(), "u")
|
||||
if err != nil || result.Summary == nil || result.Outcome.Status != "partial" {
|
||||
t.Fatalf("partial source failure result=%+v err=%v", result, err)
|
||||
@ -221,8 +221,8 @@ func TestUseCaseOutcomeContainsAggregateCountsWithoutArticleIdentifiers(t *testi
|
||||
feed := &contractScraper{name: "source", articles: []scraper.Article{{Title: "candidate-title-secret", URL: "https://private.test/x", ContentState: scraper.ContentComplete, Content: "candidate-content-secret"}}}
|
||||
ranker := &contractRanker{order: []string{"candidate-title-secret"}}
|
||||
summarizer := &contractSummarizer{}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title_content", GlobalLimit: 10, Sources: []models.Source{{ID: "source-id", Type: "source", SourceKey: testSourceKey(models.SourceYahooFinance), Enabled: true, ArticleLimit: 5}}}}, saved: map[string][]GenerationRecord{}}
|
||||
uc := NewUseCase(Dependencies{Repository: repo, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: feed}, Ranker: ranker, Summarizer: summarizer, Clock: func() time.Time { return time.Unix(1, 0) }})
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title_content", GlobalLimit: 10, Sources: []models.Source{{ID: "source-id", Type: "source", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 5}}}}, saved: map[string][]GenerationRecord{}}
|
||||
uc := NewUseCase(Dependencies{Repository: repo, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: feed}, Ranker: ranker, Summarizer: summarizer, Clock: func() time.Time { return time.Unix(1, 0) }})
|
||||
result, err := uc.Generate(context.Background(), "u")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -245,8 +245,8 @@ func TestUseCaseCountsTitleOnlyFallbackWhenContentIsUnavailable(t *testing.T) {
|
||||
feed := &contractScraper{name: "source", articles: []scraper.Article{{Title: "title-without-content", ContentState: scraper.ContentComplete, Content: ""}}}
|
||||
ranker := &contractRanker{}
|
||||
summarizer := &contractSummarizer{}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "en", RankingMode: "title_content", GlobalLimit: 4, Sources: []models.Source{{ID: "source", Type: "source", SourceKey: testSourceKey(models.SourceYahooFinance), Enabled: true, ArticleLimit: 4}}}}, saved: map[string][]GenerationRecord{}}
|
||||
uc := NewUseCase(Dependencies{Repository: repo, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: feed}, Ranker: ranker, Summarizer: summarizer, Clock: func() time.Time { return time.Unix(1, 0) }})
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "en", RankingMode: "title_content", GlobalLimit: 4, Sources: []models.Source{{ID: "source", Type: "source", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 4}}}}, saved: map[string][]GenerationRecord{}}
|
||||
uc := NewUseCase(Dependencies{Repository: repo, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: feed}, Ranker: ranker, Summarizer: summarizer, Clock: func() time.Time { return time.Unix(1, 0) }})
|
||||
result, err := uc.Generate(context.Background(), "u")
|
||||
if err != nil || result.Summary != nil || result.Outcome.FailureCode != "no_complete_content" || len(summarizer.articles) != 0 {
|
||||
t.Fatalf("missing content must prevent generation: result=%+v err=%v", result, err)
|
||||
|
||||
@ -92,7 +92,7 @@ func (s *ticket14SummaryProvider) Summarize(_ context.Context, language string,
|
||||
|
||||
func TestGenerationInjectsLayaRankerAndSummaryProviderAsSeparatePorts(t *testing.T) {
|
||||
figi := "BBG000SPX001"
|
||||
key := models.SourceYahooFinance
|
||||
key := models.SourceBloomberg
|
||||
feed := &ticket14Feed{}
|
||||
order := []string{}
|
||||
ranker := &ticket14LayaRanker{selectedTitle: "Market title B", order: &order}
|
||||
@ -135,7 +135,7 @@ func TestGenerationRunsTwoAccountsWithDistinctInjectedSummaryModels(t *testing.T
|
||||
}
|
||||
for _, account := range accounts {
|
||||
t.Run(account.id, func(t *testing.T) {
|
||||
figi, key := "BBG000SPX001", models.SourceYahooFinance
|
||||
figi, key := "BBG000SPX001", models.SourceBloomberg
|
||||
repo := &ticket14Repository{input: UserInput{Language: "en", RankingMode: "title", GlobalLimit: 1, Assets: []models.UserAsset{{Name: "S&P 500", Symbol: "SPX", FIGI: &figi}}, Sources: []models.Source{{ID: "yahoo-row", Type: "yahoo", SourceKey: &key, Enabled: true, ArticleLimit: 5}}}}
|
||||
feed := &ticket14Feed{}
|
||||
ranker := &ticket14LayaRanker{selectedTitle: "Market title A"}
|
||||
@ -168,7 +168,7 @@ func TestGenerationInputCarriesTheUsersSelectedSummaryModel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGenerationWithoutSelectedSummaryProviderFailsBeforeScrapeOrLaya(t *testing.T) {
|
||||
figi, key := "BBG000SPX001", models.SourceYahooFinance
|
||||
figi, key := "BBG000SPX001", models.SourceBloomberg
|
||||
feed := &ticket14Feed{}
|
||||
ranker := &ticket14LayaRanker{selectedTitle: "Market title A"}
|
||||
repo := &ticket14Repository{input: UserInput{Language: "en", RankingMode: "title", GlobalLimit: 1, Assets: []models.UserAsset{{Name: "S&P 500", Symbol: "SPX", FIGI: &figi}}, Sources: []models.Source{{ID: "yahoo-row", Type: "yahoo", SourceKey: &key, Enabled: true, ArticleLimit: 10}}}}
|
||||
@ -210,7 +210,7 @@ func TestGenerationDoesNotSummarizeWhenLayaFailsOrReturnsInvalidSelectedIDs(t *t
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
figi := "BBG000SPX001"
|
||||
key := models.SourceYahooFinance
|
||||
key := models.SourceBloomberg
|
||||
feed := &ticket14Feed{}
|
||||
ranker := &ticket14LayaRanker{selectedTitle: "unknown"}
|
||||
tc.setup(ranker)
|
||||
@ -235,7 +235,7 @@ func TestGenerationDoesNotSummarizeWhenLayaFailsOrReturnsInvalidSelectedIDs(t *t
|
||||
|
||||
func TestGenerationRejectsDuplicateSelectedCandidateIDFromLaya(t *testing.T) {
|
||||
figi := "BBG000SPX001"
|
||||
key := models.SourceYahooFinance
|
||||
key := models.SourceBloomberg
|
||||
feed := &ticket14Feed{}
|
||||
bad := ticket14DuplicateRanker{}
|
||||
repo := &ticket14Repository{input: UserInput{Language: "fr", RankingMode: "title", GlobalLimit: 10, Assets: []models.UserAsset{{Name: "S&P 500", Symbol: "SPX", FIGI: &figi}}, Sources: []models.Source{{ID: "yahoo-row", Type: "stocktwits", SourceKey: &key, Enabled: true, ArticleLimit: 10}}}}
|
||||
|
||||
@ -62,7 +62,7 @@ func TestTicket28GenerationAggregatesAllAssetsBeforeSelectionAndFailsClosed(t *t
|
||||
}))
|
||||
defer srv.Close()
|
||||
ranker, _ := ai.NewLayaHTTPRanker(ai.LayaHTTPConfig{BaseURL: srv.URL, BatchSize: 2})
|
||||
model, key := "model", models.SourceYahooFinance
|
||||
model, key := "model", models.SourceBloomberg
|
||||
feed := &ticket17HTTPScraper{articles: []scraper.Article{{Title: "first", URL: "https://fixture.invalid/first", ContentState: scraper.ContentComplete, Content: content}, {Title: "second", URL: "https://fixture.invalid/second", ContentState: scraper.ContentComplete, Content: content}}}
|
||||
summary := &ticket17HTTPSummary{}
|
||||
repo := &ticket17HTTPRepo{input: generation.UserInput{SummaryModelID: &model, Language: "fr", RankingMode: "title_content", GlobalLimit: 1, Assets: []models.UserAsset{{Name: strings.Repeat("A", 400), Symbol: "A"}, {Name: strings.Repeat("B", 400), Symbol: "B"}}, Sources: []models.Source{{ID: "source", SourceKey: &key, Enabled: true, ArticleLimit: 2}}}}
|
||||
|
||||
@ -91,7 +91,7 @@ func TestGenerationUsesLayaHTTPContractThenSelectedSummaryModel(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
modelID := "summary-model-user-a"
|
||||
key := models.SourceYahooFinance
|
||||
key := models.SourceBloomberg
|
||||
feed := &ticket17HTTPScraper{}
|
||||
summary := &ticket17HTTPSummary{}
|
||||
resolver := &ticket17HTTPResolver{provider: summary}
|
||||
@ -161,7 +161,7 @@ func TestGenerationLogsSanitizedLayaFailureCause(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
modelID := "summary-model-user-a"
|
||||
key := models.SourceYahooFinance
|
||||
key := models.SourceBloomberg
|
||||
feed := &ticket17HTTPScraper{articles: []scraper.Article{{Title: articleTitle, ContentState: scraper.ContentComplete, Content: articleBody, URL: articleURL}}}
|
||||
summary := &ticket17HTTPSummary{}
|
||||
repo := &ticket17HTTPRepo{input: generation.UserInput{SummaryModelID: &modelID, Language: "en", RankingMode: "title", GlobalLimit: 1, Assets: []models.UserAsset{{Name: "S&P 500", Symbol: "SPX"}}, Sources: []models.Source{{ID: "source-yahoo", Type: "yahoo", SourceKey: &key, Enabled: true, ArticleLimit: 5}}}}
|
||||
|
||||
@ -59,7 +59,7 @@ func TestTicket29CompactGroupsIntegrateBeforeSelectionAndFailureIsGlobal(t *test
|
||||
assets[i] = models.UserAsset{Name: fmt.Sprintf("Company %02d Incorporated", i), Symbol: fmt.Sprintf("T%02d", i)}
|
||||
}
|
||||
ranker, _ := ai.NewLayaHTTPRanker(ai.LayaHTTPConfig{BaseURL: srv.URL, BatchSize: 4})
|
||||
model, key := "selected-model", models.SourceYahooFinance
|
||||
model, key := "selected-model", models.SourceBloomberg
|
||||
feed := &ticket17HTTPScraper{articles: []scraper.Article{{Title: "first", URL: "https://fixture.invalid/1"}, {Title: "second", URL: "https://fixture.invalid/2"}}}
|
||||
summary := &ticket17HTTPSummary{}
|
||||
repo := &ticket17HTTPRepo{input: generation.UserInput{SummaryModelID: &model, Language: "en", RankingMode: "title", GlobalLimit: 1, Assets: assets, Sources: []models.Source{{ID: "source", SourceKey: &key, Enabled: true, ArticleLimit: 2}}}}
|
||||
|
||||
@ -35,7 +35,7 @@ func (r *ticket17SummaryResolver) Resolve(_ context.Context, user string, select
|
||||
func TestTicket17GenerationScrapesThenLayaRanksThenUsesSelectedSummaryModel(t *testing.T) {
|
||||
order := []string{}
|
||||
modelID := "summary-catalog-a"
|
||||
key := models.SourceYahooFinance
|
||||
key := models.SourceBloomberg
|
||||
feed := &ticket17Feed{order: &order}
|
||||
ranker := &ticket14LayaRanker{selectedTitle: "candidate title", order: &order}
|
||||
summary := &ticket14SummaryProvider{order: &order, content: "summary from selected catalogue model"}
|
||||
|
||||
@ -56,8 +56,8 @@ func TestLegacyNullFIGIAssetStillContributesToGenerationPostgres(t *testing.T) {
|
||||
`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,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 sources(id,name,type,enabled,article_limit,source_key) VALUES ('00000000-0000-0000-0000-000000000421','test source','ticket4',TRUE,20,'bloomberg')`,
|
||||
`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,'investing_com')`,
|
||||
`INSERT INTO settings(key,value) VALUES ('summary_max_articles','50'),('ai_system_prompt','Configured generation context')`,
|
||||
} {
|
||||
if _, err := db.Exec(statement); err != nil {
|
||||
@ -72,7 +72,7 @@ func TestLegacyNullFIGIAssetStillContributesToGenerationPostgres(t *testing.T) {
|
||||
if input.SummaryContext != "Configured generation context" {
|
||||
t.Fatal("existing generation context lost")
|
||||
}
|
||||
if len(input.Sources) != 1 || input.Sources[0].SourceKey == nil || *input.Sources[0].SourceKey != models.SourceYahooFinance || input.Sources[0].ArticleLimit != 20 {
|
||||
if len(input.Sources) != 1 || input.Sources[0].SourceKey == nil || *input.Sources[0].SourceKey != models.SourceBloomberg || 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" {
|
||||
@ -91,7 +91,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{models.SourceYahooFinance: feed},
|
||||
Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: feed},
|
||||
Ranker: ranker,
|
||||
Summarizer: summarizer,
|
||||
Clock: func() time.Time { return time.Unix(1, 0).UTC() },
|
||||
|
||||
@ -13,6 +13,7 @@ func TestGenerationRoutesOnlyAllowlistedSourceKeysEvenWhenLegacyRowsAreEnabled(t
|
||||
var sources []models.Source
|
||||
if err := json.Unmarshal([]byte(`[
|
||||
{"id":"y","name":"Yahoo Finance","type":"stocktwits","source_key":"yahoo_finance","enabled":true,"article_limit":20},
|
||||
{"id":"i","name":"Investing.com","type":"investing_com","source_key":"investing_com","enabled":true,"article_limit":20},
|
||||
{"id":"b","name":"Bloomberg","type":"bloomberg","source_key":"bloomberg","enabled":true,"article_limit":20},
|
||||
{"id":"c","name":"CNBC Business","type":"cnbc_business","source_key":"cnbc_business","enabled":true,"article_limit":20},
|
||||
{"id":"w","name":"Watcher.Guru","type":"watcherguru","source_key":"watcher_guru","enabled":true,"article_limit":20},
|
||||
@ -23,7 +24,7 @@ func TestGenerationRoutesOnlyAllowlistedSourceKeysEvenWhenLegacyRowsAreEnabled(t
|
||||
}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"user": {Language: "fr", RankingMode: "title", GlobalLimit: 10, Assets: []models.UserAsset{{Symbol: "SPX"}}, Sources: sources}}, saved: map[string][]GenerationRecord{}}
|
||||
feeds := map[string]*contractScraper{}
|
||||
for _, key := range []string{"yahoo_finance", "bloomberg", "cnbc_business", "watcher_guru", "stocktwits", "reuters"} {
|
||||
for _, key := range []string{"yahoo_finance", "bloomberg", "cnbc_business", "investing_com", "watcher_guru", "stocktwits", "reuters"} {
|
||||
feeds[key] = &contractScraper{name: key, articles: []scraper.Article{{Title: key}}}
|
||||
}
|
||||
scrapers := map[string]scraper.Scraper{}
|
||||
@ -34,17 +35,17 @@ func TestGenerationRoutesOnlyAllowlistedSourceKeysEvenWhenLegacyRowsAreEnabled(t
|
||||
if err != nil || result.Summary == nil {
|
||||
t.Fatalf("generation result=%+v err=%v", result, err)
|
||||
}
|
||||
for _, key := range []string{"yahoo_finance", "bloomberg", "cnbc_business"} {
|
||||
for _, key := range []string{"bloomberg", "investing_com"} {
|
||||
if len(feeds[key].calls) != 1 {
|
||||
t.Errorf("target %s calls=%d, want one", key, len(feeds[key].calls))
|
||||
}
|
||||
}
|
||||
for _, key := range []string{"watcher_guru", "stocktwits", "reuters"} {
|
||||
for _, key := range []string{"yahoo_finance", "cnbc_business", "watcher_guru", "stocktwits", "reuters"} {
|
||||
if len(feeds[key].calls) != 0 {
|
||||
t.Errorf("unsupported enabled source %s was invoked %d times", key, len(feeds[key].calls))
|
||||
}
|
||||
}
|
||||
if result.Outcome.TotalCandidates != 3 {
|
||||
t.Errorf("target candidate count=%d, want 3", result.Outcome.TotalCandidates)
|
||||
if result.Outcome.TotalCandidates != 2 {
|
||||
t.Errorf("target candidate count=%d, want 2", result.Outcome.TotalCandidates)
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestTicket40CanonicalSourceKeyAndReachabilitySeparateFromContent(t *testing.T) {
|
||||
for _, key := range []string{models.SourceYahooFinance, models.SourceBloomberg, models.SourceCNBCBusiness} {
|
||||
for _, key := range []string{models.SourceBloomberg, models.SourceInvesting} {
|
||||
t.Run(key, func(t *testing.T) {
|
||||
feed := &ticket39ContentFeed{}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title_content", GlobalLimit: 3, Assets: []models.UserAsset{{Name: "Followed fixture"}}, Sources: []models.Source{{ID: "s", Type: "stocktwits", SourceKey: &key, Enabled: true, ArticleLimit: 3}}}}, saved: map[string][]GenerationRecord{}}
|
||||
@ -34,3 +34,18 @@ func TestTicket40CanonicalSourceKeyAndReachabilitySeparateFromContent(t *testing
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTicket42HistoricalSourceKeysAndTypesRemainReadable(t *testing.T) {
|
||||
const payload = `{"status":"partial","source_stats":[{"source_key":"yahoo_finance","source_type":"stocktwits","source_id":"old-y","article_limit":83,"status":"ok"},{"source_key":"cnbc_business","source_type":"cnbc_business","source_id":"old-c","article_limit":31,"status":"ok"}]}`
|
||||
var historical GenerationOutcome
|
||||
if err := json.Unmarshal([]byte(payload), &historical); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if historical.Status != "partial" || len(historical.SourceStats) != 2 || historical.SourceStats[0].SourceKey != models.SourceYahooFinance || historical.SourceStats[0].SourceType != "stocktwits" || historical.SourceStats[0].ArticleLimit != 83 || historical.SourceStats[1].SourceKey != models.SourceCNBCBusiness || historical.SourceStats[1].SourceType != "cnbc_business" || historical.SourceStats[1].ArticleLimit != 31 {
|
||||
t.Fatal("historical outcome was reclassified")
|
||||
}
|
||||
raw, err := json.Marshal(historical)
|
||||
if err != nil || !strings.Contains(string(raw), `"source_key":"yahoo_finance"`) || !strings.Contains(string(raw), `"source_key":"cnbc_business"`) {
|
||||
t.Fatal("legacy source keys disappeared from history")
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,8 +25,8 @@ func TestTicket34MixedSourceUsesReceiptOrderBeforeInputLimit(t *testing.T) {
|
||||
t.Fatalf("mixed source reordered before N: got %v want %v", got, want)
|
||||
}
|
||||
sum := &contractSummarizer{}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 2, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceYahooFinance), Enabled: true, ArticleLimit: 2}}}}, saved: map[string][]GenerationRecord{}}
|
||||
result, err := NewUseCase(Dependencies{Repository: repo, Decider: &allYesMention{}, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: &contractScraper{articles: articles}}}).Generate(context.Background(), "u")
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 2, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 2}}}}, saved: map[string][]GenerationRecord{}}
|
||||
result, err := NewUseCase(Dependencies{Repository: repo, Decider: &allYesMention{}, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: &contractScraper{articles: articles}}}).Generate(context.Background(), "u")
|
||||
if err != nil || result.Outcome.TotalCandidates != 2 || len(sum.articles) != 1 || !reflect.DeepEqual(candidateTitles(sum.articles[0]), want) {
|
||||
t.Fatal("source mode must be chosen before N and preserved through passes", result.Outcome, err)
|
||||
}
|
||||
@ -38,8 +38,8 @@ func TestTicket34MergePreservesEachSourceOrderIncludingMixedDates(t *testing.T)
|
||||
sum := &contractSummarizer{}
|
||||
a := &contractScraper{articles: []scraper.Article{reviewDate("a-old", 1), {Title: "a-undated"}, reviewDate("a-new", 9)}}
|
||||
b := &contractScraper{articles: []scraper.Article{reviewDate("b-new", 10), reviewDate("b-mid", 5)}}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 5, Sources: []models.Source{{ID: "a", SourceKey: testSourceKey(models.SourceYahooFinance), Enabled: true, ArticleLimit: 3}, {ID: "b", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 2}}}}, saved: map[string][]GenerationRecord{}}
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Decider: gate, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: a, models.SourceBloomberg: b}}).Generate(context.Background(), "u")
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 5, Sources: []models.Source{{ID: "a", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 3}, {ID: "b", SourceKey: testSourceKey(models.SourceInvesting), Enabled: true, ArticleLimit: 2}}}}, saved: map[string][]GenerationRecord{}}
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Decider: gate, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: a, models.SourceInvesting: b}}).Generate(context.Background(), "u")
|
||||
if err != nil || r.Summary == nil {
|
||||
t.Fatal(r, err)
|
||||
}
|
||||
|
||||
@ -29,9 +29,9 @@ func TestTicket35SummaryFailureDistinguishesTimeoutCancellationAndProvider(t *te
|
||||
{"provider", errors.New("PRIVATE_BODY timeout https://PRIVATE_URL.invalid"), "summary_failed"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 1, Assets: []models.UserAsset{{Name: "Fixture Company"}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceYahooFinance), Enabled: true, ArticleLimit: 1}}}}, saved: map[string][]GenerationRecord{}}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 1, Assets: []models.UserAsset{{Name: "Fixture Company"}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 1}}}}, saved: map[string][]GenerationRecord{}}
|
||||
sum := &contractSummarizer{err: tc.err}
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Decider: &allYesMention{}, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: &contractScraper{articles: []scraper.Article{{Title: "Fixture Company"}}}}}).Generate(context.Background(), "u")
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Decider: &allYesMention{}, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: &contractScraper{articles: []scraper.Article{{Title: "Fixture Company"}}}}}).Generate(context.Background(), "u")
|
||||
if err != nil || r.Summary != nil || r.Outcome.Status != "failed" || r.Outcome.FailureCode != tc.code {
|
||||
t.Fatalf("status=%s code=%s err=%v", r.Outcome.Status, r.Outcome.FailureCode, err)
|
||||
}
|
||||
@ -71,11 +71,11 @@ func (r *terminalRepo) SaveGeneration(ctx context.Context, user string, record G
|
||||
return r.contractRepository.SaveGeneration(ctx, user, record)
|
||||
}
|
||||
func TestTicket35CanceledSummaryStillPersistsSafeTerminalOutcome(t *testing.T) {
|
||||
base := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 1, Assets: []models.UserAsset{{Name: "Fixture Company"}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceYahooFinance), Enabled: true, ArticleLimit: 1}}}}, saved: map[string][]GenerationRecord{}}
|
||||
base := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 1, Assets: []models.UserAsset{{Name: "Fixture Company"}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 1}}}}, saved: map[string][]GenerationRecord{}}
|
||||
repo := &terminalRepo{contractRepository: base, expectedJob: "fixture-job"}
|
||||
ctx, cancel := context.WithCancel(models.WithGenerationJob(context.Background(), repo.expectedJob))
|
||||
defer cancel()
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Decider: &allYesMention{}, Summarizer: cancelSummary{cancel}, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: &contractScraper{articles: []scraper.Article{{Title: "Fixture Company"}}}}}).Generate(ctx, "u")
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Decider: &allYesMention{}, Summarizer: cancelSummary{cancel}, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: &contractScraper{articles: []scraper.Article{{Title: "Fixture Company"}}}}}).Generate(ctx, "u")
|
||||
if err != nil || !repo.checked || r.Summary != nil || r.Outcome.FailureCode != "summary_canceled" || len(base.saved["u"]) != 1 {
|
||||
t.Fatal(r.Outcome, err)
|
||||
}
|
||||
@ -106,10 +106,10 @@ func TestTicket35ThreePassBudgetIsSharedAndFailureDropsAllSelection(t *testing.T
|
||||
for i := 0; i < 65; i++ {
|
||||
articles = append(articles, scraper.Article{Title: fmt.Sprintf("unmatched %d", i)})
|
||||
}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 100, Assets: []models.UserAsset{{Name: "Fixture Company"}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceYahooFinance), Enabled: true, ArticleLimit: 100}}}}, saved: map[string][]GenerationRecord{}}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 100, Assets: []models.UserAsset{{Name: "Fixture Company"}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 100}}}}, saved: map[string][]GenerationRecord{}}
|
||||
gate := &budgetMention{failIndirect: true}
|
||||
sum := &contractSummarizer{}
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Decider: gate, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: &contractScraper{articles: articles}}}).Generate(context.Background(), "u")
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Decider: gate, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: &contractScraper{articles: articles}}}).Generate(context.Background(), "u")
|
||||
if err != nil || r.Summary != nil || r.Outcome.FailureCode != "ranking_failed" || len(sum.articles) != 0 || gate.budgetCalls != 1 || len(gate.contexts) != 3 {
|
||||
t.Fatal(r.Outcome, err)
|
||||
}
|
||||
@ -139,9 +139,9 @@ func TestTicket35BloombergMissingContentProducesHonestGenerationFallback(t *test
|
||||
io.WriteString(w, `{"articles":[{"title":"Fixture Company","url":"https://fixture.invalid/article","published_at":null}]}`)
|
||||
}))
|
||||
defer server.Close()
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title_content", GlobalLimit: 1, Assets: []models.UserAsset{{Name: "Fixture Company"}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 1}}}}, saved: map[string][]GenerationRecord{}}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title_content", GlobalLimit: 1, Assets: []models.UserAsset{{Name: "Fixture Company"}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceInvesting), Enabled: true, ArticleLimit: 1}}}}, saved: map[string][]GenerationRecord{}}
|
||||
summary := &contractSummarizer{}
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Decider: &allYesMention{}, Summarizer: summary, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: bloombergFixtureFeed{bloomberg.New(server.URL)}}}).Generate(context.Background(), "u")
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Decider: &allYesMention{}, Summarizer: summary, Scrapers: map[string]scraper.Scraper{models.SourceInvesting: bloombergFixtureFeed{bloomberg.New(server.URL)}}}).Generate(context.Background(), "u")
|
||||
if err != nil || r.Summary != nil || requests != 1 || r.Outcome.ContentFallbacks != 1 || r.Outcome.SourceStats[0].ContentFallbacks != 1 || len(summary.articles) != 0 || r.Outcome.FailureCode != "no_complete_content" {
|
||||
t.Fatal("inaccurate Bloomberg content availability", r.Outcome, err)
|
||||
}
|
||||
@ -157,10 +157,10 @@ func (s *liveContextSummary) Summarize(ctx context.Context, _ string, _ []models
|
||||
return "fixture synthesis", nil
|
||||
}
|
||||
func TestTicket35SummaryDoesNotInheritCanceledSelectionBudget(t *testing.T) {
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 1, Assets: []models.UserAsset{{Name: "Fixture Company"}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceYahooFinance), Enabled: true, ArticleLimit: 1}}}}, saved: map[string][]GenerationRecord{}}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 1, Assets: []models.UserAsset{{Name: "Fixture Company"}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 1}}}}, saved: map[string][]GenerationRecord{}}
|
||||
gate := &budgetMention{}
|
||||
sum := &liveContextSummary{}
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Decider: gate, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: &contractScraper{articles: []scraper.Article{{Title: "unmatched"}}}}}).Generate(context.Background(), "u")
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Decider: gate, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: &contractScraper{articles: []scraper.Article{{Title: "unmatched"}}}}}).Generate(context.Background(), "u")
|
||||
if err != nil || r.Summary == nil || !sum.called || gate.budgetCalls != 1 || len(gate.contexts) != 2 {
|
||||
t.Fatal(r.Outcome, err)
|
||||
}
|
||||
|
||||
@ -41,8 +41,8 @@ func TestTicket34ThreePassesInputPoolPriorityAndLastBatchTrim(t *testing.T) {
|
||||
b := &contractScraper{articles: []scraper.Article{{Title: "b1"}, {Title: "b2"}, {Title: "b3"}, {Title: "excluded-b"}}}
|
||||
gate := &mentionFixture{yes: map[string]map[string]bool{"direct": {"a9": true, "b1": true}, "indirect": {"a8": true, "b2": true, "b3": true}}}
|
||||
sum := &contractSummarizer{}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 4, Assets: []models.UserAsset{{Name: "Acme Holdings"}}, Sources: []models.Source{{ID: "a", SourceKey: testSourceKey(models.SourceYahooFinance), Enabled: true, ArticleLimit: 4}, {ID: "b", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 3}}}}, saved: map[string][]GenerationRecord{}}
|
||||
uc := NewUseCase(Dependencies{Repository: repo, Decider: gate, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: a, models.SourceBloomberg: b}})
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 4, Assets: []models.UserAsset{{Name: "Acme Holdings"}}, Sources: []models.Source{{ID: "a", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 4}, {ID: "b", SourceKey: testSourceKey(models.SourceInvesting), Enabled: true, ArticleLimit: 3}}}}, saved: map[string][]GenerationRecord{}}
|
||||
uc := NewUseCase(Dependencies{Repository: repo, Decider: gate, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: a, models.SourceInvesting: b}})
|
||||
result, err := uc.Generate(context.Background(), "u")
|
||||
if err != nil || result.Summary == nil {
|
||||
t.Fatalf("%+v %v", result.Outcome, err)
|
||||
@ -58,10 +58,10 @@ func TestTicket34ThreePassesInputPoolPriorityAndLastBatchTrim(t *testing.T) {
|
||||
}
|
||||
}
|
||||
func TestTicket34NoPartialSummaryOnMentionFailure(t *testing.T) {
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 5, Assets: []models.UserAsset{{Name: "Acme"}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceYahooFinance), Enabled: true, ArticleLimit: 5}}}}, saved: map[string][]GenerationRecord{}}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 5, Assets: []models.UserAsset{{Name: "Acme"}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 5}}}}, saved: map[string][]GenerationRecord{}}
|
||||
sum := &contractSummarizer{}
|
||||
gate := &mentionFixture{err: errors.New("private failure")}
|
||||
uc := NewUseCase(Dependencies{Repository: repo, Decider: gate, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: &contractScraper{articles: []scraper.Article{{Title: "Acme"}, {Title: "unmatched"}}}}})
|
||||
uc := NewUseCase(Dependencies{Repository: repo, Decider: gate, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: &contractScraper{articles: []scraper.Article{{Title: "Acme"}, {Title: "unmatched"}}}}})
|
||||
r, err := uc.Generate(context.Background(), "u")
|
||||
if err != nil || r.Summary != nil || r.Outcome.Status != "failed" || len(sum.articles) != 0 {
|
||||
t.Fatal(r, err)
|
||||
@ -89,8 +89,8 @@ func TestTicket34StopsAtReachingBatchWithoutReplacingEarlierPass(t *testing.T) {
|
||||
}
|
||||
old := newest.Add(-1000 * time.Hour)
|
||||
articles = append(articles, scraper.Article{Title: "Acme Holdings", PublishedAt: &old})
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 66, Assets: []models.UserAsset{{Name: "Acme Holdings"}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceYahooFinance), Enabled: true, ArticleLimit: 200}}}}, saved: map[string][]GenerationRecord{}}
|
||||
uc := NewUseCase(Dependencies{Repository: repo, Decider: gate, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: &contractScraper{articles: articles}}})
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title", GlobalLimit: 66, Assets: []models.UserAsset{{Name: "Acme Holdings"}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 200}}}}, saved: map[string][]GenerationRecord{}}
|
||||
uc := NewUseCase(Dependencies{Repository: repo, Decider: gate, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: &contractScraper{articles: articles}}})
|
||||
r, err := uc.Generate(context.Background(), "u")
|
||||
if err != nil || r.Outcome.Selected != 66 || !reflect.DeepEqual(gate.passes, []string{"direct", "direct"}) || !reflect.DeepEqual(gate.sizes, []int{64, 64}) {
|
||||
t.Fatal(r.Outcome, gate.passes, gate.sizes, err)
|
||||
@ -114,9 +114,9 @@ func TestTicket34DeterministicMentionUsesResolvedNamesAliasesAndModeOnly(t *test
|
||||
id := "resolved"
|
||||
gate := &mentionFixture{yes: map[string]map[string]bool{}}
|
||||
sum := &contractSummarizer{}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: mode, GlobalLimit: 1, Assets: []models.UserAsset{{Name: "untrusted stored spelling", Symbol: "INTC", CompanyID: &id}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceYahooFinance), Enabled: true, ArticleLimit: 2}}}}, saved: map[string][]GenerationRecord{}}
|
||||
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: mode, GlobalLimit: 1, Assets: []models.UserAsset{{Name: "untrusted stored spelling", Symbol: "INTC", CompanyID: &id}}, Sources: []models.Source{{ID: "s", SourceKey: testSourceKey(models.SourceBloomberg), Enabled: true, ArticleLimit: 2}}}}, saved: map[string][]GenerationRecord{}}
|
||||
feed := &contractScraper{articles: []scraper.Article{{Title: "Intelligence and INTC", ContentState: scraper.ContentComplete, Content: "Intel invests."}}}
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Decider: gate, Names: fixtureNames{}, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: feed}}).Generate(context.Background(), "u")
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Decider: gate, Names: fixtureNames{}, Summarizer: sum, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: feed}}).Generate(context.Background(), "u")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user