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.

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.

  • npmVirtualPackumentSlot swaps off the interim 501. npmVirtualComposition now carries Assembly, the one assembly Resolution is built over, and the slot hands it to the handler instead of building a second one. Its deps field is AssemblyDeps.
  • The slot builds the handler through part 1's VirtualDocumentHandlerDeps and passes npm.max_versions_per_package, carried through npmVirtualWiring, as MaxVersionsPerPackage, 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 the remote_negative_cache_ops_total row in docs/dev/observability.md now describe the wired route: the packument read is bounded by resolve_timeout, reaches the read-error mapper and its veto row, and reports under virtual_packument.
  • The run recipe flips the packument smoke check from 501 and documents the route. The hard-coded smoke count is untouched, per the plan. driver.sh smoke passes 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 under resolve_timeout, in the reference and in config.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)

Edited by David Fernandez

Merge request reports

Loading
Loading