forked from longtao.wu/droboticflow
73 lines
2.7 KiB
Go
73 lines
2.7 KiB
Go
package store
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
|
|
"droboticflow/internal/domain"
|
|
)
|
|
|
|
// A small public page must advance past more than one batch of invalid or
|
|
// unready records. Admission and batch checks must precede the returned limit.
|
|
func TestAdminAnnotationPoolMongoMetadataLimitAndCursor(t *testing.T) {
|
|
if os.Getenv("POOL_LOCAL_MONGO_URI") == "" {
|
|
t.Skip("isolated local Mongo opt-in")
|
|
}
|
|
ctx, s := poolLocalMongo(t)
|
|
if err := s.EnsureIndexes(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
const org = "metadata-page-org"
|
|
batch := domain.HumanBatchRecord{ID: "batch", OrganizationID: org, Stages: domain.DefaultFanyuV58HumanStages()}
|
|
if err := s.UpsertHumanBatch(ctx, batch); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
items, tasks, jobs := []any{}, []any{}, []any{}
|
|
for n := 0; n < 226; n++ {
|
|
id := fmt.Sprintf("z-blocked-%03d", n)
|
|
item := domain.HumanItemRecord{ID: id, OrganizationID: org, BatchID: batch.ID, PluginID: "annotation-qa", CurrentStageID: "annotation_combined", Status: domain.HumanItemReady, LegacyTaskID: id, CreatedAt: "2026-11-10T00:00:00Z", Subject: domain.HumanSubjectRef{ItemKey: id}}
|
|
if n < 224 {
|
|
if n%2 == 0 {
|
|
item.BatchID = "missing-batch"
|
|
}
|
|
} else {
|
|
item.ID = []string{"good-b", "good-a"}[n-224]
|
|
item.LegacyTaskID, item.Subject.ItemKey = item.ID, item.ID
|
|
}
|
|
items = append(items, item)
|
|
tasks = append(tasks, domain.AnnotationTaskRecord{ID: item.LegacyTaskID, OrganizationID: org, SourceIsFullVideo: true, TemplateVersion: 6, ArtifactID: "video"})
|
|
status, fingerprint := "failed", ""
|
|
if n >= 224 {
|
|
status, fingerprint = "completed", "fixture-full-source-"+item.LegacyTaskID
|
|
}
|
|
jobs = append(jobs, domain.AnnotationIndexJob{ID: item.LegacyTaskID, OrganizationID: org, Status: status, SourceFingerprint: fingerprint})
|
|
}
|
|
for name, rows := range map[string][]any{"humanItems": items, "annotationTasks": tasks, "annotationIndexJobs": jobs} {
|
|
if _, err := s.db.Collection(name).InsertMany(ctx, rows); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
q := AdminAnnotationPoolQuery{Pool: "available", UserID: "admin", Limit: 1}
|
|
for _, want := range []string{"good-b", "good-a", ""} {
|
|
page, err := s.ListAdminAnnotationPool(ctx, org, q)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if want == "" {
|
|
if len(page) != 0 {
|
|
t.Fatal("cursor repeated the last page")
|
|
}
|
|
break
|
|
}
|
|
if len(page) != 1 || page[0].ID != want || page[0].SourceValidationStatus != "" {
|
|
t.Fatalf("limit/source/cursor changed: want=%s page=%+v", want, page)
|
|
}
|
|
q.Cursor = &domain.HumanItemCursor{CreatedAt: page[0].CreatedAt, ID: page[0].ID}
|
|
}
|
|
counts, err := s.CountAdminAnnotationPools(ctx, org, q)
|
|
if err != nil || counts != (AdminAnnotationPoolCounts{All: 114, Available: 2}) {
|
|
t.Fatalf("totals/cursor changed: counts=%+v err=%v", counts, err)
|
|
}
|
|
}
|