Files
memoryweave/go/internal/distill/density_gate_test.go
T

54 lines
2.0 KiB
Go

// t_ab5b2461 信息密度判据单测(判据 = 交付里贴出的口径,测试即文档)。
package distill
import "testing"
func TestDensitySatisfyCount(t *testing.T) {
cases := []struct {
name string
fact string
wantN int
keep bool
}{
{"命令+阈值", "重启用 ~/.hermes/scripts/zhiyi-restart-with-lock.sh,健康检查 40 秒内必须返回 200,否则回滚", 3, true},
{"路径+因果", "state.db 损坏时走 db-op-gate.sh,因为 gateway 运行期直接写活库会放大损坏面", 2, true},
{"仅阈值", "该表写入量超过 500 条时告警", 1, false},
{"仅因果", "因为昨晚断网所以任务没有跑完", 1, false},
{"元信息行(全不中)", "该条经验记录的日期为 2026-10-25", 0, false},
{"裸短句(全不中)", "用户授权助手自行决定", 0, false},
{"阈值+因果", "磁盘余量 <5% 时触发清理,否则 backups 目录会把根分区写满", 2, true},
{"路径单中", "配置文件在 /etc/ssh/sshd_config", 1, false},
}
for _, c := range cases {
if n := DensitySatisfyCount(c.fact); n != c.wantN {
t.Errorf("%s: DensitySatisfyCount(%q)=%d, want %d", c.name, c.fact, n, c.wantN)
}
if got := DensityKeep(c.fact); got != c.keep {
t.Errorf("%s: DensityKeep(%q)=%v, want %v", c.name, c.fact, got, c.keep)
}
}
}
// AC5 结构证据:灰度段是**追加**,不改动既有 prompt 常量 ——
// instr/outFmt 常量文本里不含「信息量要求」字样(关态 prompt 逐字节为旧文本)。
func TestDensityAddendumOnlyAppended(t *testing.T) {
if len(densityPromptAddendum) == 0 {
t.Fatal("addendum 不能为空")
}
// 追加段自带独有锚点,供源内定位(防止误删)。
if !contains(densityPromptAddendum, "禁止为凑长度堆修饰词") {
t.Error("addendum 缺「禁为长度而长度」红线锚点")
}
}
func contains(s, sub string) bool {
return len(s) >= len(sub) && (func() bool {
for i := 0; i+len(sub) <= len(s); i++ {
if s[i:i+len(sub)] == sub {
return true
}
}
return false
})()
}