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

@ -0,0 +1,56 @@
package generation
import (
"context"
"github.com/tradarr/backend/internal/models"
"github.com/tradarr/backend/internal/scraper"
"testing"
)
func TestTicket39NoContentIsExplicit(t *testing.T) {
key := models.SourceYahooFinance
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")
if err != nil || r.Summary != nil || r.Outcome.FailureCode != "no_complete_content" || r.Outcome.PromptBudget.RequestedTokens != 250000 {
t.Fatalf("incomplete body was selected: %+v %v", r.Outcome, err)
}
}
type ticket39ContentFeed struct{ calls, size int }
func (*ticket39ContentFeed) Name() string { return "fixture" }
func (*ticket39ContentFeed) Scrape(context.Context, []string) ([]scraper.Article, error) {
return []scraper.Article{{Title: "Followed fixture one", URL: "https://fixture.invalid/one"}, {Title: "Followed fixture two", URL: "https://fixture.invalid/two"}, {Title: "Followed fixture three", URL: "https://fixture.invalid/three"}, {Title: "outside source limit"}}, nil
}
func (f *ticket39ContentFeed) Enrich(_ context.Context, a []scraper.Article) ([]scraper.Article, error) {
f.calls++
f.size = len(a)
out := append([]scraper.Article(nil), a...)
for i := range out {
switch i {
case 0:
out[i].Content = "Entire editorial body."
out[i].ContentState = scraper.ContentComplete
case 1:
out[i].Content = "Partial teaser."
out[i].ContentState = scraper.ContentIncomplete
default:
out[i].ContentState = scraper.ContentUnavailable
}
}
return out, nil
}
func TestTicket39AllRuntimeSourcesEnrichAfterLimitAndOnlyCompleteSelectable(t *testing.T) {
for _, key := range []string{models.SourceBloomberg, models.SourceYahooFinance, models.SourceCNBCBusiness} {
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{}}
sum := &contractSummarizer{}
r, err := NewUseCase(Dependencies{Repository: repo, Decider: &allYesMention{}, Summarizer: sum, Scrapers: map[string]scraper.Scraper{key: feed}}).Generate(context.Background(), "u")
if err != nil || feed.calls != 1 || feed.size != 3 || r.Summary == nil || r.Outcome.Status != "partial" || r.Outcome.ContentComplete != 1 || r.Outcome.ContentIncomplete != 1 || r.Outcome.ContentUnavailable != 1 || r.Outcome.Selected != 1 || sum.articles[0][0].Article.Content != "Entire editorial body." || sum.articles[0][0].Article.Source != key {
t.Fatalf("incorrect full-content flow %+v %v", r.Outcome, err)
}
})
}
}