feat(generation): resume manual summary jobs
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/tradarr/backend/internal/ai"
|
||||
"github.com/tradarr/backend/internal/api"
|
||||
@ -62,6 +63,7 @@ func TestManualGenerationResolvesAccountModelsAndSnapshotsWithoutGlobalFallbackP
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
installJobSchema(t, db)
|
||||
repo := models.NewRepository(db)
|
||||
feed := &selectionFeed{}
|
||||
laya := &selectionLaya{}
|
||||
@ -84,14 +86,42 @@ func TestManualGenerationResolvesAccountModelsAndSnapshotsWithoutGlobalFallbackP
|
||||
request.Header.Set("Authorization", "Bearer "+token)
|
||||
w := httptest.NewRecorder()
|
||||
router.ServeHTTP(w, request)
|
||||
if w.Code != status {
|
||||
t.Fatalf("status=%d want=%d body=%s", w.Code, status, w.Body.String())
|
||||
if w.Code != 202 {
|
||||
t.Fatalf("status=%d body=%s", w.Code, w.Body)
|
||||
}
|
||||
var response struct{ Data generation.Result }
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &response); err != nil {
|
||||
var accepted struct{ Data models.GenerationJob }
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &accepted); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return response.Data
|
||||
deadline := time.Now().Add(3 * time.Second)
|
||||
for time.Now().Before(deadline) {
|
||||
job, err := repo.GetGenerationJob(context.Background(), user, accepted.Data.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if job.Status != "running" {
|
||||
var result generation.Result
|
||||
if err = json.Unmarshal(job.Outcome, &result.Outcome); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if job.SummaryID != nil {
|
||||
result.Summary, err = repo.GetOwnedSummary(*job.SummaryID, user)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if status == 502 && job.Status != "failed" {
|
||||
t.Fatal("expected terminal failure", job)
|
||||
}
|
||||
if status == 201 && job.Status != "succeeded" {
|
||||
t.Fatal("expected terminal success", job)
|
||||
}
|
||||
return result
|
||||
}
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
t.Fatal("job did not finish")
|
||||
return generation.Result{}
|
||||
}
|
||||
for _, tc := range []struct{ user, provider, model string }{{ticket14UserA, "openai", "account-model-a"}, {ticket14UserB, "ollama", "account-model-b"}} {
|
||||
result := generate(tc.user, 201)
|
||||
|
||||
Reference in New Issue
Block a user