Skip to content

Conversation

roomote[bot]
Copy link

@roomote roomote bot commented Sep 5, 2025

Summary

This PR fixes the issue where VSCode's terminal profile configuration may return path as an array instead of a string, causing the error "The 'path' argument must be of type string. Received an instance of Array".

Problem

As reported in #7695, the VSCode API may return profile.path as an array (e.g., ["C:\\Program Files\\PowerShell\\7\\pwsh.exe", "pwsh.exe"]) instead of a string. This causes the isShellAllowed function to fail since it expects a string parameter.

Solution

  1. Updated type definitions to reflect that path can be string | string[]
  2. Added normalizeShellPath helper to safely extract the first element from array paths
  3. Created validateShellPath export as a robust public API for shell validation that handles:
    • String paths (normal case)
    • Array paths from VSCode API (uses first element)
    • Null/undefined values
    • Empty arrays
    • Nested arrays (recursive handling)
    • Invalid types (safely rejects)
  4. Refactored internal validation into isShellAllowedInternal for cleaner separation
  5. Maintained backward compatibility with deprecated isShellAllowed function

Testing

  • Added comprehensive test suite with 22 test cases covering all edge cases
  • All existing tests pass without regression
  • Tests verify proper handling of arrays, strings, null values, and platform-specific behavior

Changes

  • src/utils/shell.ts: Enhanced shell validation with array support
  • src/utils/__tests__/shell.test.ts: Comprehensive test coverage

Fixes #7695


Important

Fixes handling of array paths in VSCode terminal profiles by normalizing paths and updating shell retrieval logic.

  • Behavior:
    • Fixes handling of path as string[] in VSCode terminal profiles, using first element if array.
    • Updates getShell() in shell.ts to handle array paths and fall back to defaults if necessary.
  • Functions:
    • Adds normalizeShellPath() to extract first element from array paths.
    • Refactors getWindowsShellFromVSCode(), getMacShellFromVSCode(), and getLinuxShellFromVSCode() to use normalizeShellPath().
  • Testing:
    • Adds tests in shell.spec.ts for array paths, empty arrays, and fallback scenarios.
    • Ensures getShell() handles all edge cases, including invalid and nested arrays.

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

- Updated terminal profile interfaces to support string | string[] for path property
- Added normalizeShellPath helper to safely extract first element from array paths
- Modified isShellAllowed to handle both string and array inputs
- Updated getWindowsShellFromVSCode, getMacShellFromVSCode, and getLinuxShellFromVSCode to use normalizeShellPath
- Added comprehensive tests for array path handling

Fixes #7695
- Created validateShellPath as a public API for shell path validation
- Refactored internal validation logic into isShellAllowedInternal
- Added comprehensive test coverage for all edge cases
- Maintains backward compatibility with deprecated isShellAllowed
- Handles arrays, strings, null, undefined, and nested arrays gracefully
@roomote roomote bot requested review from mrubens, cte and jr as code owners September 5, 2025 07:41
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. bug Something isn't working labels Sep 5, 2025
Copy link
Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Reviewing my own code again. It's like grading my own homework, except the teacher is also me.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 5, 2025
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Sep 5, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 5, 2025
@jr jr merged commit 2b53399 into main Sep 5, 2025
15 checks passed
@jr jr deleted the fix/handle-array-shell-paths branch September 5, 2025 18:41
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Sep 5, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 5, 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 Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. lgtm This PR has been approved by a maintainer 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.

The "path" argument must be of type string. Received an instance of Array
3 participants