Skip to content

fix(javascript): recover retained prefixed source maps - #1887

Closed
xu91102 wants to merge 1 commit into
morluto:mainfrom
xu91102:fix/retained-source-map-prefixes
Closed

xu91102 wants to merge 1 commit into
morluto:mainfrom
xu91102:fix/retained-source-map-prefixes

Conversation

@xu91102

@xu91102 xu91102 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Retained source maps with the standard )]}' response prefix lost their original-source evidence during directory analysis. Apply the existing source-map parsing normalization to retained artifacts, while preserving their original bytes and identity. Fixes #1882.

Problem and expected behavior

A bundle.js.map containing )]}' followed by a valid version-3 map produced partial graph coverage and no original.ts source node. Removing only the prefix produced complete coverage. The same retained map now recovers its original source and embedded content without changing the retained map's digest or provenance.

Change and scope

Move the existing sourceMapJsonText implementation, unchanged, to the shared domain source-map envelope module. Application analysis, browser collection, and point tracing use that single parsing view. The application parser now applies it before JSON parsing; package manifests and other JSON inputs keep their existing behavior.

Contract and boundary impact

  • Semantic owner and earliest changed stage: domain-owned source-map text framing, consumed during application artifact parsing.
  • CLI and MCP/tool-catalog contract: unchanged schemas; both analysis surfaces now recover the same original-source evidence.
  • Provider, bridge, target-format, or platform compatibility: existing source-map framing support is reused; no engine or bridge changes.
  • Evidence, artifact, provenance, or reconstruction contract: normalize only the parsing view; retain original file bytes, map SHA-256, embedded content SHA-256, and source declarations.
  • Process execution, authorization, cleanup, or containment impact: none; no new remote requests or production process execution.
  • Generated metadata, package, or installation impact: none.

Evidence and regression coverage

  • New compiled CLI and stdio MCP acceptance coverage uses a retained BOM-prefixed map with response framing and CRLF. It asserts original-source recovery, complete coverage, both digests, provenance, and unchanged retained bytes.

  • On base fb94d9dde0ccda83ae520ac6fb22b1d283562cf3, both new surface tests failed because the original-source node was absent. Both pass after the fix.

  • A separate actual CLI control reproduced the loss twice and recovered the original after removing only the prefix.

  • Existing point-tracing, browser HTTP source-map collection, filesystem source-map locations, and source-map envelope tests pass, including existing malformed-input paths.

  • Review: independent read-only review of the frozen complete patch passed both standards and issue-contract checks, with no actionable findings.

  • Remaining proof gaps: full deterministic coverage is left to upstream CI. No live browser or native-provider workflow was run; this report concerns retained local artifacts.

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

All local checks used Node 24.18.0 / npm 11.16.0 on macOS 27.0.1 arm64.

  • npm run test:focused -- tests/acceptance/applications/sourceMapPrefixCli.test.ts before the application fix — 2 expected regression failures.
  • npm run test:focused -- tests/acceptance/applications/sourceMapPrefixCli.test.ts src/javascript/sourceMaps/TraceSourceMap.test.ts tests/boundary/browser/webSourceMapFetcher.test.ts tests/boundary/filesystem/javascriptSourceMapLocations.test.ts src/domain/sourceMapEnvelope.test.ts — 111 tests passed across 5 files, including freshly built CLI/MCP workflows.
  • npm run check — passed typecheck, lint, formatting, knip, metadata, module boundaries, and architecture guards; 758 lint warnings, zero errors.
  • npm run verify:test-discovery — all 843 test files discovered exactly once.
  • git diff --check — passed.
  • Upstream CI — awaiting maintainer approval for this fork contribution (action_required); no CI jobs have executed. This is not counted as a passing check.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: actual REA CLI/MCP on macOS and existing browser HTTP boundary tests; live browser and native engines not run.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: normalization retains the existing invalid-input handling and introduces no external fetch or new execution authority.

Review checklist

  • This PR addresses a concrete reproduced problem and has one focused outcome.
  • The title follows Conventional Commits and the related issue is linked.
  • Tests cover observable evidence recovery and existing malformed-input paths.
  • No owning docs, schemas, or generated metadata require changes.
  • Representative CLI/MCP output and actual validation are recorded above.
  • The final diff contains no secrets, unrelated cleanup, or unsupported provider claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 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-11T15:55:08.505884Z 851cd98 PR opened
ℹ️ 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.

@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Superseded by #1939, which retains your implementation commit and verifies the prefixed map parsing view together with exact original bytes, digests, recovered-source provenance and the current source-map changes. #1882 remains linked for closure when the integration merges.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: The fix works. Source maps that start with the )]}' guard line now give back their original files. Six bad prefixes are still rejected, and the fast test suite passed.

This PR closed right after my test finished. #1939 now carries the fix. I'm posting these results here for the record. A rerun on #1939 comes next.

Results

