feat(ai): add personal summary models and retire Q&A
Add an admin-managed provider model catalog with per-user summary selection, migration backfill, and generation snapshots. Retire report creation and messaging while preserving owner-scoped history. Refs #15 #16 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -33,3 +33,32 @@ func TestScheduledGenerationContinuesIndependentlyPerUser(t *testing.T) {
|
||||
t.Fatalf("scheduled identities=%v", g.ids)
|
||||
}
|
||||
}
|
||||
|
||||
type modelAvailabilityGenerator struct{ ids, selectedProviders []string }
|
||||
|
||||
func (g *modelAvailabilityGenerator) Generate(_ context.Context, id string) (generation.Result, error) {
|
||||
g.ids = append(g.ids, id)
|
||||
if id == "account-a" {
|
||||
return generation.Result{}, errors.New("summary_model_unavailable")
|
||||
}
|
||||
g.selectedProviders = append(g.selectedProviders, "provider-model-b")
|
||||
return generation.Result{}, nil
|
||||
}
|
||||
|
||||
type twoPersonalModelUsers struct{}
|
||||
|
||||
func (twoPersonalModelUsers) ListUsers() ([]models.User, error) {
|
||||
return []models.User{{ID: "account-a"}, {ID: "account-b"}}, nil
|
||||
}
|
||||
|
||||
func TestScheduledUnavailablePersonalModelFailsOneAccountAndContinuesOther(t *testing.T) {
|
||||
g := &modelAvailabilityGenerator{}
|
||||
s := &Scheduler{users: twoPersonalModelUsers{}, generationUseCase: g}
|
||||
s.run()
|
||||
if !reflect.DeepEqual(g.ids, []string{"account-a", "account-b"}) {
|
||||
t.Fatalf("scheduled account order=%v", g.ids)
|
||||
}
|
||||
if !reflect.DeepEqual(g.selectedProviders, []string{"provider-model-b"}) {
|
||||
t.Fatalf("scheduled selected providers=%v, unavailable account must not fall back", g.selectedProviders)
|
||||
}
|
||||
}
|
||||
|
||||
58
backend/internal/scheduler/personal_models_test.go
Normal file
58
backend/internal/scheduler/personal_models_test.go
Normal file
@ -0,0 +1,58 @@
|
||||
package scheduler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/tradarr/backend/internal/generation"
|
||||
"github.com/tradarr/backend/internal/models"
|
||||
"github.com/tradarr/backend/internal/scraper"
|
||||
)
|
||||
|
||||
type personalInputs struct {
|
||||
saved map[string]generation.GenerationRecord
|
||||
}
|
||||
|
||||
func (p *personalInputs) LoadUserInput(_ context.Context, id string) (generation.UserInput, error) {
|
||||
key := models.SourceYahooFinance
|
||||
input := generation.UserInput{Language: "en", RankingMode: "title", GlobalLimit: 20, Sources: []models.Source{{ID: "source", Enabled: true, SourceKey: &key, ArticleLimit: 20}}}
|
||||
if id != "account-a" {
|
||||
model := "model-b"
|
||||
input.SummaryModelID = &model
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
func (p *personalInputs) SaveGeneration(_ context.Context, id string, record generation.GenerationRecord) error {
|
||||
p.saved[id] = record
|
||||
return nil
|
||||
}
|
||||
|
||||
type personalResolver struct{}
|
||||
|
||||
func (personalResolver) Resolve(_ context.Context, _ string, id *string) (generation.ResolvedSummary, error) {
|
||||
if id == nil {
|
||||
return generation.ResolvedSummary{}, errors.New("summary_model_unavailable")
|
||||
}
|
||||
return generation.ResolvedSummary{Summarizer: personalSummary{}, CatalogID: *id, ProviderID: "provider-b", Provider: "ollama", Model: "model-b"}, nil
|
||||
}
|
||||
|
||||
type personalSummary struct{}
|
||||
|
||||
func (personalSummary) Summarize(context.Context, string, []models.UserAsset, []generation.Candidate) (string, error) {
|
||||
return "safe account B summary", nil
|
||||
}
|
||||
func TestSchedulerActualUseCaseSkipsCollectionForUnselectedAccount(t *testing.T) {
|
||||
repo := &personalInputs{saved: map[string]generation.GenerationRecord{}}
|
||||
feed := &ticket13Feed{}
|
||||
uc := generation.NewUseCase(generation.Dependencies{Repository: repo, Scrapers: map[string]scraper.Scraper{models.SourceYahooFinance: feed}, LayaRanker: ticket13Ranker{}, SummaryResolver: personalResolver{}})
|
||||
s := &Scheduler{users: twoPersonalModelUsers{}, generationUseCase: uc}
|
||||
s.run()
|
||||
if feed.calls != 1 || repo.saved["account-a"].Outcome.FailureCode != "summary_model_unavailable" || repo.saved["account-a"].Summary != nil {
|
||||
t.Fatal("unselected scheduled account reached collection or no failure persisted")
|
||||
}
|
||||
second := repo.saved["account-b"].Summary
|
||||
if second == nil || second.ModelName == nil || *second.ModelName != "model-b" || second.ProviderName == nil || *second.ProviderName != "ollama" {
|
||||
t.Fatalf("scheduled model/snapshot=%+v", second)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user