From bea2849494bccbd85e340b86ac18e4e4c0346b53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=94=AF?= Date: Sat, 12 Sep 2026 18:07:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(tests):=20=E4=BF=AE=20pre-existing=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=A4=B1=E9=85=8D=EF=BC=8C=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=20make=20test=20=E5=85=A8=E7=BB=BF=20(t=5F8496e8b6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 四处均为本任务之前就存在的测试漂移(与优化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) --- go/integration_test.go | 7 ++++--- go/internal/selfoptimize/bench_test.go | 6 +++--- go/internal/selfoptimize/selfoptimize_test.go | 10 +++++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/go/integration_test.go b/go/integration_test.go index d3061ee..b72e74f 100644 --- a/go/integration_test.go +++ b/go/integration_test.go @@ -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) diff --git a/go/internal/selfoptimize/bench_test.go b/go/internal/selfoptimize/bench_test.go index 36d633f..485b07e 100644 --- a/go/internal/selfoptimize/bench_test.go +++ b/go/internal/selfoptimize/bench_test.go @@ -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++ { diff --git a/go/internal/selfoptimize/selfoptimize_test.go b/go/internal/selfoptimize/selfoptimize_test.go index 2363b1e..f698475 100644 --- a/go/internal/selfoptimize/selfoptimize_test.go +++ b/go/internal/selfoptimize/selfoptimize_test.go @@ -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")