Skip to content

fix(extract): strip query/fragment from relative JS imports - #4869

Closed
mirzasnowy wants to merge 1 commit into
Graphify-Labs:v8from
mirzasnowy:fix/4860-js-import-query-fragment
Closed

mirzasnowy wants to merge 1 commit into
Graphify-Labs:v8from
mirzasnowy:fix/4860-js-import-query-fragment

Conversation

@mirzasnowy

Copy link
Copy Markdown

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-file calls edges.

The fix strips the ?query / #fragment suffix from relative specifiers in _resolve_js_module_path before resolution, mirroring the markdown link resolver (same split order, so ./foo.js?v=134#s and ./foo.js#s?v=1 both 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

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

How was this tested?

PYTHONPATH=<clone> python r28_graphify4860_repro.py
# pristine: BUG REPRODUCED (query path does not exist on disk, phantom id)
# fixed: BUG NOT PRESENT (query path exists, same id as plain specifier)
PYTHONPATH=<clone> python -m pytest tests/test_js_query_fragment_imports.py -q
# 17 passed; on pristine code 13 failed / 4 passed (control + exclusions)
PYTHONPATH=<clone> python -m pytest tests/test_js_import_resolution.py tests/test_import_extension_resolution.py tests/test_phantom_external_import.py tests/test_resolve_memoization.py tests/test_jsconfig_baseurl.py tests/test_package_json_subpath_imports.py tests/test_unmapped_at_alias_resolution.py tests/test_astro_import_ids.py tests/test_pr10_resolution_overrides.py tests/test_language_resolvers.py tests/test_indirect_call_external_import_shadow.py tests/test_js_dynamic_imports.py tests/test_import_self_loops.py tests/test_imported_export_forwarding.py tests/test_cjs_module_extension.py tests/test_loose_sibling_import_resolution.py tests/test_src_layout_import_resolution.py tests/test_ts_import_require.py -q
# 263 passed, 12 failed; the 12 match pre-existing failures exactly (Python sibling-import, TSX-to-Python, Python layout), zero regressions
python -m ruff check graphify/extractors/resolution.py tests/test_js_query_fragment_imports.py
# All checks passed

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments.
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

I have reviewed every line of this diff.

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.
@github-actions

Copy link
Copy Markdown

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.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 — impact
  • tests/test_build.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_ejs_extractor.py — impact
  • tests/test_ext_tagged_id_clash.py — impact
  • tests/test_extract.py — impact
  • tests/test_forwarding_review_findings.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_indirect_call_block_scoped_shadow.py — impact
  • tests/test_js_exported_scalar_bindings.py — impact
  • tests/test_js_member_collisions.py — impact
  • tests/test_js_query_fragment_imports.py — impact, changed-test
  • tests/test_js_walk_order.py — impact
  • tests/test_language_override_imports.py — impact
  • tests/test_languages.py — impact
  • tests/test_loose_sibling_import_resolution.py — impact
  • tests/test_multilang.py — impact
  • tests/test_package_json_subpath_imports.py — impact
  • tests/test_pascal.py — impact
  • tests/test_pascal_resolution.py — impact
  • tests/test_phantom_external_import.py — impact
  • tests/test_pr10_resolution_overrides.py — impact
  • tests/test_python_import_resolution.py — impact
  • tests/test_python_member_call_language_gate.py — impact
  • tests/test_python_parse_memoization.py — impact
  • tests/test_rationale.py — impact
  • tests/test_resolve_memoization.py — impact
  • tests/test_source_key_memoization.py — impact
  • tests/test_src_layout_import_resolution.py — impact
  • tests/test_svelte_extraction.py — impact
  • tests/test_ts_new_expression_calls.py — impact
  • tests/test_typescript_module_extensions.py — impact
  • tests/test_unmapped_at_alias_resolution.py — impact
  • tests/test_vue_extraction.py — impact
  • tests/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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Health regression — _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.

safishamsi added a commit that referenced this pull request Oct 30, 2026
… 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]>
@safishamsi

Copy link
Copy Markdown
Member

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).

@safishamsi safishamsi closed this Oct 30, 2026
@mirzasnowy

Copy link
Copy Markdown
Author

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

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.

Relative JS imports with a query string (./foo.js?v=123) are not resolved

2 participants