381 lines
12 KiB
Go
381 lines
12 KiB
Go
package main_test
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func moduleRoot(t *testing.T) string {
|
|
t.Helper()
|
|
out, err := exec.Command("go", "env", "GOMOD").Output()
|
|
if err != nil {
|
|
t.Fatalf("go env GOMOD: %v", err)
|
|
}
|
|
return filepath.Dir(strings.TrimSpace(string(out)))
|
|
}
|
|
|
|
func TestBizdevCLIHelpAndRun(t *testing.T) {
|
|
cmd := exec.Command("go", "run", "./cmd/bizdev-cli", "-help")
|
|
cmd.Dir = moduleRoot(t)
|
|
out, _ := cmd.CombinedOutput()
|
|
if !strings.Contains(string(out), "-task") {
|
|
t.Fatalf("cli output missing -task flag: %s", string(out))
|
|
}
|
|
if !strings.Contains(string(out), "-inspect") {
|
|
t.Fatalf("cli output missing -inspect flag: %s", string(out))
|
|
}
|
|
}
|
|
|
|
func TestBizdevCLIListTasks(t *testing.T) {
|
|
cmd := exec.Command("go", "run", "./cmd/bizdev-cli", "-list-tasks")
|
|
cmd.Dir = moduleRoot(t)
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("cli -list-tasks failed: %v, out: %s", err, string(out))
|
|
}
|
|
if !strings.Contains(string(out), "intake") || !strings.Contains(string(out), "cdo_quote") {
|
|
t.Fatalf("cli output missing expected tasks: %s", string(out))
|
|
}
|
|
}
|
|
|
|
func TestBizdevCLIExecuteAndInspect(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
envContent := "ENV=dev\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\n"
|
|
envPath := filepath.Join(tmpDir, ".env")
|
|
_ = os.WriteFile(envPath, []byte(envContent), 0o644)
|
|
|
|
// 1. 执行任务
|
|
cmd := exec.Command("go", "run", "./cmd/bizdev-cli",
|
|
"-env", envPath,
|
|
"-task", "intake",
|
|
"-backend", "stub",
|
|
"-project", "CLI集成测试项目",
|
|
"-customer", "水木智造",
|
|
)
|
|
cmd.Dir = moduleRoot(t)
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("cli execute failed: %v, out: %s", err, string(out))
|
|
}
|
|
|
|
outStr := string(out)
|
|
if !strings.Contains(outStr, "任务执行成功 [intake]") {
|
|
t.Fatalf("unexpected cli output: %s", outStr)
|
|
}
|
|
if !strings.Contains(outStr, "质量门禁评分") {
|
|
t.Fatalf("cli output missing quality gate score: %s", outStr)
|
|
}
|
|
if !strings.Contains(outStr, "【B轨:贴身业务参谋决策锦囊】") {
|
|
t.Fatalf("cli output missing B-Track advisor brief: %s", outStr)
|
|
}
|
|
|
|
// 从输出提取工作区路径
|
|
var workDir string
|
|
for _, line := range strings.Split(outStr, "\n") {
|
|
if strings.HasPrefix(line, "工作区沙箱: ") {
|
|
workDir = strings.TrimSpace(strings.TrimPrefix(line, "工作区沙箱: "))
|
|
break
|
|
}
|
|
}
|
|
if workDir == "" {
|
|
t.Fatalf("failed to find workspace path in output: %s", outStr)
|
|
}
|
|
|
|
// 2. 审查工作区并动态追加步骤
|
|
inspectCmd := exec.Command("go", "run", "./cmd/bizdev-cli",
|
|
"-env", envPath,
|
|
"-inspect", workDir,
|
|
"-add-step", "writer:补写临床评价要点",
|
|
"-backend", "stub",
|
|
)
|
|
inspectCmd.Dir = moduleRoot(t)
|
|
inspectOut, err := inspectCmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("cli inspect failed: %v, out: %s", err, string(inspectOut))
|
|
}
|
|
|
|
inspectStr := string(inspectOut)
|
|
if !strings.Contains(inspectStr, "工作区状态审查") {
|
|
t.Fatalf("unexpected inspect output: %s", inspectStr)
|
|
}
|
|
if !strings.Contains(inspectStr, "动态步骤执行成功") {
|
|
t.Fatalf("expected dynamic step success: %s", inspectStr)
|
|
}
|
|
}
|
|
|
|
func TestBizdevCLIStageExecution(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
envContent := "ENV=dev\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\n"
|
|
envPath := filepath.Join(tmpDir, ".env")
|
|
_ = os.WriteFile(envPath, []byte(envContent), 0o644)
|
|
|
|
// 1. 验证 -list-stages 输出
|
|
listCmd := exec.Command("go", "run", "./cmd/bizdev-cli", "-list-stages", "-env", envPath)
|
|
listCmd.Dir = moduleRoot(t)
|
|
listOut, err := listCmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("cli -list-stages failed: %v, out: %s", err, string(listOut))
|
|
}
|
|
if !strings.Contains(string(listOut), "V0.1_triage") || !strings.Contains(string(listOut), "V1.0_quoting") {
|
|
t.Fatalf("missing stages in list: %s", string(listOut))
|
|
}
|
|
|
|
// 2. 运行 Stage 1 (V0.1_triage)
|
|
stageCmd := exec.Command("go", "run", "./cmd/bizdev-cli",
|
|
"-env", envPath,
|
|
"-stage", "V0.1_triage",
|
|
"-backend", "stub",
|
|
"-project", "腹腔镜手术机器人系统",
|
|
"-customer", "水木医用机器人中心",
|
|
"-device", "三类手术机器人",
|
|
)
|
|
stageCmd.Dir = moduleRoot(t)
|
|
stageOut, err := stageCmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("cli -stage run failed: %v, out: %s", err, string(stageOut))
|
|
}
|
|
|
|
outStr := string(stageOut)
|
|
if !strings.Contains(outStr, "阶段执行成功: V0.1 闪电摸底与盲区探测") {
|
|
t.Errorf("missing stage success headline: %s", outStr)
|
|
}
|
|
if !strings.Contains(outStr, "【B轨:贴身业务参谋决策锦囊】") {
|
|
t.Errorf("missing advisor brief section: %s", outStr)
|
|
}
|
|
if !strings.Contains(outStr, "水木医用机器人中心") {
|
|
t.Errorf("missing customer name in communication kit: %s", outStr)
|
|
}
|
|
}
|
|
|
|
func TestBizdevCLIChatQueries(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
envContent := "ENV=dev\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\n"
|
|
envPath := filepath.Join(tmpDir, ".env")
|
|
_ = os.WriteFile(envPath, []byte(envContent), 0o644)
|
|
|
|
// 1. 测试闲聊问候
|
|
cmd1 := exec.Command("go", "run", "./cmd/bizdev-cli",
|
|
"-env", envPath,
|
|
"-backend", "stub",
|
|
"-chat",
|
|
"-query", "你好,请问你是谁?",
|
|
"-project", "掌上便携超声",
|
|
)
|
|
cmd1.Dir = moduleRoot(t)
|
|
out1, err := cmd1.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("chat query 1 failed: %v, out: %s", err, string(out1))
|
|
}
|
|
if !strings.Contains(string(out1), "意图识别: CASUAL_CHAT") {
|
|
t.Errorf("expected intent CASUAL_CHAT, got: %s", string(out1))
|
|
}
|
|
if !strings.Contains(string(out1), "掌上便携超声") {
|
|
t.Errorf("expected greeting to mention project: %s", string(out1))
|
|
}
|
|
|
|
// 2. 测试进度与风险查询
|
|
cmd2 := exec.Command("go", "run", "./cmd/bizdev-cli",
|
|
"-env", envPath,
|
|
"-backend", "stub",
|
|
"-chat",
|
|
"-query", "现在这个便携超声立项评估到哪一步了?有啥风险没?",
|
|
"-project", "掌上便携超声",
|
|
)
|
|
cmd2.Dir = moduleRoot(t)
|
|
out2, err := cmd2.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("chat query 2 failed: %v, out: %s", err, string(out2))
|
|
}
|
|
if !strings.Contains(string(out2), "意图识别: QUERY_PROGRESS") {
|
|
t.Errorf("expected intent QUERY_PROGRESS, got: %s", string(out2))
|
|
}
|
|
|
|
// 3. 测试信息补充
|
|
cmd3 := exec.Command("go", "run", "./cmd/bizdev-cli",
|
|
"-env", envPath,
|
|
"-backend", "stub",
|
|
"-chat",
|
|
"-query", "客户刚才补充说,目标市场除了国内还想考虑欧洲 CE 认证",
|
|
"-project", "掌上便携超声",
|
|
)
|
|
cmd3.Dir = moduleRoot(t)
|
|
out3, err := cmd3.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("chat query 3 failed: %v, out: %s", err, string(out3))
|
|
}
|
|
if !strings.Contains(string(out3), "意图识别: SUPPLEMENT_INFO") {
|
|
t.Errorf("expected intent SUPPLEMENT_INFO, got: %s", string(out3))
|
|
}
|
|
if !strings.Contains(string(out3), "已收到并为您记录最新信息") {
|
|
t.Errorf("expected acknowledgement in reply: %s", string(out3))
|
|
}
|
|
|
|
// 4. 测试阶段推进
|
|
cmd4 := exec.Command("go", "run", "./cmd/bizdev-cli",
|
|
"-env", envPath,
|
|
"-backend", "stub",
|
|
"-chat",
|
|
"-query", "摸底表我看过了,没问题,可以进入方案论证阶段了",
|
|
"-project", "掌上便携超声",
|
|
"-customer", "水木清研",
|
|
"-device", "二类掌上超声",
|
|
)
|
|
cmd4.Dir = moduleRoot(t)
|
|
out4, err := cmd4.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("chat query 4 failed: %v, out: %s", err, string(out4))
|
|
}
|
|
if !strings.Contains(string(out4), "意图识别: ADVANCE_STAGE") {
|
|
t.Errorf("expected intent ADVANCE_STAGE, got: %s", string(out4))
|
|
}
|
|
if !strings.Contains(string(out4), "已为您成功推进并完成了【V0.5 方案成型与法规对齐】") {
|
|
t.Errorf("expected stage advance success, got: %s", string(out4))
|
|
}
|
|
}
|
|
|
|
func TestBizdevCLIThreeBranchQueries(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
envContent := "ENV=dev\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\n"
|
|
envPath := filepath.Join(tmpDir, ".env")
|
|
_ = os.WriteFile(envPath, []byte(envContent), 0o644)
|
|
|
|
// 用例 1: 极速兑现 (好)
|
|
cmd1 := exec.Command("go", "run", "./cmd/bizdev-cli",
|
|
"-env", envPath,
|
|
"-backend", "stub",
|
|
"-chat",
|
|
"-query", "好",
|
|
"-project", "掌上便携超声",
|
|
)
|
|
cmd1.Dir = moduleRoot(t)
|
|
out1, err := cmd1.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("query 1 failed: %v, out: %s", err, string(out1))
|
|
}
|
|
if !strings.Contains(string(out1), "消解分支: EXPECTATION_HIT") {
|
|
t.Errorf("expected EXPECTATION_HIT, got: %s", string(out1))
|
|
}
|
|
|
|
// 用例 2: 复合打补丁 (好,但目标市场改成欧洲CE)
|
|
cmd2 := exec.Command("go", "run", "./cmd/bizdev-cli",
|
|
"-env", envPath,
|
|
"-backend", "stub",
|
|
"-chat",
|
|
"-query", "好,但目标市场改成欧洲CE",
|
|
"-project", "掌上便携超声",
|
|
)
|
|
cmd2.Dir = moduleRoot(t)
|
|
out2, err := cmd2.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("query 2 failed: %v, out: %s", err, string(out2))
|
|
}
|
|
if !strings.Contains(string(out2), "消解分支: EXPECTATION_HIT") || !strings.Contains(string(out2), "target_market") {
|
|
t.Errorf("expected EXPECTATION_HIT with target_market patch, got: %s", string(out2))
|
|
}
|
|
|
|
// 用例 3: 否定暂缓 (先别推,等等)
|
|
cmd3 := exec.Command("go", "run", "./cmd/bizdev-cli",
|
|
"-env", envPath,
|
|
"-backend", "stub",
|
|
"-chat",
|
|
"-query", "先别推,等等",
|
|
"-project", "掌上便携超声",
|
|
)
|
|
cmd3.Dir = moduleRoot(t)
|
|
out3, err := cmd3.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("query 3 failed: %v, out: %s", err, string(out3))
|
|
}
|
|
if !strings.Contains(string(out3), "消解分支: EXPECTATION_HIT") || !strings.Contains(string(out3), "DECLINE_EXPECTATION") {
|
|
t.Errorf("expected DECLINE_EXPECTATION, got: %s", string(out3))
|
|
}
|
|
if !strings.Contains(string(out3), "听您的") {
|
|
t.Errorf("expected polite advisor reply: %s", string(out3))
|
|
}
|
|
|
|
// 用例 4: 话题突发抢占 (查一下探头功耗要怎么设计)
|
|
cmd4 := exec.Command("go", "run", "./cmd/bizdev-cli",
|
|
"-env", envPath,
|
|
"-backend", "stub",
|
|
"-chat",
|
|
"-query", "查一下探头功耗要怎么设计",
|
|
"-project", "掌上便携超声",
|
|
)
|
|
cmd4.Dir = moduleRoot(t)
|
|
out4, err := cmd4.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("query 4 failed: %v, out: %s", err, string(out4))
|
|
}
|
|
if !strings.Contains(string(out4), "消解分支: NEW_INTENT_PREEMPT") {
|
|
t.Errorf("expected NEW_INTENT_PREEMPT, got: %s", string(out4))
|
|
}
|
|
if !strings.Contains(string(out4), "功耗") {
|
|
t.Errorf("expected technical answer in reply: %s", string(out4))
|
|
}
|
|
|
|
// 用例 5: 模糊分忧 (这个先放放,你觉得呢)
|
|
cmd5 := exec.Command("go", "run", "./cmd/bizdev-cli",
|
|
"-env", envPath,
|
|
"-backend", "stub",
|
|
"-chat",
|
|
"-query", "这个先放放,你觉得呢",
|
|
"-project", "掌上便携超声",
|
|
)
|
|
cmd5.Dir = moduleRoot(t)
|
|
out5, err := cmd5.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("query 5 failed: %v, out: %s", err, string(out5))
|
|
}
|
|
if !strings.Contains(string(out5), "消解分支: AMBIGUOUS_FALLBACK") {
|
|
t.Errorf("expected AMBIGUOUS_FALLBACK, got: %s", string(out5))
|
|
}
|
|
if !strings.Contains(string(out5), "完全理解") && !strings.Contains(string(out5), "建议") {
|
|
t.Errorf("expected consultative advisor answer in reply: %s", string(out5))
|
|
}
|
|
}
|
|
|
|
func TestBizdevCLIExecuteAdhocTask(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
envContent := "ENV=dev\nDATA_DIR=" + tmpDir + "\nAGENT_BACKEND=stub\n"
|
|
envPath := filepath.Join(tmpDir, ".env")
|
|
_ = os.WriteFile(envPath, []byte(envContent), 0o644)
|
|
|
|
cmd := exec.Command("go", "run", "./cmd/bizdev-cli",
|
|
"-env", envPath,
|
|
"-task", "cleanroom_spec",
|
|
"-backend", "stub",
|
|
"-project", "十万级净化车间建设工程",
|
|
"-customer", "水木智造",
|
|
"-device", "无菌介入耗材",
|
|
)
|
|
cmd.Dir = moduleRoot(t)
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("cli execute adhoc task failed: %v, out: %s", err, string(out))
|
|
}
|
|
|
|
outStr := string(out)
|
|
if !strings.Contains(outStr, "任务执行成功 [cleanroom_spec]") {
|
|
t.Fatalf("unexpected cli output: %s", outStr)
|
|
}
|
|
|
|
// 提取工作区检查 squad.json 是否有 cleanroom_expert
|
|
var workDir string
|
|
for _, line := range strings.Split(outStr, "\n") {
|
|
if strings.HasPrefix(line, "工作区沙箱: ") {
|
|
workDir = strings.TrimSpace(strings.TrimPrefix(line, "工作区沙箱: "))
|
|
break
|
|
}
|
|
}
|
|
if workDir == "" {
|
|
t.Fatalf("workDir not found in output: %s", outStr)
|
|
}
|
|
squadData, _ := os.ReadFile(filepath.Join(workDir, "squad.json"))
|
|
if !strings.Contains(string(squadData), "cleanroom_expert") {
|
|
t.Errorf("squad.json should contain cleanroom_expert: %s", string(squadData))
|
|
}
|
|
}
|