Files
memoryweave/go/internal/selfoptimize/executor_na_test.go
T
小唯 44fd0e95b4 fix(metrics): t_c70f385c 消费者 N/A 护栏 + daily-check N/A 显示 + 反例测试
小怡终审 2026-10-17 21:05 必须修的 4 项之一(-1 哨兵被当低分 ⇒ 触发器恒 fire):

1. selfoptimize.go: 新增 IsNA(v) 判 N/A(metricNA<0)。
2. executor.go: TGapDetected/TQualityDrop/TVValueLow 阈值比较前显式判 N/A,
   -1 不再被当「低于阈值」每轮触发(与旧 recall_hit_rate 恒=1 同类失真、方向相反)。
   配 executor_na_test.go 反例(v=-1 断言不触发)+ 正向对照。
3. tuning.go: AnalyticsHandler 建议 builder 抽为纯函数 AnalyticsSuggestions,
   统一走 ratioFor(-1/valid=0/样本不足 ⇒ 不产生建议);配 tuning_analytics_test.go 反例。
4. 两个 daily-check.sh: gap/auto/usefulness 值为 -1 时显示 —(N/A),不再打印误导性 -1/天。

测试命令(go.mod 在 go/ 下,须 cd go):
  cd go && go test ./internal/selfoptimize/... ./internal/api/routes/
(TestCommitConflictGate_E2E 为既有环境性 LLM 蒸馏用例,非本次改动路径,单独 FAIL)

生产部署仍待小怡终审 + 牧尘放行(本卡边界)。
2026-10-17 21:22:28 +08:00

54 lines
2.3 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,
"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")
}
}