forked from longtao.wu/droboticflow
- random-claims: my directed rework item is returned as-is (no version bump) before any random draw, and keeps priority on repeat claims until the rework is submitted; other annotators never receive someone else's directed item (assigned filter unchanged) - quality pool rows gain a 返工复查 badge + detail line for round>0 items; workbench header shows the same state; DetailedTaskStatus widened - pool list stable-sorts rework items to the top (先清自己的错再领新) - tests: rework-first claim matrix (priority, idempotent resume, priority release after submit, invisible to others) green; api suite failures identical to baseline (65); frontend failures identical (14); tsc clean
86 lines
3.5 KiB
Go
86 lines
3.5 KiB
Go
package api
|
||
|
||
import (
|
||
"droboticflow/internal/domain"
|
||
"encoding/json"
|
||
"net/http"
|
||
"testing"
|
||
)
|
||
|
||
// B03 返工优先领取(spec §5.4-6):定向归属我的返工任务优先于随机新任务;
|
||
// 他人的定向任务对随机领取保持不可见。
|
||
|
||
func TestRandomClaimPrefersDirectedReworkBeforeNewTasks(t *testing.T) {
|
||
f := randomClaimFixture(t, 2)
|
||
// 造一条定向归属 f.annotator 的返工任务(round 1,annotation_combined claimed)。
|
||
reworkItem := f.item
|
||
reworkItem.ID = "directed-rework-item"
|
||
reworkItem.LegacyTaskID = "directed-rework-task"
|
||
reworkItem.Status = domain.HumanItemClaimed
|
||
reworkItem.AssignedUserID = f.annotator.ID
|
||
reworkItem.SupplierID = "random-supplier"
|
||
reworkItem.ReviewRound = 1
|
||
reworkItem.CurrentStageID = domain.FanyuV58StageAnnotationCombined
|
||
reworkItem.Version = 4
|
||
if e := f.store.UpsertHumanItem(f.ctx, reworkItem); e != nil {
|
||
t.Fatal(e)
|
||
}
|
||
reworkTask := f.task
|
||
reworkTask.ID = "directed-rework-task"
|
||
reworkTask.AssignedUserID = f.annotator.ID
|
||
reworkTask.SupplierID = "random-supplier"
|
||
reworkTask.Status = domain.AnnotationTaskStatusRework
|
||
if e := f.store.UpsertAnnotationTask(f.ctx, reworkTask); e != nil {
|
||
t.Fatal(e)
|
||
}
|
||
before, _ := f.store.GetHumanItem(f.ctx, reworkItem.ID)
|
||
|
||
claimed := claimRandom(t, f, "rework-first-000000001")
|
||
if claimed.ID != "directed-rework-item" {
|
||
t.Fatalf("claim must prefer my directed rework item, got %s", claimed.ID)
|
||
}
|
||
after, _ := f.store.GetHumanItem(f.ctx, reworkItem.ID)
|
||
if after.Version != before.Version {
|
||
t.Fatalf("resume must not bump version: %d -> %d", before.Version, after.Version)
|
||
}
|
||
// 返工未提交期间重复领取仍返回同一任务(先清自己的错再领新),且版本不变。
|
||
again := claimRandom(t, f, "rework-first-000000002")
|
||
if again.ID != "directed-rework-item" {
|
||
t.Fatalf("open rework must keep priority on repeat claims, got %s", again.ID)
|
||
}
|
||
// 提交返工(状态离开返工/领取)后才随机领新。
|
||
submitted := reworkItem
|
||
submitted.Status = domain.HumanItemSubmitted
|
||
submitted.CurrentStageID = domain.FanyuV58StageQualityReview
|
||
submitted.AssignedUserID = ""
|
||
submitted.Version = before.Version + 1
|
||
if e := f.store.UpsertHumanItem(f.ctx, submitted); e != nil {
|
||
t.Fatal(e)
|
||
}
|
||
fresh := claimRandom(t, f, "rework-first-000000003")
|
||
if fresh.ID == "directed-rework-item" {
|
||
t.Fatal("submitted rework must release claim priority")
|
||
}
|
||
|
||
// 他人的定向返工任务对随机领取不可见:另一位标注员领到的是新任务。
|
||
other := domain.UserRecord{ID: "other-annotator", OrganizationID: domain.DefaultOrganizationID, Role: domain.UserRoleAnnotator, SupplierID: "random-supplier", Status: domain.UserStatusActive}
|
||
if e := f.store.UpsertUser(f.ctx, other); e != nil {
|
||
t.Fatal(e)
|
||
}
|
||
if e := f.store.UpsertProjectMember(f.ctx, domain.ProjectMemberRecord{ID: "random-member-other", OrganizationID: domain.DefaultOrganizationID, ProjectID: f.task.ProjectID, UserID: other.ID, SupplierID: "random-supplier", Roles: []domain.AnnotationAssignmentRole{domain.AnnotationRoleAnnotator}}); e != nil {
|
||
t.Fatal(e)
|
||
}
|
||
r := f.request(http.MethodPost, "/api/plugins/annotation-qa/random-claims", other, map[string]any{"projectId": f.task.ProjectID, "requestId": "other-claim-00000001"})
|
||
if r.Code != 200 {
|
||
t.Fatalf("other claim: %d %s", r.Code, r.Body.String())
|
||
}
|
||
var out struct {
|
||
Item domain.HumanItemRecord `json:"item"`
|
||
}
|
||
json.Unmarshal(r.Body.Bytes(), &out)
|
||
if out.Item.ID == "directed-rework-item" {
|
||
t.Fatal("another annotator must never receive someone else's directed rework")
|
||
}
|
||
_ = http.StatusOK
|
||
}
|