App images have no templates/ checkout, so GetDocTemplate fell back to a two-section stub and prelim_design lost its real contract. Co-authored-by: Cursor <cursoragent@cursor.com>
70 lines
2.1 KiB
Go
70 lines
2.1 KiB
Go
package template_test
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"chat-agent-system/internal/template"
|
|
)
|
|
|
|
func TestLoadDocTemplatesAndAgents(t *testing.T) {
|
|
tmpl, err := template.GetDocTemplate("intake")
|
|
if err != nil {
|
|
t.Fatalf("failed to load intake template: %v", err)
|
|
}
|
|
if !strings.Contains(tmpl, "用户初始需求收集表") {
|
|
t.Errorf("template intake.md missing title header")
|
|
}
|
|
if !strings.Contains(tmpl, "写满四段式") {
|
|
t.Errorf("template intake.md missing self-describing guidance '写满四段式'")
|
|
}
|
|
|
|
inst, err := template.GetAgentInstruction("leader")
|
|
if err != nil {
|
|
t.Fatalf("failed to load leader agent instructions: %v", err)
|
|
}
|
|
if !strings.Contains(inst, "商务对接负责人") {
|
|
t.Errorf("leader.md missing expected role definition")
|
|
}
|
|
|
|
rendered := template.RenderDoc(tmpl, map[string]string{
|
|
"project_name": "测试手术机器人",
|
|
"customer_name": "水木医疗",
|
|
})
|
|
if !strings.Contains(rendered, "测试手术机器人") {
|
|
t.Errorf("render failed to replace project_name")
|
|
}
|
|
if !strings.Contains(rendered, "水木医疗") {
|
|
t.Errorf("render failed to replace customer_name")
|
|
}
|
|
}
|
|
|
|
func TestGetDocTemplate_PrelimDesignOfficialNotStub(t *testing.T) {
|
|
tmpl, err := template.GetDocTemplate("prelim_design")
|
|
if err != nil {
|
|
t.Fatalf("prelim_design must load from embed/disk: %v", err)
|
|
}
|
|
if !strings.Contains(tmpl, "系统初步设计方案") {
|
|
t.Fatalf("official prelim_design title missing")
|
|
}
|
|
if !strings.Contains(tmpl, "```mermaid") {
|
|
t.Fatalf("official prelim_design must keep mermaid context diagram")
|
|
}
|
|
if strings.Contains(tmpl, "## 1. 结论") && strings.Contains(tmpl, "待确认") && !strings.Contains(tmpl, "子系统划分") {
|
|
t.Fatalf("must not fall back to two-section stub")
|
|
}
|
|
}
|
|
|
|
func TestGetDocTemplate_WorksWithoutDiskCheckout(t *testing.T) {
|
|
t.Chdir(t.TempDir())
|
|
for _, key := range []string{"intake", "prelim_design", "research"} {
|
|
tmpl, err := template.GetDocTemplate(key)
|
|
if err != nil {
|
|
t.Fatalf("%s must resolve from embed when cwd has no templates/: %v", key, err)
|
|
}
|
|
if strings.TrimSpace(tmpl) == "" {
|
|
t.Fatalf("%s embed was empty", key)
|
|
}
|
|
}
|
|
}
|