feat(npm): add the virtual tarball handler
What this MR does
This MR adds npm.VirtualTarballHandler, the GET and HEAD handler for the tarball route of an npm virtual repository.
For each read, the handler does these steps:
- It validates the target before any resolution:
400for an unsafe file name,404 file_not_foundfor an unparseable file name,422for an invalid package name. - It parses the version from the file name, so that a version rule matches against it.
- It resolves over the upstream list and serves the bytes of the priority winner, with no re-point.
A stored winner is served by proxy or by a
307redirect, and a cold remote winner streams its upstream body. - A hosted winner sends
npm_files.created_atasLast-Modified, andCache-Controlfollows the virtual repository. - A winner whose stored blob is gone answers by its kind:
404for a hosted winner,503for a remote winner (ruling E18). - Every no-winner verdict answers through
writeVirtualReadError.
The handler arms the write deadline two times, the same as in !3111 (merged).
A failed arm increments gitlab_artifact_registry_npm_virtual_response_deadline_arm_failures_total and logs a Warn line that names the tarball route.
Nothing wires the handler yet.
Interim behavior that part 4 replaces
Two paths are simpler in this part than in the final handler:
- A body copy that fails after the
200writes one Warn line. Part 4 adds the outcome booking per body source, the rationed deadline-kill line, and the abort of a chunked relay that ends short. - A cold
HEADwhose drain fails answers throughwriteVirtualReadErrordirectly. Part 4 sends the failure toResolveDrainFailure(part 2), which can serve the cached copy of the winner.
Tests
virtual_tarball_test.go holds the main suite: winner selection, rules, no-winner verdicts, target rejection, HEAD parity, conditionals, Cache-Control, the delivery-mode override, the close of a cold stream body, and wiring faults.
virtual_tarball_faults_test.go starts with the redirect, storage-fault, vanished-blob, and unservable-resolution cases.
It also holds the write-deadline arm cases, the arm-failure counter case, and the client-disconnect 499 cases.
Part 4 adds the rest of that file.
virtual_tarball_internal_test.go tests two unexported paths: the deadline re-arm, and the 500 fallback of writeReadError.
The rows map to the spec as the coverage table of !3111 (merged) states.
Size
This part has about 590 lines of production code and about 2,420 lines of tests, with about 790 lines of shared fixture. A further split does not help review: every test needs the fixture, and the handler has no smaller unit that serves a read.
Plan and spec amendments
This MR implements no plan step. It changes one row of the spec:
docs/specs/S31-npm-virtual.md, metrics table: thegitlab_artifact_registry_npm_virtual_response_deadline_arm_failures_totalrow now covers the packument, dist-tags, and tarball routes. Before this change, the row covered only the two metadata routes.
internal/format/npm/metrics.md (## Response-deadline and proxy series) has the same change.
Split of !3111 (merged)
This MR is one part of a split of !3111 (merged) into six stacked MRs. Each part targets the branch of the part before it, so each diff shows only that part. Merge the parts in order: 1, 2, 3, 4, 5, then !3111 (merged) itself as part 6.
| Part | MR | Contents |
|---|---|---|
| 1 | !3150 (merged) | npm_files.created_at to the hosted tarball winner |
| 2 | !3147 (merged) | Resolver re-entry on a virtual drain failure |
| 3 | !3148 (merged) | VirtualTarballHandler, not wired |
| 4 | !3149 (merged) | Copy-fault accounting, kill log, cold HEAD drain failure |
| 5 | !3151 (merged) | Usage events |
| 6 | !3111 (merged) | Slot wiring, run recipe, docs |
At the split, the six parts together were byte-identical to the original !3111 (merged) diff (same git patch-id --stable).
This part received review fixes after the split, so that statement is true only for the parts as they were at the split.
The spec coverage table, the rulings (E1 to E22), and the spec gaps stay in the description of !3111 (merged).
E2E scenario catalog and user documentation
This part adds no e2e scenario and changes no file in docs/user/.
Nothing wires the virtual tarball handler before part 6, so the route still answers 501 and no client-visible behavior changes.
Related to #898 (closed)