Skip to content

fix(source-maps): accept short sourcesContent arrays as missing slots - #2869

Closed
Jackzigen wants to merge 2 commits into
morluto:mainfrom
Jackzigen:fix/source-map-short-sources-content
Closed

Jackzigen wants to merge 2 commits into
morluto:mainfrom
Jackzigen:fix/source-map-short-sources-content

Conversation

@Jackzigen

Copy link
Copy Markdown
Contributor

Summary

A version-3 map whose sourcesContent array is shorter than its sources inventory is rejected by hasValidSourceMapContents, which drops every original-source declaration during analyze-javascript-application instead of decoding missing trailing slots as null content. Padding the same array with null restores all sources, so the cardinality gate is stricter than the decoding algorithm.

Per ECMA-426 DecodeSourceMapSources step 6.5, a content entry is read only when the source index is within sourcesContent; the decoded source then starts with null content. The algorithm iterates the source inventory, so decoding never depends on exact cardinality.

This relaxes the shared validator from contents.length === sourceCount to contents.length <= sourceCount:

  • trailing missing slots validate and decode as null content, matching the padded-array behavior;
  • scalar content fields and non-string/non-null entries are still rejected;
  • extra entries beyond the source inventory are still rejected, since decoding ignores them silently and that signals a mismatched map.

Both consumers already read content by source ordinal and map absent entries to null (JavaScriptArtifactAnalysis.ts via typeof rawContent === "string", SourceMapFormat.ts via ?? null), so no consumer changes are needed.

Fixes #2821

Verification

  • npx vitest run src/domain/sourceMapContents.test.ts — 2 tests (added the short/empty/extra boundary cases, flipped the short-array expectation per ECMA-426).
  • npx vitest run src/application/javascript/JavaScriptArtifactAnalysis.sourceMaps.test.ts src/javascript/sourceMaps/TraceSourceMap.test.ts — 26 passed, no regressions at either consumer.
  • Issue reproduction on the built CLI (scripts/rea.mjs analyze-javascript-application, short vs padded fixtures):
{ name: 'short', coverage: 'partial' -> 'complete', originals: 0 -> 2 }
{ name: 'padded', coverage: 'complete', originals: 2 }  // unchanged
  • npm run typecheck — clean.
  • npx oxfmt --check + repo lint gates — clean on the two changed files.

A version-3 map whose sourcesContent array is shorter than its sources
inventory was rejected by hasValidSourceMapContents, dropping every
original-source declaration during analyze-javascript-application
instead of decoding missing trailing slots as null content.

Per ECMA-426 DecodeSourceMapSources step 6.5, a content entry is read
only when the source index is within sourcesContent; the decoded source
then starts with null content. Relax the shared validator from exact
cardinality to contents.length <= sourceCount:

- trailing missing slots validate and decode as null content, matching
  the padded-array behavior;
- scalar content fields and non-string/non-null entries are still
  rejected;
- extra entries beyond the source inventory are still rejected, since
  decoding ignores them silently and that signals a mismatched map.

Both consumers already read content by source ordinal and map absent
entries to null, so no consumer changes are needed.

Fixes morluto#2821
@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-13T16:12:02.944474Z 9e249ca 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: 3a208d11c4

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

Comment thread src/domain/sourceMapContents.ts Outdated
contents === null ||
(Array.isArray(contents) &&
contents.length === sourceCount &&
contents.length <= sourceCount &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update boundary tests for accepted short content arrays

When the Vitest boundary projects run, the new [] <= 1 case is accepted here, but the unchanged cases in tests/boundary/filesystem/javascriptArtifactReconstruction.test.ts:135-169 and tests/boundary/browser/webSourceMapFetcher.test.ts:809-842 feed exactly sources: ["source.ts"] with sourcesContent: [] and still assert an invalid result. Those two parameterized cases now fail, so update them to assert accepted missing content and preserve their malformed-cardinality coverage with an oversized array rather than changing only the module test.

AGENTS.md reference: AGENTS.md:L77-L77

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Changes source map validation logic for trailing content slots.

The PR appears safe to merge, with a non-blocking recommendation to test the restored application output.

Findings

  1. P2 Restored sources lack test coverage ▶
Fix with agent prompt
### Issue 1
src/domain/sourceMapContents.test.ts:12-15
The new test checks only `hasValidSourceMapContents`, not the analysis output this fix restores. A future change could drop original-source declarations again while these tests still pass. Add a regression test through `analyzeJavaScriptArtifactFiles` with two sources and one content entry. Assert that both declarations survive, the first keeps its content, and the second has null content and hash.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

hasValidSourceMapContents now accepts shorter sourcesContent arrays while still rejecting extra entries and invalid entry types.

  • Source maps keep source declarations when content lists end early.

Reviews (1) · Last reviewed commit: "fix(source-maps): accept short sourcesCo..." · Reviewed by Greptile

Comment thread src/domain/sourceMapContents.test.ts Outdated
Comment on lines +12 to +15
it("accepts trailing missing content slots as null content per ECMA-426", () => {
expect(hasValidSourceMapContents(2, ["retained source"])).toBe(true);
expect(hasValidSourceMapContents(2, [])).toBe(true);
expect(hasValidSourceMapContents(2, ["a", "b", "extra"])).toBe(false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Restored sources lack test coverage

The new test checks only hasValidSourceMapContents, not the analysis output this fix restores. A future change could drop original-source declarations again while these tests still pass. Add a regression test through analyzeJavaScriptArtifactFiles with two sources and one content entry. Assert that both declarations survive, the first keeps its content, and the second has null content and hash.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/sourceMapContents.test.ts
Line: 12-15

Comment:
**Restored sources lack test coverage**

The new test checks only `hasValidSourceMapContents`, not the analysis output this fix restores. A future change could drop original-source declarations again while these tests still pass. Add a regression test through `analyzeJavaScriptArtifactFiles` with two sources and one content entry. Assert that both declarations survive, the first keeps its content, and the second has null content and hash.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

The source-map cardinality fix is already integrated in #2873 (3f80b75708f88e51c64eb0122c178b96789c53b3), including short and empty content arrays. The updated branch now has exactly the same Git tree as captured main 72b9ab4af16a4f19383aa6dde4b12f25fab7f59f, with no remaining source change to merge. Closing this superseded PR. Thanks @Jackzigen for the original contribution and reproduction.

Validation for this maintenance update was source and Git tree/ancestry inspection only; no tests or executable checks were run.

@morluto morluto closed this Oct 13, 2026
@morluto morluto added the bug Something isn't working label Oct 14, 2026
@morluto morluto added the area: evidence Evidence, artifacts, and reconstruction label Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants