Skip to content

#298: Extract shared git-root resolver for project key lookups#299

Merged
bguidolim merged 2 commits intomainfrom
bruno/298-shared-git-root-resolver
Mar 26, 2026
Merged

#298: Extract shared git-root resolver for project key lookups#299
bguidolim merged 2 commits intomainfrom
bruno/298-shared-git-root-resolver

Conversation

@bguidolim
Copy link
Copy Markdown
Collaborator

Summary

mcs export from a subdirectory project silently missed project-scoped MCP servers because ConfigurationDiscovery did a direct projects[projectRoot.path] lookup without walking up to the git root. PR #297 fixed the same issue in MCPServerCheck but with an inline loop — this PR extracts the walk-up logic into a shared utility and fixes the remaining bug.

Closes #298

Changes

  • Add ProjectDetector.resolveProjectKey(from:in:) — walks up from a starting path, checking each ancestor against a set of known ~/.claude.json project keys, stopping at the .git boundary
  • Fix ConfigurationDiscovery.discoverMCPServers() to use the shared utility instead of a direct single-key lookup
  • Refactor MCPServerCheck.check() to use the shared utility instead of the inline walk-up loop from PR fix: MCPServerCheck false negative in subdirectory projects #297
  • Add 5 unit tests for resolveProjectKey (exact match, walk-up, git boundary, no match, empty keys)
  • Add 3 sandbox tests for MCPServerCheck walk-up behavior (subdirectory pass, boundary stop, exact match regression)
  • Add 1 integration test in DoctorRunnerIntegrationTests for the full DoctorRunner → MCPServerCheck walk-up flow

Test plan

  • swift test passes locally (884 tests)
  • swiftformat --lint . and swiftlint pass without violations
  • Affected commands verified with a real pack (e.g. mcs sync, mcs doctor)
Checklist for engine changes
  • Integration tests updated for new features (LifecycleIntegrationTests or DoctorRunnerIntegrationTests)

- Add ProjectDetector.resolveProjectKey(from:in:) to walk up from project root to git root when resolving ~/.claude.json project keys
- Fix ConfigurationDiscovery.discoverMCPServers() using the shared utility (mcs export was silently missing MCP servers in subdirectory projects)
- Refactor MCPServerCheck to use the shared utility instead of inline walk-up loop
…discovery

- Walk-up finds servers keyed at git root from subdirectory project
- Exact match when projectRoot equals gitRoot (regression)
- Boundary: nested .git prevents escaping to outer repo
@bguidolim bguidolim enabled auto-merge (squash) March 26, 2026 11:00
@bguidolim bguidolim merged commit 706125f into main Mar 26, 2026
4 checks passed
@bguidolim bguidolim deleted the bruno/298-shared-git-root-resolver branch March 26, 2026 11:03
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.

Extract shared git-root resolver for ~/.claude.json project key lookups

1 participant