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

@ -95,8 +95,8 @@ func TestUseCaseIsolatesTwoUsersAndUsesOnlyEnabledSourcesAndUserInputs(t *testin
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}
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", Content: "alpha-secret"}}}
betaScraper := &contractScraper{name: "beta", articles: []scraper.Article{{Title: "beta-only", URL: "https://private.test/beta", Content: "beta-secret"}}}
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"}}}
disabledScraper := &contractScraper{name: "disabled"}
ranker := &contractRanker{}
summarizer := &contractSummarizer{}
@ -195,7 +195,7 @@ func TestUseCaseNoResultsInvalidLayaAndSummaryFailurePersistNoSummary(t *testing
}
func TestUseCasePartialSourceFailureCanSummarizeRemainingSources(t *testing.T) {
good := &contractScraper{name: "good", articles: []scraper.Article{{Title: "good-result"}}}
good := &contractScraper{name: "good", articles: []scraper.Article{{Title: "good-result", ContentState: scraper.ContentComplete, Content: "Synthetic full report."}}}
bad := &contractScraper{name: "bad", err: errors.New("private error with URL https://private.test/article")}
ranker := &contractRanker{order: []string{"good-result"}}
summarizer := &contractSummarizer{}
@ -218,7 +218,7 @@ func TestUseCasePartialSourceFailureCanSummarizeRemainingSources(t *testing.T) {
}
func TestUseCaseOutcomeContainsAggregateCountsWithoutArticleIdentifiers(t *testing.T) {
feed := &contractScraper{name: "source", articles: []scraper.Article{{Title: "candidate-title-secret", URL: "https://private.test/x", Content: "candidate-content-secret"}}}
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{}}
@ -242,14 +242,14 @@ func TestUseCaseOutcomeContainsAggregateCountsWithoutArticleIdentifiers(t *testi
}
func TestUseCaseCountsTitleOnlyFallbackWhenContentIsUnavailable(t *testing.T) {
feed := &contractScraper{name: "source", articles: []scraper.Article{{Title: "title-without-content", Content: ""}}}
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) }})
result, err := uc.Generate(context.Background(), "u")
if err != nil || result.Summary == nil {
t.Fatalf("content fallback should permit generation: result=%+v err=%v", result, err)
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)
}
if result.Outcome.ContentFallbacks != 1 {
t.Fatalf("content fallback count=%d, want 1", result.Outcome.ContentFallbacks)