gofmt -l 实测 66 文件不合规(历史遗留+gofmt 1.25 规范化: 单行 if/for/case 展开成块、Go1.19+ doc 注释 // 与段落 // 空行)。 本 commit 只含格式化,零逻辑改动: - 66/66 文件「去注释+去空白+分号归一」后 token 流与 HEAD 完全一致 - go build ./... exit 0;go vet ./... exit 0(改前后一致) - go test ./... 17 包全 ok(改前后一致) 验收: gofmt -l . 为空;git diff -w 非空系 gofmt 1.25 非纯空白特性, 非逻辑改动(等价性以 token 流 + test 兜底)。
107 lines
4.4 KiB
Go
107 lines
4.4 KiB
Go
package distill
|
||
|
||
import (
|
||
"os"
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
// TestIsEchoScore_Positive 阳性对照:照抄旧 prompt 示例 → 必须报 true。
|
||
// 量具铁律:新量具先用正例证明它会报阳性,否则"没报警"毫无意义。
|
||
func TestIsEchoScore_Positive(t *testing.T) {
|
||
echo := FiveDScore{IS: 0.8, SU: 0.7, PA: 0.6, VD: 0.9, RU: 0.7}
|
||
if !IsEchoScore(echo) {
|
||
t.Fatalf("阳性对照失败:照抄示例 %+v 未被识别为 echo(量具失灵)", echo)
|
||
}
|
||
}
|
||
|
||
// TestIsEchoScore_Negative 阴性对照:不得滥报。
|
||
func TestIsEchoScore_Negative(t *testing.T) {
|
||
cases := map[string]FiveDScore{
|
||
"仅一位不同": {IS: 0.8, SU: 0.7, PA: 0.6, VD: 0.9, RU: 0.8},
|
||
"全零": {},
|
||
"真实差异评分": {IS: 0.95, SU: 0.4, PA: 0.2, VD: 0.85, RU: 0.6},
|
||
"全一分": {IS: 1, SU: 1, PA: 1, VD: 1, RU: 1},
|
||
}
|
||
for name, s := range cases {
|
||
if IsEchoScore(s) {
|
||
t.Errorf("阴性对照失败[%s]:%+v 被误判为 echo(滥报)", name, s)
|
||
}
|
||
}
|
||
}
|
||
|
||
// TestEchoVectorMatchesWeightedOverall 证明 echo 向量的加权分恰好是观测到的恒定值 0.755。
|
||
// 这条是"因果链"的证据固化:0.755 ≥ 0.7 阈值 ⇒ 闸门恒不触发。
|
||
func TestEchoVectorMatchesWeightedOverall(t *testing.T) {
|
||
echo := FiveDScore{IS: 0.8, SU: 0.7, PA: 0.6, VD: 0.9, RU: 0.7}
|
||
overall := echo.IS*Weights.IS + echo.SU*Weights.SU + echo.PA*Weights.PA +
|
||
echo.VD*Weights.VD + echo.RU*Weights.RU
|
||
// 0.80*0.20 + 0.70*0.20 + 0.60*0.15 + 0.90*0.25 + 0.70*0.20 = 0.755
|
||
if overall < 0.7549 || overall > 0.7551 {
|
||
t.Fatalf("加权分应为 0.755,实得 %.4f(权重被改动?)", overall)
|
||
}
|
||
if overall < 0.7 {
|
||
t.Fatalf("echo 加权分 %.4f < 0.7 阈值 —— 与「闸门恒不触发」的观测矛盾", overall)
|
||
}
|
||
}
|
||
|
||
// TestIsDegenerateScore 退化向量检测(阳性 + 阴性对照)。
|
||
//
|
||
// ⚠️ 本函数只做**观测标记**,不得单独用作丢弃判据 —— 见 engine.go 中 IsDegenerateScore 注释。
|
||
func TestIsDegenerateScore(t *testing.T) {
|
||
// 阳性:五维相同(含全零)
|
||
for name, s := range map[string]FiveDScore{
|
||
"全零(可能字段缺失)": {IS: 0, SU: 0, PA: 0, VD: 0, RU: 0},
|
||
"全0.5": {IS: 0.5, SU: 0.5, PA: 0.5, VD: 0.5, RU: 0.5},
|
||
"全0.8": {IS: 0.8, SU: 0.8, PA: 0.8, VD: 0.8, RU: 0.8},
|
||
"全一": {IS: 1, SU: 1, PA: 1, VD: 1, RU: 1},
|
||
} {
|
||
if !IsDegenerateScore(s) {
|
||
t.Errorf("阳性对照失败[%s]:五维相同的 %+v 未被识别为退化评分", name, s)
|
||
}
|
||
}
|
||
// 阴性:至少一维不同 → 不算退化
|
||
for name, s := range map[string]FiveDScore{
|
||
"真实分维度(实测样本)": {IS: 0.8, SU: 0.8, PA: 0.7, VD: 0.6, RU: 0.5},
|
||
"仅一位不同": {IS: 0.8, SU: 0.8, PA: 0.8, VD: 0.8, RU: 0.7},
|
||
"历史echo向量": {IS: 0.8, SU: 0.7, PA: 0.6, VD: 0.9, RU: 0.7},
|
||
} {
|
||
if IsDegenerateScore(s) {
|
||
t.Errorf("阴性对照失败[%s]:%+v 被误判为退化评分(滥报)", name, s)
|
||
}
|
||
}
|
||
}
|
||
|
||
// TestPromptHasNoEchoLiterals 回归守卫:**prompt 评分段**不得再出现具体示例小数。
|
||
//
|
||
// 起因:示例写成具体数值 ⇒ 模型照抄 ⇒ 每条 overall 恒为 0.755 ⇒ 评分闸门形同虚设。
|
||
// 二次踩坑:改成"禁止沿用(例如 0.8/0.7/0.6/0.9/0.7)"后,模型转而锚定 0.6 ⇒ 恒定 0.600。
|
||
// 因此守卫必须**只扫 prompt 模板段**(文件别处的 echoScoreVectors 注释本就需要记录历史值)。
|
||
func TestPromptHasNoEchoLiterals(t *testing.T) {
|
||
src, err := os.ReadFile("engine.go")
|
||
if err != nil {
|
||
t.Fatalf("读 engine.go 失败: %v", err)
|
||
}
|
||
s := string(src)
|
||
|
||
start := strings.Index(s, "输出格式(严格JSON)")
|
||
end := strings.Index(s, `fmt.Sprintf("内容:\n%s"`)
|
||
if start < 0 || end < 0 || end <= start {
|
||
t.Fatal("无法定位 prompt 评分段(模板被重构?请更新本测试的锚点)")
|
||
}
|
||
prompt := s[start:end]
|
||
|
||
if !strings.Contains(prompt, `"is": <小数>`) {
|
||
t.Fatal("回归:prompt 里已找不到 <小数> 占位符 —— 示例可能又被写成具体数字")
|
||
}
|
||
if !strings.Contains(prompt, "禁止给出固定不变的分数组合") {
|
||
t.Error("prompt 缺少「禁止固定数值组合」的约束句")
|
||
}
|
||
// 评分段不得出现任何具体小数(0.0/1.0 范围端点除外)
|
||
for _, bad := range []string{"0.8", "0.9", "0.7", "0.6", "0.5"} {
|
||
if strings.Contains(prompt, bad) {
|
||
t.Fatalf("回归:prompt 评分段出现具体示例小数 %q —— 会变成锚点(实测会把评分钉成常数)", bad)
|
||
}
|
||
}
|
||
}
|