Skip to content

fix(javascript): preserve Node package lookup and artifact path identity - #2702

Closed
rohitg00 wants to merge 24 commits into
morluto:mainfrom
rohitg00:fix/node-package-main-resolution
Closed

rohitg00 wants to merge 24 commits into
morluto:mainfrom
rohitg00:fix/node-package-main-resolution

Conversation

@rohitg00

@rohitg00 rohitg00 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Match Node package-main lookup while preserving artifact directory ownership and unknown symlink targets in offline JavaScript reconstruction.

Problem and expected behavior

Node ignores a non-string main and can resolve an index. CommonJS probes normalized main paths; legacy ESM also finalizes the original main plus its selected suffix. Collapsing those stages creates false or missing dependencies.

Retained directory paths also need their container identity: an outer directory cannot establish a package inside a nested ASAR. The inventory's root spelling must match resolver candidates. A symlink at a selected final target, such as lib/.js for main ./lib/, establishes uncertainty rather than absence.

The slash-main case was reported in the resolver discussion; the retained-path gaps were raised in review. No separate issue was identified for these fixes.

Change and scope

  • Interpret non-string main as absent only for Node loaders and keep generic filesystem policy separate.
  • Preserve loader-specific probes, finalization failures, and CommonJS ancestor-stop behavior. Root-pointing mains cannot select root dotfile decoys.
  • Project retained directory and symlink facts with container digests. Normalize the inventory root once and share those facts with graph relationships and the Electron summary.
  • Check directory ownership before fallback inference. Recognize nested container roots explicitly.
  • Preserve unknown symlink targets at file, metadata, and main-selection boundaries. Do not follow links or substitute a later candidate. Propagate the limitation through module and source-map consumers.

Existing upstream integrations and the bounded Apple fixture compiler timeout are retained.

Contract and boundary impact

  • Semantic owners: retained inventory path projection, package metadata interpretation, and Node package-main resolution.
  • Contribution scope: static correctness within existing boundaries; a new maintainer authority decision is not applicable.
  • CLI/MCP: public schemas/catalog unchanged; relationships retain loader mode, selected candidate, and unavailable limitations.
  • Compatibility: generic metadata/confinement policy remains intact. Symlink targets remain unestablished for both Node loaders.
  • Evidence: raw declarations and artifact identities remain retained; foreign-container paths and unknown targets cannot establish a dependency.
  • Authority/cleanup: no new target execution, symlink traversal, or resource ownership.
  • Generated metadata, dependencies, installation, or migrations: none.

Expected effects:

  • Read existing files or captured data.

Evidence and regression coverage

Existing CLI/stdio MCP and native-control sources cover non-string main, trailing slash, root/index fallback, dotfile decoys, and ESM finalization. Added regression sources cover outer versus nested ASAR directories, empty directories, artifact-root identity without metadata/index, foreign-container path facts, symlink finalization, unknown earlier probes, and linked parent directories.

The new symlink fixture is excluded on Windows because it creates filesystem links; platform-independent source-level cases still cover retained symlink ownership. No new cases have been executed.

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity and source provenance remain preserved.
  • Unsupported and unavailable outcomes remain visible.

Validation performed

Merged current main (cf0a38a). An ESM subpath that normalizes to the artifact root is now admitted to directory-form rejection instead of being rejected as an empty declaration. Retained path owners come from a container map lookup. Executed on Node 24.19.0 (macOS arm64): JavaScriptArtifactPathResolution.test.ts, packagePathInventoryCli, JavaScriptModuleLookupCli and packageSpecifierSuffixCli, 175/175 passed through CLI and stdio MCP, including native Node controls; tsc --noEmit and npm run lint have 0 errors. Not run: Windows, Node 22 native controls (they expect Node 24 loader codes), the full suite, real Electron apps, large-input timing.

Compatibility, safety, and release

No public schema or dependency change. Same-container admission remains mandatory for retained paths. REA does not follow or execute symlinks. Latest runtime and cross-platform behavior remain unverified.

Author readiness

Human owner: @rohitg00

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • Concrete problem, scope, related discussion, and semantic owners identified.
  • Retained path consumers and regression sources updated.
  • Final source diff reviewed for unrelated changes and unsupported claims.
  • Latest changes verified by required automated checks.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T06:27:05.377768Z 60bb965 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] No new blocking issues were found; the remaining large-scan responsiveness concern is non-blocking.

Summary

The PR preserves directory ownership and unknown symlink targets during offline JavaScript lookup.

  • Node package mains use loader-specific lookup and finalization.
  • Retained paths keep their container owner and unknown link targets.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Artifact inventory] --> B[Retain directories and symlinks with container digests]
  B --> C[Shared path lookup]
  D[Analyzed and unanalyzed files] --> C
  C --> E{Same-container symlink on candidate path?}
  E -->|Yes| F[Unavailable: stop lookup]
  E -->|No| G[Apply loader-specific file and directory probes]
  F --> H[Graph relationships]
  G --> H
  C --> I[Electron summary]
Loading

Reviews (18) · Last reviewed commit: "fix(javascript): reject artifact-root ES..." · Reviewed by Greptile

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 87bdcf8442

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@greptile-apps

greptile-apps Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cd0afeebb4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4e029384ce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open.

  1. thread 1

The package-main resolver checked only finalized files, then discarded the distinct inventoried-directory failure. Commit 496cedd checks the finalized candidate with the existing container-aware directory predicate before the not-found fallback, retaining rejected directory-import semantics without trying later candidates. The public CLI/MCP package-main regression includes lib.js alongside lib/.js/child.js and the Node ERR_UNSUPPORTED_DIR_IMPORT control. Existing resolution helpers own the interpretation; no separate directory classifier or downstream repair remains.

Source and affected-consumer inspection, targeted formatting with two threads, and git diff --check completed. Regression coverage was authored; tests, builds, typechecks, lint, provider execution and CI reruns were skipped at the user’s request.

@morluto morluto added bug Something isn't working area: domain Domain logic, errors, and pure functions P2: medium Medium priority issue labels Oct 13, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 924f74c501

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…HEAD

# Conflicts:
#	scripts/lib/clean-linux-hopper-runtime.mjs
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Source fixes and publication evidence for the review findings below. Tests and executable checks were skipped at the maintainer's request. Findings that still require a decision or execution evidence remain open.

review thread

Root cause: P2 Badge Retain omitted directory identities for ESM finalization. Structural fix: Artifact path resolution receives the inventory’s directory facts so ESM main resolution retains an omitted-only known directory as rejected with its candidate path rather than not-found. Merged latest main 8fef2aa; only conflict was formatting in clean-linux-hopper-runtime and main formatting retained. git diff --check; no tests. Public evidence: 275d62b is published on the PR branch; validation was pinned formatting and git diff --check only, with tests not run per instruction. No directly related cleanup remains from this thread.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 275d62b8bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c5127f3670

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

morluto added a commit that referenced this pull request Oct 14, 2026
Preserve CommonJS literal paths and confined ESM URL semantics, including package main fallback, directory intent, Unicode identity, and present opaque modules. Parse extraction inputs at their AST/source owner, retain skipped HTML and source-map coverage, and distinguish endpoint candidates from proven receiver facts. Version structural fingerprints with computed literal contents and propagate them through worker contracts.

Reviewed fixes include #1810, #1840, #2642, #2700, #2702, #2714, #2803, #2960, #2968, #2986, #3035, and #3036.

Validation: 158 resolver tests passed; public CLI/MCP module lookup controls, package-main/Unicode workflows, and six builtin workflows passed in the current compiled lane. Worker schema/fingerprint regressions passed. Large public pdf.js completion and real Electron analysis remain unverified.
@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.

@rohitg00 rohitg00 changed the title fix(javascript): match Node package main resolution fix(javascript): preserve Node package lookup and artifact path identity Oct 14, 2026
@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.

@rohitg00
rohitg00 marked this pull request as draft October 14, 2026 10:14
@rohitg00
rohitg00 marked this pull request as ready for review October 14, 2026 10:22
@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.

@CassieFox23

CassieFox23 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Edit: new results on head 60bb965 are in #2702 (comment).

TL;DR: The symlink and container fixes work on Node 24 and 26. Two of the six new inventory tests fail, in the same way on GitHub. They expect the words "names a directory", but the code says "The declared path is empty."

I tested head 17fa9dc as pushed. Main already holds the earlier package-main work. Commit b58adaf is already in this branch's base, 44d98de. Main does not hold the container and symlink part, so I tested that. GitHub reports no conflict. A merge of the 14 shared files onto main acca91d (#3831) also had no text conflict.

Results

Check on head Node 24.18.0 Node 26.11.1
Path resolution unit file (165 tests) pass pass
Module lookup CLI file (2 tests) pass pass
Inventory file, nested ASAR case pass pass
Inventory file, symlink case pass pass
Inventory file, artifact root case 2 fail 2 fail
Same unit and lookup files on main pass not run

The inventory file is the new test file this PR adds. The artifact root case fails through the CLI and through stdio MCP.

Before and after

I built three fixtures and ran the analyze command on main and on head. Main gave the same edges as the base 44d98de, so each change below comes from this PR.

Import Main Head
Empty folder outside the archive not found external
Empty folder inside the archive not found not-found
Main "./lib/", symlink at lib/.js not found unavailable
Main "./lib", symlink at lib resolved unavailable
Path through a linked folder not found unavailable

Node 24 and Node 26 gave the same edges. The artifact root fixture gave "rejected" on both builds. Its limitation reads "The declared path is empty." The head test wants "names a directory". In the source, the subpath code rejects an empty path at line 867 of the path resolution file. That comes before the directory check at line 898. I did not trace this at run time (unverified).

Not run

  • Head merged onto current main, built and tested.
  • Node 22, Windows and macOS.
  • The rest of the suite, and anything under tests/acceptance/setup.
  • A real Electron app.

Thanks, Rohit, for the fix and the thorough tests.

Test setup
Commands
npm ci && npm run build && npm run test:prepare
node scripts/run-development-tests.mjs focused src/application/javascript/JavaScriptArtifactPathResolution.test.ts tests/acceptance/applications/packagePathInventoryCli.test.ts tests/acceptance/applications/JavaScriptModuleLookupCli.test.ts
node scripts/rea.mjs analyze-javascript-application <fixture> --format json

Each run sat under nice and systemd-run --user --scope -p MemoryMax=6G.

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

A legacy ESM subpath that normalizes to the artifact root produced an empty encoded path and was rejected as an empty declaration before directory-form handling. Admit the empty root path so it reaches the directory rejection Node reports as ERR_UNSUPPORTED_DIR_IMPORT. Resolve retained path owners through a container map instead of scanning every container per occurrence.
@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: Fixed. On head 60bb965, all 173 tests in the three test files pass on Node 24 and 26. The two inventory tests that failed on head 17fa9dc now pass. The empty-path case now says the import has URL directory form.

This follows my earlier result on head 17fa9dc. Head is now 60bb965. The merge-base with today's main 9d6651e is cf0a38a. Thanks, Rohit, for the fix.

Check on head 60bb965 Node 24.18.0 Node 26.11.1
Three test files together: 173 pass, 0 fail (was 171 pass, 2 fail) pass pass

The three files are the path resolution unit file, the inventory file and the module lookup CLI file. The inventory file is the one that failed before.

The case I reported. The artifact root fixture used to end with the limitation The declared path is empty. The test wanted the words "names a directory". On this head the fixture says ESM package subpath "local/../.." has URL directory form; directory imports are unsupported and no exact-file, package main or index lookup was attempted. The status is still "rejected". The test on this head looks for the words "directory imports are unsupported", so the test and the code now agree. I did not trace which source line changed.

Before and after, again. I rebuilt my three fixtures and ran the analyze command on head 60bb965 with Node 24 and Node 26. Both gave the same edges. Two fixtures give the same edges as head 17fa9dc. The third is the artifact root fixture, where only the limitation text changed.

Import Head 60bb965 Same as on 17fa9dc?
Empty folder outside the archive external yes
Empty folder inside the archive not-found yes
Main "./lib/", symlink at lib/.js unavailable yes
Main "./lib", symlink at lib unavailable yes
Path through a linked folder unavailable yes
Artifact root, local/../.. rejected, new text status yes, text changed

I did not rerun main this time. The "before" columns of my earlier result stay as posted.

Not run

  • Main again, and head merged onto today's main, built and tested.
  • Node 22, Windows and macOS.
  • The rest of the suite, and anything under tests/acceptance/setup.
  • A real Electron app.

The box was shared with other test jobs. Timings are not benchmarks.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 24.18.0, 26.11.1
  • Head: 60bb965
  • Base: cf0a38a
  • Other: fixtures built with the repo's own asar package
Commands
npm ci && npm run build && npm run test:prepare
node scripts/run-development-tests.mjs focused src/application/javascript/JavaScriptArtifactPathResolution.test.ts tests/acceptance/applications/packagePathInventoryCli.test.ts tests/acceptance/applications/JavaScriptModuleLookupCli.test.ts
node scripts/rea.mjs analyze-javascript-application <fixture> --format json

Each test run sat under systemd-run --user --scope -p MemoryMax=8G with a throwaway home folder. The trees share one node_modules from npm ci, since the lockfiles match.

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@rohitg00

Copy link
Copy Markdown
Contributor Author

Closing as superseded. Main already has the Node package-main lookup (b58adaf), and #4941 redefined container admission for runtime paths, so the remaining retained-path change no longer fits main's rules.

@rohitg00 rohitg00 closed this Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working P2: medium Medium priority issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants