Repository navigation
fix(javascript): retain runtime scope in bundled module relationships - #1577
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
I am independently reviewing the frozen head |
N0zoM1z0
left a comment
There was a problem hiding this comment.
Independent review of the final source head against current main 0d899783: the complete reviewed tree equals the source/main merge tree. All 26 affected tests across six files and eight static/documentation/architecture/discovery checks passed. Fresh compiled public CLI/pinned-SDK MCP checks passed for the original 411-byte reproduction, a 572-byte dual-runtime behavior control, a 161-byte same-runtime shared-chunk control and a corrected 356-byte NUL-key control. They preserve source bytes, complete same-version CLI/MCP results and Evidence IDs, text/structured parity and subsequent ping. Runtime entrypoints, requires and findings remain within their recovered factory ownership; same-runtime chunks still share modules. All 20 checks and both exact-source-head workflows are successful. This independently verifies static JavaScript on Linux; it does not establish live Electron/native-provider behavior.
|
TL;DR: This merged while I tested, as I tested main
On my four real inputs, nothing has a Webpack or Rspack chunk, so there was nothing to re-attribute. Your head gave the same app graph ID, semantic graph ID and Evidence SHA-256 as its parent on all four. Main gave other IDs on all four, because of main's own changes. The merge I saw no slowdown. For the launcher, the median of 3 was 44.1 s on the parent, 45.2 s on main and 43.6 s with the PR. The other three inputs are in the fold. Both changed test files pass on Node 22, 24 and 26 (11 tests), on the head and on the merge. Your new CLI test file fails on main in 3 of 7 cases: colliding IDs, reversed order, and Webpack with Rspack. The other 4 pass. Not run
Thanks, dakjdakd, for the clear repro and the test that covers delimiter strings. All variant casesEach row ran on the parent, main and the PR. "Own" means each runtime's entry, calls and requires land on its own modules.
Real inputs: IDs and run timeThe four real inputs. One is the Beyond All Reason launcher. Its code, spring-launcher, is MIT (LICENSE). Its Flathub build is GPL-2.0-or-later, as its metadata file says. One is a vendor chunk from Hermes Desktop (MIT, LICENSE). The other two are your 1,200-function file and the #1495 file with N = 2,000. None of the four has a Webpack or Rspack chunk push, and none yields a chunk node. On the 1,200 file and the Hermes chunk, main's other IDs trace to changed labels, such as Median of 3 runs on Node 24, in seconds. Load counts the programs that ran or waited for one of the box's 24 CPU threads. It is a one-minute average, read at the start of each run. It was 2.2 to 6.0, because I ran another test job on the box at the same time.
The runs were interleaved: parent, main, PR, input by input. The 3 runs of one input and tree differ by up to 7%. One Hermes parent run took 11.3 s, against 7.7 s and 7.8 s in the other two. I don't know why. App graph ID, semantic graph ID, Evidence SHA-256 (of the CLI JSON), first 8 to 14 characters:
Every run of one tree gave the same bytes (3 of 3). The merge FixturesThe issue repro, as one
CommandsPATH=$HOME/.local/opt/node24/bin:$PATH
git archive <sha> | tar -x -C <dir> # parent, PR head, main
npm ci && npm run build # fake HOME, HUSKY=0, Node 24
node scripts/rea.mjs analyze-javascript-application <dir> --artifact-format directory --json
node scripts/rea.mjs analyze-javascript-application app.asar --artifact-format asar --json
npm run test:focused -- tests/boundary/cli/javascriptBundlerRuntimeScopes.test.ts src/domain/javascript/javascriptStaticAnalysisModuleIndex.test.ts
npm run check:fastThe merge ran the same commands. Main also ran your new test file copied into its tree, with the same Raw outputTests, Node 22.23.1, 24.18.0 and 26.11.1, on the PR head: 2 files passed, 11 tests passed, on all three. Your new CLI test file on main (Node 24): On the parent
Issue repro on main, edges that matter: Issue repro on the PR: Test setup
🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
Merged as |
Summary
Fixes #1576.
Preserve a recovered factory's runtime from static parsing through application graph projection. Previously, two Webpack/Rspack runtimes in the same asset could reuse module IDs and cause one runtime's entrypoint, dependencies and behavior to attach to the other's factories. This change makes module ownership resolve through
(asset path, runtime, module ID)and uses collision-free tuple encoding for module and chunk lookups.The public graph already distinguishes module identities by runtime namespace. This PR makes lookup and finding ownership consistent with those identities, while retaining shared module resolution across chunks of the same runtime.
Problem and expected behavior
Consider two registrations in
bundle.js, one namedwebpackChunkAppAand another namedwebpackChunkAppB. Both define module1, which requires module2and calls a different endpoint. The graph creates four distinct module nodes, but the lookup used to connect them previously stored only the asset path and module ID. Registering AppB overwrote AppA's entries.The observable contradiction was an AppA entry edge with
runtime: "webpackChunkAppA"andresolution_status: "resolved"pointing at a node with namespacewebpackChunkAppB:module. The call to/aretained its AppA source range but originated at AppB module1. Both require operations could resolve through AppB's1and2factories. Successful graph construction andcompletecoverage did not disclose this incorrect attribution.The expected invariant is straightforward: every bundled finding belongs to its recovered factory's runtime, and a runtime's entry or require lookup may select only that runtime's modules. Registrations in different chunks of the same runtime still share their module namespace. Registration order must not change this meaning.
The identity tuple also needs an unambiguous encoding. A runtime string ending in
\0xand a module string beginning withx\0can collide if variable-length fields are joined with NUL. The added regression includes those strings and analogous chunk keys, so runtime separation covers the actual source-string domain rather than only conventional identifier spellings.Change and scope
The change starts at the producer instead of recovering ownership from graph labels later, following the existing architecture ownership rules and behavioral testing guidance.
javascriptStaticAnalysisState.tsadds runtime toJavaScriptModuleRange.javascriptStaticAnalysisBundler.tspasses the registration's runtime into factory recovery, including the existing esbuild wrapper runtime names. Each indexed factory range now contains the identity context needed to attribute expressions encountered during the shared traversal.javascriptStaticAnalysisFindings.tsattachesmodule_runtimewhen finalizing a finding inside a recovered factory. Findings outside factories retain their previous shape.javascriptStaticAnalysisTypes.tsandelectronStaticAnalysisTypes.tsdeclare the field as optional, allowing existing internal finding values to remain representable without claiming a runtime they do not contain. The existing range index and its overlap precedence are unchanged.The application projection consumes that same ownership in every affected path:
JavaScriptArtifactGraphContext.tsencodes module and chunk lookup tuples with the existingcompositeKeyutility.sourceNodeForrequires runtime when selecting a recovered bundled module.JavaScriptArtifactGraphBundlers.tsregisters and resolves modules using the registration runtime, including runtime entry loads.JavaScriptArtifactGraphFindings.tscarries runtime into reference, endpoint, storage and discovered-role ownership. Require targets use the source finding's runtime; asynchronous chunk candidate selection also filters by that runtime before using the chunk lookup.ElectronBoundaryGraphContext.tsshares the same source lookup.ElectronBoundaryGraphWindows.ts,ElectronBoundaryGraphIpc.tsandElectronBoundaryGraphNative.tspass runtime for windows, bridge APIs, utility processes, IPC operations, sender validations and native-addon findings.The remaining two files provide the behavioral regression and strengthen the existing producer coverage. These 14 files implement one ownership correction across the producer and its consumers; there is no new service, dependency or alternate graph-building path.
This does not add cross-file runtime reconstruction or change ordinary source-module resolution. If an older internal finding lacks runtime, it cannot select a bundled module by ID alone. Existing unresolved-reference projection remains available, rather than confidently choosing another runtime's factory.
Contract and boundary impact
analyze-javascript-applicationoutput has corrected relationship ownership.module_runtimeis intermediate static-analysis data and is not added to the public normalized result schema.docs/public/product-catalog.json), package, or installation impact: None. No dependency, package version, installation logic, authored skill or tracked generated contract changes. Generated-document checks passed, and build outputs are excluded from the commit.Evidence and regression coverage
tests/boundary/cli/javascriptBundlerRuntimeScopes.test.tsadds seven compiled CLI scenarios.src/domain/javascript/javascriptStaticAnalysisModuleIndex.test.tsnow checks runtime as well as module key for recovered references across its existing factory-range fixture./aowner are now AppA module1; its require target is AppA module2. The corresponding AppB relationships stay in AppB. Storage,BrowserWindowand factory-level async-chunk relationships are checked in the same returned graph.The seven CLI scenarios cover reused numeric IDs, reversed registrations, one runtime, disjoint IDs, mixed Webpack/Rspack runtimes, multiple chunks sharing one runtime, and delimiter-containing runtime/module/chunk strings. The existing self-reference CLI tests also run alongside them to preserve the graph's self-edge omission behavior. Existing esbuild/Vite and Electron composition tests verify the affected consumer families without introducing another fixture framework.
For evidence-bearing changes:
Validation performed
Validation used Node.js 24.18.0 and npm 11.16.0, as pinned by the repository. The branch was rebased onto main revision
c19e15a2b3f09b3f693d7eab5263d83f4d2d1cd4; the CLI, source, full static and generated-document checks below were rerun on that baseline. The branch contains one focused fix commit,294426d5.npm run test:focused -- tests/boundary/cli/javascriptBundlerRuntimeScopes.test.ts tests/boundary/cli/javascriptBundlerSelfReferences.test.ts— 10 tests passed across two files: seven runtime-scope cases and three existing self-reference cases. This also built the runtime required by the compiled CLI boundary.npm run test:local -- src/domain/javascript/javascriptStaticAnalysisModuleIndex.test.ts tests/composition/javascript-applications/javascriptBundlerAdapters.test.ts tests/composition/javascript-applications/electronApplicationAnalysis.test.ts— 13 tests passed across three files. The strengthened module-index assertions were also rerun successfully.npm run check— passed, including typecheck, lint, resolved module boundaries, repository formatting, knip, metadata and architecture guards.npm run docs:check— passed against the final implementation, including the generated catalog, skill, evidence and error-schema freshness checks.npm run verify:test-discovery— passed; all 736 test files were discovered exactly once.npm run verify:architecture-guards— passed across 1,025 source files.git diff --check— passed. The pre-commit formatting and lint checks also passed.Compatibility, safety, and release
Review checklist
type(scope): outcome.