Skip to content

fix(javascript): match source-map originals that name parent directories - #1215

Merged
N0zoM1z0 merged 9 commits into
morluto:mainfrom
jayhemnani9910:fix/source-map-parent-paths
Oct 9, 2026
Merged

N0zoM1z0 merged 9 commits into
morluto:mainfrom
jayhemnani9910:fix/source-map-parent-paths

Conversation

@jayhemnani9910

@jayhemnani9910 jayhemnani9910 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

compare-source-to-bundle never matches a historical source file to a source-map original when the map names it relative to the map's own directory, such as ../src/a.js. Rollup, Vite, esbuild and rolldown write sources this way by default, so for their bundles every source file loses its path evidence.

Problem and expected behavior

Trigger: dist/main.js with dist/main.js.map whose sources is ["../src/a.js"], compared with a reference tree containing src/a.js.

Before: normalizeCurrentPath returns null for any path that contains a .. segment (src/domain/javascript/sourceToBundleSignals.ts:287), so the source-module node gets no path, suffix or basename entries. An edited src/a.js is reported as unknown with "No candidate was observed, but incomplete input or graph coverage prevents a removal claim." An unedited file is still found, but only through its digest.

Expected: ../src/a.js is the same location as src/a.js for matching, so the node gets a source-map-original-path signal for src/a.js.

Change and scope

normalizeCurrentPath now collapses .. segments lexically instead of discarding the whole path; entries starting with ../ are resolved against the map file's directory first. The value is used only for path matching and for the signal's current_values, never to read a file. Scoring, weights and classification are unchanged.

Contract and boundary impact

  • Semantic owner and earliest changed stage: source-to-bundle candidate indexing (sourceToBundleSignals.ts).
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: source-map originals with .. segments now produce path signals; current_values show the collapsed path.
  • Process execution, authorization, cleanup, or containment impact: none; no filesystem access uses this value.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated: matches source-map originals named relative to the map in tests/boundary/filesystem/sourceToBundlePaths.test.ts (real analyzer on a dist/main.js + map with sources: ["../src/a.js"]). It fails on current main and passes with this change. The existing test there now shares a small helper.
  • Base reproduction or other evidence: executed with a two-module rolldown bundle (default output, sources: ["../src/a.js","../src/main.js"]) and src/a.js edited in the reference tree, on main and on rea-agents 6.0.0: src/a.js unknown unknown ['No candidate was observed, ...']. With this change the source-module candidate carries source-map-original-path and current-path-exact for src/a.js (score 155, confidence high).
  • User-visible CLI/MCP output: the item and candidate above.
  • Remaining proof gaps: when the map and reference digests differ, the item is still unknown ("comparable source digests are unavailable"); that classification is a separate bug in classifyMapping, fixed in a separate PR. With both changes the edited file is reported modified.

Validation performed

  • npm run test:focused -- tests/boundary/filesystem/sourceToBundlePaths.test.ts — 3 passed; the new test fails with the fix reverted.
  • npx vitest run src/domain/javascript/ — 512 passed.
  • npm run check:fast — passed.
  • npx vitest run (after npm run build:cached) — 5316 passed; the 10 failures are firmware (local Binwalk is not 3.1.x) and two ASAR reconstruction tests, which fail the same way on untouched main here.
  • Re-ran the rolldown repro: src/a.js now has the source-map-original-path candidate; src/main.js stays unchanged.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; static JavaScript analysis only, no provider involved.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the collapsed path is a matching key only.

Copilot AI balanced review requested due to automatic review settings October 9, 2026 06:20

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 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-09T10:02:41.257902Z 89fd82d 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.

@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: 50642d0282

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@jayhemnani9910

Copy link
Copy Markdown
Contributor Author

Pushed b48702a for maps in a nested directory: a source-map entry starting with ../ is now resolved against the map file's own directory (from the source-module node's parse-local-source-map evidence) before matching. web/maps/main.js.map with ../src/a.js now matches web/src/a.js instead of src/a.js. New boundary test resolves parent segments against a nested source map's directory uses the real analyzer and fails without the change. Maps next to the bundle behave as before. npx vitest run src/domain/javascript/ tests/boundary/filesystem/ (1282 passed) and check:fast pass.

@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: b48702a4ee

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@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: 75f0c9d314

ℹ️ 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: 819579cc9f

ℹ️ 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: 0118c44461

ℹ️ 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: c2a9dde0cc

ℹ️ 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: 89fd82dd12

ℹ️ 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".

mapPath?: string,
): SourceMapPath | null => {
const portable = source.replaceAll("\\", "/");
const windowsPath = /^[a-z]:\//iu.test(portable) || source.startsWith("\\\\");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve relative Windows source-map filename syntax

When a supported relative Windows declaration contains literal URL punctuation (for example, a map at pkg/maps/main.map names ..\src\a%23b.js), windowsPath is false because this detector accepts only drive-qualified and UNC paths. The declaration then goes through URL path processing, which decodes %23 (and would treat # as a fragment), projecting pkg/src/a#b.js instead of the real pkg/src/a%23b.js; with changed or absent sourcesContent, the high path signal can select that decoy and the actual file can be reported removed under complete coverage. The newly added ..\src\a.js boundary case establishes that relative backslash declarations are supported, so retain their raw Windows filename semantics while resolving them against the map directory.

AGENTS.md reference: AGENTS.md:L59-L59

Useful? React with 👍 / 👎.

@N0zoM1z0 N0zoM1z0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 89fd82d integrated with main and #1216. All 64 focused tests pass, covering nested/merged maps, URI and Windows/UNC declarations, literal filesystem punctuation and rejected path projections. The sourceRoot case matches the pinned TraceMap resolver.

Actual CLI and stdio MCP agree: changed source → modified, equal digest → unchanged, missing digest → unknown, two current sources → split; the same-basename decoy gets no strong path signal. Raw declarations remain preserved. All 23 CI checks pass.

@N0zoM1z0
N0zoM1z0 merged commit 889fb37 into morluto:main Oct 9, 2026
23 checks passed
@jayhemnani9910
jayhemnani9910 deleted the fix/source-map-parent-paths branch October 9, 2026 11:46
@morluto

morluto commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Thank you for fixing parent directory source map matching. I went through how normalizeCurrentPath now collapses dot dot segments lexically and resolves leading parent entries against the map file directory, so Rollup style ../src/a.js maps correctly for path signals only. The nested directory boundary test that fails without the change shows the care here. Really appreciate it.

darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…ies (morluto#1215)

* fix(javascript): match source-map originals that name parent directories

* fix(javascript): resolve parent segments against the source map's directory

* fix(javascript): resolve source originals against their map location

* fix(javascript): preserve URI and empty source map path semantics

* fix(javascript): separate source URL paths from opaque URI payloads

* fix(javascript): preserve filesystem names during URI classification

* style(javascript): format source URI presence guard

* fix(javascript): resolve source map references with URL semantics

* fix(javascript): preserve literal UNC source map paths

---------

Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
@morluto morluto added bug Something isn't working area: domain Domain logic, errors, and pure functions labels Oct 14, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants