refactor(cmd): move the nil-client check into the store factory (S04-A required encryption block plan: 7/16)
Summary
The check that a present encryption block has a database client moves out
of wireEncryption and into defaultNamespaceKeyStore, the production store
factory. Step 9 needs this. The unit-test stub boots with no database client,
and its fake store factories can build the tier only once the check stops
sitting in front of them.
- The check now runs after the root key is read and decoded. The refusal
still carries
errEncryptionRequiresDatabase, now wrapped ascomposition: constructing namespace key store. - Without the check, the datastore constructor panics on a nil client. The factory refuses it first with the named error.
- Only a test reaches this arm. A production boot always has a client, or fails earlier in the database tier. No fixture carries the block yet, so no boot changes behavior.
TestWireEncryption_PresentBlockWithoutDatabaseFailsBootnow boots with a valid root key and the production store factory. It sets that factory explicitly, so a fake store from an earlier override cannot replace it.- Comments that named the old guard now describe the new place.
Governing ADRs
None. The change moves one check inside the composition root. ADR-007
(encryption keys) describes the key tables, not boot wiring. ADR-023 covers
code structure and the composition root's size, which this change does not
move. ./scripts/adr-freshness.sh reports the mirror one commit behind, on
ADR-003's upload-session cap paragraph, which this change does not touch. The
two internal ADRs were not checked at their source.
Testing
- The pre-commit
go testhook passed the unit suite on the last commit. - Each mutation below was applied through
go test -overlay, so the tree never changed:
| Mutation | Fails |
|---|---|
remove the nil check from defaultNamespaceKeyStore |
PresentBlockWithoutDatabaseFailsBoot, on ErrorIs |
keep that check and restore the old early guard in wireEncryption |
PresentBlockWithoutDatabaseFailsBoot, on ErrorContains |
| build the store before the root-key read | SecretReadFailureFailsBoot only. The test above cannot see this order. |
delete the explicit d.newNamespaceKeyStore = defaultNamespaceKeyStore |
nothing yet |
The last row is expected. No stub installs a store factory today, so the
override changes nothing. It starts to matter in Step 9, when
stubbedDatabaseOnly installs a fake store that accepts a nil client. From
then on, deleting the override fails this test, because the boot passes the
fake store and stops at the manager spy instead.
No e2e scenario is affected, and no user documentation: only a test boot reaches the moved check.
Spec coverage
| # | Criterion | Tests |
|---|---|---|
| Step 7 | the store factory refuses a nil client | TestWireEncryption_PresentBlockWithoutDatabaseFailsBoot |
| AC-28 / E-1 | no encryption block fails startup, naming it | none added. Step 12 owns it. |
| E-2 | root key file missing | TestWireEncryption_SecretReadFailureFailsBoot, unchanged |
| E-3 | root key not 32 bytes | TestWireEncryption_MalformedSecretFailsBoot, unchanged |
| E-4 | root key file holds zero valid keys | TestWireEncryption_MalformedSecretFailsBoot, unchanged |
Every other AC, E and S row: not this step. This MR changes none of their code.
Plan and spec amendments
This step's review corrected the plan:
- Step 7's Files list gains
wire_encryption_test.go. ItsstubbedDatabaseWithUnstartedClientdoc named the old guard. - Step 7's Shared seams says Step 9 edits that same helper and is stacked on this step, and that Step 10 edits other declarations in the file, so the two merge in either order.
- Step 10's Shared seams names Step 7 beside Step 9. Step 10 has !3344 (merged) open. That MR does not touch these lines, and the two merge cleanly.
No spec text changes.
Overlaps
No merge order is needed. Step 9 will stack on this branch.
- !3343 (merged) (Step 8) edits other declarations in
wire_encryption_failure_test.go, which merge cleanly. Its Status row 8 sits next to this branch's row 7, so whichever lands second rebases that one line. - !3344 (merged) (Step 10) edits other declarations in
wire_encryption_test.go, and its own Status row. It merges cleanly. - !3320 (merged) (Step 5) edits the plan. It merges cleanly.
- !2969 (merged) and !3226 (closed) (draft) overlap
wire.go, which merges cleanly. Both already conflict withmainin files this branch does not change, so they need a rebase either way.
Closes https://gitlab.com/gitlab-org/ops/artifact-registry/-/work_items/1483