52 lines
1.8 KiB
Go
52 lines
1.8 KiB
Go
package ai
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"github.com/tradarr/backend/internal/generation"
|
|
"github.com/tradarr/backend/internal/models"
|
|
"github.com/tradarr/backend/internal/scraper"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
type budget47Repo struct {
|
|
incident37Repo
|
|
fixed bool
|
|
}
|
|
|
|
func (r *budget47Repo) LoadUserInput(ctx context.Context, user string) (generation.UserInput, error) {
|
|
input, err := r.incident37Repo.LoadUserInput(ctx, user)
|
|
input.SummaryPromptTokenBudget = 3000
|
|
if r.fixed {
|
|
input.SummaryContext = strings.Repeat("PRIVATE_FIXED", 1000)
|
|
}
|
|
return input, err
|
|
}
|
|
func TestTicket47BudgetFailureOutcomeAndCanonicalCounter(t *testing.T) {
|
|
for _, fixed := range []bool{true, false} {
|
|
repo := &budget47Repo{fixed: fixed}
|
|
p := &incident37Provider{}
|
|
uc := generation.NewUseCase(generation.Dependencies{Repository: repo, Decider: &incident37Laya{}, Summarizer: fullGenerationSummarizer{provider: p}, Scrapers: map[string]scraper.Scraper{models.SourceBloomberg: incident37Feed{oversized: true}}})
|
|
result, err := uc.Generate(context.Background(), "u")
|
|
want, removed := "no_articles_fit_prompt_budget", 60
|
|
if fixed {
|
|
want, removed = "summary_fixed_context_budget_exceeded", 0
|
|
}
|
|
if err != nil || result.Outcome.FailureCode != want || result.Outcome.ArticlesRemovedForPromptBudget != removed || p.calls != 0 || len(repo.saved) != 1 {
|
|
t.Fatalf("wrong safe failure: %+v err=%v", result.Outcome, err)
|
|
}
|
|
raw, _ := json.Marshal(repo.saved[0])
|
|
var payload struct{ Outcome map[string]json.RawMessage }
|
|
json.Unmarshal(raw, &payload)
|
|
var usage map[string]json.RawMessage
|
|
json.Unmarshal(payload.Outcome["prompt_budget"], &usage)
|
|
if _, duplicate := usage["articles_removed_for_prompt_budget"]; duplicate {
|
|
t.Fatal("duplicate counter in prompt_budget")
|
|
}
|
|
if strings.Contains(string(raw), "PRIVATE") {
|
|
t.Fatal("private content persisted")
|
|
}
|
|
}
|
|
}
|