fix(extract): default the AST cache location to CWD, not the analyzed source tree (#1774)#1802
Open
SimiSips wants to merge 1 commit into
Open
Conversation
… source tree (Graphify-Labs#1774) extract() without cache_root derived the cache root from the inferred common parent of the input files, so analyzing a corpus outside CWD silently created graphify-out/cache/ inside the analyzed source tree (read-only corpora, other people's checkouts). The cache is an output: effective_root now defaults to Path('.'), matching cache_dir()'s own default. The inferred root still anchors node ids and symbol resolution unchanged, and an explicit cache_root still wins (CLI/watch behavior is untouched — they already pass it).
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.
Fixes #1774.
Problem
extract()called withoutcache_rootderives the cache root from the inferred common parent of the input files — i.e. the analyzed source tree. Analyzing a corpus outside CWD (a read-only knowledge base, someone else's checkout) silently createsgraphify-out/cache/inside that corpus, defeating output isolation via CWD. Reproduced on currentv8(0.9.13). The CLI and watcher are unaffected — they already passcache_rootexplicitly (added in 01fb51b for #350) — so this only bites library callers andpython -m graphify.extract.Fix
One line:
effective_root(the cache location) now defaults toPath('.')whencache_rootisNone, matchingcache_dir()'s own default. An explicitcache_rootstill wins.Deliberately not the patch suggested in the issue (defaulting
rootitself to CWD):rootalso anchors node-id relativization (path.relative_to(root)) and_augment_symbol_resolution_edges(), and pointing it at CWD would degrade ids for corpora outside CWD. Only the cache side changes; id/symbol anchoring is untouched.Notes
file_hash()keys include the path relative to the cache root, so existing source-tree caches of library callers go cold once and re-extract (CLI/watch caches are unaffected). No correctness impact.source_filepaths — an already-handled pass-through in_relativize_source_files_in/_absolutize_source_files_in.Tests
tests/test_extract_cache_location.py: default cache lands in CWD and the corpus stays untouched; the CWD cache round-trips on a second run; explicitcache_rootstill wins.uv run pytest tests/ -q— 3162 passed, 3 skipped on macOS (Python 3.12).