feat: refactor HandoffGraph to use structured arguments and add unit tests for buildReason method

This commit is contained in:
mlogclub
2026-04-14 11:08:02 +08:00
parent 2211f29da7
commit a5b0ddc760
2 changed files with 38 additions and 15 deletions
@@ -0,0 +1,31 @@
package graphs
import (
"testing"
"cs-agent/internal/models"
)
func TestHandoffGraphBuildReason(t *testing.T) {
graph := NewHandoffGraph(&models.Conversation{ID: 1}, &models.AIAgent{Name: "AI"})
reason, err := graph.buildReason(`{"reason":" 用户需要人工确认 "}`)
if err != nil {
t.Fatalf("buildReason returned error: %v", err)
}
if reason != "用户需要人工确认" {
t.Fatalf("unexpected reason: %q", reason)
}
}
func TestHandoffGraphBuildReasonFallback(t *testing.T) {
graph := NewHandoffGraph(&models.Conversation{ID: 1}, &models.AIAgent{Name: "AI"})
reason, err := graph.buildReason(`{}`)
if err != nil {
t.Fatalf("buildReason returned error: %v", err)
}
if reason != "用户需要转人工支持" {
t.Fatalf("unexpected fallback reason: %q", reason)
}
}