droboticflow/internal/api/annotation_feedback_names_test.go

56 lines
2.5 KiB
Go

package api
import (
"encoding/json"
"strings"
"testing"
"droboticflow/internal/domain"
)
func TestNewUnnamedSplitCannotBecomeHistoricalNameAtSubmission(t *testing.T) {
f := continuousFixture(t)
seedCompletedMaterialization(t, f, 1)
item, _ := f.store.GetHumanItem(f.ctx, f.item.ID)
item.Subject.Payload["sliceWorkflow"] = map[string]any{"status": "completed", "phase": "annotate"}
item.Subject.Payload["annotationWorkspace"] = map[string]any{
"sliceSegments": []domain.SliceSegment{{ID: "parent", Name: "测试切片", Start: 0, End: 10}},
"segments": []domain.AnnotationSegment{{ID: "a", Start: 0, End: 10, Status: "pending"}},
}
if err := f.store.UpsertHumanItem(f.ctx, *item); err != nil {
t.Fatal(err)
}
path := "/api/plugins/annotation-qa/tasks/" + f.task.ID
split := []domain.SliceSegment{{ID: "child-a", SourceIDs: []string{"parent"}, Start: 0, End: 5}, {ID: "child-b", SourceIDs: []string{"parent"}, Start: 5, End: 10}}
actions := []domain.AnnotationSegment{{ID: "a1", Start: 0, End: 5, Status: "pending"}, {ID: "a2", Start: 5, End: 10, Status: "pending"}}
r := f.request("POST", path+"/slice-edit-applications", f.annotator, sliceEditApplicationInput{ApplicationID: "unnamed-split", combinedAnnotationDraftInput: combinedAnnotationDraftInput{Version: item.Version, SliceSegments: split, Segments: actions}})
if r.Code != 200 {
t.Fatalf("save split: %d %s", r.Code, r.Body.String())
}
var got struct {
Workspace combinedAnnotationDraftInput `json:"workspace"`
}
if err := json.Unmarshal(r.Body.Bytes(), &got); err != nil {
t.Fatal(err)
}
item, _ = f.store.GetHumanItem(f.ctx, item.ID)
got.Workspace.Version = item.Version
r = f.request("POST", path+"/combined-submissions", f.annotator, got.Workspace)
if r.Code != 400 || !strings.Contains(r.Body.String(), "slice_dictionary_name_required") {
t.Fatalf("unnamed new slices submitted: %d %s", r.Code, r.Body.String())
}
unchanged, _ := f.store.GetHumanItem(f.ctx, item.ID)
if unchanged.Version != item.Version || unchanged.CurrentStageID != item.CurrentStageID {
t.Fatal("rejection changed the task")
}
// Naming the slices must preserve the anonymous pending actions, which are
// valid classification results and must never be silently marked invalid.
for i := range got.Workspace.SliceSegments {
got.Workspace.SliceSegments[i].Name = "测试切片"
}
r = f.request("POST", path+"/combined-submissions", f.annotator, got.Workspace)
if r.Code != 201 {
t.Fatalf("named split: %d %s", r.Code, r.Body.String())
}
}