Skip to content

fix(javascript): reject invalid package exports configurations - #1333

Closed
ac1982 wants to merge 1 commit into
morluto:mainfrom
ac1982:fix/javascript-invalid-export-conditions
Closed

ac1982 wants to merge 1 commit into
morluto:mainfrom
ac1982:fix/javascript-invalid-export-conditions

Conversation

@ac1982

@ac1982 ac1982 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Reject invalid package exports configurations instead of selecting an apparent dependency target. Mixed subpath/condition keys and numeric condition keys must fail as configuration errors; an exports array must not recover from that error by choosing a later file.

No linked issue: this is a focused correctness bug reproduced against Node. Related #591, #606 and #1046 cover condition order, target fallback and root arrays, respectively; this change handles configuration errors those paths still accepted.

Problem and expected behavior

For example, exports: {"node":[{"0":null},"./index.cjs"],"default":"./index.cjs"} makes Node throw ERR_INVALID_PACKAGE_CONFIG, but REA selects index.cjs. Likewise, mixing "." with "import" at the root selects a target despite Node rejecting the configuration.

Change and scope

Validate root key categories before root-subpath selection. Validate numeric condition keys only when that condition object is visited, using Node's numeric-key predicate. Carry a distinct private invalid-configuration outcome through array traversal; preserve ordinary invalid-target fallback, inactive branches, and early successful selections.

Contract and boundary impact

  • Semantic owner and earliest changed stage: application package-exports interpretation before artifact target selection.
  • CLI and MCP/tool-catalog contract: unchanged tools and schemas; invalid configurations no longer produce a resolved dependency.
  • Provider, bridge, target-format, or platform compatibility: static JavaScript analysis; real Node 24.18.0 import/require comparisons on Linux arm64.
  • Evidence, artifact, provenance, or reconstruction contract: existing source identities and unresolved relationship representation preserved.
  • Process execution, authorization, cleanup, or containment impact: none in production; tests execute owned inert packages.
  • Generated metadata, package, or installation impact: none.

Evidence and regression coverage

  • Five new cases fail on d83cbd2a, with 39 passing controls/existing tests.
  • Differential tests check Node's actual error code and REA's rejected outcome for mixed keys, numeric keys at root and under ".", and an invalid object before an array fallback. Both import and require are exercised after the fix.
  • Controls preserve "01", "4294967295", unvisited invalid branches, early array success and ordinary subpath maps.
  • Built CLI analyze-javascript-application <fixture> --json retains {"specifier":"fixture","resolved_path":null} rather than linking index.cjs. The resolver supplies a specific configuration diagnostic; this does not claim the application graph exposes every resolver diagnostic.
  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity and source provenance remain preserved.
  • Unsupported and uncertain outcomes remain visible.

Validation performed

Node 24.18.0 / npm 11.16.0:

  • npm run test:focused -- tests/boundary/javascript/packageConditionalExports.test.ts tests/boundary/filesystem/javascriptPackagePrecedence.test.ts src/application/javascript/JavaScriptArtifactPathResolution.test.ts src/application/javascript/JavaScriptModuleSpecifierPaths.test.ts — 158 passed across four files.
  • npm run check — all six tasks passed, warnings and no errors.
  • Built CLI reproduction and git diff --check — passed.

Compatibility, safety, and release

No migration, dependency, metadata, or execution-authority changes. Unsupported package subpaths remain outside this fix. Real Hopper/Ghidra/browser verification and the complete repository test suite were not run; those providers are unchanged. Hosted CI is separate from local validation.

Review checklist

  • Concrete problem and one focused outcome with a conventional title.
  • Related PRs and reason for no linked issue documented; duplicate search completed.
  • Tests cover refusals and successful controls against real Node.
  • Existing contracts/docs remain accurate; no generated changes needed.
  • Representative CLI output included.
  • Final diff reviewed for unrelated changes, credentials, and unsupported claims.

Prepared with OpenAI Codex assistance.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@morluto

morluto commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Closing as superseded by work already landed on main: 7a4f2685.

Main rejects mixed subpath/condition exports objects and visited numeric condition keys, propagating invalid-configuration outcomes instead of recovering through an array fallback. Real-Node controls remain.

The follow-up refactor/test consolidation is on main in 392f1f31. Closure is based on the behavior now present on main, not on treating this branch as merged. Thank you for documenting the issue and regression cases.

@morluto morluto closed this Oct 9, 2026
@morluto morluto added bug Something isn't working area: build Build, CI, packaging, and publishing labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: build Build, CI, packaging, and publishing bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants