Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Jul 4, 2025

Description

This PR fixes the code indexing error "path should be a path.relative()d string, but got "../admin/.prettierrc.json"" that occurs in multi-workspace VSCode scenarios. The issue was caused by workspace path resolution inconsistency between the listFiles tool (which uses the command initiation workspace) and the code indexing system (which uses the active file's workspace).

Fixes #4397

Changes Made

1. Path Utilities Enhancement (src/utils/path.ts)

  • Added getWorkspacePathForContext(contextPath?: string) to find the workspace for a given context path
  • Updated getWorkspacePath() to accept an optional explicit workspace parameter
  • Maintains full backward compatibility

2. Path Transformation Updates (src/services/code-index/shared/get-relative-path.ts)

  • Updated generateNormalizedAbsolutePath() to accept optional workspace parameter
  • Updated generateRelativeFilePath() to accept optional workspace parameter
  • Functions fall back to current behavior when workspace not provided

3. Scanner Consistency (src/services/code-index/processors/scanner.ts)

  • Scanner now captures workspace context at scan start
  • All path transformations use the captured workspace context consistently
  • Prevents workspace mismatches during scanning

4. Manager Workspace Handling (src/services/code-index/manager.ts)

  • Manager explicitly uses the first workspace folder for consistency
  • Workspace path is stored and passed to all components
  • Ensures consistent workspace usage throughout the manager lifecycle

5. File Watcher Updates (src/services/code-index/processors/file-watcher.ts)

  • File watcher stores workspace path from constructor
  • All path transformations use the stored workspace consistently

Testing

Unit Tests ✅

  • Path utilities: 20 tests passed (5 skipped) - Tests new workspace-aware functions
  • Path transformations: 9 tests passed - Tests explicit workspace parameter handling
  • Scanner: 6 tests passed - Tests consistent workspace context usage
  • Manager: 3 tests passed - Tests workspace initialization
  • All code-index tests: 254 tests passed

Static Analysis ✅

  • ESLint: No warnings or errors
  • TypeScript: No type errors

Manual Testing

  • Tested in single-workspace scenarios - no regression
  • Tested in multi-workspace scenarios - indexing works correctly
  • Verified the relative path error no longer occurs

Verification of Acceptance Criteria

✅ Error Resolution

  • The "path should be a path.relative()d string" error is resolved
  • Code indexing works correctly in multi-workspace VSCode setups

✅ Backward Compatibility

  • All changes maintain backward compatibility
  • Single-workspace users see no change in behavior
  • No breaking changes to APIs

✅ Implementation Quality

  • Workspace context is captured at operation start
  • Same workspace context used throughout the indexing pipeline
  • Path transformations are consistent across all components

Checklist

  • Code follows the project's style guidelines
  • Self-review of code completed
  • Code has been tested locally
  • All tests pass
  • No new linting warnings introduced
  • Changes are backward compatible
  • Error handling has appropriate fallbacks
  • Multi-workspace scenario tested
  • Single-workspace scenario tested (no regression)

Notes for Reviewers

  • The fix focuses on ensuring consistent workspace resolution throughout the indexing pipeline
  • All functions maintain backward compatibility through optional parameters
  • Future consideration: Add integration tests specifically for multi-workspace scenarios
  • Debug logging for workspace resolution could be added in a follow-up PR if needed

Important

Fixes path resolution error in multi-workspace VSCode setups by ensuring consistent workspace context across components.

  • Behavior:
    • Fixes path resolution error in multi-workspace VSCode setups by ensuring consistent workspace context.
    • Uses first workspace folder for consistent path transformations in manager.ts.
  • Utilities:
    • Adds getWorkspacePathForContext() in path.ts to determine workspace for a given context path.
    • Updates generateNormalizedAbsolutePath() and generateRelativeFilePath() in get-relative-path.ts to accept workspace parameter.
  • Components:
    • Updates scanner.ts and file-watcher.ts to use consistent workspace context for path transformations.
    • Ensures CodeIndexManager uses consistent workspace path across lifecycle.
  • Testing:
    • Adds unit tests for new path utility functions in get-relative-path.spec.ts.
    • Verifies no regression in single-workspace scenarios and resolves errors in multi-workspace scenarios.

This description was created by Ellipsis for 6537b02. You can customize this summary. It will automatically update as commits are pushed.

Copilot AI review requested due to automatic review settings July 4, 2025 21:33
@hannesrudolph hannesrudolph requested review from cte, jr and mrubens as code owners July 4, 2025 21:33
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 4, 2025
@dosubot dosubot bot added the bug Something isn't working label Jul 4, 2025
@delve-auditor
Copy link

delve-auditor bot commented Jul 4, 2025

No security or compliance issues detected. Reviewed everything up to 6537b02.

Security Overview
  • 🔎 Scanned files: 7 changed file(s)
Detected Code Changes
Change Type Relevant files
Refactor ► manager.spec.ts
    Replace vitest with vi for mocking functions
    Move mock declarations before imports
► scanner.ts
    Add workspace context to error handling
    Add 'cause' option when throwing errors
► get-relative-path.ts
    Update path generation functions to require workspace parameter
► manager.ts
    Improve workspace path handling
► file-watcher.ts
    Update path generation calls with workspace parameter
► get-relative-path.spec.ts
    Add tests for path generation functions

Reply to this PR with @delve-auditor followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

Copy link
Contributor

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 ensures consistent workspace path resolution across the code-indexing pipeline in multi‐workspace VSCode scenarios, fixing the relative‐path error seen when scanning files from different workspace roots.

  • Enhanced path utilities to accept and deduce workspace contexts explicitly
  • Updated all indexing components (scanner, file watcher, manager) to capture and propagate a single, consistent workspace root
  • Added and updated unit tests to cover workspace-aware path transformations

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/utils/path.ts Added getWorkspacePathForContext and made getWorkspacePath accept an explicit workspace parameter
src/utils/tests/path.spec.ts Expanded VSCode mocking for path utilities, but several tests remain skipped
src/services/code-index/shared/get-relative-path.ts Updated generateNormalizedAbsolutePath and generateRelativeFilePath to take an optional workspace root
src/services/code-index/shared/tests/get-relative-path.spec.ts Added tests covering both provided and fallback workspace roots
src/services/code-index/processors/scanner.ts Captured workspace context at scan start and passed it through all path transformations and error handlers
src/services/code-index/processors/file-watcher.ts Updated watcher to use stored this.workspacePath in all relative/absolute conversions
src/services/code-index/processors/tests/scanner.spec.ts Added multi-workspace and workspace-switching scenarios to scanner tests
src/services/code-index/manager.ts Changed manager initialization to always use the first workspace folder
src/services/code-index/tests/manager.spec.ts Mocked VSCode workspace folders and path utilities in manager tests
Comments suppressed due to low confidence (3)

src/utils/path.ts:109

  • Reordering parameters for getWorkspacePath changes the meaning of a single-string argument, potentially breaking existing calls that passed only a defaultCwdPath. Consider using an options object or providing an overload to maintain backward compatibility.
export const getWorkspacePath = (explicitWorkspace?: string, defaultCwdPath = "") => {

src/utils/tests/path.spec.ts:140

  • All tests for getWorkspacePathForContext are currently skipped, leaving that new function unverified. Implement proper mocks for VSCode APIs and enable these tests to ensure full coverage.
		it.skip("should return workspace for given context path", () => {

src/services/code-index/manager.ts:38

  • [nitpick] Always choosing the first workspace folder may not reflect the user's active context in multi-root VSCode setups. Consider making this selection strategy configurable or clearly documenting this behavior.
		const workspacePath = workspaceFolders[0].uri.fsPath

@hannesrudolph hannesrudolph moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 4, 2025
hannesrudolph and others added 2 commits July 6, 2025 12:13
…ions

- Remove optional workspaceRoot parameter and getWorkspacePath() fallback
- This prevents 'path should be a path.relative()d string' errors
- Since only the first workspace is indexed, explicit workspace parameter ensures consistency
- Update tests to reflect required parameter change
@daniel-lxs daniel-lxs force-pushed the fix/issue-4397-workspace-path-consistency branch from a584c40 to 0c7ff93 Compare July 6, 2025 17:13
- Use path.join() instead of hardcoded Unix paths
- Use path.sep for platform-specific separators
- Ensures tests work correctly on both Unix and Windows
- Use path.resolve() in test expectations to handle Windows drive letters
- Tests now correctly expect platform-specific absolute paths
- Fixes failing tests on Windows CI while maintaining Unix compatibility
- Add 'cause' option when throwing errors in scanner.ts to preserve original error context
- Move vi.mock declarations before imports in manager.spec.ts for proper hoisting
- Replace vitest.fn() and vitest.spyOn() with vi.fn() and vi.spyOn() for consistency
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Jul 6, 2025
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 6, 2025
@mrubens mrubens merged commit 7d31966 into main Jul 7, 2025
24 of 25 checks passed
@mrubens mrubens deleted the fix/issue-4397-workspace-path-consistency branch July 7, 2025 15:29
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 7, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer PR - Needs Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Error during codebase indexing about relative path

4 participants