forked from longtao.wu/droboticflow
90 lines
3.3 KiB
Go
90 lines
3.3 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"reflect"
|
|
"testing"
|
|
"time"
|
|
|
|
"droboticflow/internal/domain"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
func TestHumanMineQueryMatchesPostFilter(t *testing.T) {
|
|
verify := func(t *testing.T, s Store) {
|
|
ctx := context.Background()
|
|
org := domain.DefaultOrganizationID
|
|
id := 0
|
|
for _, stage := range []string{"annotation_combined", "quality_review", "semantic_review", "acceptance", "prepackage_acceptance"} {
|
|
for _, status := range []domain.HumanItemStatus{domain.HumanItemReady, domain.HumanItemSubmitted, domain.HumanItemClaimed, domain.HumanItemInProgress, domain.HumanItemRework, domain.HumanItemAccepted, domain.HumanItemCancelled} {
|
|
for _, assignee := range []string{"actor", "other", ""} {
|
|
for _, author := range []string{"actor", "other"} {
|
|
id++
|
|
row := domain.HumanItemRecord{ID: fmt.Sprintf("item-%03d", id), OrganizationID: org, PluginID: "annotation-qa", ProjectID: fmt.Sprintf("p-%d", id%2), BatchID: "batch", CurrentStageID: stage, Status: status, AssignedUserID: assignee, LatestAuthorUserID: author, Subject: domain.HumanSubjectRef{ItemKey: fmt.Sprint(id)}, CreatedAt: "2026-10-01T00:00:00Z"}
|
|
if err := s.UpsertHumanItem(ctx, row); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for _, view := range []string{"", "active", "submitted"} {
|
|
for _, project := range []string{"", "p-0"} {
|
|
for _, stage := range []string{"", "quality_review", "acceptance"} {
|
|
q := domain.HumanItemQuery{PluginID: "annotation-qa", ActorUserID: "actor", AnnotationView: view, ProjectID: project, CurrentStageID: stage}
|
|
legacy, err := s.ListHumanItems(ctx, org, q)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := []string{}
|
|
for _, row := range legacy {
|
|
if view != "" || row.AssignedUserID == "actor" || (row.LatestAuthorUserID == "actor" && row.CurrentStageID == "quality_review" && (row.Status == domain.HumanItemReady || row.Status == domain.HumanItemSubmitted)) {
|
|
want = append(want, row.ID)
|
|
}
|
|
}
|
|
q.MinePoolOnly = true
|
|
q.Limit = 7
|
|
got := []string{}
|
|
for page := 0; page < 100; page++ {
|
|
rows, err := s.ListHumanItems(ctx, org, q)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, row := range rows {
|
|
got = append(got, row.ID)
|
|
}
|
|
if len(rows) < q.Limit {
|
|
break
|
|
}
|
|
last := rows[len(rows)-1]
|
|
q.Cursor = &domain.HumanItemCursor{CreatedAt: last.CreatedAt, ID: last.ID}
|
|
}
|
|
if !reflect.DeepEqual(want, got) {
|
|
t.Fatalf("view=%s project=%s stage=%s got=%v want=%v", view, project, stage, got, want)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
t.Run("memory", func(t *testing.T) { verify(t, NewMemoryStore()) })
|
|
t.Run("mongo", func(t *testing.T) {
|
|
if os.Getenv("ANNOTATION_BUFFER_MONGO_STORE") != "1" {
|
|
t.Skip("local isolated Mongo opt-in")
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
defer cancel()
|
|
client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://127.0.0.1:27018/?directConnection=true"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer client.Disconnect(context.Background())
|
|
db := client.Database(fmt.Sprintf("mine_query_test_%d", time.Now().UnixNano()))
|
|
defer db.Drop(context.Background())
|
|
verify(t, NewMongoStore(db))
|
|
})
|
|
}
|