feat(npm): charge the merge parse's retained state, part 2/5
Summary
Part 2 of 5 of a stack of merge requests (each targets the previous one; review and merge bottom-up) that bounds the npm virtual metadata merge's memory with a charged parse and a shared merge memory budget, as the Maven virtual merge already does (#1524 (closed)).
No plan file exists for this work: the work item graded as needing a spec amendment first, and the operator chose to ship the S13 (virtual-remote-foundation), S30 (maven-virtual) and S31 (npm-virtual) amendments in this stack instead of a plan MR.
This part makes npm's first merge pass charge what the second pass will retain. Pass 1 reads each input as a token stream, keeps nothing, and adds up a charge: each retained field at two string headers plus its encoded bytes (a descriptive key at its quoted length), plus measured per-version, per-time-entry and per-tag allowances. An input whose charge passes its cap, max(2 x stored size, 64 KiB), is dropped from the merge as omitted with ErrMergeInputTooLarge. The interim per-object member bound stays.
Output change: a descriptive top-level key holding <, >, &, U+2028 or U+2029 is now emitted as the raw character instead of a \uXXXX escape, because both passes quote it with one function. Both forms are valid JSON and decode to the same key.
Governing ADRs
ADR 004 (25,000 versions per package, 20 upstreams per virtual) governs the interim member bound, which this part keeps. No conflict found.
Testing
- Charge table tests, a pin of each measured allowance against the heap (measured value at most the constant, constant at most twice the measured), a never-overcharge property, and omission tests for an over-cap input and an escaped descriptive key charged at its quoted length.
- Build, vet and the unit tests of the touched packages pass at this part.
- No e2e row is added or affected: an over-cap input needs a document shape no black-box scenario produces. No
docs/userchange: no user page covers npm virtual merge outcomes.
Plan and spec amendments
- S31 (npm-virtual): the first pass also charges retained state, the over-cap outcomes (
omittedfor byte cap, member bound and charge), the 200-partial error row, the size-bound bullet, and the amended note on the per-read parse bound.
Size
1,310 reviewable lines: 343 production, 922 tests, 45 specs. Over the 500 ceiling because the charge code and its heap tests cannot be separated: the tests pin the measured constants the code uses, and the S31 text describes exactly this charge.
Stacked MRs (review/merge bottom-up)
- refactor(virtual): share one merge memory budge... (!3184 - merged) • David Fernandez • 19.5
- feat(npm): charge the merge parse's retained st... (!3185 - merged) • David Fernandez • 19.5
👈 - feat(npm): hold the merge tail at its encoded s... (!3186 - merged) • David Fernandez • 19.5
- feat(npm): admit the virtual merge against the ... (!3187 - merged) • David Fernandez, Dzmitry (Dima) Meshcharakou • 19.6
- feat(npm): hold the merge budget until the stre... (!3188 - merged) • David Fernandez, Dzmitry (Dima) Meshcharakou • 19.6
Related to #1524 (closed)