forked from longtao.wu/droboticflow
429 lines
20 KiB
Go
429 lines
20 KiB
Go
package worker
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"droboticflow/internal/domain"
|
|
"droboticflow/internal/store"
|
|
)
|
|
|
|
func TestHumanReleaseTargetUsesApprovedGateEdge(t *testing.T) {
|
|
workflow := &domain.WorkflowRecord{Edges: []domain.WorkflowEdge{
|
|
{ID: "approved", Source: "gate", SourceHandle: "approved", Target: "package"},
|
|
{ID: "rejected", Source: "gate", SourceHandle: "rejected", Target: "quarantine"},
|
|
}}
|
|
target, err := humanReleaseTarget(workflow, "gate")
|
|
if err != nil || target != "package" {
|
|
t.Fatalf("target=%q err=%v", target, err)
|
|
}
|
|
}
|
|
|
|
func TestHumanReleaseTargetAllowsMultiportApprovedEdgesToOnePackage(t *testing.T) {
|
|
workflow := &domain.WorkflowRecord{Edges: []domain.WorkflowEdge{
|
|
{ID: "approved-videos", Source: "gate", SourceHandle: "approvedVideos", Target: "package"},
|
|
{ID: "annotations", Source: "gate", SourceHandle: "annotations", Target: "package"},
|
|
{ID: "rejected", Source: "gate", SourceHandle: "rejected", Target: "quarantine"},
|
|
}}
|
|
target, err := humanReleaseTarget(workflow, "gate")
|
|
if err != nil || target != "package" {
|
|
t.Fatalf("target=%q err=%v", target, err)
|
|
}
|
|
}
|
|
|
|
func TestHumanReleaseBaselineCompletesGateWithPartitionArtifacts(t *testing.T) {
|
|
workflow := domain.WorkflowRecord{
|
|
Nodes: []domain.WorkflowNode{{ID: "source"}, {ID: "gate"}, {ID: "package"}},
|
|
Edges: []domain.WorkflowEdge{{Source: "source", Target: "gate"}, {Source: "gate", Target: "package"}},
|
|
}
|
|
parent := domain.RunRecord{NodeExecutions: []domain.NodeExecutionRecord{
|
|
{NodeID: "source", Status: domain.NodeExecutionStatusCompleted},
|
|
{NodeID: "gate", Status: domain.NodeExecutionStatusWaitingForHuman},
|
|
}}
|
|
artifacts := []domain.ExecutionArtifact{{ID: "partition-manifest", Name: "annotations-manifest.json"}}
|
|
baseline := humanReleaseBaseline(workflow, parent, "gate", "package", artifacts)
|
|
if len(baseline) != 2 {
|
|
t.Fatalf("baseline=%#v", baseline)
|
|
}
|
|
for _, execution := range baseline {
|
|
if execution.NodeID == "gate" {
|
|
if execution.Status != domain.NodeExecutionStatusCompleted || len(execution.Artifacts) != 1 {
|
|
t.Fatalf("gate baseline=%#v", execution)
|
|
}
|
|
return
|
|
}
|
|
}
|
|
t.Fatal("gate baseline missing")
|
|
}
|
|
|
|
func TestHumanReleaseManifestDigestIsStableAcrossOrdering(t *testing.T) {
|
|
left := domain.HumanReleaseManifestDigest([]string{"item-b", "item-a"})
|
|
right := domain.HumanReleaseManifestDigest([]string{"item-a", "item-b"})
|
|
if left == "" || left != right {
|
|
t.Fatalf("digest must be stable: left=%q right=%q", left, right)
|
|
}
|
|
}
|
|
|
|
func TestHumanReleaseChildRunIDIsStableAndPartitionScoped(t *testing.T) {
|
|
left := humanReleaseChildRunID("gate:1:digest-a")
|
|
repeated := humanReleaseChildRunID("gate:1:digest-a")
|
|
right := humanReleaseChildRunID("gate:2:digest-b")
|
|
if left == "" || left != repeated || left == right {
|
|
t.Fatalf("child ids left=%q repeated=%q right=%q", left, repeated, right)
|
|
}
|
|
}
|
|
|
|
func TestReconcileHumanReleasePartitionsIsolatesMalformedLegacyBatch(t *testing.T) {
|
|
ctx := context.Background()
|
|
dataStore := store.NewMemoryStore()
|
|
project, err := dataStore.CreateProject(ctx, domain.CreateProjectInput{Name: "release isolation", Description: "isolation"})
|
|
if err != nil {
|
|
t.Fatalf("create project: %v", err)
|
|
}
|
|
workflow, err := dataStore.CreateWorkflow(ctx, domain.CreateWorkflowInput{
|
|
ProjectID: project.ID,
|
|
Name: "malformed legacy release",
|
|
Type: domain.WorkflowTypeBatch,
|
|
Nodes: []domain.WorkflowNode{{ID: "gate", Type: "operator"}, {ID: "package", Type: "operator"}},
|
|
Edges: []domain.WorkflowEdge{{ID: "plain", Source: "gate", Target: "package"}},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("create workflow: %v", err)
|
|
}
|
|
parent, err := dataStore.CreateRun(ctx, workflow.ID, domain.RunTriggerManual)
|
|
if err != nil {
|
|
t.Fatalf("create parent run: %v", err)
|
|
}
|
|
batch := domain.HumanBatchRecord{
|
|
ID: "batch-malformed-legacy", OrganizationID: domain.DefaultOrganizationID,
|
|
ProjectID: project.ID, WorkflowID: workflow.ID, RunID: parent.ID, GateNodeID: "gate",
|
|
Status: domain.HumanBatchActive, CreatedAt: nowISO(), UpdatedAt: nowISO(),
|
|
}
|
|
if err := dataStore.UpsertHumanBatch(ctx, batch); err != nil {
|
|
t.Fatalf("upsert batch: %v", err)
|
|
}
|
|
partition := domain.ReleasePartitionRecord{
|
|
ID: "partition-malformed-legacy", OrganizationID: domain.DefaultOrganizationID,
|
|
BatchID: batch.ID, GateNodeID: batch.GateNodeID, UniqueKey: "malformed:1:digest",
|
|
ManifestDigest: "digest", Status: domain.ReleasePartitionPending,
|
|
}
|
|
if err := dataStore.UpsertReleasePartition(ctx, partition); err != nil {
|
|
t.Fatalf("upsert partition: %v", err)
|
|
}
|
|
runtime := &Runtime{store: dataStore}
|
|
if err := runtime.reconcileHumanReleasePartitions(ctx); err != nil {
|
|
t.Fatalf("malformed legacy batch must be isolated from other release work: %v", err)
|
|
}
|
|
stored, err := dataStore.GetReleasePartitionByUniqueKey(ctx, domain.DefaultOrganizationID, partition.UniqueKey)
|
|
if err != nil || stored == nil {
|
|
t.Fatalf("get failed partition: %#v err=%v", stored, err)
|
|
}
|
|
if stored.Status != domain.ReleasePartitionFailed {
|
|
t.Fatalf("expected malformed partition to retain failed evidence, got %#v", stored)
|
|
}
|
|
}
|
|
|
|
func TestAnnotationPoseSummaryRequiresNonEmptyVerifiedHeadposeFrames(t *testing.T) {
|
|
empty := annotationPoseSummary([]domain.ExecutionArtifact{{
|
|
ID: "headpose-empty",
|
|
Data: map[string]any{"schemaVersion": "droboticflow.headpose/v1", "enabled": true, "frameCount": 0, "frames": []any{}},
|
|
}})
|
|
if annotationPoseSummaryHasRequiredHeadpose(empty) {
|
|
t.Fatalf("empty Headpose evidence must fail closed: %#v", empty)
|
|
}
|
|
valid := annotationPoseSummary([]domain.ExecutionArtifact{
|
|
{
|
|
ID: "headpose-valid", NodeID: "headpose", Name: "headpose-manifest.json",
|
|
Data: map[string]any{"schemaVersion": "droboticflow.headpose/v1", "enabled": true, "frameCount": 2, "frames": []any{map[string]any{"timestamp": 0.0}, map[string]any{"timestamp": 1.0}}},
|
|
},
|
|
{ID: "headpose-render", NodeID: "headpose", Name: "headpose-annotated.mp4", Type: domain.PortTypeVideo},
|
|
{
|
|
ID: "hand-prelabel", NodeID: "handpose", Name: "wilor-result.json",
|
|
Data: map[string]any{"schemaVersion": "droboticflow.wilor.hand_pose_result/v1", "enabled": true, "result": map[string]any{"frameCount": 3}},
|
|
},
|
|
{ID: "hand-prelabel-render", NodeID: "handpose", Name: "wilor-annotated-video.mp4", Type: domain.PortTypeVideo},
|
|
})
|
|
if !annotationPoseSummaryHasRequiredHeadpose(valid) || valid["headposeFrameCount"] != 2 {
|
|
t.Fatalf("non-empty verified Headpose evidence must be retained: %#v", valid)
|
|
}
|
|
if valid["handPrelabelAvailable"] != true || valid["handPrelabelFrameCount"] != 3 || len(valid["headposeRenderArtifacts"].([]map[string]any)) != 1 || len(valid["handPrelabelRenderArtifacts"].([]map[string]any)) != 1 {
|
|
t.Fatalf("rendered hand/head prelabel evidence must be retained: %#v", valid)
|
|
}
|
|
}
|
|
|
|
func TestFanyuV5FinalSliceCoordinatesSeparateClipAndSourceTimelines(t *testing.T) {
|
|
task := domain.AnnotationTaskRecord{ClipStart: 200, ClipEnd: 400}
|
|
clipStart, clipEnd, sourceStart, sourceEnd, err := fanyuV5FinalSliceCoordinates(task, domain.SliceSegment{ID: "final", Start: 220, End: 260})
|
|
if err != nil || clipStart != 20 || clipEnd != 60 || sourceStart != 220 || sourceEnd != 260 {
|
|
t.Fatalf("coordinates clip=[%v,%v) source=[%v,%v) err=%v", clipStart, clipEnd, sourceStart, sourceEnd, err)
|
|
}
|
|
if _, _, _, _, err := fanyuV5FinalSliceCoordinates(task, domain.SliceSegment{ID: "outside", Start: 190, End: 210}); err == nil {
|
|
t.Fatal("source slice outside its clip must fail closed")
|
|
}
|
|
}
|
|
|
|
func TestFanyuV5FinalSliceCoordinatesAllowVirtualFullVideoExpansion(t *testing.T) {
|
|
task := domain.AnnotationTaskRecord{ClipStart: 10, ClipEnd: 12, SourceIsFullVideo: true, SourceDurationSeconds: 30}
|
|
clipStart, clipEnd, sourceStart, sourceEnd, err := fanyuV5FinalSliceCoordinates(task, domain.SliceSegment{ID: "expanded", Start: 8, End: 14})
|
|
if err != nil || clipStart != 8 || clipEnd != 14 || sourceStart != 8 || sourceEnd != 14 {
|
|
t.Fatalf("virtual coordinates clip=[%v,%v) source=[%v,%v) err=%v", clipStart, clipEnd, sourceStart, sourceEnd, err)
|
|
}
|
|
if _, _, _, _, err := fanyuV5FinalSliceCoordinates(task, domain.SliceSegment{ID: "outside", Start: 8, End: 31}); err == nil {
|
|
t.Fatal("virtual source slice outside full duration must fail closed")
|
|
}
|
|
}
|
|
|
|
func TestCompletedDeliveryPackageCreatesUnassignedAcceptanceHumanItem(t *testing.T) {
|
|
ctx := context.Background()
|
|
dataStore := store.NewMemoryStore()
|
|
runtime := &Runtime{store: dataStore}
|
|
batch := domain.HumanBatchRecord{
|
|
ID: "batch-a", OrganizationID: "org-a", PluginID: "annotation-qa", ProjectID: "project-a",
|
|
WorkflowID: "workflow-a", RunID: "run-parent", GateNodeID: "gate", Status: domain.HumanBatchActive,
|
|
Stages: domain.DefaultAnnotationHumanStages(), ReleasePolicy: domain.HumanReleaseAcceptedPartition,
|
|
}
|
|
partition := domain.ReleasePartitionRecord{
|
|
ID: "partition-a", OrganizationID: "org-a", BatchID: batch.ID, ChildRunID: "run-child",
|
|
ManifestDigest: "digest-a", ItemIDs: []string{"human-a"}, Status: domain.ReleasePartitionDispatched,
|
|
}
|
|
if err := dataStore.UpsertHumanItem(ctx, domain.HumanItemRecord{
|
|
ID: "human-a", OrganizationID: "org-a", BatchID: batch.ID, ProjectID: batch.ProjectID,
|
|
WorkgroupID: "group-a", VendorID: "vendor-a", Subject: domain.HumanSubjectRef{ItemKey: "clip-a"},
|
|
CurrentStageID: "quality_review", Status: domain.HumanItemAccepted, Version: 1,
|
|
}); err != nil {
|
|
t.Fatalf("create source item: %v", err)
|
|
}
|
|
if err := dataStore.UpsertRun(ctx, domain.RunRecord{
|
|
ID: partition.ChildRunID, OrganizationID: "org-a", ProjectID: batch.ProjectID, WorkflowID: batch.WorkflowID,
|
|
Status: domain.RunStatusCompleted, Artifacts: []domain.ExecutionArtifact{
|
|
{ID: "artifact-headpose", Name: "headpose-manifest.json", NodeID: "headpose"},
|
|
{ID: "artifact-handpose", Name: "handpose-manifest.json", NodeID: "wilor"},
|
|
},
|
|
}); err != nil {
|
|
t.Fatalf("create child run: %v", err)
|
|
}
|
|
if err := runtime.syncDeliveryPackage(ctx, batch, partition); err != nil {
|
|
t.Fatalf("sync package: %v", err)
|
|
}
|
|
packages, err := dataStore.ListDeliveryPackages(ctx, "org-a", domain.DeliveryPackageQuery{ReleasePartitionID: partition.ID})
|
|
if err != nil || len(packages) != 1 {
|
|
t.Fatalf("packages=%#v err=%v", packages, err)
|
|
}
|
|
item := packages[0]
|
|
if item.Status != domain.DeliveryPackagePendingAcceptance || item.AcceptanceHumanItemID == "" || len(item.HeadposeArtifactIDs) != 1 || len(item.HandposeArtifactIDs) != 1 {
|
|
t.Fatalf("package=%#v", item)
|
|
}
|
|
acceptance, err := dataStore.GetHumanItem(ctx, item.AcceptanceHumanItemID)
|
|
if err != nil || acceptance == nil {
|
|
t.Fatalf("acceptance item=%#v err=%v", acceptance, err)
|
|
}
|
|
if acceptance.CurrentStageID != "acceptance" || acceptance.Status != domain.HumanItemReady || acceptance.AssignedUserID != "" || acceptance.WorkgroupID != "group-a" || acceptance.VendorID != "vendor-a" {
|
|
t.Fatalf("acceptance item must enter the scoped available pool: %#v", acceptance)
|
|
}
|
|
}
|
|
|
|
func TestV5PrePackageAcceptanceFinalizesDeliveryWithoutLegacySecondAcceptance(t *testing.T) {
|
|
ctx := context.Background()
|
|
dataStore := store.NewMemoryStore()
|
|
runtime := &Runtime{store: dataStore}
|
|
batch := domain.HumanBatchRecord{ID: "batch-v5-final", OrganizationID: "org-v5", PluginID: "annotation-qa", ProjectID: "project-v5", WorkflowID: "workflow-v5", RunID: "run-parent-v5", GateNodeID: "gate-v5", RequirePrePackageAcceptance: true, ReleasePolicy: domain.HumanReleaseAllAccepted}
|
|
partition := domain.ReleasePartitionRecord{ID: "partition-v5-final", OrganizationID: batch.OrganizationID, BatchID: batch.ID, ChildRunID: "run-child-v5", ItemIDs: []string{"item-v5"}, Status: domain.ReleasePartitionDispatched}
|
|
if err := dataStore.UpsertHumanBatch(ctx, batch); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := dataStore.UpsertRun(ctx, domain.RunRecord{ID: batch.RunID, OrganizationID: batch.OrganizationID, ProjectID: batch.ProjectID, WorkflowID: batch.WorkflowID, Status: domain.RunStatusWaitingForHuman, CurrentNodeID: batch.GateNodeID, NodeExecutions: []domain.NodeExecutionRecord{{NodeID: batch.GateNodeID, NodeLabel: "Human", Status: domain.NodeExecutionStatusWaitingForHuman}}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
acceptanceBatch := domain.HumanBatchRecord{ID: "human-batch-fanyu-v5-prepackage-acceptance-" + batch.ID, OrganizationID: batch.OrganizationID, PluginID: batch.PluginID, ProjectID: batch.ProjectID, WorkflowID: batch.WorkflowID, RunID: batch.RunID, SourceBatchID: batch.ID, Stages: []domain.HumanStageDefinition{{ID: "prepackage_acceptance", Kind: domain.HumanStageAcceptance, RequiredRole: "quality_reviewer", ConfirmOnly: true}}}
|
|
if err := dataStore.UpsertHumanBatch(ctx, acceptanceBatch); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := dataStore.UpsertHumanItem(ctx, domain.HumanItemRecord{ID: "human-item-fanyu-v5-prepackage-acceptance-" + batch.ID, OrganizationID: batch.OrganizationID, PluginID: batch.PluginID, BatchID: acceptanceBatch.ID, ProjectID: batch.ProjectID, WorkflowID: batch.WorkflowID, RunID: batch.RunID, CurrentStageID: "prepackage_acceptance", Status: domain.HumanItemAccepted, AcceptedAt: "2026-08-20T00:00:00Z", AcceptedByUserID: "acceptance-reviewer", Version: 2, Subject: domain.HumanSubjectRef{ItemKey: batch.ID, Payload: map[string]any{"statistics": map[string]any{"taskCount": 1}}}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := dataStore.UpsertRun(ctx, domain.RunRecord{ID: partition.ChildRunID, OrganizationID: batch.OrganizationID, ProjectID: batch.ProjectID, WorkflowID: batch.WorkflowID, Status: domain.RunStatusCompleted, Artifacts: []domain.ExecutionArtifact{{ID: "artifact-upstream", RunID: batch.RunID, Name: "annotations-manifest.json"}, {ID: "artifact-final", RunID: partition.ChildRunID, Name: "packages-manifest.json"}}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := runtime.syncDeliveryPackage(ctx, batch, partition); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
packages, err := dataStore.ListDeliveryPackages(ctx, batch.OrganizationID, domain.DeliveryPackageQuery{ReleasePartitionID: partition.ID})
|
|
if err != nil || len(packages) != 1 {
|
|
t.Fatalf("packages=%#v err=%v", packages, err)
|
|
}
|
|
item := packages[0]
|
|
if item.Status != domain.DeliveryPackageAccepted || item.AcceptanceHumanItemID != "" || len(item.FinalExportArtifactIDs) != 1 || item.FinalExportArtifactIDs[0] != "artifact-final" || len(item.AcceptanceReviews) != 1 {
|
|
t.Fatalf("v5 package must finalize from pre-package confirmation without legacy acceptance: %#v", item)
|
|
}
|
|
parent, err := dataStore.GetRun(ctx, batch.RunID)
|
|
if err != nil || parent == nil || parent.Status != domain.RunStatusCompleted || parent.CurrentNodeID != "" || parent.NodeExecutions[0].Status != domain.NodeExecutionStatusCompleted {
|
|
t.Fatalf("accepted v5 package must terminalize the waiting human parent: parent=%#v err=%v", parent, err)
|
|
}
|
|
}
|
|
|
|
func TestConfirmOnlyAggregateBatchDoesNotCreateReleasePartition(t *testing.T) {
|
|
ctx := context.Background()
|
|
dataStore := store.NewMemoryStore()
|
|
runtime := &Runtime{store: dataStore}
|
|
batch := domain.HumanBatchRecord{
|
|
ID: "aggregate-confirm-only", OrganizationID: "org", SourceBatchID: "source-batch", ReleasePolicy: domain.HumanReleaseAcceptedPartition,
|
|
Stages: []domain.HumanStageDefinition{{ID: "prepackage_acceptance", ConfirmOnly: true}},
|
|
}
|
|
if err := dataStore.UpsertHumanBatch(ctx, batch); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := dataStore.UpsertHumanItem(ctx, domain.HumanItemRecord{ID: "aggregate-item", OrganizationID: "org", BatchID: batch.ID, Status: domain.HumanItemAccepted, AcceptedAt: nowISO(), Version: 1}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := runtime.ensureDueHumanReleasePartitions(ctx, &batch); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
partitions, err := dataStore.ListReleasePartitions(ctx, "org", batch.ID)
|
|
if err != nil || len(partitions) != 0 {
|
|
t.Fatalf("confirm-only aggregate batch must not release itself: partitions=%#v err=%v", partitions, err)
|
|
}
|
|
}
|
|
|
|
func TestSyncDeliveryPackage_DebugRunModeInheritance(t *testing.T) {
|
|
ctx := context.Background()
|
|
dataStore := store.NewMemoryStore()
|
|
runtime := &Runtime{store: dataStore}
|
|
batch := domain.HumanBatchRecord{
|
|
ID: "batch-dbg", OrganizationID: "org-a", PluginID: "annotation-qa", ProjectID: "project-a",
|
|
WorkflowID: "workflow-a", RunID: "run-parent-dbg", GateNodeID: "gate", Status: domain.HumanBatchActive,
|
|
Stages: domain.DefaultAnnotationHumanStages(), ReleasePolicy: domain.HumanReleaseAcceptedPartition,
|
|
}
|
|
partition := domain.ReleasePartitionRecord{
|
|
ID: "partition-dbg", OrganizationID: "org-a", BatchID: batch.ID, ChildRunID: "run-child-dbg",
|
|
ManifestDigest: "digest-dbg", ItemIDs: []string{"human-dbg"}, Status: domain.ReleasePartitionDispatched,
|
|
}
|
|
// Parent run has Mode: RunModeDebug
|
|
if err := dataStore.UpsertRun(ctx, domain.RunRecord{
|
|
ID: batch.RunID,
|
|
OrganizationID: "org-a",
|
|
ProjectID: batch.ProjectID,
|
|
WorkflowID: batch.WorkflowID,
|
|
Mode: domain.RunModeDebug,
|
|
}); err != nil {
|
|
t.Fatalf("create parent run: %v", err)
|
|
}
|
|
// Child run also has Mode: RunModeDebug
|
|
if err := dataStore.UpsertRun(ctx, domain.RunRecord{
|
|
ID: partition.ChildRunID,
|
|
OrganizationID: "org-a",
|
|
ProjectID: batch.ProjectID,
|
|
WorkflowID: batch.WorkflowID,
|
|
Mode: domain.RunModeDebug,
|
|
Status: domain.RunStatusCompleted,
|
|
}); err != nil {
|
|
t.Fatalf("create child run: %v", err)
|
|
}
|
|
|
|
if err := runtime.syncDeliveryPackage(ctx, batch, partition); err != nil {
|
|
t.Fatalf("sync package: %v", err)
|
|
}
|
|
packages, err := dataStore.ListDeliveryPackages(ctx, "org-a", domain.DeliveryPackageQuery{ReleasePartitionID: partition.ID, Mode: domain.RunModeAll})
|
|
if err != nil || len(packages) != 1 {
|
|
t.Fatalf("packages=%#v err=%v", packages, err)
|
|
}
|
|
item := packages[0]
|
|
if item.Mode != domain.RunModeDebug {
|
|
t.Fatalf("expected Mode=debug, got %s", item.Mode)
|
|
}
|
|
if !item.Temporary {
|
|
t.Fatalf("expected Temporary=true, got false")
|
|
}
|
|
}
|
|
|
|
func TestDispatchHumanReleasePartition_ProvenanceInheritance(t *testing.T) {
|
|
ctx := context.Background()
|
|
dataStore := store.NewMemoryStore()
|
|
runtime := &Runtime{store: dataStore}
|
|
|
|
workflow := domain.WorkflowRecord{
|
|
ID: "wf-release-1",
|
|
OrganizationID: "org-a",
|
|
ProjectID: "proj-a",
|
|
Nodes: []domain.WorkflowNode{{ID: "source"}, {ID: "gate"}, {ID: "package"}},
|
|
Edges: []domain.WorkflowEdge{{ID: "e1", Source: "source", Target: "gate"}, {ID: "e2", Source: "gate", SourceHandle: "approved", Target: "package"}},
|
|
DefinitionVersion: 3,
|
|
}
|
|
if err := dataStore.UpsertWorkflow(ctx, workflow); err != nil {
|
|
t.Fatalf("upsert workflow: %v", err)
|
|
}
|
|
|
|
parent := domain.RunRecord{
|
|
ID: "run-parent-1",
|
|
OrganizationID: "org-a",
|
|
ProjectID: "proj-a",
|
|
WorkflowID: workflow.ID,
|
|
Mode: domain.RunModeProduction,
|
|
ReleaseID: "rel-123",
|
|
WorkflowVersion: 3,
|
|
GitCommitSha: "abcdef1234567890",
|
|
ImageDigest: "sha256:fedcba0987654321",
|
|
Attempt: 1,
|
|
RestartFromNodeID: "source",
|
|
Status: domain.RunStatusRunning,
|
|
NodeExecutions: []domain.NodeExecutionRecord{
|
|
{
|
|
NodeID: "gate",
|
|
Status: domain.NodeExecutionStatusWaitingForHuman,
|
|
},
|
|
},
|
|
}
|
|
if err := dataStore.UpsertRun(ctx, parent); err != nil {
|
|
t.Fatalf("upsert parent run: %v", err)
|
|
}
|
|
|
|
batch := domain.HumanBatchRecord{
|
|
ID: "batch-rel-1",
|
|
OrganizationID: "org-a",
|
|
ProjectID: "proj-a",
|
|
WorkflowID: workflow.ID,
|
|
RunID: parent.ID,
|
|
GateNodeID: "gate",
|
|
Status: domain.HumanBatchActive,
|
|
}
|
|
if err := dataStore.UpsertHumanBatch(ctx, batch); err != nil {
|
|
t.Fatalf("upsert human batch: %v", err)
|
|
}
|
|
partition := domain.ReleasePartitionRecord{
|
|
ID: "partition-rel-1",
|
|
OrganizationID: "org-a",
|
|
BatchID: batch.ID,
|
|
UniqueKey: "gate:1:digest-xyz",
|
|
ItemIDs: []string{},
|
|
Status: domain.ReleasePartitionPending,
|
|
}
|
|
if err := dataStore.UpsertReleasePartition(ctx, partition); err != nil {
|
|
t.Fatalf("upsert release partition: %v", err)
|
|
}
|
|
|
|
if err := runtime.dispatchHumanReleasePartition(ctx, batch, partition); err != nil {
|
|
t.Fatalf("dispatch human release partition: %v", err)
|
|
}
|
|
|
|
childRunID := humanReleaseChildRunID(partition.UniqueKey)
|
|
child, err := dataStore.GetRun(ctx, childRunID)
|
|
if err != nil || child == nil {
|
|
t.Fatalf("child run not found: %v", err)
|
|
}
|
|
|
|
if child.Mode != domain.RunModeProduction {
|
|
t.Fatalf("expected child.Mode == production, got %s", child.Mode)
|
|
}
|
|
if child.ReleaseID != "rel-123" {
|
|
t.Fatalf("expected child.ReleaseID == rel-123, got %s", child.ReleaseID)
|
|
}
|
|
if child.WorkflowVersion != 3 {
|
|
t.Fatalf("expected child.WorkflowVersion == 3, got %d", child.WorkflowVersion)
|
|
}
|
|
if child.GitCommitSha != "abcdef1234567890" {
|
|
t.Fatalf("expected child.GitCommitSha == abcdef1234567890, got %s", child.GitCommitSha)
|
|
}
|
|
if child.ImageDigest != "sha256:fedcba0987654321" {
|
|
t.Fatalf("expected child.ImageDigest == sha256:fedcba0987654321, got %s", child.ImageDigest)
|
|
}
|
|
}
|