-
-
Notifications
You must be signed in to change notification settings - Fork 11.5k
fix(resolution): decouple the JS/TS family from the AST-cache-bypass set (#3326) #3537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abhay-codes07
wants to merge
1
commit into
Graphify-Labs:v8
Choose a base branch
from
abhay-codes07:fix/decouple-js-family-from-cache-bypass
base: v8
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+80
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
|
|
||
| from typing import Any, Callable | ||
| from pathlib import Path | ||
| from graphify.extractors.models import LanguageConfig, _JS_CACHE_BYPASS_SUFFIXES, _NamespaceExportFact, _StarExportFact, _SymbolAliasFact, _SymbolDeclarationFact, _SymbolExportFact, _SymbolImportFact, _SymbolResolutionFacts, _SymbolUseFact, _WORKSPACE_PACKAGE_CACHE # noqa: E402,F401 | ||
| from graphify.extractors.models import LanguageConfig, _JS_FAMILY_SUFFIXES, _NamespaceExportFact, _StarExportFact, _SymbolAliasFact, _SymbolDeclarationFact, _SymbolExportFact, _SymbolImportFact, _SymbolResolutionFacts, _SymbolUseFact, _WORKSPACE_PACKAGE_CACHE # noqa: E402,F401 | ||
| from graphify.extractors.base import ( # noqa: F401 | ||
| _LANGUAGE_BUILTIN_GLOBALS, | ||
| _file_stem, | ||
|
|
@@ -1891,7 +1891,7 @@ def _ts_walk_class_members(class_node, source: bytes, path: Path, class_nid: str | |
| def _collect_js_symbol_resolution_facts(paths: list[Path], facts: _SymbolResolutionFacts) -> None: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
fans out to 26 callees (efferent coupling). Grounded coupling-delta finding (deterministic), not an LLM guess. |
||
| js_paths = [ | ||
| path for path in paths | ||
| if path.suffix in _JS_CACHE_BYPASS_SUFFIXES | ||
| if path.suffix in _JS_FAMILY_SUFFIXES | ||
| ] | ||
| if not js_paths: | ||
| return | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """The JS/TS language family is decoupled from the AST-cache bypass set (#3326). | ||
|
|
||
| `_collect_js_symbol_resolution_facts` used to pick which files go through JS/TS | ||
| cross-file resolution by testing membership in `_JS_CACHE_BYPASS_SUFFIXES` — a | ||
| cache-policy constant. So a change made for caching reasons silently changed | ||
| which files produced INFERRED edges, invisible from either call site. The | ||
| resolution filter now keys on `_JS_FAMILY_SUFFIXES` (a language-membership | ||
| fact); the two are independent objects. | ||
| """ | ||
|
|
||
| import graphify.extractors.models as models | ||
| import graphify.extractors.resolution as resolution | ||
| from graphify.extract import extract | ||
|
|
||
|
|
||
| def test_family_and_cache_bypass_are_distinct_objects(): | ||
| fam = models._JS_FAMILY_SUFFIXES | ||
| cache = models._JS_CACHE_BYPASS_SUFFIXES | ||
| assert fam is not cache, "the two sets must be independent, not the same object" | ||
| # They coincide in value today, but mutating one must not touch the other. | ||
| probe = ".decoupling-probe" | ||
| cache_copy = set(cache) | ||
| try: | ||
| cache.add(probe) | ||
| assert probe not in fam, "mutating the cache set leaked into the family set" | ||
| finally: | ||
| cache.clear() | ||
| cache.update(cache_copy) | ||
|
|
||
|
|
||
| def test_resolution_filter_uses_the_family_constant(): | ||
| # Read the source, not __code__.co_names: the constant is referenced inside | ||
| # a list comprehension, whose names live in a separate code object on Python | ||
| # 3.10/3.11 (they were only inlined into the enclosing function in 3.12, | ||
| # PEP 709) — so a co_names check is Python-version-dependent. The source is | ||
| # not. | ||
| import inspect | ||
|
|
||
| src = inspect.getsource(resolution._collect_js_symbol_resolution_facts) | ||
| assert "_JS_FAMILY_SUFFIXES" in src, ( | ||
| "JS symbol resolution must select files by the language family" | ||
| ) | ||
| assert "_JS_CACHE_BYPASS_SUFFIXES" not in src, ( | ||
| "resolution must not gate on the cache-bypass policy constant" | ||
| ) | ||
|
|
||
|
|
||
| def test_ts_cross_file_resolution_still_works(tmp_path, monkeypatch): | ||
| """Behavior is unchanged: a .ts import call still resolves cross-file.""" | ||
| monkeypatch.chdir(tmp_path) | ||
| (tmp_path / "m.ts").write_text( | ||
| "export function foo() { return 1; }\n", encoding="utf-8") | ||
| (tmp_path / "u.ts").write_text( | ||
| "import { foo } from './m';\nexport function use() { return foo(); }\n", | ||
| encoding="utf-8") | ||
| r = extract(sorted(tmp_path.glob("*.ts")), cache_root=tmp_path) | ||
| labels = {n["id"]: n.get("label", "") for n in r["nodes"]} | ||
| calls = {(labels.get(e["source"], ""), labels.get(e["target"], "")) | ||
| for e in r["edges"] if e["relation"] == "calls"} | ||
| assert any("use" in s.lower() and t.rstrip("()") == "foo" for s, t in calls), calls | ||
|
|
||
|
|
||
| def test_family_contains_the_js_ts_suffixes(): | ||
| for suffix in (".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".vue", ".svelte"): | ||
| assert suffix in models._JS_FAMILY_SUFFIXES |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_collect_js_symbol_resolution_facts()fans out to 26 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.