diff --git a/go/internal/api/routes/scorecache_guard_test.go b/go/internal/api/routes/scorecache_guard_test.go deleted file mode 100644 index bcca7d0..0000000 --- a/go/internal/api/routes/scorecache_guard_test.go +++ /dev/null @@ -1,28 +0,0 @@ -// 织忆 MemoryWeave — routes 包测试护栏(t_b7a8ed9c):默认关闭 distill 打分缓存。 -// -// 背景:distill 打分记忆化(0dc571d)+ Redis L2(36db9bb,键 zhiyi:distill-score:*, -// TTL 168h)后,**本包 E2E 测试(zz_commit_conflict_gate_test.go)会读写生产 Redis**: -// 第一次 run L2 miss → 真调 mock LLM 并把「测试内容哈希 → 结果」写进生产; -// 7 天内后续 run L2 hit → LLM 被静默短路 → 数 LLM 调用次数的断言(base+1)必挂。 -// 实测 2026-10-17:TestCommitConflictGate_E2E 16.5s 固定 FAIL, -// 「expected >= 1 LLM distill calls, got 0」,生产键 TTL≈40h 残留即污染源。 -// -// 治法(对齐项目门禁规矩③:加缓存必须给该包 TestMain 加关闭开关): -// TestMain 里 Setenv ZHIYI_SCORE_CACHE=0 —— distill.getScoreCache 的 Once 闭包 -// 活读 env(包级变量在 init 时已定型,跨包设不了),本进程内缓存整体禁用: -// 不读 L2(LLM 真被调用,计数断言有覆盖)、不写 L2(不再污染生产)。 -// -// ⚠️ 合并提示:t_e5997ca4 分支在 routes 加了 testmain_test.go(ZHIYI_DASHBOARD_PATH -// 护栏,另一个 TestMain)。两卡分支合并到 main 后同包两个 TestMain 编译冲突, -// 合并时必须把两个 TestMain 体合并进一个文件。 -package routes - -import ( - "os" - "testing" -) - -func TestMain(m *testing.M) { - _ = os.Setenv("ZHIYI_SCORE_CACHE", "0") - os.Exit(m.Run()) -} diff --git a/go/internal/api/routes/testmain_test.go b/go/internal/api/routes/testmain_test.go index aa3096e..76f09b2 100644 --- a/go/internal/api/routes/testmain_test.go +++ b/go/internal/api/routes/testmain_test.go @@ -1,8 +1,32 @@ -// 织忆 MemoryWeave — 路由层测试隔离(t_e5997ca4 起) +// 织忆 MemoryWeave — routes 包测试隔离(两个护栏合并 · t_e5997ca4 + t_b7a8ed9c) // -// 单元测试不得写到生产落盘点。selfoptimize 包已有同款 TestMain 先例 -// (曾实测:整套测试跑完把 /var/lib/memoryweave/dashboard.json 写成测试数字)。 +// ⚠️ 本文件是**两个 TestMain 的合并体**。两卡分支各自加了一个 TestMain: +// · t_e5997ca4 → testmain_test.go(落盘点护栏) +// · t_b7a8ed9c → scorecache_guard_test.go(打分缓存护栏) +// 在各自分支上互不干扰,合并到 main 后同包两个 TestMain **编译冲突** +// (multiple definitions of TestMain)⇒ 必须合进一个文件。 +// (此点由 t_b7a8ed9c 在 scorecache_guard_test.go 顶部预先标注;小怡合并时未读文件 +// 而漏看,由全套测试的 setup failed 拦下 —— 见 worklog 教训。) +// +// 护栏①:单元测试不得写到生产落盘点(t_e5997ca4) +// --------------------------------------------------------------- +// selfoptimize 包已有同款 TestMain 先例(曾实测:整套测试跑完把 +// /var/lib/memoryweave/dashboard.json 写成测试数字)。 // gap close/repair 端点会触发 Dash.persist()(本地 JSON 兜底)⇒ 统一重定向到临时目录。 +// +// 护栏②:默认关闭 distill 打分缓存(t_b7a8ed9c) +// --------------------------------------------------------------- +// 背景:distill 打分记忆化(0dc571d)+ Redis L2(36db9bb,键 zhiyi:distill-score:*, +// TTL 168h)后,**本包 E2E 测试(zz_commit_conflict_gate_test.go)会读写生产 Redis**: +// 第一次 run L2 miss → 真调 mock LLM 并把「测试内容哈希 → 结果」写进生产; +// 7 天内后续 run L2 hit → LLM 被静默短路 → 数 LLM 调用次数的断言(base+1)必挂。 +// 实测 2026-10-17:TestCommitConflictGate_E2E 16.5s 固定 FAIL, +// 「expected >= 1 LLM distill calls, got 0」。 +// +// 治法(对齐项目门禁规矩③:加缓存必须给该包 TestMain 加关闭开关): +// Setenv ZHIYI_SCORE_CACHE=0 —— distill.getScoreCache 的 Once 闭包**活读 env** +// (包级变量在 init 时已定型,跨包设不了),本进程内缓存整体禁用: +// 不读 L2(LLM 真被调用,计数断言有覆盖)、不写 L2(不再污染生产)。 package routes import ( @@ -12,12 +36,16 @@ import ( ) func TestMain(m *testing.M) { + // 护栏①:落盘点重定向到临时目录(宁可测试直接失败,也不写生产落盘点) dir, err := os.MkdirTemp("", "routes-test-dash-*") if err != nil { - // 宁可测试直接失败,也不写生产落盘点 panic(err) } _ = os.Setenv("ZHIYI_DASHBOARD_PATH", filepath.Join(dir, "dashboard.json")) + + // 护栏②:关闭 distill 打分缓存(不读/不写生产 Redis L2) + _ = os.Setenv("ZHIYI_SCORE_CACHE", "0") + code := m.Run() _ = os.RemoveAll(dir) os.Exit(code)