Skip to content

refactor(store/memory): split adapter by domain and document helpers#57

Merged
jmgilman merged 1 commit into
masterfrom
session-034/memory-split
May 26, 2026
Merged

refactor(store/memory): split adapter by domain and document helpers#57
jmgilman merged 1 commit into
masterfrom
session-034/memory-split

Conversation

@jmgilman
Copy link
Copy Markdown
Contributor

Summary

  • Splits store/memory/store.go (782 lines, 5 fused domains) into per-domain files: principal.go, role.go, provisioning.go, identity.go, oidc.go, plus clone.go (defensive-copy helpers) and validation.go (shared validators). Existing token.go and passkey.go are kept but gain godocs on previously-undocumented unexported helpers.
  • Mirrors the production split in tests: helpers_test.go carries the shared createPrincipal helper and package test constants; each domain has a matching *_test.go with a TestStoreSatisfiesXContracts compile-time port-assertion bundle plus that domain's existing local unit tests. The legacy monolithic store_test.go is deleted (its content is fully redistributed).
  • Adds inline comments calling out the cross-principal identity-rebind rejection in LinkIdentity and CreateRegistration, the credential-binding immutability in UpdateCredentialAfterLogin, and the write-lock-for-whole-operation reasoning in ProvisionIdentity.
  • Public surface unchanged: go doc ./store/memory still shows exactly type Store struct{ ... } and func NewStore() *Store. Behavior unchanged.

This is PR B of a three-PR storage refactor; PR A (internal/storetest sub-suite split, #56) landed first. PR C will mirror the same shape for store/postgres plus extract withTx/codec/error/clone helpers.

Test plan

  • moon run root:check --summary minimal (vet, lint, build, unit tests)
  • moon run root:integration (postgres Testcontainers suite)
  • go doc ./store/memory matches master
  • git diff --check (no whitespace damage)
  • Heaviest file dropped from 782 → 346 (passkey.go, unchanged structurally); store.go itself now 88 lines

🤖 Generated with Claude Code

Break the 782-line store.go into per-domain files (principal, role,
provisioning, identity, oidc) plus clone.go and validation.go, while keeping
the package surface frozen at NewStore/*Store. Test files mirror the new
layout with per-domain TestStoreSatisfiesXContracts compile-time assertions
and helpers_test.go for the shared createPrincipal/constants. Every
unexported helper gains a one-line godoc; ProvisionIdentity, CreateRegistration,
and UpdateCredentialAfterLogin now carry inline comments naming the
write-lock and credential-binding security invariants.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jmgilman jmgilman merged commit 0cd5314 into master May 26, 2026
2 checks passed
@jmgilman jmgilman deleted the session-034/memory-split branch May 26, 2026 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant