87 lines
2.8 KiB
Go
87 lines
2.8 KiB
Go
package chat
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"chat-agent-system/internal/coordinator"
|
|
"chat-agent-system/internal/docgov"
|
|
"chat-agent-system/internal/intent"
|
|
)
|
|
|
|
func TestSetProjectIDSyncsCoordinatorProject(t *testing.T) {
|
|
sess := NewSession("sess-p6022-u74", &coordinator.UserProjectContext{}, nil, nil)
|
|
sess.SetProjectID(6022)
|
|
if sess.Project() != 6022 {
|
|
t.Fatalf("session project=%d", sess.Project())
|
|
}
|
|
if sess.UserCtx.Project.ID != "6022" {
|
|
t.Fatalf("coordinator project=%q", sess.UserCtx.Project.ID)
|
|
}
|
|
sess.SetProjectID(0)
|
|
if sess.UserCtx.Project.ID != "" {
|
|
t.Fatalf("cleared project=%q", sess.UserCtx.Project.ID)
|
|
}
|
|
}
|
|
|
|
func TestBindCoordinatorIdentityUsesNumericUser(t *testing.T) {
|
|
sess := NewSession("sess-p6022-u74", &coordinator.UserProjectContext{
|
|
User: coordinator.UserInfo{ID: "u_sess-p6022-u74"},
|
|
}, nil, nil)
|
|
sess.UserID = 74
|
|
sess.SetProjectID(6022)
|
|
sess.bindCoordinatorIdentity()
|
|
if sess.UserCtx.User.ID != "74" {
|
|
t.Fatalf("user=%q", sess.UserCtx.User.ID)
|
|
}
|
|
if sess.UserCtx.ChatSessionID != "sess-p6022-u74" {
|
|
t.Fatalf("session=%q", sess.UserCtx.ChatSessionID)
|
|
}
|
|
if sess.UserCtx.Project.ID != "6022" {
|
|
t.Fatalf("project=%q", sess.UserCtx.Project.ID)
|
|
}
|
|
}
|
|
|
|
func TestWorkflowPrerequisiteHintSuggestsResearch(t *testing.T) {
|
|
docs := []docgov.WorkflowDocumentSummary{
|
|
{TaskKey: "bd_research", IsTemplateOnly: true, Title: "调研报告"},
|
|
{TaskKey: "bd_feasibility_dev", IsTemplateOnly: true},
|
|
}
|
|
hint, key := workflowPrerequisiteHint("开始生成设计开发可行性评估报告", docs, true)
|
|
if hint == "" || key != "bd_research" {
|
|
t.Fatalf("hint=%q key=%q", hint, key)
|
|
}
|
|
ready, _ := researchMaterialReady([]docgov.WorkflowDocumentSummary{
|
|
{TaskKey: "bd_research", IsTemplateOnly: false},
|
|
})
|
|
if !ready {
|
|
t.Fatal("finished research should be ready")
|
|
}
|
|
if h, _ := workflowPrerequisiteHint("今天天气怎么样", docs, true); h != "" {
|
|
t.Fatalf("unrelated hint=%q", h)
|
|
}
|
|
if h, _ := workflowPrerequisiteHint("开始生成可行性评估", nil, false); h != "" {
|
|
t.Fatalf("unknown ledger hint=%q", h)
|
|
}
|
|
}
|
|
|
|
func TestAugmentWorkflowGuidanceSetsExpectationAndStageNote(t *testing.T) {
|
|
sess := NewSession("sess-1", &coordinator.UserProjectContext{}, nil, nil)
|
|
res := &coordinator.CoordinationResult{
|
|
NaturalReply: "任务执行失败: bizdev: workflow stage access denied: task \"bd_feasibility_dev\"",
|
|
UpdatedContext: sess.UserCtx,
|
|
}
|
|
sess.augmentWorkflowGuidance(context.Background(), "开始生成设计开发可行性评估报告", res)
|
|
if !strings.Contains(res.NaturalReply, stageAdvanceGuidance) {
|
|
t.Fatalf("reply=%q", res.NaturalReply)
|
|
}
|
|
exp := researchFirstExpectation("bd_research")
|
|
if exp.DefaultOption == nil || exp.DefaultOption.Slots[intent.SlotTargetTask] != "bd_research" {
|
|
t.Fatalf("expectation=%+v", exp)
|
|
}
|
|
if !exp.AllowAffirmative {
|
|
t.Fatal("affirmative should start research")
|
|
}
|
|
}
|