fix: normalize path separators for import graph on Windows#2
Open
hamb3r wants to merge 1 commit intoMikeRecognex:mainfrom
Open
fix: normalize path separators for import graph on Windows#2hamb3r wants to merge 1 commit intoMikeRecognex:mainfrom
hamb3r wants to merge 1 commit intoMikeRecognex:mainfrom
Conversation
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.
Problem
On Windows,
os.path.relpath()returns paths with backslashes (src\myproject\core.py), but all import resolution methods (_resolve_python_import,_resolve_ts_import,_resolve_rust_import,_resolve_go_import,_resolve_csharp_import) normalize candidate paths to forward slashes before looking them up in theall_filesset.This means every lookup fails on Windows:
As a result,
import_graphandreverse_import_graphare always empty{}on Windows. This silently breaks:get_file_dependencies/get_file_dependentsMCP toolsget_change_impactanalysis (misses cross-file impact via imports)test_index_mcp_codebase_index_sourceCI runs on
ubuntu-latestwhereos.sepis/, so the bug was never caught.Root cause
Four calls to
os.path.relpath()inproject_indexer.pyproduce OS-native separators that become dict keys inProjectIndex.files. The import resolvers already normalize candidates to/, but the keys they search against still contain\on Windows.Fix
Append
.replace(os.sep, "/")to everyos.path.relpath()call inproject_indexer.py, so that file path keys are always forward-slash-normalized regardless of platform:index()main loopreindex_file()remove_file()_discover_files()This is a one-character-class fix (4 lines changed), zero new logic. All existing import resolvers already expect forward-slash paths, so they start working correctly with no further changes.
Test plan
TestImportGraph::test_python_import_resolutionTestImportGraph::test_reverse_import_graphTestImportGraph::test_typescript_relative_importTestIntegration::test_index_mcp_codebase_index_sourceruff check src/ tests/— all checks passedos.sepis already/, so.replace("/", "/")is a no-op)