140 lines
5.2 KiB
Go
140 lines
5.2 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"droboticflow/internal/domain"
|
|
"droboticflow/internal/store"
|
|
)
|
|
|
|
func TestUpsertBuiltinOperatorPreservesSharedMemoryOverride(t *testing.T) {
|
|
ctx := context.Background()
|
|
server := &server{store: store.NewMemoryStore()}
|
|
existing := domain.OperatorRecord{
|
|
ID: "operator-builtin-shm",
|
|
Name: "SHM operator",
|
|
Type: "builtin",
|
|
Resources: &domain.OperatorResources{
|
|
CPULimit: "2",
|
|
SharedMemorySize: "16Gi",
|
|
},
|
|
}
|
|
builtin := existing
|
|
builtin.Resources = &domain.OperatorResources{CPULimit: "4"}
|
|
|
|
items, err := upsertBuiltinOperator(ctx, server, []domain.OperatorRecord{existing}, builtin)
|
|
if err != nil {
|
|
t.Fatalf("upsert builtin operator: %v", err)
|
|
}
|
|
if len(items) != 1 || items[0].Resources == nil {
|
|
t.Fatalf("unexpected upserted items: %#v", items)
|
|
}
|
|
if items[0].Resources.CPULimit != "4" || items[0].Resources.SharedMemorySize != "16Gi" {
|
|
t.Fatalf("expected catalog CPU and user SHM override, got %#v", items[0].Resources)
|
|
}
|
|
}
|
|
|
|
func TestUpsertBuiltinOperatorPreservesEnvironmentSpecificIndependentImage(t *testing.T) {
|
|
ctx := context.Background()
|
|
server := &server{store: store.NewMemoryStore()}
|
|
existing := domain.OperatorRecord{
|
|
ID: "operator-builtin-package",
|
|
Name: "Package",
|
|
Type: "builtin",
|
|
Image: "registry.example/fanyu/droboticflow-operator-package:fanyu-release",
|
|
ImageID: "registry.example/fanyu/droboticflow-operator-package@sha256:" + strings.Repeat("a", 64),
|
|
}
|
|
builtin := existing
|
|
builtin.Image = "registry.example/poc/droboticflow-operator-package:poc-release"
|
|
builtin.ImageID = "registry.example/poc/droboticflow-operator-package@sha256:" + strings.Repeat("b", 64)
|
|
|
|
items, err := upsertBuiltinOperator(ctx, server, []domain.OperatorRecord{existing}, builtin)
|
|
if err != nil {
|
|
t.Fatalf("upsert builtin operator: %v", err)
|
|
}
|
|
if len(items) != 1 || items[0].Image != existing.Image || items[0].ImageID != existing.ImageID {
|
|
t.Fatalf("environment-specific image was replaced: %#v", items)
|
|
}
|
|
}
|
|
|
|
func TestFanyuRequiredOperatorDefaultsMatchDeliveryContract(t *testing.T) {
|
|
items, err := builtinOperatorRecords("2026-08-19T00:00:00Z", "registry.example/runner:test")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want := map[string][3]string{
|
|
"operator-builtin-diffusion-policy-train": {"16", "96Gi", "1"},
|
|
"operator-builtin-openvla-finetune": {"24", "128Gi", "1"},
|
|
"operator-builtin-openvla-inference": {"12", "64Gi", "1"},
|
|
"operator-builtin-yolo-embodied-detection-train": {"16", "64Gi", "1"},
|
|
"operator-builtin-yolo-video-target-clip": {"12", "32Gi", "1"},
|
|
}
|
|
for id, expected := range want {
|
|
item := findBuiltinOperator(items, id, "")
|
|
if item == nil || item.Resources == nil {
|
|
t.Fatalf("missing resources for %s", id)
|
|
}
|
|
if item.Resources.CPULimit != expected[0] || item.Resources.MemoryLimit != expected[1] || item.Resources.GPULimit != expected[2] || item.Resources.GPUType != "NVIDIA A800 80GB" {
|
|
t.Fatalf("resources for %s = %#v", id, item.Resources)
|
|
}
|
|
}
|
|
sampling := findBuiltinOperator(items, "operator-builtin-audit-sample", "")
|
|
if sampling == nil {
|
|
t.Fatal("missing audit sampling operator")
|
|
}
|
|
var rules []map[string]any
|
|
for _, hyperparam := range sampling.Hyperparams {
|
|
if hyperparam.Key == "RULES_JSON" {
|
|
if err := json.Unmarshal([]byte(hyperparam.Value), &rules); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
if len(rules) != 4 {
|
|
t.Fatalf("sampling rules=%#v", rules)
|
|
}
|
|
}
|
|
|
|
func TestBuiltinCatalogIncludesNativeAnnotationGateContract(t *testing.T) {
|
|
items, err := builtinOperatorRecords("2026-08-18T00:00:00Z", "registry.example/droboticflow-operator-runner:test")
|
|
if err != nil {
|
|
t.Fatalf("load builtin operator catalog: %v", err)
|
|
}
|
|
item := findBuiltinOperator(items, "operator-builtin-annotation-gate", "")
|
|
if item == nil {
|
|
t.Fatal("expected native annotation gate in builtin catalog")
|
|
}
|
|
if item.Category != "HUMAN" || len(item.Inputs) != 13 || len(item.Outputs) != 6 {
|
|
t.Fatalf("unexpected annotation gate ports: %#v", item)
|
|
}
|
|
for _, portID := range []string{"clips", "prelabels", "boundaries", "fullLeftVideos", "fullRightVideos", "leftTimestamps", "rightTimestamps", "imu", "roughCutWindows", "headposeEvidence", "handposeEvidence", "headpose", "handpose", "approvedVideos", "annotations", "rejected", "aggregateSummary", "acceptedSliceDirectory", "acceptanceSummary"} {
|
|
found := false
|
|
for _, port := range append(append([]domain.PortDefinition{}, item.Inputs...), item.Outputs...) {
|
|
if port.ID == portID {
|
|
found = true
|
|
if port.Container == "" || port.PayloadMode == "" {
|
|
t.Fatalf("annotation gate port %s lacks explicit contract: %#v", portID, port)
|
|
}
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatalf("annotation gate port %s is missing", portID)
|
|
}
|
|
}
|
|
keys := map[string]bool{}
|
|
for _, hyperparam := range item.Hyperparams {
|
|
keys[hyperparam.Key] = true
|
|
}
|
|
for _, key := range []string{"ANNOTATION_TEMPLATE_ID", "ANNOTATION_SUPPLIER_ID", "REQUIRE_PREPACKAGE_ACCEPTANCE"} {
|
|
if !keys[key] {
|
|
t.Fatalf("annotation gate is missing hyperparameter %s", key)
|
|
}
|
|
}
|
|
if keys["ANNOTATION_ASSIGNED_USER_ID"] {
|
|
t.Fatal("new annotation tasks must enter the available pool without a pre-assigned user")
|
|
}
|
|
}
|