Repository navigation
fix(source-maps): keep sources when sourcesContent length differs - #2873
Conversation
ECMA-426 DecodeSourceMapSources reads a content slot only while its index is within sourcesContent, so a shorter array leaves trailing sources without content and a longer array adds no sources. Local application analysis and browser collection rejected any length mismatch and dropped every original from the map. The content helper now checks only entry types. Browser collection drops its separate check because the leaf schema already validates every supplied entry, and the raw records are still budgeted before parsing. Fixes morluto#2821
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
|
Welcome to REA, @rileygramlich. Thanks for keeping source declarations when |
Summary
Fixes #2821.
When a source map's
sourcesContentarray is shorter or longer thansources, keep every source declaration and whatever embedded text is present. This applies to local application analysis and to browser source-map collection.Problem and expected behavior
With
sources: ["a.ts", "b.ts"]andsourcesContent: ["export const answer = 42;"]:analyze-javascript-application) marked the map invalid. It dropped both originals and reported the graph aspartial.Padding the array with one
nullmade both work.ECMA-426 DecodeSourceMapSources, step 6.5, reads a content entry only when its index is within
sourcesContent, and starts each source with null content. A shorter array leaves trailing sources without content. Extra entries add no sources, because the loop runs oversources.Change and scope
hasValidSourceMapContentsdrops the source-count parameter and the equality check. It now checks only that the field is absent, null, or an array of strings and nulls.z.array(z.string().nullable()).nullable().optional()) already rejects bad entry types, and raw content records are still counted against the budget before parsing.TraceSourceMap) already accepted short arrays (TraceSourceMap.test.tsmaps two sources to one content entry), so all three paths now agree.Not included: a non-string, non-null entry still makes the map invalid. The spec allows treating such an entry as null with an optional error. That is a separate policy change.
This is an ordinary fix within existing boundaries, so no maintainer scope decision is needed.
Contract and boundary impact
Semantic owner and earliest changed stage:
src/domain/sourceMapContents.ts(content admission), used by local analysis;SourceMapFormatleaf structure for browser collection.Contribution scope fit and linked maintainer decision: not applicable (bug fix in read-only source-map interpretation).
CLI and MCP/tool-catalog contract: no schema change. Maps that were rejected are now admitted. The limitation text for invalid content changes to "must be an array of strings or null entries".
Provider, bridge, target-format, or platform compatibility: none.
Evidence, artifact, provenance, or reconstruction contract:
source_indexanddeclaration_indexstay aligned withsources. Sources past the end ofsourcesContentreport no content.Target selection, authority, upstream behavior, and cleanup details: not applicable.
Generated metadata, package, or installation impact: none.
Read existing files or captured data.
Evidence and regression coverage
Tests added or updated:
tests/boundary/filesystem/javascriptArtifactReconstruction.test.ts: shorter and longer arrays keep both originals (a.tswith content,b.tswithout), and coverage stayscomplete. Removed the case that expected a length mismatch to be invalid.tests/boundary/browser/webSourceMapFetcher.test.ts: the same two cases for browser collection (included, two originals, artifact only fora.ts). Removed the wrong-length invalid case; the scalar and non-string entry cases still fail.src/domain/sourceMapContents.test.ts: updated for the new signature.Base reproduction: all four new boundary cases fail on
origin/mainand pass with this change. The script from [Bug] Short sourcesContent arrays discard valid source-map originals #2821 now prints{ name: 'short', coverage: 'complete', originals: 2 }(previouslypartial,0).Remaining proof gaps: browser collection was verified through the boundary test with a stubbed fetch, not against a live browser.
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 run test:focused -- <every *.test.ts that mentions sourcesContent>(14 files): 276 passed.npm run check:fast: typecheck and lint passed.npm run verify:test-discovery: all 1088 test files discovered exactly once.npm run build:cached: short, padded, and longer maps all reportcompletewith 2 originals.Compatibility, safety, and release
Related: #2829 (the reporter's closed PR for this issue) and #2831 (merged; it touched the neighbouring
namescheck inSourceMapFormat.ts). This change is rebased on top of #2831.#2869 also targets this issue. It allows only shorter arrays (
length <= sourceCount), so a longersourcesContentis still rejected, and it leaves the boundary tests that expectsourcesContent: []to be invalid. This PR accepts both directions, as step 6 of the spec does, and updates those boundary tests.Before merge
type(scope): outcome.