From dfc6f580eb143e090bbcf34223a5a05f3a51b5a7 Mon Sep 17 00:00:00 2001 From: zyh Date: Mon, 12 Oct 2026 11:23:56 +0800 Subject: [PATCH] =?UTF-8?q?test(distill):=20=E5=9B=9E=E6=98=BE=E9=98=B2?= =?UTF-8?q?=E7=BA=BF=E7=9C=9F=E6=A8=A1=E5=9E=8B=E7=8E=B0=E5=9C=BA=E6=8E=A2?= =?UTF-8?q?=E9=92=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实证(真 2B 输出):易诱发输入下模型逐字吐出 prompt 教学示例 (用户昨天买了苹果。/ 用户的朋友John在学医。),防线剔除 facts=2 entities=1 且 allEcho=true → 落到上游启发式提取;B/C/D 三条真实内容零误杀。 --- .../distill/echo_guard_liveprobe_test.go | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 go/internal/distill/echo_guard_liveprobe_test.go diff --git a/go/internal/distill/echo_guard_liveprobe_test.go b/go/internal/distill/echo_guard_liveprobe_test.go new file mode 100644 index 0000000..0130339 --- /dev/null +++ b/go/internal/distill/echo_guard_liveprobe_test.go @@ -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) +}