feat(summary): send complete articles within user budget (#39)

This commit is contained in:
2026-11-24 17:39:26 +01:00
parent d0c7cb7cae
commit 79953ce49f
73 changed files with 1688 additions and 288 deletions

View File

@ -24,6 +24,7 @@ func (f *contentFeed) Enrich(_ context.Context, a []scraper.Article) ([]scraper.
}
out := append([]scraper.Article(nil), a...)
for i := range out {
out[i].ContentState = scraper.ContentComplete
out[i].Content = "synthetic editorial paragraph"
d := time.Date(2026, 1, 1, i+1, 0, 0, 0, time.UTC)
out[i].PublishedAt = &d
@ -45,10 +46,16 @@ func TestTicket36EnrichmentAfterPoolAndNoReordering(t *testing.T) {
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{}}
sum := &contractSummarizer{}
r, err := NewUseCase(Dependencies{Repository: repo, Decider: &allYesMention{}, Summarizer: sum, Scrapers: map[string]scraper.Scraper{source: feed}}).Generate(context.Background(), "u")
if mode == "failure" {
if err != nil || r.Summary != nil || r.Outcome.FailureCode != "no_complete_content" || feed.calls != 1 || r.Outcome.ContentFallbacks != 2 {
t.Fatal("incomplete enrichment must stop before summary")
}
return
}
if err != nil || r.Summary == nil {
t.Fatal(err, r.Outcome)
}
if mode == "title_content" {
if mode == "title_content" || mode == "other_source" {
if feed.calls != 1 || feed.sizes[0] != 2 || sum.articles[0][0].Article.Content == "" || r.Outcome.ContentFallbacks != 0 {
t.Fatal("enrichment missing or before N", feed.calls, feed.sizes)
}
@ -70,7 +77,7 @@ func TestTicket36EnrichedDateDoesNotChangeCrossSourceOrder(t *testing.T) {
keyB, keyY := models.SourceBloomberg, models.SourceYahooFinance
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", PublishedAt: &old}}}
other := &contractScraper{articles: []scraper.Article{{Title: "Fixture Yahoo", ContentState: scraper.ContentComplete, Content: "synthetic full Yahoo body", PublishedAt: &old}}}
repo := &contractRepository{inputs: map[string]UserInput{"u": {Language: "fr", RankingMode: "title_content", GlobalLimit: 2, Assets: []models.UserAsset{{Name: "Fixture"}}, Sources: []models.Source{{ID: "b", SourceKey: &keyB, Enabled: true, ArticleLimit: 1}, {ID: "y", SourceKey: &keyY, Enabled: true, ArticleLimit: 1}}}}, saved: map[string][]GenerationRecord{}}
sum := &contractSummarizer{}
r, err := NewUseCase(Dependencies{Repository: repo, Decider: &allYesMention{}, Summarizer: sum, Scrapers: map[string]scraper.Scraper{keyB: feed, keyY: other}}).Generate(context.Background(), "u")