feat(npm): serve the virtual dist-tags route (S31 plan: 16/19)
Summary
Serves GET and HEAD on a virtual (kind=1) repository's dist-tags route: the merged tag map, collected across every eligible upstream and re-pointed by nothing, because a dist-tags body carries no URL.
The route is a target plus the shared virtual document serve. virtual_disttags.go names the kind=1 document through VirtualDistTagsTarget and answers through newVirtualDocumentServe and serveRead, so the arm order, the body floor, the re-point pass, the validators, and the refusal mapping are Step 15's, shared with the packument route rather than reimplemented. cmd/artifact-registry/wire_npm_virtual.go builds one VirtualDocumentHandlerDeps for both metadata slots, so neither route's read surface can drift from the other's.
Stacked on sshen/s31-npm-virtual-step-15 (!3109 (merged)). Both parts of Step 15 merge first: part 2/2 adds the composition's UpstreamAssembly field this step's slot reads, so the branch does not compile against a base at part 1/2. Review the commits after c1bfb06f2, the current tip of that branch: it is the base this MR was rebased onto and validated against.
Governing ADRs
- ADR-005 (delivery mode): dist-tags is a metadata document, so both arms force-stream — the hosted read and the merge's input blob — a redirect is a fault rather than a redirect, and the media type comes from the target rather than from the storage backend.
- ADR-009 (API design): the route is the one the ADR names for npm dist-tags, and the virtual kind serves the same URL as hosted and remote.
HEADon this route is S31's own extension; the ADR's npm rows enumerateGETandPUT/DELETEonly. - ADR-007 (database schema): no schema, migration, or query change; the read addresses
kind=1(dist_tags) as the ADR's legend defines it. - ADR-001 / ADR-004: not implicated — no anchor, quota, or limit code. The unenforced 20-upstream cap is pre-existing and already recorded in the plan.
Spec coverage
Spec: docs/specs/S31-npm-virtual.md
Acceptance criteria
| # | Criterion | Tests |
|---|---|---|
| Packument re-point #9 | The merged dist-tags map is served with no rewriting | TestVirtualDistTagsHandler_ServesTheMergedMapUnrewritten, TestVirtualDistTagsHandler_ServesTheMergedMapAcrossContributorMixes |
| Resolution, "A just-published package is found on its hosted upstream" (dist-tags slice) | A publish's force-expired hosted position contributes and the remote is asked rather than skipped | TestNpmVirtualDistTags_AJustPublishedPackageIsFoundOnItsHostedUpstream |
| Resolution, "A tag-less hosted package is a Hit, not a Miss" (end-to-end half) | The hosted empty map is a contribution, so the remote is still collected and the served map is the union | TestVirtualDistTagsHandler_TagLessHostedPositionContributesItsEmptyMap (three subtests, the third being hosted alone answering {} at 200) |
| Packument merge #6 (closed) | The two dist-tags surfaces agree | TestVirtualDistTagsHandler_AgreesWithThePackumentRoutesDistTags, TestNpmVirtualDistTags_AgreesWithThePackumentRouteThroughTheMount |
| Validation and reads #1, dist-tags third | HEAD matches GET |
TestVirtualDistTagsHandler_HeadMatchesGet, TestVirtualDistTagsHandler_HeadFramesARefusalAsItsGetDoes |
| Validation and reads #4 (closed) | An invalid package name is refused before any resolution | TestVirtualDistTagsHandler_InvalidPackageNameIsRefusedBeforeResolution |
Error cases
| Condition | Status / code | Tests |
|---|---|---|
| Invalid package name | 422 package_name_invalid |
TestVirtualDistTagsHandler_InvalidPackageNameIsRefusedBeforeResolution, which also asserts zero list reads, zero rule reads, zero statements, and zero upstream calls |
| Merge produced no document, an absence established | 404 package_not_found |
TestVirtualDistTagsHandler_ServesTheMergedMapAcrossContributorMixes, whose all-absent mix is the case |
| Merge read with some positions omitted | 200, merged_partial |
The collector's, driven with a dist-tags target: TestNpmMergeCollect_DistTagsAndAbbreviatedKinds |
| A resolution or virtual binding missing from the request context | 500 internal_server_error |
TestVirtualDistTagsHandler_WiringFaultsAnswer500 |
An unset npm.public_registry_url over a remote position |
500, before any upstream is asked | TestNewVirtualDistTagsHandler_AcceptsAnEmptyPublicRegistryURL |
| A merge-side panic | 500 with the body truncated, never a partial document | Step 13's serve suite: TestVirtualDocumentServe_AMergePanicAnswers500 |
| A shed hosted rebuild | 503 inline_build_*, relayed |
TestNpmMergeCollect_AShedHostedRebuildVetoesTheRead, whose inline_build_capacity_exceeded_dist_tags case drives a dist-tags target |
| No absence established and a consulted position failed, or every eligible position is unhealthy | 503 upstream_unavailable + Retry-After |
The verdict is the collector's (TestNpmMergeCollect_NoDocumentAnswersTheCollectionVerdict) and the route serves whatever it returns. Not asserted end to end on this route; the packument route carries that journey. |
| The route's slot is not wired | 501 not_implemented |
TestBuildNpmDispatcher_WiredCompositionAnswers501OnEachUnservedVirtualRoute |
Security considerations
| Concern | Tests |
|---|---|
| The contributing upstream's host and the re-point base stay out of the served document | TestVirtualDistTagsHandler_ServesTheMergedMapUnrewritten, which asserts NotContains on both |
| Name validation precedes resolution, so a name no position could hold costs no statement and no request | TestVirtualDistTagsHandler_InvalidPackageNameIsRefusedBeforeResolution |
The merge's retained state is bounded by max_versions_per_package |
TestNpmVirtualMergeLimits_BoundsAnInputObjectByMaxVersionsPerPackage (Step 13's suite), and TestNewVirtualDistTagsHandler_PanicsOnANonPositiveKnob, which pins that the bound cannot be wired to zero |
| Authorization is on the addressed repository, with no per-upstream check | S13's model, unchanged here. This route adds no check and no test. |
| Denied upstreams are indistinguishable in the response | Rule evaluation is Step 11's, and virtual_rules_test.go drives a dist-tags target. This route serves the collector's verdict and has no case of its own. |
| No new outbound surface: SSRF covers, redirect credential stripping, outbound path-segment validation | Every request runs through S13's client and S15's operations, unchanged. No test here. |
Testing
internal/format/npm/virtual_disttags_test.go: handler tables across contributor mixes, thekind=1document addressed directly rather than derived from a packument,HEADparity, the tag-less hosted position contributing an empty map on both fixtures, the two-surfaces agreement against the packument route, both deadline arms, wiring faults, and name validation proving no resolution ran.cmd/artifact-registry/wire_npm_virtual_disttags_integration_test.go: the mounted journey — a publish to the hosted position with its metadata rows force-expired, read beside a remote holding the same name — and the two surfaces agreeing through the production mount.cmd/artifact-registry/wire_npm_virtual_test.go,wire_npm_virtual_integration_test.go: Step 14's slot and mount tables, whose interim-501arms this route leaving501invalidates.
Mirror diff against Step 15's suites, per ## Mirroring an existing suite. Unit: virtual_packument_test.go holds seven tests and this suite covers six of them plus eight of its own; the seventh, NegotiatedAcceptReachesTheAssembly, is replaced by AddressesTheDistTagsDocumentDirectly, because this URL negotiates no variant, and the plan's Tests bullet records that substitution. Integration: the two files are not mirror images. Of the eleven packument journeys not repeated here, two are variant-specific (AbbreviatedVariantForwardsItsAccept, OneVariantsFillDoesNotAnswerTheOther), three are covered at handler level instead of through the mount (ContributorMixes, HeadMatchesGet, InvalidPackageNameIsRefusedBeforeResolution), and the rest are the collector's target-agnostic verdicts, driven with a dist-tags target in virtual_collect_internal_test.go.
Ran locally: the full unit suite; the integration suite above; golangci-lint run ./...; golangci-lint run --build-tags=integration ./cmd/artifact-registry/... --max-same-issues=0 --max-issues-per-linter=0 --uniq-by-line=false; the comment-cap check; and driver.sh smoke on an isolated rig, 97 passed, 0 failed.
No e2e scenario added or affected, because the catalog section is owned by Step 19, the plan's single owning step for docs/testing/e2e/npm.md.
No user documentation is affected: docs/user/repositories/_index.md makes no claim this change falsifies, and no install journey completes until the tarball route lands.
The run-recipe edits are guardrail 21's — the recipe moves in the same MR as the dispatch change — not a standalone skill MR; Step 15 part 2's MR does the same.
Plan and spec amendments
docs/plans/2026-08-21-s31-npm-virtual.md, in Step 16's own text:
- Depends on names the merge order (both parts of Step 15 first) and the window it closes.
- Files names the two cmd test files this step's slot flip invalidates and the new integration file, rather than leaving them under "the paired test files". The Dependencies-table row and the graph edge carry the same dependency declaration.
- Tests names the mounted twin of the two-surfaces agreement, records the two deliberate deletions against Step 15's suite, states that the mounted journey runs inside the post-publish window with no fresh-row case, and records the served body's exact-rendering assertion alongside the two-surface equality.
- The integration-journey list names Step 16 beside Steps 15 and 19.
No spec clause changes.
MR size
1,423 insertions across 9 files, past the 500-line guideline. Production Go is 86 lines (virtual_disttags.go 57, wire_npm_virtual.go 29); tests are 1,286 (virtual_disttags_test.go 985, the new integration file 275, the two Step 14 tables 26); the run recipe is 21; the plan is 30. Splitting the tests from the handler would land a route with no coverage, which is the split the plan's Seam interrogation rejects.
Related to #897 (closed)