droboticflow/internal/worker/slice_disposition_test.go

70 lines
3.9 KiB
Go

package worker
import (
"context"
"droboticflow/internal/domain"
"droboticflow/internal/store"
"strings"
"testing"
)
func TestDiscardPackageDeploymentOnlyChangesPackageAndRecordsActualDigest(t *testing.T) {
image := "registry.example/package@sha256:" + strings.Repeat("a", 64)
t.Setenv("FANYU_SLICE_DISCARD_PACKAGE_IMAGE", image)
node := domain.WorkflowNode{ID: "package", Data: domain.WorkflowNodeData{OperatorID: "operator-builtin-package", Image: "registry.example/old:tag", OperatorImageID: "registry.example/old@sha256:" + strings.Repeat("b", 64)}}
if got := chooseImage(node, "fallback"); got != image {
t.Fatal(got)
}
var record domain.NodeExecutionRecord
applyNodeExecutionSnapshot(&record, node, nil, nil, nil)
if record.OperatorImage != image || record.OperatorImageID != image {
t.Fatal("execution snapshot did not record actual package digest")
}
node.Data.OperatorID = "operator-builtin-orbbec-data-normalize"
if chooseImage(node, "fallback") == image {
t.Fatal("override leaked into preprocessing")
}
}
func TestAllDiscardClosesParentWithoutExportingReviewArtifacts(t *testing.T) {
ctx := context.Background()
db := store.NewMemoryStore()
r := &Runtime{store: db}
parent := domain.RunRecord{ID: "parent", OrganizationID: domain.DefaultOrganizationID, WorkflowID: "wf", Status: domain.RunStatusWaitingForHuman, NodeExecutions: []domain.NodeExecutionRecord{{NodeID: "human", Status: domain.NodeExecutionStatusWaitingForHuman}}}
parent.TaskID = "capture"
db.UpsertWorkflow(ctx, domain.WorkflowRecord{ID: "wf", OrganizationID: parent.OrganizationID})
db.UpsertRun(ctx, parent)
db.UpsertCaptureRecord(ctx, domain.CaptureRecord{ID: "capture", OrganizationID: parent.OrganizationID, WorkflowID: "wf", RunID: parent.ID, SamplingDecision: &domain.CaptureSamplingDecision{Decision: domain.CaptureSamplingNotSelected}})
batch := domain.HumanBatchRecord{ID: "b", OrganizationID: parent.OrganizationID, RunID: parent.ID, WorkflowID: "wf", GateNodeID: "human", RequirePrePackageAcceptance: true, ProcessingProfile: domain.ProcessingProfileRawHuman}
child := domain.RunRecord{ID: "child", OrganizationID: parent.OrganizationID, Status: domain.RunStatusCompleted, Artifacts: []domain.ExecutionArtifact{{ID: "private-video", RunID: parent.ID, Name: "left.mp4"}, {ID: "outcome", RunID: "child", PortID: "deliverySummary", Data: map[string]any{"schemaVersion": "droboticflow.delivery-summary/v2", "outcome": "no_deliverables"}}}}
db.UpsertRun(ctx, child)
p := domain.ReleasePartitionRecord{ID: "partition", ChildRunID: child.ID}
if err := r.syncDeliveryPackage(ctx, batch, p); err != nil {
t.Fatal(err)
}
packages, _ := db.ListDeliveryPackages(ctx, parent.OrganizationID, domain.DeliveryPackageQuery{ReleasePartitionID: p.ID})
if len(packages) != 1 || packages[0].Status != domain.DeliveryPackageNoDeliverables || len(packages[0].FinalExportArtifactIDs) != 0 || packages[0].FinalExportedAt != "" {
t.Fatalf("empty package advertised: %#v", packages)
}
saved, _ := db.GetRun(ctx, parent.ID)
if !domain.RunHasNoDeliverables(saved) || saved.Status != domain.RunStatusCompleted {
t.Fatal("parent left waiting or marked delivered")
}
capture, _ := db.GetCaptureRecord(ctx, "capture")
if capture.Status != domain.CaptureRecordCompleted || capture.BusinessStage != domain.CaptureStageNoDeliverables {
t.Fatal("capture remained waiting when no listener is running")
}
}
func TestNoDeliverablesOutcomeSurvivesArtifactCompaction(t *testing.T) {
data := compactArtifactData(map[string]any{"schemaVersion": "droboticflow.delivery-summary/v2", "outcome": "no_deliverables", "sliceCount": 0, "discardedSliceCount": 3})
run := domain.RunRecord{Status: domain.RunStatusCompleted, Artifacts: []domain.ExecutionArtifact{{PortID: "deliverySummary", Data: data}}}
if !domain.RunHasNoDeliverables(&run) {
t.Fatal("empty delivery outcome lost")
}
run.Status = domain.RunStatusRunning
if domain.RunHasNoDeliverables(&run) {
t.Fatal("unfinished run reported as closed")
}
}