Files
Agent-System/internal/chat/session_test.go
T

87 lines
2.8 KiB
Go

package chat_test
import (
"context"
"strings"
"testing"
"chat-agent-system/internal/chat"
"chat-agent-system/internal/coordinator"
"chat-agent-system/internal/intent"
"chat-agent-system/internal/squad"
)
func TestChatSession_EndToEndDialog(t *testing.T) {
rec := intent.NewRecognizer()
engine := coordinator.NewCoordinatorEngine(nil)
userCtx := &coordinator.UserProjectContext{
SnapshotID: "sess_ctx_1",
User: coordinator.UserInfo{
ID: "u1",
Name: "张工",
Role: "engineer",
ProjectRole: "composer",
},
Project: coordinator.ProjectInfo{
Name: "掌上无线超声系统",
},
LatestAdvisorBrief: &squad.AdvisorBriefing{
MaturityScore: 75,
MaturityLevel: "V0.1",
MaturityHeadline: "初步框架已就绪",
PreemptiveRisks: []string{"探头功耗与散热设计"},
NextBestActions: []string{"补充客户供电参数", "推进到V0.5可行性论证"},
CommunicationKit: "建议与客户确认供电方式",
},
}
session := chat.NewSession("sess_001", userCtx, rec, engine)
// Turn 1: 问候
resp1, err := session.SendMessage(context.Background(), "你好,请问你是谁?")
if err != nil {
t.Fatalf("turn 1 failed: %v", err)
}
if resp1.IntentResult.TopIntent.Intent != intent.IntentCasualChat {
t.Errorf("turn 1 expected CASUAL_CHAT, got %s", resp1.IntentResult.TopIntent.Intent)
}
// Turn 2: 查进展与风险
resp2, err := session.SendMessage(context.Background(), "现在这个项目进展怎么样?有啥风险没?")
if err != nil {
t.Fatalf("turn 2 failed: %v", err)
}
if resp2.IntentResult.TopIntent.Intent != intent.IntentQueryProgress {
t.Errorf("turn 2 expected QUERY_PROGRESS, got %s", resp2.IntentResult.TopIntent.Intent)
}
if !strings.Contains(resp2.ReplyText, "掌上无线超声系统") {
t.Errorf("turn 2 reply should mention project name: %s", resp2.ReplyText)
}
// Turn 3: 补充信息
resp3, err := session.SendMessage(context.Background(), "客户补充说目标市场是国内及欧洲CE")
if err != nil {
t.Fatalf("turn 3 failed: %v", err)
}
if resp3.IntentResult.TopIntent.Intent != intent.IntentSupplementInfo {
t.Errorf("turn 3 expected SUPPLEMENT_INFO, got %s", resp3.IntentResult.TopIntent.Intent)
}
if session.UserCtx.BlackboardFacts["target_market"] != "国内及欧洲CE" {
t.Errorf("target_market not updated: %v", session.UserCtx.BlackboardFacts)
}
// Turn 4: 推进阶段
resp4, err := session.SendMessage(context.Background(), "好的,进入方案论证阶段吧")
if err != nil {
t.Fatalf("turn 4 failed: %v", err)
}
if resp4.IntentResult.TopIntent.Intent != intent.IntentAdvanceStage {
t.Errorf("turn 4 expected ADVANCE_STAGE, got %s", resp4.IntentResult.TopIntent.Intent)
}
if len(session.Messages) != 8 {
t.Errorf("expected 8 messages (4 user + 4 asst), got %d", len(session.Messages))
}
}