Skip to content

refactor(trace): deduplicate workspace helpers, eliminate double scan, add error logging#164

Open
jugrajsingh wants to merge 3 commits intoyoanbernabeu:mainfrom
jugrajsingh:refactor/trace-dedup-and-logging
Open

refactor(trace): deduplicate workspace helpers, eliminate double scan, add error logging#164
jugrajsingh wants to merge 3 commits intoyoanbernabeu:mainfrom
jugrajsingh:refactor/trace-dedup-and-logging

Conversation

@jugrajsingh
Copy link
Contributor

Description

Addresses the three non-blocking review suggestions from PR #121:

  1. Extract shared workspace symbol store helpersloadWorkspaceSymbolStores and closeSymbolStores were duplicated in cli/trace.go and mcp/server.go. Extracted into trace/workspace.go as exported functions LoadWorkspaceSymbolStores / CloseSymbolStores, used by both consumers.

  2. Eliminate double filesystem scanrunInitialScan in cli/watch.go called scanner.ScanMetadata() twice: once inside IndexAllWithBatchProgress and once more for symbol extraction. Added ScannedFiles field to IndexStats so callers can reuse the file list from the first scan.

  3. Add error logging for silent discards — ~21 instances of _, _ := on symbol store lookups and config loads across cli/trace.go and mcp/server.go now log warnings via log.Printf instead of silently discarding errors.

Related Issue

Follow-up to #121

Type of Change

  • Refactoring (no functional changes)

How Has This Been Tested?

  • Unit tests
  • Manual testing

Unit tests:

  • Added 6 new tests in trace/workspace_test.go covering: missing config, unknown workspace, unknown project, multi-project loading, project filtering, and CloseSymbolStores
  • All existing tests pass (make pre-commit)

Manual testing:

  • Built and replaced local CLI binary
  • grepai watch --workspace <name> — 10 projects, 1043 files, 4695 chunks, 4987 symbols indexed successfully
  • grepai trace callers <symbol> --workspace <name> — verified callers found across workspace for multiple symbols

Test Configuration:

  • OS: Fedora 43 (Linux 6.18.12)
  • Go version: 1.22+
  • Embedding provider: Ollama

Checklist

  • My code follows the project's code style
  • I have run golangci-lint run and fixed any issues
  • I have added tests that prove my fix/feature works
  • I have updated the documentation if needed
  • My changes generate no new warnings
  • All new and existing tests pass

Additional Notes

  • The mcp/server.go version of loadWorkspaceSymbolStores was a *Server method but never used any receiver fields, making extraction straightforward
  • No user-facing behavior changes; CHANGELOG not updated per maintainer guidance

Extract shared LoadWorkspaceSymbolStores and CloseSymbolStores
into trace/workspace.go, eliminating ~50 lines of duplication
between cli/trace.go and mcp/server.go.

Add ScannedFiles field to IndexStats so runInitialScan reuses
the file list from IndexAllWithBatchProgress instead of calling
scanner.ScanMetadata() a second time.

Replace ~21 silent error discards (_, _ :=) on symbol store
and config operations with log.Printf warnings in both
cli/trace.go and mcp/server.go.
Covers LoadWorkspaceSymbolStores with missing config, unknown
workspace, unknown project, multi-project loading, and single
project filtering. Also tests CloseSymbolStores.
Remove trailing whitespace and normalize alignment
detected by gofmt and whitespace hooks.
@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

❌ Patch coverage is 31.81818% with 75 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.51%. Comparing base (a322537) to head (536238d).
⚠️ Report is 84 commits behind head on main.

Files with missing lines Patch % Lines
cli/trace.go 0.00% 39 Missing ⚠️
mcp/server.go 16.66% 24 Missing and 6 partials ⚠️
trace/workspace.go 81.81% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #164       +/-   ##
===========================================
+ Coverage   27.16%   44.51%   +17.35%     
===========================================
  Files          32       67       +35     
  Lines        3711    12769     +9058     
===========================================
+ Hits         1008     5684     +4676     
- Misses       2620     6526     +3906     
- Partials       83      559      +476     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant