Repository navigation
fix(javascript): require exact loader suffix case - #9428
ShuaixinHuang wants to merge 25 commits into
Conversation
…58-loader-origin-fix # Conflicts: # src/application/javascript/JavaScriptArtifactGraphBuilder.ts
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@morluto This PR addresses: fix(javascript): require exact loader suffix case. I have reviewed the final diff and validation evidence and am submitting it for review. |
|
Issue opened for tracking: #9446 |
[Medium impact] The PR changes JavaScript analysis across module, effect, and Electron graph results. Fix the wrapped loader-call check before merging. Findings
Fix with agent prompt### Issue 1
src/domain/javascript/javascriptStaticAnalysisCalls.ts:90-96
The new `call`/`apply` check reads `node.callee` before removing TypeScript wrappers. In a `.cts` file, `require.call = () => 0; (require.call as any)(null, "./dep.cjs");` therefore skips the member checks and calls `requireCallSpecifier` without `index`. The shared reader then maps the arguments as a genuine CommonJS call and reports `./dep.cjs` as a resolvable dependency, although the replacement loads nothing.
Normalize the callee before deciding whether member checks are needed, or move that decision into the shared call owner.
### Issue 2
src/domain/javascript/javascriptSemanticRequireOrigin.ts:852-855
In an unknown-host file, `const load = require; load("./dep.cjs")` now loses the literal dependency name. The candidate marker is added only when the callable is literally named `require`. The alias goes through `selectedRequireSourcesAt`, which returns an unknown loader without that marker. `requireCallSpecifier` then emits a null specifier instead of the candidate request.
Carry candidate authority through the shared loader-selection result rather than recovering it from the callee’s spelling.
### Issue 3
src/domain/javascript/javascriptSemanticRequireOrigin.ts:748-754
The new member check also rejects writes below the selected callable. For example, `require.resolve.paths = custom; require.resolve("./dep.cjs")` changes a helper property, not `require.resolve` itself. The overlap query includes that child write, so this branch marks the resolver unproved and the static reference loses its literal request. Adding a property to `require.call` likewise discards the mapped load arguments.
Distinguish writes that can replace the callable from writes to its unrelated properties.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryThe PR makes loader suffix checks case-sensitive and carries uncertain loader identity through references, Electron findings, worker transfer, and graph output.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A["Source and exact suffix"] --> B["Shared loader facts"]
B --> C{"Loader proved?"}
C -- Yes --> D["Resolve relationships"]
C -- No --> E["Keep candidates and limitations"]
D --> F["Application and semantic graphs"]
E --> F
Reviews (2) · Last reviewed commit: "Merge commit 'e47bb152c2ee64d4b082792678..." · Reviewed by Greptile |
|
Thank you, @ShuaixinHuang, for investigating the loader suffix and contributing the implementation. We are continuing this in #9477, which retains your original commits and attribution and addresses the three review findings. I am closing this PR as superseded; the replacement remains a draft while we investigate a related conservative receiver-escape limitation and finish reviewing the inherited diff and CI. |
Summary
Fixes #8973. An uppercase
.MJSentrypoint could be reported as an ES module solely because its filename was case-folded. Removing that inference also exposed an existing fallback that claimed a CommonJS wrapper and resolvedrequireeven when the loader was unknown.Use one exact-case loader-suffix owner across parsing, module resolution and format projection. Preserve literal
requireand CommonJS export observations as candidates when wrapper authority is unknown; do not resolve those relationships, claim a module format, or claim proven Electron/native API identity from an unproved loader. Candidate authority survives alias provenance, deduplication, worker transfer, static references and graph Evidence. Conditional Node builtin effects and Electron windows, protocols, IPC, call paths and renderer destinations retain their observations and limitations without being promoted to proven identities or matched to proven IPC endpoints. Explicit CommonJS, ESM, createRequire and bundler-loader facts retain their existing roles.This is a static analysis correction within existing authority; no new target execution or provider capability. No CLI/MCP operation names or input schemas change. Static-reference and graph outputs gain a candidate authority marker and limitation where required.
Review follow-up: pathless provenance fixtures had asserted a proven CommonJS loader without supplying host context. Tests that require that proof now establish it explicitly, while separate unknown-host controls retain candidate behavior. The acceptance tests check structured authority, confidence, and resolution facts instead of freezing limitation sentences. Full CI on the updated head remains pending.
Review follow-up also corrects shared boundaries: Electron identity checks now respect initialization order for proven and candidate bindings; semantic-query paths retain candidate authority and Evidence limitations; symbolic property reads propagate selection guards once, preventing exponential growth; conditional builtin effects mark associated callable fingerprints partial; and shared loader invocation and mutation facts inspect each nested
callorapplymember and withhold unmapped arguments when identity is uncertain.A replaced global process object followed by a write to the new object can conservatively downgrade an older captured namespace snapshot; the evidence remains conditional.
Validation
After merging main at
fc98a0653c: 45 graph/Electron source tests, 30 real CLI/MCP acceptance tests, typecheck and build passed. The conflict resolution retained both candidate-identity handling and main’s empty-Electron-coverage reporting. Fresh CI is pending.On the original [Bug] JavaScript analysis treats uppercase loader suffixes as explicit module modes #8973 fixture, the new CLI and stdio-MCP assertions fail on the prior PR head (
module_formatwascommonjs) and pass after the fix. A Node 24.22.1 control executes the fixture and prints42; this is a control, not a claim REA executed the target.After merging main
ac30fbd6,npm run build:cached,npm run check:fastandnpm run format:checkpassed on Node 24.22.1; 22 focused tests passed across CLI help annotations, bundler runtime scopes, and CLI/stdio-MCP unbound loader workflows.Before the final CI follow-up, the complete
unboundRequires.test.ts,electronDynamicIpcHandlersCli.test.tsandjavascriptGraphQueryCoverage.test.tspublic acceptance suites passed 30 tests, covering CLI and real stdio MCP, package/preload controls, conditional require and export edges, renderer paths, mixed IPC authority, and shadowed or mutated loaders.On the earlier follow-up, 43 affected JavaScript domain and worker-schema files passed 1,712 tests. They cover provenance, alias/wrapper mutation, Electron and native identities, worker transfer, optional calls and proven CommonJS controls; unknown-host tests preserve conditional findings and classic-script semantics.
After the CI follow-up, a bounded JavaScript domain and application run passed 5,753 tests across 206 files, including all 13 previously failing source files. Four CLI/MCP boundary and acceptance files passed 43 tests, including all three previously failing shard files and conditional builtin controls. The CLI and stdio MCP loader suite passed 11 tests, including nested mutated loader controls. The wrapped Electron call-path and renderer endpoint boundary suites passed 29 tests, including CLI and stdio MCP unknown-host controls. The bundler runtime scope boundary suite passed 10 tests, with explicit CommonJS controls and an unknown-host candidate control across colliding runtimes.
Before the final renderer-path follow-up, a bounded completed CLI analysis of an adapted Electron conformance fixture produced 232,236 baseline versus 238,913 candidate cl100k tokens (+2.9%); first/repeat wall times were 0.940/0.949 s versus 0.921/0.927 s, CPU 1.108/1.131 s versus 1.125/1.145 s, and sampled process-family summed RSS peaks 425,728/420,656 KiB versus 420,128/415,168 KiB. Each run used a fresh process; OS cache was uncontrolled and 30 ms RSS sampling can miss peaks or double-count shared memory. This single small fixture does not establish a general performance trend.
Before the final invocation-ordering adjustment, a bounded run of the same adapted six-file fixture compared
b4a5d68with the follow-up: first/repeat wall time 1.014/0.996 s versus 0.884/0.935 s, CPU 1.351/1.298 s versus 1.094/1.094 s, and sampled summed RSS 432,752/422,416 KiB versus 418,704/416,768 KiB. Output rose from 238,913 to 241,889 cl100k tokens (+1.25%) as conditional evidence was retained. The same sampling and cache limitations apply; this small fixture does not establish a general performance trend.A candidate native re-export regression passes; removing its receiver-authority guard makes it fail by reporting a false re-export.
git diff --check origin/main— passed. Full CI, Windows and real external applications were not run locally. The original published PR head's hosted checks do not qualify this follow-up; CI must run on the updated head.Author readiness
Human owner: @ShuaixinHuang