feat(generation): enforce prompt budget with whole article eviction (#47)
This commit is contained in:
@ -73,7 +73,7 @@ func TestTicket37MetadataAndCollectorIsolation(t *testing.T) {
|
||||
var events []SummaryDiagnostic
|
||||
a := generationSummarizer{providerName: "gemini", model: "gemini-2.5-flash", provider: p, diagnostics: func(d SummaryDiagnostic) error { events = append(events, d); return nil }}
|
||||
_, err := a.Summarize(context.Background(), "fr", nil, []generation.Candidate{{Article: scraper.Article{Title: strings.Repeat("PRIVATE_TITLE", 30000)}}})
|
||||
if err == nil || p.calls != 0 || len(events) != 1 || events[0].Category != "prompt_budget_exceeded" || events[0].PromptBytes <= 24576 {
|
||||
if err == nil || p.calls != 0 || len(events) != 1 || events[0].Category != "prompt_budget_exceeded" {
|
||||
t.Fatal("missing preflight diagnostic")
|
||||
}
|
||||
sentinel := errors.New("PRIVATE_ERROR")
|
||||
@ -89,8 +89,17 @@ func TestTicket37MetadataAndCollectorIsolation(t *testing.T) {
|
||||
if failure == "nil" {
|
||||
collector = nil
|
||||
}
|
||||
got, e := (generationSummarizer{providerName: "gemini", model: "gemini-2.5-flash", provider: provider, diagnostics: collector}).Summarize(context.Background(), "fr", nil, nil)
|
||||
if e != providerErr || got != "synthetic synthesis" || provider.calls != 1 {
|
||||
got, e := (generationSummarizer{providerName: "gemini", model: "gemini-2.5-flash", provider: provider, diagnostics: collector}).Summarize(context.Background(), "fr", nil, []generation.Candidate{{Article: scraper.Article{Content: "body"}}})
|
||||
wantContent := "synthetic synthesis"
|
||||
wantCode := ""
|
||||
if providerErr != nil {
|
||||
wantContent, wantCode = "", "summary_failed"
|
||||
}
|
||||
code := ""
|
||||
if e != nil {
|
||||
code = e.Error()
|
||||
}
|
||||
if code != wantCode || got != wantContent || provider.calls != 1 {
|
||||
t.Fatal("collector changed provider outcome")
|
||||
}
|
||||
}
|
||||
@ -114,7 +123,7 @@ func TestTicket37HTTPStatusAcrossProviderAdapters(t *testing.T) {
|
||||
for _, p := range []Provider{ollama, anthropic, gemini, oa} {
|
||||
t.Run(p.Name(), func(t *testing.T) {
|
||||
events := []SummaryDiagnostic{}
|
||||
_, err := (generationSummarizer{providerName: "gemini", model: "gemini-2.5-flash", provider: p, diagnostics: func(d SummaryDiagnostic) error { events = append(events, d); return nil }}).Summarize(context.Background(), "fr", nil, nil)
|
||||
_, err := (generationSummarizer{providerName: "gemini", model: "gemini-2.5-flash", provider: p, diagnostics: func(d SummaryDiagnostic) error { events = append(events, d); return nil }}).Summarize(context.Background(), "fr", nil, []generation.Candidate{{Article: scraper.Article{Content: "body"}}})
|
||||
if err == nil || len(events) != 1 || events[0].Category != "provider_http_error" || events[0].HTTPStatus != 503 {
|
||||
t.Fatal("HTTP status lost")
|
||||
}
|
||||
@ -132,7 +141,7 @@ func TestTicket37PipelineCollectorAndDefaultSilence(t *testing.T) {
|
||||
log.SetOutput(&logs)
|
||||
defer log.SetOutput(old)
|
||||
pipeline := NewPipeline(nil, nil)
|
||||
_, _ = (generationSummarizer{providerName: "gemini", model: "gemini-2.5-flash", p: pipeline, provider: &contentProvider{}}).Summarize(context.Background(), "fr", nil, nil)
|
||||
_, _ = (generationSummarizer{providerName: "gemini", model: "gemini-2.5-flash", p: pipeline, provider: &contentProvider{}}).Summarize(context.Background(), "fr", nil, []generation.Candidate{{Article: scraper.Article{Content: "body"}}})
|
||||
if logs.Len() != 0 {
|
||||
t.Fatal("default diagnostic must be silent")
|
||||
}
|
||||
@ -144,7 +153,7 @@ func TestTicket37PipelineCollectorAndDefaultSilence(t *testing.T) {
|
||||
}
|
||||
return nil
|
||||
})
|
||||
_, _ = (generationSummarizer{providerName: "gemini", model: "gemini-2.5-flash", p: pipeline, provider: &contentProvider{}}).Summarize(context.Background(), "fr", nil, nil)
|
||||
_, _ = (generationSummarizer{providerName: "gemini", model: "gemini-2.5-flash", p: pipeline, provider: &contentProvider{}}).Summarize(context.Background(), "fr", nil, []generation.Candidate{{Article: scraper.Article{Content: "body"}}})
|
||||
if count != 1 {
|
||||
t.Fatal("pipeline collector not wired")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user