102 lines
2.8 KiB
Go
102 lines
2.8 KiB
Go
package squad
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestRoleRegistryDefaultRoles(t *testing.T) {
|
|
reg := NewRoleRegistry()
|
|
roles := reg.ListRoles()
|
|
|
|
if len(roles) < 8 {
|
|
t.Fatalf("expected at least 8 standard roles, got %d", len(roles))
|
|
}
|
|
|
|
expectedRoles := []string{
|
|
"organizer",
|
|
"searcher",
|
|
"regulatory",
|
|
"engineer",
|
|
"market",
|
|
"finance",
|
|
"writer",
|
|
"leader",
|
|
}
|
|
|
|
for _, r := range expectedRoles {
|
|
spec, found := reg.GetRole(r)
|
|
if !found {
|
|
t.Errorf("expected role %s to be registered", r)
|
|
}
|
|
if spec.Source != RoleSourceStandard {
|
|
t.Errorf("role %s source expected standard, got %s", r, spec.Source)
|
|
}
|
|
if spec.BashPermission != "deny" {
|
|
t.Errorf("role %s bash_permission must be deny, got %s", r, spec.BashPermission)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRoleRegistryRecommend(t *testing.T) {
|
|
reg := NewRoleRegistry()
|
|
|
|
tests := []struct {
|
|
query string
|
|
expected string
|
|
}{
|
|
{"医疗器械分类界定与注册审评路径", "regulatory"},
|
|
{"公开文献、标准号溯源检索", "searcher"},
|
|
{"竞品横向功能对比与市场容量测算", "market"},
|
|
{"系统硬件模块与嵌入式结构方案设计", "engineer"},
|
|
{"材料提取、缺口与字段回填", "organizer"},
|
|
{"CDO成本核算与定价工时拆解", "finance"},
|
|
{"撰写正式交付文档正文终稿", "writer"},
|
|
{"商务合同把关与终审交付", "leader"},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
rec, found := reg.RecommendRole(tc.query)
|
|
if !found {
|
|
t.Errorf("recommendation failed for query: %s", tc.query)
|
|
}
|
|
if rec.Role != tc.expected {
|
|
t.Errorf("for query '%s', expected %s, got %s", tc.query, tc.expected, rec.Role)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRoleRegistrySpawnAdHocRole(t *testing.T) {
|
|
reg := NewRoleRegistry()
|
|
|
|
adHoc, err := reg.SpawnAdHocRole(AdHocRoleRequest{
|
|
RoleKey: "biocompatibility_expert",
|
|
Name: "生物相容性评估专员",
|
|
BaseRole: "engineer",
|
|
DomainTopic: "动物源性材料与生物学评价GB/T 16886",
|
|
Responsibilities: []string{"生物相容性接触类型识别", "植入与血液相容性风险评估"},
|
|
ForbiddenActions: []string{"严禁代替国家局检验中心出具最终报告"},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("spawn ad hoc role failed: %v", err)
|
|
}
|
|
|
|
if adHoc.Source != RoleSourceAdHoc {
|
|
t.Errorf("expected source ad_hoc, got %s", adHoc.Source)
|
|
}
|
|
if adHoc.BaseRole != "engineer" {
|
|
t.Errorf("expected base_role engineer, got %s", adHoc.BaseRole)
|
|
}
|
|
if adHoc.BashPermission != "deny" {
|
|
t.Errorf("ad-hoc role must deny bash permission, got %s", adHoc.BashPermission)
|
|
}
|
|
|
|
// 确认派生角色被登记入注册中心
|
|
fetched, found := reg.GetRole("biocompatibility_expert")
|
|
if !found {
|
|
t.Fatalf("expected spawned role to be retrievable from registry")
|
|
}
|
|
if fetched.Name != "生物相容性评估专员" {
|
|
t.Errorf("expected name 生物相容性评估专员, got %s", fetched.Name)
|
|
}
|
|
}
|