feat(summary): send complete articles within user budget (#39)
This commit is contained in:
41
backend/internal/e2estack/content_ticket39_test.go
Normal file
41
backend/internal/e2estack/content_ticket39_test.go
Normal file
@ -0,0 +1,41 @@
|
||||
package e2estack
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tradarr/backend/internal/scraper"
|
||||
"github.com/tradarr/backend/internal/summarybudget"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTicket39FakeScraperDeclaresCompleteEditorialContent(t *testing.T) {
|
||||
f := NewFakes()
|
||||
base, closeServer, err := Listen(f.Handler())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer closeServer()
|
||||
articles, err := (FakeScraper{URL: base, Client: LoopbackClient()}).Scrape(context.Background(), []string{"FIX"})
|
||||
if err != nil || len(articles) != 1 {
|
||||
t.Fatal("fixture scrape failed", err)
|
||||
}
|
||||
if articles[0].ContentState != scraper.ContentComplete || scraper.ContentStatus(articles[0]) != scraper.ContentComplete {
|
||||
t.Fatal("fixture editorial body is not explicitly complete")
|
||||
}
|
||||
}
|
||||
func TestTicket39FakeSummaryProfileIsExplicitAndNotInProductionRegistry(t *testing.T) {
|
||||
if _, ok := summarybudget.Lookup("ollama", "fake-summary"); ok {
|
||||
t.Fatal("fake capacity leaked into production registry")
|
||||
}
|
||||
p, ok := FixtureSummaryProfile("ollama", "fake-summary")
|
||||
if !ok {
|
||||
t.Fatal("fixture capacity missing")
|
||||
}
|
||||
if _, err := p.Measure("fixture prompt", 250000); err != nil {
|
||||
t.Fatal("fixture profile invalid", err)
|
||||
}
|
||||
for _, pair := range [][2]string{{"openai", "fake-summary"}, {"ollama", "unknown"}} {
|
||||
if _, ok := FixtureSummaryProfile(pair[0], pair[1]); ok {
|
||||
t.Fatal("fixture profile accepted unknown model")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -15,6 +15,7 @@ import (
|
||||
"github.com/tradarr/backend/internal/generation"
|
||||
"github.com/tradarr/backend/internal/models"
|
||||
"github.com/tradarr/backend/internal/scraper"
|
||||
"github.com/tradarr/backend/internal/summarybudget"
|
||||
)
|
||||
|
||||
type Fixtures struct {
|
||||
@ -112,7 +113,7 @@ func (f *Fakes) Handler() http.Handler {
|
||||
return
|
||||
}
|
||||
f.record(Event{Kind: "scraperCalls", Symbols: symbols})
|
||||
_ = json.NewEncoder(w).Encode([]scraper.Article{{Title: f.Fixture.ArticleTitle, Content: f.Fixture.ArticleContent, URL: f.Fixture.ArticleURL}})
|
||||
_ = json.NewEncoder(w).Encode([]scraper.Article{{ContentState: scraper.ContentComplete, Title: f.Fixture.ArticleTitle, Content: f.Fixture.ArticleContent, URL: f.Fixture.ArticleURL}})
|
||||
})
|
||||
mux.HandleFunc("/api/generate", func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
@ -270,3 +271,12 @@ func (c FakeCompanyCatalog) MentionNames(id string) ([]string, error) {
|
||||
}
|
||||
return []string{company.Name}, nil
|
||||
}
|
||||
|
||||
// FixtureSummaryProfile belongs only to the isolated browser stack. It is never
|
||||
// registered globally or used by the production server's composition.
|
||||
func FixtureSummaryProfile(provider, model string) (summarybudget.Profile, bool) {
|
||||
if provider != "ollama" || model != "fake-summary" {
|
||||
return summarybudget.Profile{}, false
|
||||
}
|
||||
return summarybudget.Profile{ContextWindowTokens: 8192, InputLimitTokens: 8192, OutputReserveTokens: 1024, Counter: summarybudget.UTF8UpperBound, FramingTokens: 1024}, true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user