feat: complete SOP execution workflow
This commit is contained in:
@@ -42,6 +42,12 @@ func TestValidateForPublishBusinessRules(t *testing.T) {
|
||||
{name: "high risk without escalation", mutate: func(_ *[]model.SOPNode, edges *[]model.SOPEdge, _ *ValidationContext) {
|
||||
(*edges)[1].TargetNodeKey = "finish"
|
||||
}, want: "没有明确的转人工或转诊路径"},
|
||||
{name: "terminal node has outgoing edge", mutate: func(_ *[]model.SOPNode, edges *[]model.SOPEdge, _ *ValidationContext) {
|
||||
*edges = append(*edges, model.SOPEdge{SourceNodeKey: "finish", TargetNodeKey: "screen", Condition: jsonData(`{}`)})
|
||||
}, want: "不能配置下一步"},
|
||||
{name: "ambiguous condition group", mutate: func(_ *[]model.SOPNode, edges *[]model.SOPEdge, _ *ValidationContext) {
|
||||
(*edges)[1].Condition = jsonData(`{"all":[{"field":"emergency","operator":"equals","value":true}],"any":[{"field":"emergency","operator":"equals","value":true}]}`)
|
||||
}, want: "不能同时包含全部满足和任一满足"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
@@ -55,6 +61,29 @@ func TestValidateForPublishBusinessRules(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateGraphRequiresConfiguredStartType(t *testing.T) {
|
||||
nodes, edges, _ := validPublishGraph()
|
||||
if problems := ValidateGraph("screen", nodes, edges); !containsProblem(problems, "必须指向 start 类型节点") {
|
||||
t.Fatalf("ValidateGraph() problems = %v", problems)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateForPublishChoiceConfiguration(t *testing.T) {
|
||||
nodes := []model.SOPNode{
|
||||
{NodeKey: "start", Type: "start", Title: "开始", Config: jsonData(`{}`)},
|
||||
{NodeKey: "choice", Type: "choice", Title: "客户意向", Config: jsonData(`{"field_key":"intent","options":["继续","无效"]}`)},
|
||||
{NodeKey: "finish", Type: "finish", Title: "结束", Config: jsonData(`{}`)},
|
||||
}
|
||||
edges := []model.SOPEdge{
|
||||
{SourceNodeKey: "start", TargetNodeKey: "choice", Condition: jsonData(`{}`)},
|
||||
{SourceNodeKey: "choice", TargetNodeKey: "finish", Condition: jsonData(`{}`)},
|
||||
}
|
||||
context := ValidationContext{Fields: []model.ScenarioField{{FieldKey: "intent", FieldName: "客户意向", FieldType: "select", Options: jsonData(`["继续","暂不考虑"]`)}}}
|
||||
if problems := ValidateForPublish("start", nodes, edges, context); !containsProblem(problems, "不在字段选项中") {
|
||||
t.Fatalf("ValidateForPublish() problems = %v", problems)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateGraphRejectsNonTerminatingCycle(t *testing.T) {
|
||||
nodes := []model.SOPNode{
|
||||
{NodeKey: "start", Type: "start", Title: "开始", Config: jsonData(`{}`)},
|
||||
|
||||
Reference in New Issue
Block a user