// 触发器 N/A 哨兵护栏 —— 反例 + 正向对照。 // // 本卡 t_c70f385c(小怡终审 2026-10-17 21:05)事故面: // 加了「samples<20 ⇒ -1」的最小样本门后,gap_closure_rate=-1 时 // `executor.go:131 case TGapDetected: return metrics["gap_closure_rate"] < 0.5` 的 // `-1 < 0.5` 恒真 ⇒ 触发器每轮都 fire。这与旧 recall_hit_rate 恒=1 是**同一类 // 判定失真(方向相反)**。要求:所有消费点先显式判 N/A,且每个消费点配一条反例测试。 package selfoptimize import "testing" // TestTriggerEvaluate_NA_Sentinel 反例:N/A 哨兵(-1)不得触发任何比率类触发器。 func TestTriggerEvaluate_NA_Sentinel(t *testing.T) { te := &TriggerExecutor{} na := map[string]float64{ "recall_usefulness_rate": -1, "gap_closure_rate": -1, "auto_resolve_rate": -1, "avg_distill_loss": -1, } if te.evaluate(&TriggerDef{Type: TGapDetected, Condition: true}, na) { t.Fatal("gap_closure_rate=-1(N/A)不应触发 t5,实际触发了") } if te.evaluate(&TriggerDef{Type: TQualityDrop, Condition: 0.3}, na) { t.Fatal("recall_usefulness_rate=-1(N/A)不应触发 t4,实际触发了") } if te.evaluate(&TriggerDef{Type: TVValueLow, Condition: 0.2}, na) { t.Fatal("recall_usefulness_rate=-1(N/A)不应触发 t7,实际触发了") } if te.evaluate(&TriggerDef{Type: TRecallMiss, Condition: 3}, na) { t.Fatal("recall_usefulness_rate=-1(N/A)不应触发 t3(rate>0 不成立),实际触发了") } } // TestTriggerEvaluate_ValidLow 正向对照:有效且低于阈值时仍要触发(护栏没把功能焊死)。 func TestTriggerEvaluate_ValidLow(t *testing.T) { te := &TriggerExecutor{} valid := map[string]float64{ "recall_usefulness_rate": 0.2, "gap_closure_rate": 0.2, } if !te.evaluate(&TriggerDef{Type: TGapDetected, Condition: true}, valid) { t.Fatal("gap_closure_rate=0.2 (<0.5, 有效) 应触发 t5") } if !te.evaluate(&TriggerDef{Type: TQualityDrop, Condition: 0.3}, valid) { t.Fatal("recall_usefulness_rate=0.2 (<0.3, 有效) 应触发 t4") } // 有效且高于阈值 ⇒ 不触发 hi := map[string]float64{"gap_closure_rate": 0.9, "recall_usefulness_rate": 0.9} if te.evaluate(&TriggerDef{Type: TGapDetected, Condition: true}, hi) { t.Fatal("gap_closure_rate=0.9 (>0.5, 有效) 不应触发 t5") } }