// db_ops_test.go - DBOps Section 契约测试. // // 测试 Section 的 API 契约而非文本内容 (文本会迭代, 契约必须稳定): // 1. DBOps 非 nil // 2. Name == "db_ops" (消费层可能按 name 查找) // 3. Static == true (决定缓存策略) // 4. Text 非空 (防止空 Section 被引用导致 Agent 无行为引导) // 5. 跨行业中立性: 不出现已知业务词 (轻量防御, 不是完备检查) package sections import ( "strings" "testing" ) func TestDBOps_NotNil(t *testing.T) { if DBOps == nil { t.Fatal("DBOps should not be nil") } } func TestDBOps_Name(t *testing.T) { // name 是消费层按 key 查找/覆盖 Section 的依据, 必须稳定. if DBOps.Name != "db_ops" { t.Errorf("DBOps.Name: got %q, want \"db_ops\"", DBOps.Name) } } func TestDBOps_IsStatic(t *testing.T) { // Static=true 使 Section 进入全局缓存, 不在每轮对话重算. // DB 行为准则不依赖会话状态, 应为静态. if !DBOps.Static { t.Error("DBOps should be Static=true (DB behavior doctrine does not depend on session state)") } } func TestDBOps_TextNonEmpty(t *testing.T) { if DBOps.Text == "" { t.Fatal("DBOps.Text is empty - would give Agent no DB behavior guidance") } // 最小字节阈值: 即使精简到极限, 4 块内容 + header 也应 >= 500 字节. if len(DBOps.Text) < 500 { t.Errorf("DBOps.Text unexpectedly short: %d bytes (< 500 threshold)", len(DBOps.Text)) } } func TestDBOps_CoversFourBlocks(t *testing.T) { // 契约: 文本必须包含四大块的 header, 保证所有技术行为维度都被覆盖. // 任一 header 缺失都意味着 Section 内容回退, 必须 fail. requiredHeaders := []string{ "## 读取数据", "## 写入数据", "## 并发安全", "## 危险操作", } for _, h := range requiredHeaders { if !strings.Contains(DBOps.Text, h) { t.Errorf("DBOps.Text missing required header %q", h) } } } func TestDBOps_CrossIndustryNeutral(t *testing.T) { // 跨行业中立性防御: Section 不应出现特定行业业务词. // 不是完备检查 (撞不到的词不代表没有), 但能拦住常见回退: // 后续 contributor 加了 "库存扣减" / "订单状态机" 等示例会立即 fail. forbiddenIndustryWords := []string{ "库存", "订单", "病历", "患者", "波次", "发货", "处方", "理赔", "保单", "凭证", "审计凭证", "账户", } for _, w := range forbiddenIndustryWords { if strings.Contains(DBOps.Text, w) { t.Errorf("DBOps.Text contains industry-specific word %q - Section should stay cross-industry neutral", w) } } } func TestDBOps_ReferencesCheckpoint(t *testing.T) { // "危险操作" 块通过 cross-reference 让 Agent 知道 Checkpoint 机制存在. // Section 不重复 Checkpoint 实现, 但必须指引 Agent 不要绕它. // 这是 Section 层和工具层职责边界的契约体现. if !strings.Contains(DBOps.Text, "Checkpoint") { t.Error("DBOps.Text should reference Checkpoint mechanism so Agent knows not to bypass") } }