Fix: Stop recursion at workspace folder boundary to prevent root folder error #669
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The extension throws a fatal error when discovering test files in workspaces with deeply nested directory structures:
This occurs in monorepo structures and projects with many nested folders (like the BlockNote repository), where the extension attempts to create test items for files deep within the workspace hierarchy.
Root Cause
The
getOrCreateFolderTestItem
method recursively creates parent folder test items to build the folder hierarchy in the test explorer. However, it lacked a workspace folder boundary check, causing the recursion to continue beyond the workspace folder all the way to the filesystem root/
. When it reaches the root,dirname("/")
returns"/"
itself, triggering the error condition.Example flow in a monorepo:
Solution
Added a workspace folder boundary check in
getOrCreateFolderTestItem
that stops recursion when it reaches the workspace folder. The method now:This ensures folder item creation stops at the workspace boundary rather than continuing to the filesystem root.
Changes
Testing
✅ TypeScript compilation passes
✅ ESLint passes
✅ Build succeeds
✅ Logic verified for edge cases:
Impact
This fix resolves crashes when working with:
Fixes #XXX (replace with issue number)
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
update.code.visualstudio.com
node /home/REDACTED/work/vscode/vscode/node_modules/.bin/../@vscode/test-cli/out/bin.mjs
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>Error: Attempted to get parent of root folder "/"</issue_title>
<issue_description>### Describe the bug
I keep getting failures of it looking up directories when starting the vitest extension in VS Code.
Reproduction
https://github.com/TypeCellOS/BlockNote/
Output