forked from longtao.wu/droboticflow
53 lines
2.0 KiB
Go
53 lines
2.0 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
"time"
|
|
|
|
"droboticflow/internal/domain"
|
|
)
|
|
|
|
func TestAnnotationDetailSharesDescriptionConfirmationReadiness(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name, status, phase, expected string
|
|
ready bool
|
|
}{
|
|
{"completed", "completed", "annotate", "annotate", true},
|
|
{"failed-with-old-phase", "failed", "annotate", "slice", false},
|
|
{"failed-with-draft", "failed", "", "slice", false},
|
|
{"inconsistent-completed", "completed", "slice", "slice", false},
|
|
{"processing", "processing", "slice", "materializing", false},
|
|
{"legacy-confirmed", "", "", "annotate", true},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
f := continuousFixture(t)
|
|
item := f.item
|
|
item.Subject.Payload["annotationWorkspace"] = map[string]any{"sliceSegments": []domain.SliceSegment{{ID: "s", Name: "测试切片", Start: 0, End: 10}}, "segments": []domain.AnnotationSegment{{ID: "a", Start: 0, End: 10, Status: "pending"}}}
|
|
if tc.status != "" {
|
|
item.Subject.Payload["sliceWorkflow"] = map[string]any{"status": tc.status, "phase": tc.phase, "leaseExpiresAt": time.Now().Add(time.Hour).UTC().Format(time.RFC3339Nano)}
|
|
}
|
|
if err := f.store.UpsertHumanItem(f.ctx, item); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
r := f.request("GET", "/api/plugins/annotation-qa/tasks/"+f.task.ID, f.annotator, nil)
|
|
if r.Code != 200 {
|
|
t.Fatalf("detail: %d %s", r.Code, r.Body.String())
|
|
}
|
|
var body struct {
|
|
EditorState annotationEditorState `json:"editorState"`
|
|
}
|
|
if err := json.Unmarshal(r.Body.Bytes(), &body); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if body.EditorState.Phase != tc.expected || body.EditorState.CanConfirmDescriptions != tc.ready {
|
|
t.Fatalf("state=%+v", body.EditorState)
|
|
}
|
|
ready, err := (&server{store: f.store}).legacyAnnotationConfirmationReady(f.ctx, f.task, &item)
|
|
if err != nil || ready != body.EditorState.CanConfirmDescriptions {
|
|
t.Fatalf("gate differs: %v %v", ready, err)
|
|
}
|
|
})
|
|
}
|
|
}
|