Skip to content

Commit a490d25

Browse files
committed
Add namespace support to benchmark command and create corresponding tests
1 parent 2cf93e4 commit a490d25

4 files changed

Lines changed: 122 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ pyproject.toml
2626
*.db-wal
2727
/web/wiki/dist/
2828
/web/wiki/node_modules/
29+
search-retrieval.md

internal/cli/benchmark.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import (
1212
"strings"
1313

1414
"github.com/spf13/cobra"
15+
"github.com/spf13/viper"
1516
"github.com/tae2089/trace"
1617

1718
"github.com/tae2089/code-context-graph/internal/benchmark"
19+
"github.com/tae2089/code-context-graph/internal/ctxns"
1820
"github.com/tae2089/code-context-graph/internal/store/gormstore"
1921
storesearch "github.com/tae2089/code-context-graph/internal/store/search"
2022
)
@@ -279,7 +281,8 @@ func newBenchmarkTokenBenchCmd(deps *Deps) *cobra.Command {
279281
return trace.Wrap(err, "load corpus")
280282
}
281283
backend := storesearch.NewSQLiteBackend()
282-
results, err := benchmark.RunTokenBenchWithOptions(cmd.Context(), deps.DB, backend, gormstore.New(deps.DB), corpus, repoRoot, exts, limit, benchmark.RunTokenBenchOptions{
284+
ctx := ctxns.WithNamespace(cmd.Context(), viper.GetString("namespace"))
285+
results, err := benchmark.RunTokenBenchWithOptions(ctx, deps.DB, backend, gormstore.New(deps.DB), corpus, repoRoot, exts, limit, benchmark.RunTokenBenchOptions{
283286
Naive: benchmark.NaiveTokensOptions{Excludes: resolveExcludes(excludePatterns)},
284287
})
285288
if err != nil {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package cli
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"os"
7+
"path/filepath"
8+
"testing"
9+
10+
"github.com/tae2089/code-context-graph/internal/benchmark"
11+
"github.com/tae2089/code-context-graph/internal/ctxns"
12+
"github.com/tae2089/code-context-graph/internal/model"
13+
)
14+
15+
func TestBenchmarkTokenBench_RespectsNamespace(t *testing.T) {
16+
deps, stdout, stderr, db := setupSearchTest(t)
17+
18+
nodeA := model.Node{Namespace: "ns-a", Name: "SharedA", QualifiedName: "pkg.SharedA", Kind: model.NodeKindFunction, FilePath: "a.go", StartLine: 1, EndLine: 1, Language: "go"}
19+
nodeB := model.Node{Namespace: "ns-b", Name: "SharedB", QualifiedName: "pkg.SharedB", Kind: model.NodeKindFunction, FilePath: "b.go", StartLine: 1, EndLine: 1, Language: "go"}
20+
if err := db.Create(&nodeA).Error; err != nil {
21+
t.Fatalf("create nodeA: %v", err)
22+
}
23+
if err := db.Create(&nodeB).Error; err != nil {
24+
t.Fatalf("create nodeB: %v", err)
25+
}
26+
if err := db.Create(&model.SearchDocument{Namespace: "ns-a", NodeID: nodeA.ID, Content: "sharedterm alpha", Language: "go"}).Error; err != nil {
27+
t.Fatalf("create docA: %v", err)
28+
}
29+
if err := db.Create(&model.SearchDocument{Namespace: "ns-b", NodeID: nodeB.ID, Content: "sharedterm beta", Language: "go"}).Error; err != nil {
30+
t.Fatalf("create docB: %v", err)
31+
}
32+
if err := deps.SearchBackend.Rebuild(ctxns.WithNamespace(context.Background(), "ns-a"), db); err != nil {
33+
t.Fatalf("rebuild ns-a search: %v", err)
34+
}
35+
if err := deps.SearchBackend.Rebuild(ctxns.WithNamespace(context.Background(), "ns-b"), db); err != nil {
36+
t.Fatalf("rebuild ns-b search: %v", err)
37+
}
38+
39+
root := t.TempDir()
40+
if err := os.WriteFile(filepath.Join(root, "b.go"), []byte("package p\nfunc SharedB() {}\n"), 0o644); err != nil {
41+
t.Fatalf("write repo file: %v", err)
42+
}
43+
corpusPath := filepath.Join(t.TempDir(), "queries.yaml")
44+
if err := os.WriteFile(corpusPath, []byte(`queries:
45+
- id: q1
46+
description: sharedterm
47+
expected_symbols:
48+
- SharedB
49+
`), 0o644); err != nil {
50+
t.Fatalf("write corpus: %v", err)
51+
}
52+
53+
if err := executeCmd(deps, stdout, stderr, "--namespace", "ns-b", "benchmark", "token-bench", "--corpus", corpusPath, "--repo", root, "--exts", ".go"); err != nil {
54+
t.Fatalf("token-bench: %v\nstderr=%s", err, stderr.String())
55+
}
56+
57+
var results []benchmark.TokenBenchResult
58+
if err := json.Unmarshal(stdout.Bytes(), &results); err != nil {
59+
t.Fatalf("decode output: %v\nstdout=%s", err, stdout.String())
60+
}
61+
if len(results) != 1 {
62+
t.Fatalf("results = %d, want 1", len(results))
63+
}
64+
if results[0].ResultCount == 0 || results[0].SymbolsHit != 1 {
65+
t.Fatalf("token-bench did not use ns-b search results: %+v", results[0])
66+
}
67+
}

task.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,53 @@ Red fixture + 통합 테스트 작성: `testdata/binding_gap/{typescript,kotlin,
287287
- `lsp_diagnostics` clean
288288
- `CGO_ENABLED=1 go test -tags "fts5" ./... -count=1`
289289
- `CGO_ENABLED=1 go test -tags "fts5" ./internal/cli ./internal/mcp -count=1`
290+
291+
---
292+
293+
## 2026-05-06 — 세션 복구 후 최종 검증
294+
295+
- [x] Verify: `CGO_ENABLED=1 go test -tags "fts5" ./... -count=1` 전체 통과
296+
- 모든 패키지 green (45개 패키지, 0 실패)
297+
- 경고: lua parser null character (tree-sitter 라이브러리 수준, 무시 가능)
298+
299+
- [x] Verify: `lsp_diagnostics` clean on changed files
300+
- internal/ 디렉토리 50개 파일 스캔 → 0 에러
301+
302+
### 결론
303+
304+
**모든 재코드리뷰 후속 수정 완료 및 검증 통과**
305+
306+
- P0 (주석-심볼 바인딩 견고성): 완료
307+
- Python decorated_definition + docstring 수집/바인딩
308+
- Rust normalizer `///` 처리
309+
- Kotlin multiline_comment 수집
310+
- TypeScript export_statement wrapper
311+
- PHP normalizer 추가
312+
- Go directive 오염 제거
313+
314+
- P1 (언어별 실측): 완료
315+
- 12개 언어 cross-language 계약 테스트 (11 PASS + 1 Red 계약)
316+
317+
- P2 (JSDoc/YARD 호환): 완료
318+
- @returns alias
319+
- @throws / @typedef 지원
320+
- YARD/JSDoc 타입 prefix 파싱
321+
322+
- P3 (테스트 정비): 완료
323+
- Kotlin golden.json 배포 확인
324+
- Cross-language @intent 바인딩 계약 테스트
325+
326+
- P4 (코드리뷰 후속): 완료
327+
- indexer 필드 전파 누락 수정
328+
- nameIndex dedup 동명 메서드 오병합 수정
329+
330+
- 코드리뷰 후속 3건 (2026-04-21): 완료
331+
- DeleteGraph() unresolved edge 정리
332+
- Build() preflight 실패 경계 재정의
333+
- MCP incremental + include_paths replace semantics 통일
334+
335+
### 다음 단계
336+
337+
1. 기존 계획 문서 정리 (task.md / implementation.md / workthrough.md)
338+
2. 새로운 기능 개발 또는 사용자 요청 대기
339+

0 commit comments

Comments
 (0)