80 lines
2.4 KiB
Go
80 lines
2.4 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"droboticflow/internal/domain"
|
|
"droboticflow/internal/store"
|
|
)
|
|
|
|
type mineReadProbe struct {
|
|
store.Store
|
|
candidates int
|
|
legacy bool
|
|
}
|
|
|
|
func (s *mineReadProbe) ListHumanItems(ctx context.Context, org string, q domain.HumanItemQuery) ([]domain.HumanItemRecord, error) {
|
|
if s.legacy {
|
|
q.MinePoolOnly = false
|
|
}
|
|
rows, err := s.Store.ListHumanItems(ctx, org, q)
|
|
if q.PoolCandidateProjection && q.ActorUserID != "" {
|
|
s.candidates += len(rows)
|
|
}
|
|
return rows, err
|
|
}
|
|
func TestHumanMineDoesNotReadDiscardedAuthorHistory(t *testing.T) {
|
|
f := newFanyuV5FourStageFixture(t, "quality_review", domain.HumanItemReady, "", 0)
|
|
f.batch.Stages = domain.DefaultFanyuV58HumanStages()
|
|
if err := f.store.UpsertHumanBatch(f.ctx, f.batch); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
user := domain.UserRecord{ID: "mine-admin", OrganizationID: domain.DefaultOrganizationID, Role: domain.UserRoleAdmin, Status: domain.UserStatusActive}
|
|
for i := 0; i < 120; i++ {
|
|
row := f.item
|
|
row.ID = fmt.Sprintf("history-%03d", i)
|
|
row.Status = domain.HumanItemAccepted
|
|
row.AssignedUserID = ""
|
|
row.LatestAuthorUserID = user.ID
|
|
if err := f.store.UpsertHumanItem(f.ctx, row); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
own := f.item
|
|
own.ID = "assigned"
|
|
own.AssignedUserID = user.ID
|
|
own.LatestAuthorUserID = "other"
|
|
own.Status = domain.HumanItemInProgress
|
|
if err := f.store.UpsertHumanItem(f.ctx, own); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
legacy := &mineReadProbe{Store: f.store, legacy: true}
|
|
f.handler = NewHandler(legacy, nil)
|
|
before := f.request(http.MethodGet, "/api/human-items?pool=mine&pluginId=annotation-qa", user, nil)
|
|
if legacy.candidates != 121 {
|
|
t.Fatalf("legacy waste not reproduced: %d", legacy.candidates)
|
|
}
|
|
probe := &mineReadProbe{Store: f.store}
|
|
f.handler = NewHandler(probe, nil)
|
|
response := f.request(http.MethodGet, "/api/human-items?pool=mine&pluginId=annotation-qa", user, nil)
|
|
var body struct {
|
|
Items []domain.HumanItemRecord `json:"items"`
|
|
}
|
|
if err := json.Unmarshal(response.Body.Bytes(), &body); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if response.Code != 200 || len(body.Items) != 1 || body.Items[0].ID != "assigned" {
|
|
t.Fatalf("mine changed: %d %+v", response.Code, body.Items)
|
|
}
|
|
if before.Body.String() != response.Body.String() {
|
|
t.Fatal("response differs from legacy query")
|
|
}
|
|
if probe.candidates != 1 {
|
|
t.Fatalf("discarded history crossed candidate boundary: %d", probe.candidates)
|
|
}
|
|
}
|