Repository navigation
fix: resolve calls through destructured CommonJS barrel requires - #5104
qq2514568380 wants to merge 1 commit into
Conversation
A destructured require that reaches a symbol through a barrel
(`const { SourceCode } = require('./index')`, where `index.js` re-exports
`SourceCode` from another module) left the symbol import edge on the
barrel. The barrel defines no node, so cross-file call resolution found no
import evidence and dropped the `calls` edge.
Keep the required target file and imported name on the structural require
edge, then follow the target's exports to the declaring symbol before
cross-file resolution runs. The keys are internal and removed from the
final graph.
Fixes Graphify-Labs#5034
|
Thanks for the pull request, @qq2514568380. 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.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.
Not checked: tests were not run; formal verification proved 0 of 2 changed function(s) (2 not verified).
Formal verification. PR-changed functions: 0/2 verified (0 proven, 0 may-equivalent, 0 distinguished) · 2 not verified (1 vacuous, 1 unsupported).
Not verified on this run: \_require\_imports\_js (vacuous: never exercised), \_apply\_symbol\_resolution\_facts (unsupported).
Graphify review — findings
Fixes constructor calls made through a destructured require of a CommonJS barrel, so new SourceCode() now resolves to the class in the module the barrel re-exports instead of dropping the calls edge. _require_imports_js stamps each require-derived imports edge with a private target file and imported name, and _apply_symbol_resolution_facts follows the barrel via resolve_exported_origin and retargets the edge to the declaring symbol. When no symbol facts exist, the early-return path strips the temporary keys, but those keys sit on edges that per-file extractors emit, so any path that skips the resolution pass could carry them into output. Adds a regression test covering the source.js / index.js / consumer.js case.
Worth a look
- Private
_require_*keys can leak into edges returned by per-file extractors —graphify/extractors/engine.py:4248· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 4161 functions depend on the 591 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract()— 1162 callers, 69 callees
Verification — 4161 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: 2184 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
64 of 533 test file(s) selected (12%) via static blast radius.
tests/test_4909_reference_binding_scale.py— impacttests/test_4992_ts_import_types.py— impacttests/test_astro_extraction.py— impacttests/test_build.py— impacttests/test_cjs_module_extension.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_csharp_partial_classes.py— impacttests/test_dotnet.py— impacttests/test_ejs_extractor.py— impacttests/test_ext_tagged_id_clash.py— impacttests/test_extract.py— impacttests/test_extract_php_closures.py— impacttests/test_forwarding_review_findings.py— impacttests/test_go_type_alias.py— impacttests/test_import_extension_resolution.py— impacttests/test_indirect_call_block_scoped_shadow.py— impacttests/test_indirect_dispatch.py— impacttests/test_indirect_dispatch_assign_return.py— impacttests/test_indirect_dispatch_getattr.py— impacttests/test_java_member_calls.py— impacttests/test_js_cjs_barrel_require_call.py— changed-testtests/test_js_exported_scalar_bindings.py— impacttests/test_js_member_collisions.py— impacttests/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_php_unparsed_casts.py— impacttests/test_pr10_resolution_overrides.py— impacttests/test_python_import_resolution.py— impacttests/test_python_inherited_method_calls.py— impacttests/test_python_injected_factory_calls.py— impacttests/test_python_member_call_language_gate.py— impacttests/test_python_parse_memoization.py— impacttests/test_python_property_reads.py— impacttests/test_python_pytest_fixture_receivers.py— impacttests/test_python_underscore_resolution.py— impacttests/test_rationale.py— impacttests/test_resolution_one_parse_per_file.py— impacttests/test_resolve_memoization.py— impacttests/test_ruby_resolution.py— impacttests/test_scala_context_bounds.py— impacttests/test_scala_extension_methods.py— impacttests/test_scala_given_instances.py— impacttests/test_scala_self_type.py— impact- … and 14 more
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
Could not verify: Could not verify \_require\_imports\_js.
The verifier did not have enough to check \_require\_imports\_js, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 264 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)
Could not verify: Could not verify \_apply\_symbol\_resolution\_facts.
The verifier did not have enough to check \_apply\_symbol\_resolution\_facts, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: no capturable inputs from the test suite; property tier: parameter `facts` is annotated `_SymbolResolutionFacts` — outside the synthesizable primitive/collection set
· 1 more finding(s) on lines outside this diff (see the check run).
5d64203 to
689e18a
Compare
|
Landed on |
Summary
Fixes #5034: a constructor reached through a destructured require of a CommonJS barrel now resolves to the class the barrel re-exports.
Root cause
const { SourceCode } = require('./index')emits a structural symbol-levelimportsedge from the consumer to the barrel (index.SourceCode).index.jsonly re-exports the class:The barrel defines no node, so the edge target dangles. Cross-file call resolution matched the class by name but found no import evidence pointing at the declaring file, and dropped the
callsedge. The direct-require case already worked because its edge points at the class node.Fix
graphify/extractors/engine.py: keep the required target file and imported name on the structural symbol-level require edge as internal keys.graphify/extractors/resolution.py: before cross-file resolution, follow the target module's export facts with the existingresolve_exported_origin()and point the edge at the declaring symbol. The internal keys are removed from every edge, sograph.jsonis unchanged in shape.The change is limited to destructured
requiresymbol edges; whole-module requires already carrySymbolImportFacts and are untouched.Regression test
tests/test_js_cjs_barrel_require_call.pybuilds the three-file reproduction from the issue and assertscreate() -> SourceCodewith the target insource.js.calls == [].The full suite on this Windows host reports 9954 passed, 194 failed. The failures are the existing Windows/hook/wiki/install group; the only
test_extract.pyfailure (test_python_external_calls_survive_real_incremental_context) reproduces on the unmodifiedv8baseline. No JS/TS resolution test fails, and no_require_*internal key survives into the extracted graph.AI disclosure
Implemented with Claude Code; the commit carries the
Co-Authored-Bymetadata requested inCONTRIBUTING.md.