package squad import ( "strings" "testing" ) func TestPlanFixedAdaptive_Default(t *testing.T) { reg := NewRoleRegistry() planner := NewAdaptivePlanner(reg, nil) req := PlannerRequest{ TaskKey: "intake", ProjectName: "掌上便携超声", CustomerName: "北京水木东方", DeviceType: "超声诊断仪", } res, err := planner.Plan(req) if err != nil { t.Fatalf("planner.Plan failed: %v", err) } if res.PlanningMode != PlanModeFixedAdaptive { t.Errorf("expected planning mode %s, got %s", PlanModeFixedAdaptive, res.PlanningMode) } if len(res.Workflow.Steps) < 3 { t.Errorf("expected at least 3 steps, got %d", len(res.Workflow.Steps)) } if len(res.Squad.Agents) < 3 { t.Errorf("expected at least 3 agents in squad, got %d", len(res.Squad.Agents)) } } func TestPlanFixedAdaptive_MaterialSnifferInsertStep(t *testing.T) { reg := NewRoleRegistry() planner := NewAdaptivePlanner(reg, nil) req := PlannerRequest{ TaskKey: "research", ProjectName: "人工心脏瓣膜", CustomerName: "北京水木东方", DeviceType: "植入式心脏瓣膜", Materials: []MaterialItem{ { Filename: "raw_spec.txt", Content: []byte("本项目采用牛心包生物源材料,属于血液长期接触植入物,需高度关注动物源病毒灭活与免疫原性。"), }, }, } res, err := planner.Plan(req) if err != nil { t.Fatalf("planner.Plan failed: %v", err) } // 验证动态插入了动物源或生物相容性专属步骤 foundSpecialStep := false for _, s := range res.Workflow.Steps { if strings.Contains(s.ID, "biocompatibility") || strings.Contains(s.Title, "生物相容性") || strings.Contains(s.Title, "动物源") { foundSpecialStep = true if !s.AllowDynamicAdjustment { t.Errorf("special step should have AllowDynamicAdjustment=true") } break } } if !foundSpecialStep { t.Errorf("expected dynamic step for biocompatibility to be inserted into research workflow") } // 验证 Squad 中包含对应的专家角色 foundExpert := false for _, a := range res.Squad.Agents { if a.Role == "biocompatibility_expert" || a.Role == "regulatory" { foundExpert = true break } } if !foundExpert { t.Errorf("expected biocompatibility or regulatory expert in squad") } } func TestPlanAutonomousAdhoc_CleanroomDesign(t *testing.T) { reg := NewRoleRegistry() planner := NewAdaptivePlanner(reg, nil) req := PlannerRequest{ TaskKey: "cleanroom_spec", Title: "洁净厂房十万级车间建设需求与环境控制方案", ProjectName: "无菌导管生产线", CustomerName: "北京水木东方", DeviceType: "无菌介入导管", Materials: []MaterialItem{ { Filename: "facility.txt", Content: []byte("规划建设十万级GMP净化车间,包括压差梯度设计、高效过滤送风与沉降菌监测规程。"), }, }, } res, err := planner.Plan(req) if err != nil { t.Fatalf("planner.Plan for adhoc document failed: %v", err) } if res.PlanningMode != PlanModeAutonomousAdhoc { t.Errorf("expected planning mode %s, got %s", PlanModeAutonomousAdhoc, res.PlanningMode) } if len(res.Workflow.Steps) != 4 { t.Fatalf("expected 4-stage WBS steps (organize, specialize, draft, review), got %d", len(res.Workflow.Steps)) } // 验证各步骤角色匹配与模式 stepRoles := []string{res.Workflow.Steps[0].Role, res.Workflow.Steps[1].Role, res.Workflow.Steps[2].Role, res.Workflow.Steps[3].Role} if stepRoles[0] != "organizer" { t.Errorf("step 1 should be organizer, got %s", stepRoles[0]) } if stepRoles[2] != "writer" { t.Errorf("step 3 should be writer, got %s", stepRoles[2]) } if stepRoles[3] != "leader" { t.Errorf("step 4 should be leader, got %s", stepRoles[3]) } // 验证第2步为专门工程/洁净专员 specRole := res.Workflow.Steps[1].Role _, exists := reg.GetRole(specRole) if !exists { t.Errorf("specialist role %s not registered in registry", specRole) } // 验证模板自动合成且包含核心章节 if !strings.Contains(res.TemplateContent, "洁净厂房十万级车间建设需求与环境控制方案") { t.Errorf("template should contain document title") } if !strings.Contains(res.TemplateContent, "待确认清单") { t.Errorf("template should contain pending checklist section") } }