Skip to content

refactor(initcmd): delete the failureKind relay - #44

Merged
rianjs merged 2 commits into
mainfrom
refactor/34-initcmd-failurekind
Jul 25, 2026
Merged

rianjs merged 2 commits into
mainfrom
refactor/34-initcmd-failurekind

Conversation

@rianjs

@rianjs rianjs commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • delete the private failureKind enum, initializationFailure carrier, and relay classifier
  • classify initializer failures directly at each failure site
  • return initializer errors unchanged from the command runner

LOC delta

  • 15 additions, 53 deletions (net -38)

Verification

  • go build ./...
  • go vet ./...
  • make test
  • golangci-lint run

Closes #34

@rianjs

rianjs commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

Architect review — approved. Pure relay deletion: each failInitialization site now classifies inline with the exact mapping the deleted classifyInitialization performed (Generic/Config direct, authorization/verification via the retained local classifiers); run() returns errors unwrapped. The one semantic nuance — non-wrapped errors from injected doubles losing the explicit Generic fallback — is covered by default exit-code resolution. Two files, no drive-bys.

@rianjs

rianjs commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

TDD assessment

Verdict: insufficient.

The existing tests do pin several exit codes through the init Cobra command, so run returning initializer errors unchanged is exercised end-to-end: missing config saver, authorization classifications, generic verification failure, credential write/redaction, config-save failure, and both rollback-failure variants would fail if run collapsed them to the wrong code.

But the distributed mapping is not covered site by site. Exact missing exit-code assertions are:

  • nil OpenStore → Generic
  • OpenStore error → Config
  • Exists error → Config
  • existing credential without --overwrite → Generic (the two current init tests assert only errors.Is(err, credstore.ErrExists))
  • Get of the previous credential failing → Config
  • nil Authorize → Generic
  • nil Verify → Generic
  • token encode/marshal failure → Config
  • a verification error from the Config branch of classifyVerification (for example auth.ErrInvalidGrant or client.ErrUnauthorized) → Config; the current verification test covers only the Upstream/default branch

The less-traveled save paths are covered well: config-save failure asserts Config for both delete-new and restore-old rollback, rollback errors remain Config, and credential-write/rollback store errors assert Config while checking redaction.

Cheapest placement: add one table-driven test in internal/cmd/initcmd/init_test.go, extending initHarness/initStore only with opener, Exists, and Get error hooks (and dependency overrides), then execute the command and assert exitcode.Code for each row. Return an invalid envelope from Authorize for the encode case and add one Config-class verification row to the existing verification coverage. Also add Generic to either existing-credential refusal assertion; no new abstraction is needed.

@rianjs
rianjs merged commit b9e8d20 into main Jul 25, 2026
9 checks passed
@rianjs
rianjs deleted the refactor/34-initcmd-failurekind branch July 25, 2026 16:38
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.

refactor(initcmd): delete the failureKind relay

1 participant