90 lines
3.4 KiB
Go
90 lines
3.4 KiB
Go
package plugins
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"droboticflow/internal/domain"
|
|
)
|
|
|
|
func stringSliceContains(values []string, expected string) bool {
|
|
for _, value := range values {
|
|
if value == expected {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func TestAnnotationCapabilitiesAreDerivedFromGateNode(t *testing.T) {
|
|
workflow := domain.WorkflowRecord{ID: "workflow-1", Nodes: []domain.WorkflowNode{{
|
|
ID: "gate",
|
|
Data: domain.WorkflowNodeData{OperatorID: "operator-builtin-annotation-gate"},
|
|
}}}
|
|
if capabilities := WorkflowCapabilities(workflow, false); len(capabilities) != 0 {
|
|
t.Fatalf("disabled plugin must not expose capabilities: %#v", capabilities)
|
|
}
|
|
capabilities := WorkflowCapabilities(workflow, true)
|
|
if len(capabilities) != 5 {
|
|
t.Fatalf("expected five annotation capabilities, got %#v", capabilities)
|
|
}
|
|
if capabilities[0].Path != "/plugins/annotation-qa/workflows/workflow-1/clip" {
|
|
t.Fatalf("unexpected annotation deep link: %s", capabilities[0].Path)
|
|
}
|
|
}
|
|
|
|
func TestFanyuV58ExposesOnlyThreeCombinedHumanCapabilities(t *testing.T) {
|
|
workflow := domain.WorkflowRecord{ID: "workflow-v58", DefinitionVersion: 8, Nodes: []domain.WorkflowNode{{
|
|
ID: "gate",
|
|
Data: domain.WorkflowNodeData{
|
|
OperatorID: "operator-builtin-annotation-gate",
|
|
Hyperparams: []domain.HyperParam{{Key: "ANNOTATION_TEMPLATE_ID", Value: "tpl-fanyu-convenience-store-v6-org-fanyu"}},
|
|
},
|
|
}}}
|
|
capabilities := WorkflowCapabilities(workflow, true)
|
|
if len(capabilities) != 3 {
|
|
t.Fatalf("v5.8 must expose exactly three combined human capabilities: %#v", capabilities)
|
|
}
|
|
if capabilities[0].ID != "human_annotation" || capabilities[0].Label != "真实切分与语义标注" ||
|
|
capabilities[1].ID != "human_quality_review" || capabilities[1].Label != "切分与标注审核" ||
|
|
capabilities[2].ID != "human_acceptance" || capabilities[2].Label != "整包验收" {
|
|
t.Fatalf("unexpected v5.8 capabilities: %#v", capabilities)
|
|
}
|
|
}
|
|
|
|
func TestAnnotationManifestContributesWorkbenchesAndOperators(t *testing.T) {
|
|
manifest, ok := Get(AnnotationQAID)
|
|
if !ok {
|
|
t.Fatal("annotation plugin manifest is missing")
|
|
}
|
|
if len(manifest.Navigation) != 3 {
|
|
t.Fatalf("expected three-role navigation contributions, got %#v", manifest.Navigation)
|
|
}
|
|
if manifest.Navigation[0].ID != "annotate" || manifest.Navigation[2].ID != "acceptance" {
|
|
t.Fatalf("unexpected navigation order: %#v", manifest.Navigation)
|
|
}
|
|
for _, item := range manifest.Navigation {
|
|
if item.GroupID != "annotation-center" || item.GroupLabel != "标注中心" || item.GroupIcon != "tags" {
|
|
t.Fatalf("annotation navigation must share one primary group: %#v", item)
|
|
}
|
|
}
|
|
rolesByID := map[string][]string{}
|
|
for _, item := range manifest.Navigation {
|
|
rolesByID[item.ID] = item.RequiredRoles
|
|
}
|
|
if !stringSliceContains(rolesByID["acceptance"], "acceptance_reviewer") || !stringSliceContains(rolesByID["acceptance"], "member") {
|
|
t.Fatalf("final acceptance must be exposed to project-scoped members and independently enforced by membership role: %#v", rolesByID["acceptance"])
|
|
}
|
|
wanted := map[string]bool{
|
|
"operator-builtin-annotation-gate": true,
|
|
"operator-builtin-audit-sample": true,
|
|
"operator-builtin-semantic-prelabel": true,
|
|
"operator-builtin-ms-swift-dataset-export": true,
|
|
}
|
|
for _, operatorID := range manifest.OperatorIDs {
|
|
delete(wanted, operatorID)
|
|
}
|
|
if len(wanted) != 0 {
|
|
t.Fatalf("annotation plugin is missing operator contributions: %#v", wanted)
|
|
}
|
|
}
|