fix(tests): 修 pre-existing 测试失配,恢复 make test 全绿 (t_8496e8b6)

四处均为本任务之前就存在的测试漂移(与优化B 无关,但让 go test ./... 无法通过):

1. selfoptimize: 2a350cf 给 NewGapDetector 增加了 (emb, ldb) 两个参数,
   8 处测试调用点未跟进,整包 test 构建失败。测试只用到 RecordMiss/Close/List,
   不需要真实依赖,传 nil, nil 即可。
2. integration_test.go:296 selfoptimize.NewGapDetector() 同上。
3. integration_test.go:323 InMemoryGraph.Navigate 新增 relFilter 参数,补 nil。
4. integration_test.go:339 /api/v1/triggers/fire 的夹具用了 "t1"(那是 executor
   内部编号),routes.Triggers 的真实 ID 是 t_decay/t_distill/t_merge 等,
   导致 Fire 返回 404 trigger not found。夹具改用 t_decay。

验证: go vet ./... 无输出; go test ./... -count=1 全部 ok(根包 8.1s)
This commit is contained in:
小唯
2026-09-12 18:07:40 +08:00
parent 41230ccb0a
commit bea2849494
3 changed files with 12 additions and 11 deletions
+4 -3
View File
@@ -293,7 +293,7 @@ func TestEdge_ConcurrentCommits(t *testing.T) {
}
func TestEdge_GapDetectionThreshold(t *testing.T) {
gd := selfoptimize.NewGapDetector()
gd := selfoptimize.NewGapDetector(nil, nil)
// 2 misses — no gap
if gap := gd.RecordMiss("test"); gap != nil {
@@ -320,7 +320,7 @@ func TestEdge_GraphEmpty(t *testing.T) {
t.Error("empty graph should return all zeros")
}
paths, err := g.Navigate("nonexistent", 2, "shared")
paths, err := g.Navigate("nonexistent", 2, "shared", nil)
if err != nil {
t.Errorf("navigate on empty graph should not error: %v", err)
}
@@ -336,7 +336,8 @@ func TestEdge_TriggersFired(t *testing.T) {
"X-API-Key": "zhiyi-dev-key-2026",
}
body := map[string]string{"trigger_id": "t1"}
// 触发器 ID 与 routes.Triggers 一致(t1..t8 是 executor 的内部编号,不是 API ID)
body := map[string]string{"trigger_id": "t_decay"}
req := httptest.NewRequest("POST", "/api/v1/triggers/fire", bytesBody(body))
for k, v := range header {
req.Header.Set(k, v)
+3 -3
View File
@@ -52,7 +52,7 @@ func BenchmarkDashboard_RecordFeedback_Parallel(b *testing.B) {
// ─── 缺口检测 ────────────────────────────────────────────
func BenchmarkGapDetector_RecordMiss(b *testing.B) {
gd := NewGapDetector()
gd := NewGapDetector(nil, nil)
topics := []string{"config", "memory", "system", "docker", "nginx"}
b.ResetTimer()
for i := 0; i < b.N; i++ {
@@ -61,7 +61,7 @@ func BenchmarkGapDetector_RecordMiss(b *testing.B) {
}
func BenchmarkGapDetector_List(b *testing.B) {
gd := NewGapDetector()
gd := NewGapDetector(nil, nil)
// 预填充 100 个缺口
for i := 0; i < 100; i++ {
topic := fmt.Sprintf("gap-%d", i)
@@ -76,7 +76,7 @@ func BenchmarkGapDetector_List(b *testing.B) {
}
func BenchmarkGapDetector_Close(b *testing.B) {
gd := NewGapDetector()
gd := NewGapDetector(nil, nil)
for i := 0; i < 100; i++ {
topic := fmt.Sprintf("close-%d", i)
for j := 0; j < 3; j++ {
@@ -94,7 +94,7 @@ func TestDashboard_RecordConflictResolved(t *testing.T) {
// ─── 知识缺口检测 ────────────────────────────────────────
func TestGapDetector_NotTriggeredBeforeThreshold(t *testing.T) {
gd := NewGapDetector()
gd := NewGapDetector(nil, nil)
gap := gd.RecordMiss("kubernetes")
if gap != nil {
t.Error("should not trigger gap after 1 miss")
@@ -106,7 +106,7 @@ func TestGapDetector_NotTriggeredBeforeThreshold(t *testing.T) {
}
func TestGapDetector_DetectsGapAtThreshold(t *testing.T) {
gd := NewGapDetector()
gd := NewGapDetector(nil, nil)
gd.RecordMiss("topicX")
gd.RecordMiss("topicX")
gap := gd.RecordMiss("topicX")
@@ -123,7 +123,7 @@ func TestGapDetector_DetectsGapAtThreshold(t *testing.T) {
}
func TestGapDetector_CloseGap(t *testing.T) {
gd := NewGapDetector()
gd := NewGapDetector(nil, nil)
gd.RecordMiss("topic")
gd.RecordMiss("topic")
gd.RecordMiss("topic")
@@ -136,7 +136,7 @@ func TestGapDetector_CloseGap(t *testing.T) {
}
func TestGapDetector_ClassifySynonym(t *testing.T) {
gd := NewGapDetector()
gd := NewGapDetector(nil, nil)
gd.RecordMiss("API")
gd.RecordMiss("API")
gd.RecordMiss("API")
@@ -277,7 +277,7 @@ func BenchmarkDashboardMetrics(b *testing.B) {
}
func BenchmarkGapDetection(b *testing.B) {
gd := NewGapDetector()
gd := NewGapDetector(nil, nil)
b.ResetTimer()
for i := 0; i < b.N; i++ {
gd.RecordMiss("benchmark_topic")