refactor(onboarding): readability + maintainability sweep#66
Merged
Conversation
Service today carries two heterogeneous workflows behind one type: identity attachment (find principal, then link) and principal provisioning (delegate to IdentityProvisioner). The sparse Options struct and runtime nil-port checks are the symptom of two contracts squashed into one — apps doing only attachment never set IdentityProvisioner and vice versa. Split into Attacher and Provisioner, each with a required-args constructor. Compile-time port enforcement replaces runtime nil checks. Drop the ProvisionPrincipalRequest/Result wrapper types — they were field-identical to authkit.ProvisionIdentityRequest/Result and added no value. Provisioner.ProvisionIdentity now takes and returns the root types directly. Attacher's request/result types stay package-local because they carry shapes (PrincipalID input, Principal+Link output) absent from any root type. Reorganize into per-domain files (attach.go, provision.go, validation.go) mirroring the exchange/ split from PR #63. Tests are intentionally broken at this commit and restored in the next commits. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Lift the existing tests into per-domain files mirroring the production layout: attach_test.go for the Attacher tests, provision_test.go for the Provisioner tests, helpers_test.go for the shared fixtures, consts, and hand-rolled fakes. Drop TestNewServiceAllowsSparseOptions and TestServiceMethodsRequirePorts — required-args constructors make those scenarios uncompilable. TestServicePropagatesContextCancellation splits into a per-type cancellation test per workflow. provisionRequest() now returns the root authkit.ProvisionIdentityRequest directly. Fakes are intact at this commit; mockery migration follows. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add an IdentityProvisioner entry to .mockery.yaml (PrincipalFinder and IdentityLinker were already configured), regenerate, and swap the three hand-rolled fakes for the generated authkitmocks types. Tracked-requests slice assertions subsume into EXPECT() deep-equality arg matching. Tests that short-circuit before a port call pass an unconfigured mock so a stray call would panic. Cancellation tests configure the mock to return context.Canceled explicitly since mockery mocks do not respect ctx.Err() the way the hand-rolled fakes did. .mockery.yaml grows to 19 root-port entries. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Sixth slice of the multi-session readability sweep (after
access/#61,authz/#62,exchange/#63,http/#64,management/#65). Liftsonboarding/to the same 10-criteria bar.The central change: replace the single
Service(sparseOptions+ runtime nil-port checks) with two purpose-built types, each with a required-args constructor.Attacher(find principal → link identity) takesPrincipalFinder+IdentityLinker.Provisioner(delegate to atomic create-and-link) takesIdentityProvisioner.Compile-time port enforcement replaces the runtime nil-check pattern. The redundant
ProvisionPrincipalRequest/ProvisionPrincipalResultwrapper types (field-identical toauthkit.ProvisionIdentityRequest/Result) are dropped;Provisioner.ProvisionIdentityuses the root types directly.Attacher's request/result types stay package-local because they carry shapes (PrincipalIDinput,Principal+Linkoutput) absent from any root type.Production split into per-domain files mirroring
exchange/(PR #63):attach.go,provision.go,validation.go. Tests split to match:attach_test.go,provision_test.go,helpers_test.go.Mockery picks up
IdentityProvisioner(the only missing root port —PrincipalFinderandIdentityLinkerwere already configured)..mockery.yamlgrows to 19 root-port entries. All three hand-rolled fakes are deleted;.requests/.findIDsslice assertions subsume intoEXPECT()deep-equality matching.Commits
refactor(onboarding): split Service into Attacher and Provisioner— production-only restructure.test(onboarding): split tests per workflow— mechanical lift into per-domain test files; fakes intact.test(onboarding): migrate hand-rolled fakes to mockery— generated mocks replace the three fakes.Test plan
moon run root:check --summary minimal— format, lint, build, unit, Testcontainers integration all green.go doc ./onboardingshows the intended public surface:NewAttacher,NewProvisioner,Attacher,Provisioner,AttachIdentityRequest,AttachIdentityResult. Nothing else.management/).🤖 Generated with Claude Code