feat(qa): add synthesis conversations with source retention (#52)
This commit is contained in:
45
backend/internal/generation/retention_ticket53_test.go
Normal file
45
backend/internal/generation/retention_ticket53_test.go
Normal file
@ -0,0 +1,45 @@
|
||||
package generation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/tradarr/backend/internal/models"
|
||||
"github.com/tradarr/backend/internal/scraper"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type qa53Summary struct{ fail bool }
|
||||
|
||||
func (p qa53Summary) Summarize(context.Context, string, []models.UserAsset, []Candidate) (string, error) {
|
||||
if p.fail {
|
||||
return "", errors.New("fixture failure")
|
||||
}
|
||||
return "safe summary", nil
|
||||
}
|
||||
func TestTicket53RetainsOnlyFinalSelectedArticlesOutsideAggregateJSON(t *testing.T) {
|
||||
for _, fail := range []bool{false, true} {
|
||||
key := models.SourceBloomberg
|
||||
feed := &ticket14Feed{}
|
||||
ranker := &ticket14LayaRanker{selectedTitle: "Market title B"}
|
||||
repo := &ticket14Repository{input: UserInput{SourceArticleRetentionDays: 3, Language: "en", RankingMode: "title_content", GlobalLimit: 1, Sources: []models.Source{{ID: "s", SourceKey: &key, Enabled: true, ArticleLimit: 10}}}}
|
||||
r, err := NewUseCase(Dependencies{Repository: repo, Ranker: ranker, Summarizer: qa53Summary{fail: fail}, Scrapers: map[string]scraper.Scraper{key: feed}}).Generate(context.Background(), "u")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if fail {
|
||||
if len(repo.saved[0].SourceArticles) != 0 {
|
||||
t.Fatal("failed summary retained articles")
|
||||
}
|
||||
continue
|
||||
}
|
||||
if len(repo.saved[0].SourceArticles) != 1 || repo.saved[0].SourceArticles[0].Title != "Market title B" || repo.saved[0].SourceArticleRetentionDays != 3 {
|
||||
t.Fatalf("unexpected retention snapshot %+v", repo.saved[0])
|
||||
}
|
||||
raw, _ := json.Marshal(r)
|
||||
if strings.Contains(string(raw), "Market title") || strings.Contains(string(raw), "Market body") {
|
||||
t.Fatal("sources leaked into generation DTO")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user