Repository navigation
fix(extract): strip query/fragment from relative JS imports - #4869
mirzasnowy wants to merge 1 commit into
Conversation
Relative JS imports with a Vite-style query string or fragment (`./foo.js?v=134`, `./foo.js#section`) resolved to the literal suffixed path, which does not exist on disk, so the import-target layer minted a phantom node instead of the real file. Strip the suffix for relative specifiers before resolution, mirroring the markdown link resolver. `#`-subpath imports, bare specifiers, aliases, and workspace packages are untouched. Fixes Graphify-Labs#4860.
|
Thanks for the pull request, @mirzasnowy. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.
Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 sampled, not proven).
Formal verification. PR-changed functions: 1/1 verified (0 proven, 1 may-equivalent, 0 distinguished) · 0 not verified.
Graphify review — findings
Strips ?query and #fragment suffixes from relative JS/TS import specifiers before resolving them, so ./lib/foo.js?v=134 lands on the real lib/foo.js node instead of minting a phantom ..._lib_foo_js_v_134 node. The strip runs before the .js → .ts remap and directory/index lookup, so those still work. It applies only to specifiers starting with .: bare specifiers like lodash?v=1 stay external, and #services/foo Node subpath imports keep resolving through package.json imports untouched. Adds tests covering the query/fragment shapes, the exclusions, and an end-to-end check that no phantom node ids are produced.
No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 3297 functions depend on the 192 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 1055 callers, 62 callees - worse:
_resolve_js_module_path()— 43 callers, 10 callees - worse:
_resolve_js_import_target()— 14 callers, 3 callees
Verification — 3297 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 1300 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
35 of 470 test file(s) selected (7%) via static blast radius.
tests/test_astro_extraction.py— impacttests/test_build.py— impacttests/test_cjs_module_extension.py— impacttests/test_ejs_extractor.py— impacttests/test_ext_tagged_id_clash.py— impacttests/test_extract.py— impacttests/test_forwarding_review_findings.py— impacttests/test_import_extension_resolution.py— impacttests/test_indirect_call_block_scoped_shadow.py— impacttests/test_js_exported_scalar_bindings.py— impacttests/test_js_member_collisions.py— impacttests/test_js_query_fragment_imports.py— impact, changed-testtests/test_js_walk_order.py— impacttests/test_language_override_imports.py— impacttests/test_languages.py— impacttests/test_loose_sibling_import_resolution.py— impacttests/test_multilang.py— impacttests/test_package_json_subpath_imports.py— impacttests/test_pascal.py— impacttests/test_pascal_resolution.py— impacttests/test_phantom_external_import.py— impacttests/test_pr10_resolution_overrides.py— impacttests/test_python_import_resolution.py— impacttests/test_python_member_call_language_gate.py— impacttests/test_python_parse_memoization.py— impacttests/test_rationale.py— impacttests/test_resolve_memoization.py— impacttests/test_source_key_memoization.py— impacttests/test_src_layout_import_resolution.py— impacttests/test_svelte_extraction.py— impacttests/test_ts_new_expression_calls.py— impacttests/test_typescript_module_extensions.py— impacttests/test_unmapped_at_alias_resolution.py— impacttests/test_vue_extraction.py— impacttests/test_walk_python_tree_iterative.py— impact
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Formal verification
No difference found (not proven): No behavior difference found in \_resolve\_js\_module\_path (not a proof).
The verifier ran both versions of \_resolve\_js\_module\_path on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.
Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.
Note: An input the sampler did not try could still differ.
· 1 grounded finding(s) anchored inline below; 2 more finding(s) on lines outside this diff (see the check run).
| return raw.split("#", 1)[0].split("?", 1)[0] | ||
|
|
||
|
|
||
| def _resolve_js_module_path(raw: str | Path, start_dir: Path | None = None) -> Path | None: |
There was a problem hiding this comment.
_resolve_js_module_path()
fans out to 10 callees (efferent coupling); 43 callers depend on it (afferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
… js imports, extractors, serve/export/pdf) 13 PRs folded into the unreleased 0.9.98; dups #4869/#4852/#4871 to close at release. One combined _AST_CACHE_SCHEMA bump (29->30) covers the output-changing extractors and the file/declaration id change. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
The ?query/#fragment import fix shipped in v0.9.98 via #4876, which carries the same one-line core change plus an e2e no-phantom test. Closing as a duplicate; thanks for the thorough edge-case tests, @mirzasnowy (some were borrowed into the landed test file). |
|
If this was a duplicate, nothing needed borrowing. If some of my tests were borrowed into the landed file, then my work shipped without attribution |
What does this PR do?
Fixes #4860. Relative JS/TS imports with a Vite-style query string or fragment (
./foo.js?v=134,./foo.js#section) resolved to the literal suffixed path, which does not exist on disk, so the import-target layer minted a phantom node instead of the real file, losing symbol imports and cross-filecallsedges.The fix strips the
?query/#fragmentsuffix from relative specifiers in_resolve_js_module_pathbefore resolution, mirroring the markdown link resolver (same split order, so./foo.js?v=134#sand./foo.js#s?v=1both collapse to./foo.js).#-subpath imports, bare specifiers, tsconfig aliases, and workspace packages are untouched, and the stripped specifier resolves to the byte-identical path as the plain specifier, so it shares the same cache entry and node id (no phantom).Documented limitation: a query/fragment on a tsconfig alias or
@/-prefixed specifier is not stripped. Such specifiers never resolved before either, so nothing regresses; extending the strip there would need an alias-layer decision and is left for a follow-up. No skill fragments were changed, so no skillgen regen applies.Type of change
Verification & Invariants
How was this tested?
Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments.I have reviewed every line of this diff.