59 lines
2.3 KiB
Go
59 lines
2.3 KiB
Go
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.SourceBloomberg
|
|
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.SourceBloomberg: 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)
|
|
}
|
|
}
|