forked from longtao.wu/droboticflow
156 lines
5.4 KiB
Go
156 lines
5.4 KiB
Go
package api
|
|
|
|
import (
|
|
"droboticflow/internal/domain"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestHumanPoolSearchBeyondFirst500(t *testing.T) {
|
|
f := newFanyuV5FourStageFixture(t, domain.FanyuV5StageSemanticReview, domain.HumanItemReady, "", 1)
|
|
target := f.item
|
|
target.ID = "old-search-target"
|
|
target.Subject.ItemKey = "FYLX_B02_AZER76400GJ_19700116_013952_camera_left_part0002.mp4"
|
|
target.CreatedAt = "2020-01-01T00:00:00Z"
|
|
target.LatestAuthorUserID = f.annotator.ID
|
|
if err := f.store.UpsertHumanItem(f.ctx, target); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for i := 0; i < 962; i++ {
|
|
item := f.item
|
|
item.ID = fmt.Sprintf("recent-%04d", i)
|
|
item.Subject.ItemKey = fmt.Sprintf("FYLX_OTHER_%04d/part0001/camera_left.mp4", i)
|
|
item.CreatedAt = time.Date(2026, 11, 1, 0, 0, i, 0, time.UTC).Format(time.RFC3339)
|
|
if err := f.store.UpsertHumanItem(f.ctx, item); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
response := f.request(http.MethodGet, "/api/human-items?pluginId=annotation-qa&pool=available&stageId="+target.CurrentStageID+"&limit=200&search="+url.QueryEscape("FYLX_B02_AZER76400GJ_19700116_013952/part0002"), f.quality, nil)
|
|
if response.Code != 200 {
|
|
t.Fatalf("status %d: %s", response.Code, response.Body)
|
|
}
|
|
var page humanItemListPage
|
|
if err := json.Unmarshal(response.Body.Bytes(), &page); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(page.Items) != 1 || page.Items[0].ID != target.ID || page.HasMore {
|
|
t.Fatalf("search must find the old authorized item beyond 962 newer records, got %d items, more=%v", len(page.Items), page.HasMore)
|
|
}
|
|
if page.Items[0].CanClaim == nil || !*page.Items[0].CanClaim {
|
|
t.Fatal("search lost server eligibility")
|
|
}
|
|
}
|
|
|
|
func TestHumanPoolSearchPaginationPermissionsAndHistory(t *testing.T) {
|
|
for _, pool := range []string{"available", "mine", "reviewed"} {
|
|
t.Run(pool, func(t *testing.T) {
|
|
f := newFanyuV5FourStageFixture(t, domain.FanyuV5StageSemanticReview, domain.HumanItemReady, "", 1)
|
|
const count = 611
|
|
for i := 0; i < count; i++ {
|
|
item := f.item
|
|
item.ID = fmt.Sprintf("match-%04d", i)
|
|
item.Subject.ItemKey = fmt.Sprintf("FYLX_MATCH_%04d/part0001/camera_left.mp4", i)
|
|
item.CreatedAt = time.Date(2026, 11, 1, 0, 0, i, 0, time.UTC).Format(time.RFC3339)
|
|
item.LatestAuthorUserID = f.annotator.ID
|
|
if pool == "mine" {
|
|
item.AssignedUserID = f.quality.ID
|
|
item.Status = domain.HumanItemClaimed
|
|
}
|
|
if pool == "reviewed" {
|
|
item.CurrentStageID = domain.FanyuV5StageSemanticAnnotation
|
|
item.Status = domain.HumanItemRework
|
|
}
|
|
if e := f.store.UpsertHumanItem(f.ctx, item); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if pool == "reviewed" {
|
|
if e := f.store.AppendHumanEvent(f.ctx, domain.HumanEventRecord{ID: "event-" + item.ID, OrganizationID: item.OrganizationID, ItemID: item.ID, ActorUserID: f.quality.ID, EventType: "rejected", StageID: domain.FanyuV5StageSemanticReview}); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
}
|
|
}
|
|
foreign := f.item
|
|
foreign.ID = "foreign"
|
|
foreign.Subject.ItemKey = "FYLX_MATCH_FOREIGN/part0001/camera_left.mp4"
|
|
foreign.SupplierID = "other-supplier"
|
|
foreign.VendorID = "other-supplier"
|
|
if e := f.store.UpsertHumanItem(f.ctx, foreign); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
seen := map[string]bool{}
|
|
cursor := ""
|
|
for round := 0; round < 10; round++ {
|
|
path := "/api/human-items?pluginId=annotation-qa&pool=" + pool + "&limit=200&search=FYLX_MATCH"
|
|
if pool != "reviewed" {
|
|
path += "&stageIds=quality_review,semantic_review"
|
|
}
|
|
if cursor != "" {
|
|
path += "&cursor=" + cursor
|
|
}
|
|
response := f.request(http.MethodGet, path, f.quality, nil)
|
|
if response.Code != 200 {
|
|
t.Fatalf("%d %s", response.Code, response.Body)
|
|
}
|
|
var page humanItemListPage
|
|
if e := json.Unmarshal(response.Body.Bytes(), &page); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if len(page.Items) > 200 {
|
|
t.Fatal("unbounded page")
|
|
}
|
|
for _, item := range page.Items {
|
|
if item.ID == "foreign" {
|
|
t.Fatal("foreign supplier leaked")
|
|
}
|
|
if seen[item.ID] {
|
|
t.Fatalf("duplicate %s", item.ID)
|
|
}
|
|
seen[item.ID] = true
|
|
if pool == "reviewed" && item.ReviewHistory == nil {
|
|
t.Fatal("review history lost")
|
|
}
|
|
}
|
|
if !page.HasMore {
|
|
break
|
|
}
|
|
if page.NextCursor == "" || page.NextCursor == cursor {
|
|
t.Fatal("cursor did not advance")
|
|
}
|
|
cursor = page.NextCursor
|
|
}
|
|
if len(seen) != count {
|
|
t.Fatalf("found %d, want %d", len(seen), count)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestHumanPoolSearchKeepsSelfReviewBlockedAndSearchLiteral(t *testing.T) {
|
|
f := newFanyuV5FourStageFixture(t, domain.FanyuV5StageSemanticReview, domain.HumanItemReady, "", 1)
|
|
item := f.item
|
|
item.Subject.ItemKey = "FYLX_SELF/part0001/camera_left.mp4"
|
|
item.LatestAuthorUserID = f.quality.ID
|
|
if e := f.store.UpsertHumanItem(f.ctx, item); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
r := f.request(http.MethodGet, "/api/human-items?pluginId=annotation-qa&pool=available&search=FYLX_SELF", f.quality, nil)
|
|
var page humanItemListPage
|
|
if e := json.Unmarshal(r.Body.Bytes(), &page); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if len(page.Items) != 1 || page.Items[0].CanClaim == nil || *page.Items[0].CanClaim {
|
|
t.Fatalf("self review eligibility changed: %s", r.Body)
|
|
}
|
|
r = f.request(http.MethodGet, "/api/human-items?pluginId=annotation-qa&pool=available&search="+url.QueryEscape("[.*"), f.quality, nil)
|
|
if e := json.Unmarshal(r.Body.Bytes(), &page); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if len(page.Items) != 0 {
|
|
t.Fatalf("search interpreted as regex: %s", r.Body)
|
|
}
|
|
}
|