Repository navigation
fix(paths): a project at a Windows drive root indexes its files - #2931
Merged
Merged
Conversation
A project at the root of a drive, such as a mapped network drive Z:\, a
subst drive or a UNC share root, indexed nothing on Windows: every file
was refused as "Path traversal blocked", and code reads under the root
were refused too. The containment check appended a separator to the root
before comparing, and a root such as C:\ already ends with one, so the
prefix became C:\\ and no path under the root matched. The dead code
report's default file reader had its own copy of the same check, so it
treated every file of such a project as unreadable.
The check now adds a separator only when the root doesn't already end
with one. The dead code reader uses the shared lexical containment check
instead of its own copy.
Validation on Windows 11:
- subst R: onto a two-file fixture, then codegraph init -y --force R:\:
main indexes 0 files ("all 2 files had errors", 2 "Path traversal
blocked"), and validatePathWithinRoot(R:\, a.ts) is null. The fix
indexes both files (6 nodes, 6 edges) and getCode returns both
functions' source. The mapping was removed after each run.
- Dead code report against one R:\ index: main's reader drops the unused
function as unreadable; the fix reports it.
- Tests: 3 new tests fail on main's source and pass with the fix: a file
under the filesystem root (this drive's root here, / on POSIX), path
math under Q:\ and \\server\share\, and read-only realpaths under C:\.
Reported in PR #415 by @Kamilslaoui93; this reimplements the fix
independently.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
On Windows, a project at the root of a drive indexed nothing: a mapped network drive like
Z:\, asubstdrive, or the root of a UNC share. Every file was refused asPath traversal blocked in batch reader,codegraph initreported "Indexing failed — all N files had errors", even with--force, and code reads under such a root were refused too.Root cause
isWithinDirinsrc/utils.tsdecides whether a path lies under a root withchild.startsWith(parent + path.sep). A root such asC:\(or\\server\share\, or POSIX/) already ends with its separator, so the prefix becameC:\\, and no path under the root matched. Both halves ofvalidatePathWithinRootuse it, so the indexing reader,getCodeand the viewer all refused every file.defaultSourceReaderinsrc/graph/dead-code.tshad its own copy of the same check, so the dead code report treated every file of such a project as unreadable.Fix
isSameOrUnder, which the sensitive-folder check from fix(security): the sensitive-folder guard refuses links, case variants and \\?\ paths #2929 already used, andisWithinDirkeeps its Windows case folding on top of it.lexicalPathWithinRootinstead of repeating the check.Validation
Windows 11. A two-file fixture is mapped with
subst R: <fixture>, and the mapping is removed after every run (substlists none afterwards).codegraph init -y --force R:\getCodeof both functionsvalidatePathWithinRoot('R:\\', 'a.ts')nullR:\a.tsR:\index (an unused, unexported function in an imported file)Tests (
security.test.ts, red→green by putting the two source files back to this PR's base):/on POSIX) is inside it;Q:\and\\server\share\; no drive or share is needed, and another drive or share is still outside;C:\:validatePathWithinRoot('C:\\', 'Windows'), and a missing path judged by its nearest existing ancestor, the drive root.All 3 fail on the base and pass with the fix.
Full suite: 760 files passed, 6 skipped; 9,057 tests passed, 0 failed, 85 skipped, with the kernel built (
CODEGRAPH_KERNEL_EXPECT=1) and the daemon allowed. It ran onfe007a8f, this change on5e0c42cb. After rebasing onto01873666(#2930, no overlap but CHANGELOG), I reransecurity.test.ts,dead-code.test.tsand #2930'sstatus-during-rebuild.test.tson the pushed commit: 100 passed, 4 skipped.Reported in #415 by @Kamilslaoui93; this reimplements the fix independently. Thanks to them for pinning down the exact root cause; the dead code reader and the tests that need no mapped drive are added here.
🤖 Generated with Claude Code