97 lines
4.0 KiB
Go
97 lines
4.0 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"droboticflow/internal/domain"
|
|
)
|
|
|
|
func TestContinuousActionsMalformedCoverageRejectedBeforeBothSubmissionPaths(t *testing.T) {
|
|
for _, reuse := range []bool{false, true} {
|
|
for name, segments := range map[string][]domain.AnnotationSegment{
|
|
"overlap": {{ID: "a", Start: 0, End: 6, Description: "拿起"}, {ID: "b", Start: 5, End: 10, Description: "放下"}},
|
|
"outside": {{ID: "a", Start: -1, End: 10, Description: "拿起"}},
|
|
"zero": {{ID: "a", Start: 0, End: 0, Description: "拿起"}, {ID: "b", Start: 0, End: 10, Description: "放下"}},
|
|
} {
|
|
t.Run(name+map[bool]string{false: "/generate", true: "/reuse"}[reuse], func(t *testing.T) {
|
|
f := continuousFixture(t)
|
|
if reuse {
|
|
seedCompletedMaterialization(t, f, 1)
|
|
}
|
|
r := f.request(http.MethodPost, "/api/plugins/annotation-qa/tasks/"+f.task.ID+"/combined-submissions", f.annotator, map[string]any{"version": f.item.Version, "sliceSegments": []domain.SliceSegment{{ID: "s", Name: "测试切片", Start: 0, End: 10}}, "segments": segments})
|
|
if r.Code != http.StatusBadRequest {
|
|
t.Fatalf("malformed coverage accepted: %d %s", r.Code, r.Body.String())
|
|
}
|
|
item, _ := f.store.GetHumanItem(f.ctx, f.item.ID)
|
|
if item.Version != f.item.Version || item.PendingCombinedSubmissionID != "" || item.CurrentStageID != f.item.CurrentStageID {
|
|
t.Fatal("rejected submission reserved or advanced the task")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestContinuousActionsMixedAndAllDiscardedReachReviewWithEvidence(t *testing.T) {
|
|
for _, all := range []bool{false, true} {
|
|
t.Run(map[bool]string{false: "mixed", true: "all-discarded"}[all], func(t *testing.T) {
|
|
f := continuousFixture(t)
|
|
body := dispositionFixturePayload(t, f)
|
|
for i := range body.SliceSegments {
|
|
body.SliceSegments[i].Name = "测试切片"
|
|
}
|
|
body.Segments = []domain.AnnotationSegment{{ID: "a-action", Start: 0, End: 3, Description: "拿起"}, {ID: "b-action", Start: 3, End: 7, Description: "放下"}, {ID: "c-action", Start: 7, End: 10, Status: "invalid", IsInvalid: true}}
|
|
ids := []string{"b"}
|
|
if all {
|
|
ids = []string{"a", "b", "c"}
|
|
}
|
|
for _, id := range ids {
|
|
body.SliceID = id
|
|
r := f.request(http.MethodPost, "/api/plugins/annotation-qa/tasks/"+f.task.ID+"/slice-dispositions", f.annotator, body)
|
|
if r.Code != http.StatusOK {
|
|
t.Fatalf("discard %s: %d %s", id, r.Code, r.Body.String())
|
|
}
|
|
var got struct {
|
|
Item domain.HumanItemRecord `json:"item"`
|
|
Workspace combinedAnnotationDraftInput `json:"workspace"`
|
|
}
|
|
if err := json.Unmarshal(r.Body.Bytes(), &got); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
body.combinedAnnotationDraftInput = got.Workspace
|
|
body.Version = got.Item.Version
|
|
}
|
|
seedCompletedMaterialization(t, f, 1)
|
|
r := f.request(http.MethodPost, "/api/plugins/annotation-qa/tasks/"+f.task.ID+"/combined-submissions", f.annotator, body.combinedAnnotationDraftInput)
|
|
if r.Code != http.StatusCreated {
|
|
t.Fatalf("submit: %d %s", r.Code, r.Body.String())
|
|
}
|
|
item, _ := f.store.GetHumanItem(f.ctx, f.item.ID)
|
|
if item.CurrentStageID != domain.FanyuV58StageQualityReview {
|
|
t.Fatal("not sent to quality")
|
|
}
|
|
revisions, err := f.store.ListSliceRevisions(f.ctx, f.task.OrganizationID, f.task.ID)
|
|
if err != nil || len(revisions) != 1 {
|
|
t.Fatalf("slice revisions: %v %v", revisions, err)
|
|
}
|
|
count := 0
|
|
for _, s := range revisions[0].Segments {
|
|
if s.IsDiscarded() {
|
|
count++
|
|
if s.DiscardReasonLabelID != "discard-fixture" || s.DiscardedByUserID != f.annotator.ID || len(s.DiscardedAnnotations) != 1 {
|
|
t.Fatalf("lost audit snapshot: %+v", s)
|
|
}
|
|
}
|
|
}
|
|
if count != len(ids) {
|
|
t.Fatalf("discard count=%d", count)
|
|
}
|
|
annotations, err := f.store.ListAnnotationRevisions(f.ctx, f.task.OrganizationID, f.task.ID)
|
|
if err != nil || len(annotations) != 1 || len(annotations[0].Segments) != 3-len(ids) {
|
|
t.Fatalf("unexpected active annotation results: %+v %v", annotations, err)
|
|
}
|
|
})
|
|
}
|
|
}
|