Files
memoryweave/go/internal/selfoptimize/executor_na_test.go
T
xiao-yi-dev a4e15aa4f1 refactor(metrics): t_dcad48e4 摘除 avg_distill_loss 值键(deprecated 桶无写入者,值冻结 0.35 必被误读)
- selfoptimize.go Metrics():删 avg_distill_loss 值键;保留墓碑键 avg_distill_loss_deprecated=1
  + 分母 _samples/_valid(复算用)。avgDistillLoss() 辅助函数一并删除。
- tuning.go 消费端:低召回+高loss 分支改读 distill_loss_llm(语义正确的拆分三源)。
- metrics_contract.go 契约表:avg_distill_loss 行标注「值键已摘除,读下方三拆分指标」。
- 测试全量对齐:selfoptimize_test / metrics_na_test / metrics_contract_test /
  executor_na_test / tuning_analytics_test / tuning_guard_test。
- server.go / 注释同步。
- 验证:go build EXIT=0;go test ./internal/selfoptimize/... ok;
  routes 指标相关测试 ok(TestRecall_* 为 pre-existing 测试序故障,与本次无关,stash 后 HEAD 同样 FAIL)。
2026-11-16 13:01:35 +08:00

55 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 触发器 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,
// t_dcad48e4:avg_distill_loss 值键已摘除,NA map 里不再出现它(改读拆分三源 distill_loss_llm)。
"distill_loss_llm": -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")
}
}