Files
TradarrV2/backend/internal/scheduler/generation_test.go
Blomios 989996fbd6 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>
2026-11-21 20:45:21 +01:00

65 lines
1.9 KiB
Go

package scheduler
import (
"context"
"errors"
"reflect"
"testing"
"github.com/tradarr/backend/internal/generation"
"github.com/tradarr/backend/internal/models"
)
type scheduledUsers struct{}
func (scheduledUsers) ListUsers() ([]models.User, error) {
return []models.User{{ID: "alpha"}, {ID: "beta"}}, nil
}
type scheduledGenerator struct{ ids []string }
func (g *scheduledGenerator) Generate(_ context.Context, id string) (generation.Result, error) {
g.ids = append(g.ids, id)
if id == "alpha" {
return generation.Result{}, errors.New("failure")
}
return generation.Result{}, nil
}
func TestScheduledGenerationContinuesIndependentlyPerUser(t *testing.T) {
g := &scheduledGenerator{}
s := &Scheduler{users: scheduledUsers{}, generationUseCase: g}
s.run()
if !reflect.DeepEqual(g.ids, []string{"alpha", "beta"}) {
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)
}
}