152 lines
4.7 KiB
Go
152 lines
4.7 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)
|
|
}
|
|
}
|