forked from longtao.wu/droboticflow
87 lines
3.1 KiB
Go
87 lines
3.1 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"droboticflow/internal/domain"
|
|
pluginregistry "droboticflow/internal/plugins"
|
|
"droboticflow/internal/store"
|
|
)
|
|
|
|
func TestAnnotationPluginStatusMigratesLegacyTasksIdempotently(t *testing.T) {
|
|
ctx := context.Background()
|
|
dataStore := store.NewMemoryStore()
|
|
task := domain.AnnotationTaskRecord{
|
|
ID: "annotation-task-legacy", OrganizationID: "org-a", ProjectID: "project-a",
|
|
WorkflowID: "workflow-a", RunID: "run-a", NodeID: "gate", ArtifactID: "artifact-a",
|
|
SourceVideo: "/video.mp4", ClipStart: 0, ClipEnd: 10, WorkgroupID: "group-a", VendorID: "vendor-a",
|
|
Status: domain.AnnotationTaskStatusPendingQuality, CurrentRevision: 1,
|
|
}
|
|
if err := dataStore.UpsertAnnotationTask(ctx, task); err != nil {
|
|
t.Fatalf("upsert legacy task: %v", err)
|
|
}
|
|
if err := dataStore.UpsertAnnotationRevision(ctx, domain.AnnotationRevisionRecord{
|
|
ID: "revision-a", OrganizationID: "org-a", TaskID: task.ID, Revision: 1, AuthorUserID: "annotator-a",
|
|
}); err != nil {
|
|
t.Fatalf("upsert revision: %v", err)
|
|
}
|
|
server := &server{store: dataStore}
|
|
manifest, _ := pluginregistry.Get(pluginregistry.AnnotationQAID)
|
|
for index := 0; index < 2; index++ {
|
|
status, err := server.pluginStatus(ctx, "org-a", manifest)
|
|
if err != nil || !status.Enabled {
|
|
t.Fatalf("plugin status=%#v err=%v", status, err)
|
|
}
|
|
}
|
|
items, err := dataStore.ListHumanItems(ctx, "org-a", domain.HumanItemQuery{PluginID: pluginregistry.AnnotationQAID})
|
|
if err != nil || len(items) != 1 {
|
|
t.Fatalf("migrated items=%#v err=%v", items, err)
|
|
}
|
|
if items[0].LegacyTaskID != task.ID || items[0].CurrentStageID != "quality_review" || items[0].LatestAuthorUserID != "annotator-a" {
|
|
t.Fatalf("migrated item=%#v", items[0])
|
|
}
|
|
}
|
|
|
|
func TestNormalizeAnnotationPluginConfigRejectsUnsafeValues(t *testing.T) {
|
|
_, issues := normalizeAnnotationPluginConfig(map[string]any{
|
|
"releasePolicy": "unknown", "partitionMaxItems": 32.5, "partitionMaxWaitSeconds": 0, "maxReworkRounds": 101,
|
|
})
|
|
if len(issues) != 4 {
|
|
t.Fatalf("expected four validation issues, got %#v", issues)
|
|
}
|
|
}
|
|
|
|
func TestFilterOperatorsForInstalledPlugins(t *testing.T) {
|
|
ctx := context.Background()
|
|
dataStore := store.NewMemoryStore()
|
|
server := &server{store: dataStore}
|
|
items := []domain.OperatorRecord{
|
|
{ID: "operator-builtin-human-review"},
|
|
{ID: "operator-builtin-annotation-gate"},
|
|
{ID: "operator-builtin-audit-sample"},
|
|
{ID: "operator-builtin-real-source"},
|
|
}
|
|
|
|
filtered, err := server.filterOperatorsForInstalledPlugins(ctx, "org-a", items)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(filtered) != 2 || filtered[0].ID != "operator-builtin-human-review" || filtered[1].ID != "operator-builtin-real-source" {
|
|
t.Fatalf("disabled annotation plugin leaked operators: %#v", filtered)
|
|
}
|
|
|
|
if err := dataStore.UpsertOrganizationPlugin(ctx, domain.OrganizationPluginRecord{
|
|
OrganizationID: "org-a", PluginID: pluginregistry.AnnotationQAID, Enabled: true,
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
filtered, err = server.filterOperatorsForInstalledPlugins(ctx, "org-a", items)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(filtered) != len(items) {
|
|
t.Fatalf("enabled annotation plugin did not expose all operators: %#v", filtered)
|
|
}
|
|
}
|