test(cmd): let the DB-less boot stubs build the encryption tier (S04-A required encryption block plan: 9/16)
Summary
Unit tests boot the app through stubs that have no real database.
stubbedDatabaseOnly gives the encryption tier a nil database client, and the
production store factory refuses a nil client. So once a test config carries
the encryption block, every boot through that stub would fail. This MR gets
the stubs ready for that. No test config has the block yet, so no boot changes
behavior.
stubbedDatabaseOnly(whichstubbedDatabasebuilds on) andrealDatabaseOverridenow install fake store and manager factories, through the newfakeEncryptionFactories. It makes new spies each time it is applied, because a spy records its arguments without a lock, and two parallel boots must not share one.stubbedDatabaseWithUnstartedClientbuilds onstubbedDatabase, so it now puts the production factories back. The threeTestWireEncryption_SweeperStops*goleak tests boot through it. Over a fake manager they would pass with no sweeper goroutine to leak.- The new
TestWireEncryption_BootStubsBuildTheTierboots each of the three stubs with the block and its own root key. A boot with the block passes only afterwireEncryptionhas built the row encryptor. The test also checks the type of the store and manager each stub built. recordingManagerFactorynow wraps a given factory and records the store it gets, so the new test can see it.
Governing ADRs
None. This MR changes test code only. ADR-023 (code structure) is the closest:
it sets the cmd/ and internal/ layout, and this MR edits existing test
files under cmd/ without adding any. ADR-007 describes the encryption key
tables, which this MR does not touch. ./scripts/adr-freshness.sh reports the
mirror current. The two internal ADRs were not checked at their source.
Testing
go test -race ./cmd/artifact-registry/ passes at the head, rebased on main
at c7d7b6e274. Each mutation below ran through go test -overlay, so the
tree never changed:
| Mutation | Fails |
|---|---|
remove the encryptionShutdown registration in wire_encryption.go |
TestWireEncryption_SweeperStopsOnGracefulShutdown |
remove the fakes from stubbedDatabaseOnly |
only the stubbedDatabase row of the new test, with errEncryptionRequiresDatabase |
remove the fakes from realDatabaseOverride |
only the realDatabaseOverride row, on the type checks |
remove either restore line from stubbedDatabaseWithUnstartedClient |
only the unstarted-client row |
- The third row has no boot failure to see: that stub's client is not nil, so the production factories boot too. That is why the test checks types.
- The last row is why the new test is needed: the three goleak tests stay green there, because a fake manager has no sweeper to leak.
- Not tested: that
fakeEncryptionFactoriesmakes new spies on each apply. Both callers already call it inside their own override, so every boot gets new spies either way. Sharing would need onefakeEncryptionFactories()value applied to two parallel boots, and no code does that. - Plan Step 9 asks for a test that the stub builds a row encryptor.
assembledAppexposes no row encryptor, and this step adds no production accessor.wireEncryptionreturns nil only aftercrypto.NewDefaultRowEncryptorsucceeds, so a passing boot with the block is the check.
No e2e scenario and no user documentation is affected: this MR changes test code only.
Spec coverage
| # | Criterion | Tests |
|---|---|---|
| Step 9 | the stubs without a database build the tier | TestWireEncryption_BootStubsBuildTheTier |
| 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 / E-4 | root key malformed, or no valid keys | TestWireEncryption_MalformedSecretFailsBoot, unchanged |
| S-2 | cached keys swept by a sweeper | TestWireEncryption_SweeperStops*, unchanged, still on the production manager |
Every other AC, E and S row: not this step. This MR changes none of their code.
Overlaps
No merge order is needed. Step 11 will stack on this branch.
- !3343 (merged) (Step 8) edits other declarations in
main_test.go, which merge cleanly. Its Status row 8 sits next to this branch's row 9, so whichever lands second rebases that one line. It already conflicts withmainin that table. - !3226 (closed) (draft) rewrites the same
stubbedDatabaseOnlydoc comment. It already conflicts withmaininmain_test.go, so it needs a rebase either way. - !2969 (merged) overlaps
main_test.goandwire_services_authz_boot_test.go, which merge cleanly. It already conflicts withmaininmain.go. - !3348 (merged) (draft) overlaps
main_test.goand merges cleanly.
Closes https://gitlab.com/gitlab-org/ops/artifact-registry/-/work_items/1485