chore(npm): register the attestation codes, label, and pins (S11 Provenance Attestations plan: 1/20)
Summary
The plan lands every new metric value, label, and pin move in one registry MR ahead of every emitter, so none of Steps 15 to 18 edits a pin. This MR is that one: five attestation_* codes, the attestations_get handler label, and the handler and code budgets at 16 and 46. It is Step 1 of docs/plans/2026-09-11-npm-provenance-attestations.md, landed by docs(plans): add the S11 npm provenance attesta... (!2648 - merged) • Hayley Swimelar • 19.4.
Three calls the diff does not explain:
internal/metricscount-boundshandlerand pins no value set for it, so the audit never compares a handler value against a string.attestations_gettherefore earns a dedicated literal pin, andattestations_getxwould pass every other test.s11ErrorCaseCodesis pinned at 42 against the spec table's 43. Theinline_build_supersededomission predates this branch and is owned by `s11ErrorCaseCodes` hand-transcribes S11 Error ... (#1274 - closed) • Moaz Khalifa • 19.6.attestation_not_foundanswers the three causes the handler can see, not the spec row's five. The authorization middleware answers an unauthorized private readnot_foundand the npm middleware answers a missing repositoryrepository_not_found, both ahead of the handler (plan Correction 2).
Nothing emits any of the six values until Steps 15 to 18.
Governing ADRs
scripts/adr-freshness.sh reports the mirror one commit behind upstream, on 007_database_schema.md alone, so the ADRs below read current.
- ADR 021 fixes the 404 an unreadable resource answers on direct access. This MR registers one
attestation_not_foundcode and masks nothing itself. Its comments attribute the mask to the authorization middleware. - ADR 009 enumerates the npm routes, and the attestations route is absent. This MR mounts no route, so the gap stands where the spec records it, as a Step 18 precondition.
- No ADR governs Prometheus label cardinality. ADR 012 mentions cardinality only about Service Ping flattening, and it puts LabKit's operational metrics outside its own decision.
Testing
go test ./internal/format/npm/ ./internal/metrics/ passes at the new counts. TestRequestLabels_MatchTheCardinalityBudget pins requestHandlerLabels at 16 and requestCodeLabels at 46, and TestRegisterMetrics_PassesCardinalityAudit seeds all 46 codes through the emission rotation and finds each pinned on both sides. Misspelling a code reddens that audit, verified by hand: enumerating the five without pinning them produced closed-set label "code" carries value "attestation_bundle_too_large" outside its declared constants. Misspelling the label reddens TestHandlerAttestationsGet_PinsTheWireText instead. No production path emits the six values, so nothing mints a series.
Context for LLM agents
Spec coverage
Spec: docs/specs/S11-npm-hosted.md. Plan: docs/plans/2026-09-11-npm-provenance-attestations.md, Step 1.
Step 1 acceptance
| # | Criterion | Tests |
|---|---|---|
| A-1 | Every metrics test passes at the new counts (handler 16, code 46) |
TestRequestLabels_MatchTheCardinalityBudget, TestRequestHandlerLabels_Bounded, TestRequestHandlerLabels_CoversEveryAPIContractRoute/attestations_GET, TestRequestCodeLabels_CoversErrorCasesAndSuccess/attestation_* |
| A-2 | The audit compares all six values and finds each pinned on both sides | code half: TestRegisterMetrics_PassesCardinalityAudit, which seeds all 46 through the existing rotation; the rotation's precondition (the code set stays the larger enumeration) is now enforced by a require rather than stated in a comment. handler half: not comparable. internal/metrics pins no closedSetValues["handler"], only a count, so the audit never compares a handler value against a set. Count half: TestRequestLabels_MatchTheCardinalityBudget plus internal/metrics' TestClosedSetValues_PinnedSizeWithinBudget. |
| A-3 | Misspelling any one constant reddens the audit | Codes: TestRegisterMetrics_PassesCardinalityAudit, verified by hand (enumerating the five without pinning them produced closed-set label "code" carries value "attestation_bundle_too_large" outside its declared constants), plus TestErrorCodes/CodeAttestation* and TestRequestCodeLabels_CoversErrorCasesAndSuccess/*. Label: TestHandlerAttestationsGet_PinsTheWireText, which the audit cannot do for the reason A-2 gives. |
| A-4 | No series is emitted for any of them | Not asserted, by choice. The plan names it the step's accepted smell, and an absence assertion would have to be deleted again at Steps 15 through 18. |
Error cases
| # | Condition | Tests |
|---|---|---|
| E-1 | Bundle data over npm.max_attestation_bundle_size: 422 attestation_bundle_too_large |
TestErrorCodes/CodeAttestationBundleTooLarge, TestAttestationMessages_PinTheWireText/MsgAttestationBundleTooLarge, TestRequestCodeLabels_CoversErrorCasesAndSuccess/attestation_bundle_too_large, TestRequestLabels_MatchTheCardinalityBudget. The cap and the 422 it answers with are Steps 11 and 15. |
| E-2 | Bundle fails shape validation (no dsseEnvelope, empty sig, no cert material, undecodable payload, or a subject array whose length is not one): 422 attestation_invalid |
TestErrorCodes/CodeAttestationInvalid, TestAttestationMessages_PinTheWireText/MsgAttestationInvalid, TestRequestCodeLabels_CoversErrorCasesAndSuccess/attestation_invalid. The shape rules are Step 3 and the 422 on the wire is Step 17. |
| E-3 | Non-empty dsseEnvelope.signatures[0].keyid: 422 attestation_unverifiable |
TestErrorCodes/CodeAttestationUnverifiable, TestAttestationMessages_PinTheWireText/MsgAttestationUnverifiable, TestRequestCodeLabels_CoversErrorCasesAndSuccess/attestation_unverifiable. The keyid check is Step 3 and the 422 on the wire is Step 17. |
| E-4 | In-toto subject digest or purl does not match the streamed tarball: 422 attestation_subject_mismatch |
TestErrorCodes/CodeAttestationSubjectMismatch, TestAttestationMessages_PinTheWireText/MsgAttestationSubjectMismatch, TestRequestCodeLabels_CoversErrorCasesAndSuccess/attestation_subject_mismatch. The comparison is Step 7 and the 422 on the wire is Step 17. |
| E-5 | Attestations endpoint reached for a missing package or version, or a version holding no bundle: 404 attestation_not_found |
TestErrorCodes/CodeAttestationNotFound, TestAttestationMessages_PinTheWireText/MsgAttestationNotFound, TestRequestCodeLabels_CoversErrorCasesAndSuccess/attestation_not_found. One code answering the three causes the handler can see is Steps 16 and 18. The spec's row also lists an unauthorized private read and a missing repository, which the authz and npm middlewares answer not_found and repository_not_found ahead of the handler (plan Correction 2). |
API contract
| # | Contract | Tests |
|---|---|---|
| M-1 | The attestations route adds attestations_get to the handler label of npm_request_total and npm_request_duration_seconds |
TestHandlerAttestationsGet_PinsTheWireText (the literal), TestRequestHandlerLabels_Bounded (the closed set), TestRequestHandlerLabels_CoversEveryAPIContractRoute/attestations_GET (the route maps to it), TestRequestLabels_MatchTheCardinalityBudget (the count) |
Security considerations
| # | Concern | Tests |
|---|---|---|
| S-1 | Error envelopes carry no internal detail | TestAttestationMessages_PinTheWireText pins all five texts, the closed SafeMessage type makes an ad-hoc string a compile error, and the pre-existing TestWriteError_MessageNeverLeaksInternalDetail pins WriteError as a verbatim conduit |
| S-2 | The attestations 404 names none of the causes the handler can see | TestAttestationMessages_PinTheWireText/MsgAttestationNotFound and TestErrorCodes/CodeAttestationNotFound pin the one text and the one code the three causes share. The handler answering them is Steps 16 and 18. ADR 021's existence-hiding is the authz middleware's masked not_found, ahead of this code. |
Rationale
Accepted deviations from the plan's Step 1 section:
internal/format/npm/transport_test.gois not in the plan's Files list. Guardrail 6 requires tests for the ten constants the step introduces, andtransport_test.gois where the package'sCodeandSafeMessageliterals are already pinned.- The plan's acceptance "the audit compares all six values" is unreachable for the
handlervalue.internal/metricscount-boundshandlerand pins no value set for it, so A-2 above records the handler half as not comparable and substitutes a literal pin. - Test LOC came in at 106 against a forecast of about 30. The five wire texts and the five code literals are ten table rows, and the label's literal pin is an eleventh assertion the plan did not forecast.
LOC split: source 50 (transport.go 33, metrics.go 11, cardinality.go 6), test 106 (transport_test.go 56, metrics_test.go 50), docs 39 (metrics.md 37, observability.md 2). Total 195, under the 500 reviewable ceiling.
Non-goals
- A
wantLabelliteral field onapiContractRoute, pinning all sixteen handler labels the wayTestHandlerAttestationsGet_PinsTheWireTextpins one. The other fifteen already ship, and widening the struct here would mix a pre-existing gap into this step. - Closing the
s11ErrorCaseCodestranscription gap. The helper is hand-maintained and missesinline_build_superseded, tracked in `s11ErrorCaseCodes` hand-transcribes S11 Error ... (#1274 - closed) • Moaz Khalifa • 19.6. - Editing the S11 spec. Its Metric labels paragraph still reads "
handlerat 15 andcodeat 40 today" and "move them to 16 and 45" at lines 1915 to 1916, stale becauseupload_session_capacity_exceededlanded after the spec was drafted. The plan routes that edit, with the 404 row rewrite, to onedocs(specs)follow-up outside the plan. - Amending ADR 009's npm route list. The spec records the absence as a gap for a handbook amendment, and a local edit would violate the ADR sync rule.
gitlintcoverage of these commit messages..pre-commit-config.yamlregisters the hook, nocommit-msghook is installed in the repository, and nothing ran it locally.
Related to #1273