droboticflow/internal/domain/workflow_cycle_test.go

39 lines
1.4 KiB
Go

package domain
import "testing"
func TestValidateWorkflowGraphRejectsDirectedCycle(t *testing.T) {
nodes := []WorkflowNode{{ID: "annotate"}, {ID: "review"}, {ID: "deliver"}}
edges := []WorkflowEdge{
{ID: "a-r", Source: "annotate", Target: "review"},
{ID: "r-a", Source: "review", Target: "annotate"},
{ID: "r-d", Source: "review", Target: "deliver"},
}
issues := ValidateSingleConnectedWorkflowGraph(nodes, edges)
for _, issue := range issues {
if issue.Code == WorkflowGraphIssueCycle {
if len(issue.NodeIDs) != 2 || issue.NodeIDs[0] != "annotate" || issue.NodeIDs[1] != "review" {
t.Fatalf("unexpected cycle nodes: %#v", issue.NodeIDs)
}
return
}
}
t.Fatalf("expected directed cycle issue, got %#v", issues)
}
func TestValidateWorkflowGraphAcceptsDecisionBranches(t *testing.T) {
nodes := []WorkflowNode{{ID: "source"}, {ID: "review"}, {ID: "approved"}, {ID: "rejected"}, {ID: "finish"}}
edges := []WorkflowEdge{
{ID: "s-r", Source: "source", Target: "review"},
{ID: "r-a", Source: "review", SourceHandle: "approved", Target: "approved"},
{ID: "r-x", Source: "review", SourceHandle: "rejected", Target: "rejected"},
{ID: "a-f", Source: "approved", Target: "finish"},
{ID: "x-f", Source: "rejected", Target: "finish"},
}
for _, issue := range ValidateSingleConnectedWorkflowGraph(nodes, edges) {
if issue.Code == WorkflowGraphIssueCycle {
t.Fatalf("decision branches must remain a valid DAG: %#v", issue)
}
}
}