Repository navigation
Conversation
…-Labs#5731) Only `const x = require('./m')` (and `require('./m').y`) produced an `imports_from` edge. The same call as an array element, a call argument, an object value, an assignment, a bare statement or a return value gave no edge, so rule/plugin registries such as `const rules = [require('./b.cjs')]` lost their dependencies in `path` and `affected`. The edge construction moves out of `_require_imports_js` into `_js_require_import_edge`, shared with two new call sites: the module-level JS scan (edge from the file) and `walk_calls` (edge from the enclosing callable, as for a declared require in a body). `_js_free_require_call` skips the declarator form so it still gets one edge. A computed specifier, `require.resolve()` and `obj.require()` give no edge. Tests: tests/test_js_require_in_expression.py; the three bug cases fail without this change, the two guards pass both ways. Co-Authored-By: Claude Opus 5.5
There was a problem hiding this comment.
Graphify review 
1 bug · High impact
The change factors literal require() edge creation into a helper and adds extraction for calls outside variable declarations.
Shadowed
require calls create false import edges · engine.py:6709
What this review covered
- We didn't review 1 file that isn't source code, such as docs, config, images, or generated or third-party code.
- 2 of 2 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 5056 functions depend on this change
- 693 of 693 test files are affected by this change.
- Gate, test list and every flagged function: in the Graphify check.
Reviewed 4f66c6d
| if node.type != "call_expression": | ||
| return False | ||
| fn = node.child_by_field_name("function") | ||
| if fn is None or fn.type != "identifier" or _read_text(fn, source) != "require": |
There was a problem hiding this comment.
Shadowed
require calls create false import edges
A function that uses its own require parameter can be shown as importing a local file it never loads.
Check that require resolves to the CommonJS loader before emitting edges in _js_free_require_call and declaration-form handling.
Evidence · checked against the code
Expected: Only calls to the CommonJS loader should create an imports_from edge.
Actually: The extractor treats the bare identifier spelling require as sufficient and emits an edge without checking which binding the call resolves to.
- Independent source review: The test covers
obj.require(...)and verifies that it adds no edge, but this only rules out member-expression callees. It does not guard a bare identifier shadowed by a parameter or local binding. The other tests exercise unshadowed barerequirecalls, so they do not refute the reported false edge. - The added tests cover
obj.require(...)but do not cover a barerequireidentifier shadowed by a parameter or local binding.
Prompt to fix with AI
In graphify/extractors/engine.py, _js_free_require_call (lines 6706-6709):
Problem: Shadowed `require` calls create false import edges
Expected: Only calls to the CommonJS loader should create an `imports_from` edge.
Actually: The extractor treats the bare identifier spelling `require` as sufficient and emits an edge without checking which binding the call resolves to.
Fix it at the cause, and add a test that fails without the fix.
Graphify · Checked against the code · View in Graphify
What does this PR do?
Fixes #5731.
Only
const x = require('./m')(andrequire('./m').y) produced animports_fromedge. Any other position gave nothing. On currentv8:After this change each of these gets an
imports_fromedge (EXTRACTED, same shape as the declared form).How:
extractors/engine.py:_require_imports_jsinto_js_require_import_edge, unchanged, so all forms build the same edge (unresolved specifiers keep theref:id,target_fileset when resolved)._js_free_require_callmatches arequire(...)call with an identifier callee that is not a declarator's value (the form_require_imports_jsalready handles), so that form still gets exactly one edge._scan_js_module_dispatch, which already stops at function and class boundaries) emits the edge from the file node.walk_callsemits it from the enclosing callable, the same attribution a declaredrequirein a body already gets.ARCHITECTURE.md: a short paragraph documenting the rule.Type of change
Verification & Invariants
Invariant: a
require('<string literal>')call is an import of that module wherever the call appears, and only a literal specifier creates one.Bug cases (fail before, pass after):
requirein an array literal (the issue's case);require(...).xon that side;requirereturned from a function, attributed to the function.Guards (pass before and after):
const a = require(),require().x, and a declaredrequirein a function) still give exactly one edge each;require(name)),require.resolve('./a')andobj.require('./a')give no edge.Limitations:
require(a parameter or function namedrequire) is not detected; the call is still read as CommonJSrequire.requireonly gets an edge where the existing passes already walk: module level, and function bodieswalk_callsvisits. Template-literal specifiers stay unsupported, as in the declared form.requires it, the build already collapses the two into one edge and keeps the other location inalso_seen; the primarysource_locationcan now be therequireline. No edge is lost (checked on mem0 below).Cache: the JS/TS extractor output changes (new edges), so it needs an AST cache schema bump. I've left that to the maintainers' release step, as with other extractor changes.
How was this tested?
Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (n/a)