feat(npm): hold the merge tail at its encoded size, part 3/5

Summary

Part 3 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 the second pass hold no more than the first pass charged. The merge tail's retained fields (descriptive fields, time values) are captured at their exact encoded size instead of growing a buffer, and the tail's strings are written in slices of at most 32 KiB cut at a rune start, with no second copy. MergeDistTags now streams through a buffered writer.

Behavior changes to note: merged tail strings (version keys, dist-tag names and values, time keys, time.modified and time.created) are written without HTML escaping, consistent with the rest of the merged document. The characters <, >, &, U+2028 and U+2029 come out raw instead of as \uXXXX escapes, and both forms decode to the same string. Because the served bytes change, the virtual document ETag version byte moves from 0x01 to 0x02, which invalidates every cached validator of a virtual packument or dist-tags response once. Before, an 8 MiB string of < peaked at about 7.2 times its reservation; it now peaks at about 0.5 times.

Governing ADRs

None related: this part changes how already-validated data is held and written. Checked ADR 004 (entity-count limits); it does not bear on encoding.

Testing

  • Heap tests assert the tail write stays within the reservation, that capturing a string, object or time field allocates near its size, and that an oversized string stays within the reservation at the tail write; two tests cover the quote writer's slicing.
  • Build, vet and the unit tests of the touched packages pass at this part.
  • No e2e row is added or affected: the bound is on heap, which no black-box scenario observes. No docs/user change: no user page covers npm virtual merge outcomes.

Size

800 reviewable lines: 480 production, 320 tests. Over the 500 ceiling: the capture rework, the quote writer and the streamed dist-tags share one behavior, the heap tests that prove it are most of the second half, and moving the writer code into its own file counts its lines twice.

Stacked MRs (review/merge bottom-up)

Related to #1524 (closed)

Edited by David Fernandez

Merge request reports

Loading
Loading