Files
ai-agent/internal/ai/workflow/registry/registry_test.go
T
mlogclub 21fd119b27 feat: add conversation understanding and reply policy nodes to workflow executor
- Implemented conversation understanding and reply policy execution in the workflow executor.
- Added new node types: NodeTypeConversationUnderstanding and NodeTypeReplyPolicy.
- Enhanced input and output schemas for the new nodes.
- Updated workflow registry to include new node specifications.
- Created tests for the new workflow routes and behaviors.
- Modified existing workflows to integrate the new conversation understanding and reply policy logic.
2026-06-25 22:38:34 +08:00

106 lines
3.7 KiB
Go

package registry
import "testing"
func TestDefaultRegistryExposesStartOutputs(t *testing.T) {
spec, ok := DefaultRegistry().Get(NodeTypeStart)
if !ok {
t.Fatalf("start node spec not found")
}
if !hasVariable(spec.OutputSchema, "userMessage", VariableTypeString) {
t.Fatalf("expected start output userMessage:string, got %#v", spec.OutputSchema)
}
if !hasVariable(spec.OutputSchema, "knowledgeBaseIds", VariableTypeIntegerArray) {
t.Fatalf("expected start output knowledgeBaseIds:array<int>, got %#v", spec.OutputSchema)
}
}
func TestDefaultRegistryExposesKnowledgeRetrieveInputsAndOutputs(t *testing.T) {
spec, ok := DefaultRegistry().Get(NodeTypeKnowledgeRetrieve)
if !ok {
t.Fatalf("knowledge_retrieve node spec not found")
}
if !hasRequiredVariable(spec.InputSchema, "query", VariableTypeString) {
t.Fatalf("expected knowledge_retrieve required input query:string, got %#v", spec.InputSchema)
}
if !hasVariable(spec.OutputSchema, "items", VariableTypeObjectArray) {
t.Fatalf("expected knowledge_retrieve output items:array<object>, got %#v", spec.OutputSchema)
}
}
func TestDefaultRegistryExposesSendReplyRequiredInput(t *testing.T) {
spec, ok := DefaultRegistry().Get(NodeTypeSendReply)
if !ok {
t.Fatalf("send_reply node spec not found")
}
if !hasRequiredVariable(spec.InputSchema, "replyText", VariableTypeString) {
t.Fatalf("expected send_reply required input replyText:string, got %#v", spec.InputSchema)
}
if !hasVariable(spec.OutputSchema, "sent", VariableTypeBoolean) {
t.Fatalf("expected send_reply output sent:boolean, got %#v", spec.OutputSchema)
}
}
func TestDefaultRegistryExposesConversationUnderstandingOutputs(t *testing.T) {
spec, ok := DefaultRegistry().Get(NodeTypeConversationUnderstanding)
if !ok {
t.Fatalf("conversation_understanding node spec not found")
}
if !hasRequiredVariable(spec.InputSchema, "userMessage", VariableTypeString) {
t.Fatalf("expected conversation_understanding required input userMessage:string, got %#v", spec.InputSchema)
}
for _, want := range []string{"messageIntent", "answerScope", "riskSignals", "reason"} {
if !hasVariableName(spec.OutputSchema, want) {
t.Fatalf("expected conversation_understanding output %s, got %#v", want, spec.OutputSchema)
}
}
if !hasVariable(spec.OutputSchema, "confidence", VariableTypeNumber) {
t.Fatalf("expected conversation_understanding output confidence:number, got %#v", spec.OutputSchema)
}
}
func TestDefaultRegistryExposesReplyPolicyOutputs(t *testing.T) {
spec, ok := DefaultRegistry().Get(NodeTypeReplyPolicy)
if !ok {
t.Fatalf("reply_policy node spec not found")
}
if !hasRequiredVariable(spec.InputSchema, "messageIntent", VariableTypeString) {
t.Fatalf("expected reply_policy required input messageIntent:string, got %#v", spec.InputSchema)
}
if !hasRequiredVariable(spec.InputSchema, "answerScope", VariableTypeString) {
t.Fatalf("expected reply_policy required input answerScope:string, got %#v", spec.InputSchema)
}
for _, want := range []string{"action", "replyText", "reason", "finalReplySource"} {
if !hasVariableName(spec.OutputSchema, want) {
t.Fatalf("expected reply_policy output %s, got %#v", want, spec.OutputSchema)
}
}
}
func hasRequiredVariable(items []VariableSpec, name string, variableType VariableType) bool {
for _, item := range items {
if item.Name == name && item.Type == variableType && item.Required {
return true
}
}
return false
}
func hasVariableName(items []VariableSpec, name string) bool {
for _, item := range items {
if item.Name == name {
return true
}
}
return false
}
func hasVariable(items []VariableSpec, name string, variableType VariableType) bool {
for _, item := range items {
if item.Name == name && item.Type == variableType {
return true
}
}
return false
}