test: improve scanner coverage from 59.2% to 73.1%#35
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
Pull request overview
This PR increases unit test coverage for the scanner package—particularly file-walking filters and file-graph/import-resolution helpers—and raises the CI coverage floor accordingly.
Changes:
- Added table-driven tests for walker helpers (
matchesPattern,shouldIncludeFile), gitignore cache loading, and filtered scanning behavior. - Added tests for file-index construction and import-resolution helpers (
buildFileIndex,normalizeImport,resolveRelative,fuzzyResolve), plusFileGraph/language detection behaviors. - Increased CI’s overall coverage floor from 30.0% to 35.0%.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
scanner/walker_test.go |
Adds tests for walker filtering/pattern logic and gitignore cache behavior. |
scanner/deps_test.go |
Adds tests for file indexing, import normalization/resolution, and file-graph helpers. |
.github/workflows/ci.yml |
Raises enforced total coverage floor to 35.0%. |
Comments suppressed due to low confidence (1)
.github/workflows/ci.yml:53
- The inline comment says “Floor target: 90%” but the enforced minimum is now
35.0. Please update the comment to reflect the actual coverage floor (or clarify that 90% is a long-term goal) so the workflow is self-explanatory.
total=$(go tool cover -func=coverage.out | awk '/^total:/ {gsub("%","",$3); print $3}')
# Floor target: 90%. Codex PRs will incrementally raise this value.
min=35.0
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| {name: "glob filename match", relPath: "src/user_test.go", pattern: "*_test.go", want: true}, | ||
| {name: "glob path match", relPath: "assets/icons/logo.svg", pattern: "assets/*/*.svg", want: true}, | ||
| {name: "extension with dot", relPath: "assets/logo.png", pattern: ".png", want: true}, | ||
| {name: "extension without dot", relPath: "assets/logo.PNG", pattern: "png", want: true}, | ||
| {name: "directory component", relPath: "src/Fonts/Inter.ttf", pattern: "Fonts", want: true}, | ||
| {name: "exact directory path", relPath: "Fonts", pattern: "Fonts", want: true}, | ||
| {name: "no match", relPath: "src/main.go", pattern: "images", want: false}, |
There was a problem hiding this comment.
The table cases hardcode "/"-separated paths/patterns. Since matchesPattern uses filepath.Match (OS-specific separator) and ScanFiles produces filepath.Rel output (OS-specific), these inputs can behave differently or break if tests are ever run on Windows. Consider constructing relPath/pattern with filepath.FromSlash(...) (for patterns containing separators) or standardizing with filepath.ToSlash(...) consistently (both in tests and production code paths) so the behavior is OS-independent.
| func TestBuildFileIndex(t *testing.T) { | ||
| files := []FileInfo{ | ||
| {Path: "main.go"}, | ||
| {Path: "pkg/service/handler.go"}, | ||
| {Path: "src/modules/auth/index.ts"}, | ||
| } | ||
|
|
||
| idx := buildFileIndex(files, "example.com/project") | ||
|
|
||
| if got := idx.byDir["pkg/service"]; len(got) != 1 || got[0] != "pkg/service/handler.go" { | ||
| t.Fatalf("expected pkg/service/handler.go in byDir, got %v", got) | ||
| } | ||
| if got := idx.byExact["pkg/service/handler"]; len(got) != 1 || got[0] != "pkg/service/handler.go" { | ||
| t.Fatalf("expected no-ext exact match for handler.go, got %v", got) | ||
| } | ||
| if got := idx.bySuffix["service/handler.go"]; len(got) != 1 || got[0] != "pkg/service/handler.go" { | ||
| t.Fatalf("expected suffix match for service/handler.go, got %v", got) | ||
| } | ||
| if got := idx.goPkgs["example.com/project/pkg/service"]; len(got) != 1 || got[0] != "pkg/service/handler.go" { | ||
| t.Fatalf("expected go package index for pkg/service, got %v", got) | ||
| } |
There was a problem hiding this comment.
This test suite assumes FileInfo.Path and index keys use "/" separators (e.g. bySuffix["service/handler.go"]). However buildFileIndex splits paths by filepath.Separator, and ScanFiles returns OS-native separators, so these assertions won’t be portable if tests run on Windows and can mask real separator-mismatch issues. Consider building input paths with filepath.FromSlash(...) and deriving expected keys via filepath.Join/string(filepath.Separator) (and separately ensuring Go import keys use /).
|
Addressed the portability feedback in a follow-up commit ():
Local validation re-run: ok codemap 2.548s |
|
Addressed the portability feedback in follow-up commit c56a801.
Local validation re-run: go test -race ./..., go vet ./..., and gofmt -l . (clean). |
Summary
30.0to35.0after total coverage increaseCoverage
codemap/scannerValidation
go test -race -coverprofile=coverage.out ./...go vet ./...gofmt -l .(no output)Checklist