feat: add assertions for condition branch and port edge order in workflow tests

This commit is contained in:
mlogclub
2026-06-29 13:58:13 +08:00
parent ca625396a0
commit 9be449c882
2 changed files with 54 additions and 5 deletions
@@ -92,6 +92,24 @@ func TestAIAgentServiceCreatesDefaultWorkflow(t *testing.T) {
assertConditionBranchesHavePortEdges(t, stored, "policy_route_1")
assertConditionBranchesHavePortEdges(t, stored, "ticket_confirm_route_1")
assertConditionBranchesHavePortEdges(t, stored, "answerability_route_1")
assertConditionBranchOrder(t, stored, "policy_route_1", []string{
"handoff",
"direct",
"clarify",
"end_conversation",
"ticket",
"knowledge",
"default",
})
assertConditionPortEdgeOrder(t, stored, "policy_route_1", []string{
"handoff",
"direct",
"clarify",
"end_conversation",
"ticket",
"knowledge",
"default",
})
}
func TestAIWorkflowServiceDefaultAgentWorkflowDefinitionIsValid(t *testing.T) {
@@ -317,6 +335,37 @@ func assertConditionBranchesHavePortEdges(t *testing.T, def dsl.Definition, node
}
}
func assertConditionBranchOrder(t *testing.T, def dsl.Definition, nodeID string, want []string) {
t.Helper()
branches := conditionBranches(t, def, nodeID)
if len(branches) != len(want) {
t.Fatalf("expected %s branch order %v, got %#v", nodeID, want, branches)
}
for index, branch := range branches {
if branch.ID != want[index] {
t.Fatalf("expected %s branch order %v, got branch %d = %s", nodeID, want, index, branch.ID)
}
}
}
func assertConditionPortEdgeOrder(t *testing.T, def dsl.Definition, nodeID string, want []string) {
t.Helper()
got := make([]string, 0, len(want))
for _, edge := range def.Edges {
if edge.SourceNodeID == nodeID {
got = append(got, edge.SourcePortID)
}
}
if len(got) != len(want) {
t.Fatalf("expected %s port edge order %v, got %v", nodeID, want, got)
}
for index, sourcePortID := range got {
if sourcePortID != want[index] {
t.Fatalf("expected %s port edge order %v, got edge %d = %s", nodeID, want, index, sourcePortID)
}
}
}
func workflowPortEdgeExists(def dsl.Definition, sourceID string, targetID string, sourcePortID string) bool {
for _, edge := range def.Edges {
if edge.SourceNodeID == sourceID && edge.TargetNodeID == targetID && edge.SourcePortID == sourcePortID {