feat(generation): enforce prompt budget with whole article eviction (#47)

This commit is contained in:
2026-11-25 11:47:23 +01:00
parent 3983e49ff8
commit c5b8d0d4da
31 changed files with 882 additions and 296 deletions

View File

@ -18,27 +18,28 @@ func TestTicket44TerraFullPromptAdmission(t *testing.T) {
p := &incident37Provider{}
a := fullGenerationSummarizer{provider: p, providerName: "openai", model: "gpt-6.1-terra"}
req := generation.SummaryRequest{Language: "en", Budget: 1000000, Candidates: []generation.Candidate{{ID: "fixture", Article: scraper.Article{Title: "Fixture", Content: "body", Source: "bloomberg"}}}}
_, u, err := a.SummarizeWithBudget(context.Background(), req)
_, u, _, err := a.SummarizeWithBudget(context.Background(), req)
if err != nil {
t.Fatal(err)
}
overhead := u.PromptTokens - len("body")
body := strings.Repeat("x", 1000000-overhead-1)
req.Candidates[0].Article.Content = body
_, u, err = a.SummarizeWithBudget(context.Background(), req)
_, u, _, err = a.SummarizeWithBudget(context.Background(), req)
if err != nil || u.EffectiveTokens != 1000000 || u.PromptTokens != 999999 || !strings.Contains(p.prompt, body) || p.options.MaxOutputTokens != 4096 {
t.Fatalf("near-limit full prompt rejected/changed: %+v %v", u, err)
}
calls := p.calls
req.Candidates[0].Article.Content = body + "xx"
_, _, err = a.SummarizeWithBudget(context.Background(), req)
if !errors.Is(err, summarybudget.ErrExceeded) || p.calls != calls {
_, _, _, err = a.SummarizeWithBudget(context.Background(), req)
if !errors.Is(err, summarybudget.ErrNoArticlesFit) || p.calls != calls {
t.Fatal("overflow called provider or was truncated")
}
a.model = "unknown"
_, _, err = a.SummarizeWithBudget(context.Background(), req)
if !errors.Is(err, summarybudget.ErrUnknown) || p.calls != calls {
t.Fatal("unknown capacity called provider")
req.Candidates[0].Article.Content = "body"
_, _, _, err = a.SummarizeWithBudget(context.Background(), req)
if err != nil || p.calls != calls+1 {
t.Fatal("unknown model blocked before provider")
}
}