Skip to content

test: improve scanner coverage from 59.2% to 73.1%#35

Merged
JordanCoin merged 2 commits intomainfrom
automation/test-coverage-scanner-20260303
Mar 4, 2026
Merged

test: improve scanner coverage from 59.2% to 73.1%#35
JordanCoin merged 2 commits intomainfrom
automation/test-coverage-scanner-20260303

Conversation

@JordanCoin
Copy link
Owner

Summary

  • Add table-driven unit tests for scanner file-graph and import-resolution helpers
  • Add walker helper tests for pattern matching, include/exclude filtering, and gitignore cache loading
  • Raise CI coverage floor from 30.0 to 35.0 after total coverage increase

Coverage

Scope Before After Delta
codemap/scanner 59.2% 73.1% +13.9
TOTAL 34.8% 37.3% +2.5

Validation

  • go test -race -coverprofile=coverage.out ./...
  • go vet ./...
  • gofmt -l . (no output)

Checklist

  • Tests only in scanner package (no scanner source changes)
  • Coverage floor bumped in CI because total >= previous floor + 5
  • New test code under 500 lines

Copilot AI review requested due to automatic review settings March 4, 2026 15:22
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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), plus FileGraph/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.

Comment on lines +577 to +583
{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},
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +498 to +518
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)
}
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 /).

Copilot uses AI. Check for mistakes.
@JordanCoin
Copy link
Owner Author

Addressed the portability feedback in a follow-up commit ():

  • : switched path fixtures/assertions to , , , and extension-trimmed derived keys.
  • : normalized path/pattern inputs with + in .
  • : clarified the coverage-floor comment to state 90% is the long-term target while current floor is incremental.

Local validation re-run: ok codemap 2.548s
ok codemap/cmd 1.859s
ok codemap/config 1.222s
ok codemap/handoff 1.781s
ok codemap/limits 1.590s
? codemap/mcp [no test files]
ok codemap/render 1.718s
ok codemap/scanner 2.618s
ok codemap/watch 6.799s, , (clean).

@JordanCoin
Copy link
Owner Author

Addressed the portability feedback in follow-up commit c56a801.

  • scanner/deps_test.go: switched path fixtures/assertions to filepath.FromSlash, filepath.Dir, filepath.Join, and extension-trimmed derived keys.
  • scanner/walker_test.go: normalized path/pattern inputs with filepath.FromSlash + filepath.ToSlash in TestMatchesPattern.
  • .github/workflows/ci.yml: clarified the coverage-floor comment to state 90% is the long-term target while current floor is incremental.

Local validation re-run: go test -race ./..., go vet ./..., and gofmt -l . (clean).

@JordanCoin JordanCoin merged commit 6cf3f11 into main Mar 4, 2026
12 checks passed
@JordanCoin JordanCoin deleted the automation/test-coverage-scanner-20260303 branch March 4, 2026 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants