test(distill): 回显防线真模型现场探针

实证(真 2B 输出):易诱发输入下模型逐字吐出 prompt 教学示例
(用户昨天买了苹果。/ 用户的朋友John在学医。),防线剔除 facts=2 entities=1
且 allEcho=true → 落到上游启发式提取;B/C/D 三条真实内容零误杀。
This commit is contained in:
zyh
2026-10-12 11:23:56 +08:00
parent a39e5c7e23
commit dfc6f580eb
@@ -0,0 +1,72 @@
//go:build liveprobe
package distill
import (
"fmt"
"net/http"
"strings"
"testing"
"time"
)
// TestEchoLiveProbe 直连真模型,验证「教学示例回显防线」在**真实输出**上生效。
//
// 单测喂的是我构造的文本;本探针喂的是模型**真的吐出来的东西**——
// 这才是「防线在生产路径上起作用」的证据(判据:模型真输出里出现了示例字面量,
// 且经 parseDistillOutput 后不再出现在 facts/entities 里)。
//
// go test ./internal/distill/ -tags liveprobe -run TestEchoLiveProbe -v -count=1
func TestEchoLiveProbe(t *testing.T) {
tmpl := extractPromptTemplate(t)
client := &http.Client{Timeout: 180 * time.Second}
cases := []struct{ name, content string }{
{"A-易诱发回显(苹果/John)", "[2026-10-12, 周一] 牧尘: 昨天买了苹果\n[2026-10-12, 周一] 牧尘: 我朋友John在学医"},
{"B-真实工作规则", "[2026-10-12, 周一] 牧尘: 全绿不代表能用,要实际能用,满足使用\n[2026-10-12, 周一] 小怡: 记下了,判据要覆盖真实路径而不是只看配置"},
{"C-纯寒暄(应无事实)", "[2026-10-12, 周一] 牧尘: 你好\n[2026-10-12, 周一] 小怡: 哈哈\n[2026-10-12, 周一] 牧尘: 谢谢"},
{"D-长文多实体", "[2026-10-12, 周一] 牧尘: 我在淇县负责生物制造产业专班和卫都街道,设备是小米笔记本,平时喜欢马哲经济学和剪辑。"},
}
stripTotal, echoSeen := 0, 0
for _, c := range cases {
raw := callRaw(t, client, fmt.Sprintf(tmpl, c.content))
// ① 未经防线:模型原始输出解析出什么
facts, ents, sc, ok := ParseLineFormat(raw)
var names []string
for _, e := range ents {
names = append(names, e.Name)
}
rawEcho := 0
for _, f := range facts {
if IsPromptEcho(f) {
rawEcho++
}
}
for _, e := range names {
if IsPromptEcho(e) {
rawEcho++
}
}
// ② 经防线(= 生产路径)
after, st := StripPromptEcho(LLMResponse{
IS: sc.IS, SU: sc.SU, PA: sc.PA, VD: sc.VD, RU: sc.RU,
Facts: facts, Entities: names,
})
stripTotal += st.Total()
if rawEcho > 0 {
echoSeen++
}
t.Logf("\n══════ %s ══════", c.name)
t.Logf("模型原始: %s", strings.ReplaceAll(strings.TrimSpace(raw), "\n", " ⏎ "))
t.Logf("防线前 : facts=%v entities=%v ok=%v 其中回显=%d", facts, names, ok, rawEcho)
t.Logf("防线后 : facts=%v entities=%v", after.Facts, after.Entities)
t.Logf("剔除 : facts=%d entities=%d other=%d allEcho=%v 样例=%q",
st.FactsDropped, st.EntitiesDropped, st.OtherDropped, st.AllFactsWereEcho, st.Sample)
}
t.Logf("\n══════ 汇总:%d/%d 条真实输出含回显,共剔除 %d 项 ══════", echoSeen, len(cases), stripTotal)
}