Skip to content

fix(source-maps): retain originals with partial source contents - #2829

Closed
shoyann wants to merge 1 commit into
morluto:mainfrom
shoyann:fix/source-map-partial-contents
Closed

shoyann wants to merge 1 commit into
morluto:mainfrom
shoyann:fix/source-map-partial-contents

Conversation

@shoyann

@shoyann shoyann commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #2821.

Retain original source declarations and available embedded text when sourcesContent has a different length from sources, in local application reconstruction and browser source-map collection.

Problem and expected behavior

With sources: ["a.ts", "b.ts"] and sourcesContent: ["export const answer = 42;"], local CLI/MCP analysis discarded both originals; browser collection rejected the entire map. Padding the content array with null made the same declarations work.

ECMA-426 DecodeSourceMapSources reads content by source ordinal only when an entry exists. Missing content is unavailable, and excess entries do not introduce sources. This corrects the cardinality assumption retained by #2034; malformed field/element types remain invalid.

Change and scope

Remove source-count equality from the local content admission helper and its obsolete parameter/error wording. Remove the redundant browser-profile content check: the existing leaf schema already validates every supplied content entry, and raw content records are still budgeted before schema parsing. Both existing collectors continue iterating source declarations, preserving section-local and flattened ordinals without padding, compacting, or mutating raw map evidence.

Contract and boundary impact

  • Semantic owner and earliest changed stage: source-map content admission; local source collection and shared browser leaf validation.
  • Contribution scope fit and linked maintainer decision: ordinary read-only format correction within existing workflows; separate maintainer scope decision not applicable.
  • CLI and MCP/tool-catalog contract: unchanged request and result schemas; valid maps now retain originals previously discarded.
  • Provider, bridge, target-format, or platform compatibility: version-3 regular/indexed source maps; no provider or bridge changes.
  • Evidence, artifact, provenance, or reconstruction contract: preserve exact map bytes/digest and source ordinals; unavailable content stays null, empty strings stay present, excess content creates no source.
  • Target selection, authority, upstream behavior, and cleanup details: existing file selection and allowed-origin policies remain in force; regression HTTP listener is closed in finally.
  • Generated metadata, package, or installation impact: none.

Expected workflow effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services (existing opt-in source-map collection).
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Added compiled CLI and stdio MCP regressions for indexed leaves with short/empty/excess content arrays, explicit null and empty text, source ordinals and exact map/content digests.

  • Added real loopback HTTP collection coverage asserting retained raw map evidence, content availability and generated/source mapping ordinals across sections.

  • Kept scalar/non-string rejection and changed the obsolete empty-array rejection cases to malformed excess-element cases. Existing omitted/null content and resource-budget regressions pass.

  • Base reproduction: at 9680da76c84a6833635dc7a5df607806d899f804, all 3 new regression cases failed while the other 79 cases in the two files passed. CLI/MCP returned 0 instead of 5 originals; HTTP returned invalid instead of included.

  • Public CLI reproduction from [Bug] Short sourcesContent arrays discard valid source-map originals #2821: short and padded arrays now both produce coverage: "complete", originals: 2 (short previously produced partial, 0).

  • Remaining proof gaps: no live CDP browser session was run; the production source-map HTTP fetch/parse boundary and public local CLI/MCP were exercised. No native engine is involved.

  • 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

  • npm ci --prefer-offline and npm run build:cached — passed with Node 24.18.0 / npm 11.16.0 on WSL Ubuntu x86_64.
  • npm run test:focused -- src/domain/sourceMapContents.test.ts src/javascript/sourceMaps/TraceSourceMap.test.ts src/application/javascript/JavaScriptArtifactAnalysis.sourceMaps.test.ts tests/acceptance/applications/sourceMapPrefixCli.test.ts tests/boundary/browser/webSourceMapFetcher.test.ts tests/boundary/filesystem/javascriptArtifactReconstruction.test.ts — 121 passed across 6 files.
  • npm run test:focused -- tests/boundary/browser/webSourceMapFetcher.test.ts — final test-scope cleanup verified, 74 passed.
  • npm run typecheck, npm run knip, npm run verify:module-boundaries, npm run verify:architecture-guards, npm run verify:test-discovery — passed; all 1078 test files discovered exactly once.
  • npx oxfmt --check and npx oxlint over all 7 changed files — passed (no lint errors); git diff --check passed.
  • npm run check — blocked by unrelated baseline formatting in tests/fixtures/javaClassFile.ts and existing max-lines-per-function errors in tests/boundary/providers/ghidra/ghidraLauncher.test.ts:431, src/ghidra/GhidraFunctionValues.test.ts:46, and src/domain/webBundleAnalyzer.test.ts:224. Those files are unchanged here; the individual checks above completed separately because Turbo cancels peer tasks after failure.

Compatibility, safety, and release

  • Breaking changes or migration steps: none; valid previously rejected maps are accepted.
  • Real Hopper/Ghidra, browser, or OS coverage: no native engine changes; real HTTP boundary on WSL Ubuntu, no live CDP claim.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: malformed content types remain invalid; network response/structure/evidence budgets and origin admission are unchanged. Extra content remains only in retained raw map bytes, not invented source artifacts.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed (no changes required).
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

The same formatting failure and three lint errors were independently reproduced on a clean checkout of base 9680da7. The normal pre-push hook failed on those same lint errors; after the checks above, this branch was pushed with that local hook disabled for the push only.

Integration note

Related independent fix: #2831. Both PRs target main and fix separate issues. Their deletions touch adjacent validation blocks in SourceMapFormat.ts; a local three-way merge reports a textual conflict between them. Once either merges, the other needs a small rebase retaining both removals. There is no semantic dependency, and the regression additions merge cleanly.

@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.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] This PR appears safe to merge; no actionable defects or rule violations were found.

Summary

Retains source declarations when sourcesContent is shorter or longer than sources.

  • Local and browser analysis keep sources when embedded text counts differ.

No actionable issues were found. Security checks remain in place. Tests were inspected, not run during this review. The supersession check could not complete because GitHub authentication was unavailable; local history showed no later commit.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Raw source map"] --> B{"Local or browser?"}
  B --> C["Local: check content types"]
  B --> D["Browser: check record limits and leaf schema"]
  C --> E["Walk declared sources by position"]
  D --> E
  E --> F["String: retain exact content"]
  E --> G["Missing or null: mark unavailable"]
  E --> H["Excess content: create no source"]
  F --> I["Keep source positions and raw map evidence"]
  G --> I
  H --> I
Loading

Reviews (1) · Last reviewed commit: "fix(source-maps): retain originals with ..." · Reviewed by Greptile

@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
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks @shoyann for identifying that partial source-map contents could discard original source text. Main now keeps usable source entries and derives completeness from the parsed vector, with CLI and reconstruction coverage (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 P2: medium Medium priority issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Short sourcesContent arrays discard valid source-map originals

2 participants