feat(npm): serve the virtual packument route, part 2/2 (S31 plan: 15/19)
📚 Stacked MRs
S31 plan Step 15 ships as 2 stacked MRs so each stays reviewable. Part 1 has merged, and part 2 targets main.
- feat(npm): add the virtual packument handler an... (!3154 - merged) • David Fernandez • 19.5
- feat(npm): serve the virtual packument route, p... (!3109 - merged) • David Fernandez, Sylvia Shen • 19.5
👈
This is part 2 of 2 of S31 npm virtual plan, Step 15: packument handler. Spec: S31 (npm-virtual). The plan amendments for the step ride part 1.
🔍 What
Serves GET and HEAD on the npm virtual packument route, /{slug}/npm/{repository}/{package_name}, for a kind=1 repository, through the handler part 1 adds.
npmVirtualPackumentSlotswaps off the interim501.npmVirtualCompositionnow carriesAssembly, the one assemblyResolutionis built over, and the slot hands it to the handler instead of building a second one. Its deps field isAssemblyDeps.- The slot builds the handler through part 1's
VirtualDocumentHandlerDepsand passesnpm.max_versions_per_package, carried throughnpmVirtualWiring, asMaxVersionsPerPackage, the per-object bound part 1 puts on every merge input. The handler refuses a non-positive value at construction, so the test configs that reach the full dispatcher set it too. - The npm package docs (
virtual_operations.md,virtual_read_errors.md,metrics.md), the virtual handler label comment and theremote_negative_cache_ops_totalrow indocs/dev/observability.mdnow describe the wired route: the packument read is bounded byresolve_timeout, reaches the read-error mapper and its veto row, and reports undervirtual_packument. - The run recipe flips the packument smoke check from
501and documents the route. The hard-coded smoke count is untouched, per the plan.driver.sh smokepasses from zero state: 97 passed, 0 failed. - The configuration reference describes the packument read's two deadline arms under
server.timeouts.write. It also names the packument read beside the container virtual reads underresolve_timeout, in the reference and inconfig.example.yaml.
🧪 Tests
Spec coverage, mapped to tests (I = cmd/artifact-registry/wire_npm_virtual_packument_integration_test.go, W = cmd/artifact-registry/wire_npm_virtual_test.go):
| Criterion | Test |
|---|---|
| Resolution, merge (packument half) | TestNpmVirtualPackument_ContributorMixes (I), row "two remotes both holding the package" |
| Resolution, hosted-and-remote mix | TestNpmVirtualPackument_AHostedAndRemoteMixMergesTheHostedPositionsVersions (I) |
| Resolution, a definite failure never reaches the network | TestNpmVirtualPackument_ADefiniteFailureNeverReachesTheNetwork (I): denied and unhealthy positions get zero calls, the cold peer exactly one |
| Resolution, just-published package (packument slice) | TestNpmVirtualPackument_AJustPublishedPackageIsFoundOnItsHostedUpstream (I) |
Resolution, a hosted miss alongside an unhealthy remote (metadata half: 503) |
TestNpmVirtualPackument_AHostedMissAlongsideAnUnhealthyRemoteIs503 (I): upstream_unavailable, Retry-After, zero calls to the remote |
| Resolution budget expiry, as the client receives it | TestNpmVirtualPackument_AnExpiredResolutionBudgetIs503WithRetryAfterOne (I): 503, upstream_unavailable, Retry-After: 1 |
| Packument re-point #1, #4 (closed) | requireVirtualPackument over every served read in ContributorMixes (I) |
| Packument re-point #8 (closed) | TestNpmVirtualPackument_AbbreviatedVariantForwardsItsAccept (I) |
| Concurrency #1, #2 | TestNpmVirtualPackument_ConcurrentReadsShareOneUpstreamFetch, TestNpmVirtualPackument_CoalescingHoldsAcrossVirtualRepositoriesAndADirectRead (I) |
| Validation and reads #1 (packument third) | TestNpmVirtualPackument_HeadMatchesGet (I) |
| Validation and reads #4 (closed) | TestNpmVirtualPackument_InvalidPackageNameIsRefusedBeforeResolution (I) |
| Cache parity, multi-remote, per variant | TestNpmVirtualPackument_AVirtualFillWritesTheRowADirectFillWrites (I) |
| Cross-variant | TestNpmVirtualPackument_OneVariantsFillDoesNotAnswerTheOther (I) |
| Slot wiring | TestNpmVirtualPackumentSlot_SetsOneOptionOverAWiredComposition, TestBuildNpmDispatcher_WiredCompositionServesTheVirtualPackument (W) |
| Production mount boots with the packument served | TestMountSlugAnchoredFormats_NpmVirtualRoutesAreMounted (cmd/artifact-registry/wire_npm_virtual_integration_test.go): the packument answers 404 package_not_found over an empty upstream list, the other two routes 501 |
The pre-commit hooks (go test ./... and golangci-lint) pass on the head. The integration suite runs in the pipeline.
docs/testing/ is unchanged: the merge journey is cataloged once the three npm virtual routes serve, at Step 19. docs/user/ is unchanged: npm virtual repositories are not documented for customers until the end-of-plan docs-author pass, and the dist-tags and tarball routes still answer 501.
📏 Size
1,450 reviewable LoC across 17 files, past the 500 guideline and the stack's 1,200 part ceiling:
| Group | LoC |
|---|---|
| Integration suites | 1,177 |
| Wiring tests | 94 |
| Package and observability docs | 90 |
| Slot wiring source | 51 |
| Run recipe | 30 |
| Configuration docs | 8 |
The route-neutral part of the integration harness (314 LoC) lives in wire_npm_virtual_harness_integration_test.go, so the dist-tags and tarball steps can reuse it. Everything here ships with the slot swap. Splitting the integration suite from the wiring would land a serving route without its acceptance coverage. The recipe flip is required in the same MR as the swap, and the configuration reference documents only live behaviour. The package docs say what the wired route does, so they cannot land before the route serves. That is why part 1 holds everything that can land before the route serves.
Related to #896 (closed)