Skip to content

fix: resolve calls through destructured CommonJS barrel requires - #5104

Closed
qq2514568380 wants to merge 1 commit into
Graphify-Labs:v8from
qq2514568380:fix/cjs-barrel-require-call
Closed

qq2514568380 wants to merge 1 commit into
Graphify-Labs:v8from
qq2514568380:fix/cjs-barrel-require-call

Conversation

@qq2514568380

@qq2514568380 qq2514568380 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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-level imports edge from the consumer to the barrel (index.SourceCode). index.js only re-exports the class:

const SourceCode = require('./source');
module.exports = { SourceCode };

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 calls edge. 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 existing resolve_exported_origin() and point the edge at the declaring symbol. The internal keys are removed from every edge, so graph.json is unchanged in shape.

The change is limited to destructured require symbol edges; whole-module requires already carry SymbolImportFacts and are untouched.

Regression test

tests/test_js_cjs_barrel_require_call.py builds the three-file reproduction from the issue and asserts create() -> SourceCode with the target in source.js.

  • Before the fix: fails with calls == [].
  • After the fix: passes.
uv run pytest tests/test_js_cjs_barrel_require_call.py ... (10 JS/TS resolution files)  # 215 passed
uv run ruff check <changed files>                                                     # passed

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.py failure (test_python_external_calls_survive_real_incremental_context) reproduces on the unmodified v8 baseline. 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-By metadata requested in CONTRIBUTING.md.


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

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

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.

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

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 — impact
  • tests/test_4992_ts_import_types.py — impact
  • tests/test_astro_extraction.py — impact
  • tests/test_build.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_ejs_extractor.py — impact
  • tests/test_ext_tagged_id_clash.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_php_closures.py — impact
  • tests/test_forwarding_review_findings.py — impact
  • tests/test_go_type_alias.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_indirect_call_block_scoped_shadow.py — impact
  • tests/test_indirect_dispatch.py — impact
  • tests/test_indirect_dispatch_assign_return.py — impact
  • tests/test_indirect_dispatch_getattr.py — impact
  • tests/test_java_member_calls.py — impact
  • tests/test_js_cjs_barrel_require_call.py — changed-test
  • tests/test_js_exported_scalar_bindings.py — impact
  • tests/test_js_member_collisions.py — impact
  • 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_php_unparsed_casts.py — impact
  • tests/test_pr10_resolution_overrides.py — impact
  • tests/test_python_import_resolution.py — impact
  • tests/test_python_inherited_method_calls.py — impact
  • tests/test_python_injected_factory_calls.py — impact
  • tests/test_python_member_call_language_gate.py — impact
  • tests/test_python_parse_memoization.py — impact
  • tests/test_python_property_reads.py — impact
  • tests/test_python_pytest_fixture_receivers.py — impact
  • tests/test_python_underscore_resolution.py — impact
  • tests/test_rationale.py — impact
  • tests/test_resolution_one_parse_per_file.py — impact
  • tests/test_resolve_memoization.py — impact
  • tests/test_ruby_resolution.py — impact
  • tests/test_scala_context_bounds.py — impact
  • tests/test_scala_extension_methods.py — impact
  • tests/test_scala_given_instances.py — impact
  • tests/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).

@qq2514568380
qq2514568380 force-pushed the fix/cjs-barrel-require-call branch from 5d64203 to 689e18a Compare November 9, 2026 07:30
@safishamsi

Copy link
Copy Markdown
Member

Landed on v8 and shipped in 0.9.105 (now on PyPI). I cherry-picked your commit with -x so it keeps your authorship. Thanks for resolving calls through destructured CommonJS barrel requires (#5034), @qq2514568380.

@safishamsi safishamsi closed this Nov 9, 2026
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.

CommonJS: destructured require through a barrel loses constructor calls

2 participants