Skip to content

fix(extract): default the AST cache location to CWD, not the analyzed source tree (#1774)#1802

Open
SimiSips wants to merge 1 commit into
Graphify-Labs:v8from
SimiSips:fix/extract-cache-root-default-1774
Open

fix(extract): default the AST cache location to CWD, not the analyzed source tree (#1774)#1802
SimiSips wants to merge 1 commit into
Graphify-Labs:v8from
SimiSips:fix/extract-cache-root-default-1774

Conversation

@SimiSips

Copy link
Copy Markdown

Fixes #1774.

Problem

extract() called without cache_root derives 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 creates graphify-out/cache/ inside that corpus, defeating output isolation via CWD. Reproduced on current v8 (0.9.13). The CLI and watcher are unaffected — they already pass cache_root explicitly (added in 01fb51b for #350) — so this only bites library callers and python -m graphify.extract.

Fix

One line: effective_root (the cache location) now defaults to Path('.') when cache_root is None, matching cache_dir()'s own default. An explicit cache_root still wins.

Deliberately not the patch suggested in the issue (defaulting root itself to CWD): root also 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.
  • Cache entries for out-of-root files keep absolute source_file paths — an already-handled pass-through in _relativize_source_files_in / _absolutize_source_files_in.

Tests

  • New 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; explicit cache_root still wins.
  • Full suite: uv run pytest tests/ -q3162 passed, 3 skipped on macOS (Python 3.12).

… 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extract() writes AST cache into the analyzed source tree, bypassing CWD (pollutes read-only corpora)

1 participant