I tested the PR head 851cd98 against its merge base fb94d9d. I built both and ran 17 fixture folders through the CLI and through the stdio MCP server. The two agreed on every folder. The table groups 13 of the 17 folders. The first fold lists all 17.

Retained bundle.js.map starts with Merge base fb94d9d PR head 851cd98
nothing (clean map) complete, 1 original complete, 1 original
BOM, )]}' plus text, CRLF (the PR test input) partial, 0 originals complete, 1 original
five other )]}' forms (LF, CRLF, CR only, text on the line, BOM first) partial, 0 originals complete, 1 original
six bad prefixes (see the fold) partial, 0 originals partial, 0 originals (rejected)

On every recovered row at the head, source_map_sha256 equals the SHA-256 of the file bytes on disk, prefix included. The original source hash equals the hash of the embedded text. The rejected rows still say "Source map is not valid JSON."

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
PR test plus 4 related test files (5 files, 111 tests) pass pass pass
npm run test:fast (388 files, 4551 passed, 3 skipped) not run pass not run

The PR's new test, copied into a build of fb94d9d, fails both cases (CLI and MCP) on Node 24.18.0. It passes on the PR head.

Also seen

  • A leading BOM never reaches the new helper for .map files. The file reader strips one BOM first. The helper only strips a second one. A map with two BOMs and then the prefix is recovered at the head. The PR test passes because of the )]}' handling, not because of the BOM.
  • Directory analysis does not recover inline data: source maps. That is true with or without the prefix, before and after this PR.

Not run

  • The live browser path (analyze_web_bundle needs a CDP page). The moved function there is covered only by the PR's existing boundary test, which passed.
  • recover_javascript_sources. It writes source maps and does not read retained ones.
  • A build of current main (72489a9). The PR is 41 commits behind it. A dry-run patch of the four changed source files onto main applied cleanly. I did not build or test that.
  • A real-world open-source bundle with a prefixed map. I had none at hand.
  • npm run check, the full suite, and test:fast on Node 22 and 26.
  • Maps inside archives such as zip or asar.

Thanks, xu91102, for the fix and for the clear reproduction in the issue.

All 17 fixtures
Retained map starts with Merge base fb94d9d PR head 851cd98
nothing (clean map) complete, 1 original complete, 1 original
)]}' then LF partial, 0 originals complete, 1 original
)]}' then CRLF partial, 0 originals complete, 1 original
)]}' plus text, then LF partial, 0 originals complete, 1 original
BOM, )]}' plus text, then CRLF (the PR test input) partial, 0 originals complete, 1 original
BOM, )]}', then LF partial, 0 originals complete, 1 original
BOM only complete, 1 original complete, 1 original
)]}' then CR only partial, 0 originals complete, 1 original
two BOMs, )]}', then LF partial, 0 originals complete, 1 original
)]}' with no newline partial, 0 originals partial, 0 originals (rejected)
foo then LF partial, 0 originals partial, 0 originals (rejected)
)]}' then half a map partial, 0 originals partial, 0 originals (rejected)
)]}' line only partial, 0 originals partial, 0 originals (rejected)
a space before )]}' partial, 0 originals partial, 0 originals (rejected)
)]}' twice partial, 0 originals partial, 0 originals (rejected)
inline data: map, clean complete, 0 originals complete, 0 originals
inline data: map, )]}' then LF complete, 0 originals complete, 0 originals
Commands
# build each tree (Node 24.18.0)
npm ci && npm run build && npm run test:prepare

# fixtures: scripts/gen-fixtures.mjs makes 17 folders, scripts/run-fixtures.mjs runs each folder
node scripts/rea.mjs analyze-javascript-application <folder> --format json
# MCP: tool analyze_javascript_application, input_path=<folder>, format=directory,
# over stdio against node scripts/rea.mjs mcp from the same tree

# tests
npm run test:focused -- tests/acceptance/applications/sourceMapPrefixCli.test.ts src/javascript/sourceMaps/TraceSourceMap.test.ts tests/boundary/browser/webSourceMapFetcher.test.ts tests/boundary/filesystem/javascriptSourceMapLocations.test.ts src/domain/sourceMapEnvelope.test.ts
node node_modules/vitest/vitest.mjs run <same five files>   # Node 22 and 26, by absolute path
npm run test:fast

Timing is from a shared box. Other test jobs were running. About 6 jobs wanted a CPU at once, out of 24 threads.

  • test:fast: 92 s.
  • Five-file run: 10 to 12 s.
  • The 34 fixture runs for one tree: about 28 s.
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: 22.23.1, 24.18.0, 26.11.1
  • Head / base: 851cd98 / fb94d9d (the PR's merge base; main was 72489a9)

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

@morluto morluto added bug Something isn't working area: domain Domain logic, errors, and pure functions labels Oct 14, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

@xu91102, thank you for surfacing prefixed source maps that were being missed despite containing usable mappings. The current workflow covers retained prefixed originals and checks their byte identity across public surfaces (main).

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.

[Bug] Retained prefixed source maps lose original-source evidence during application analysis

3 participants