Skip to content

refactor: cli failfast validation prerune#106

Open
kangeunchan wants to merge 2 commits intoaltuslabsxyz:mainfrom
kangeunchan:refactor/cli-failfast-validation-prerune
Open

refactor: cli failfast validation prerune#106
kangeunchan wants to merge 2 commits intoaltuslabsxyz:mainfrom
kangeunchan:refactor/cli-failfast-validation-prerune

Conversation

@kangeunchan
Copy link
Collaborator

Enhancement Description

Make CLI validation fail-fast by moving checks to PreRunE and centralizing shared validators.

Summary

This PR moves validation out of RunE and into PreRunE (or parent persistent hooks where appropriate), so invalid input fails before expensive initialization.
It also introduces a shared validation package for consistent error rules/messages.

Scope

  • Move validations from RunE to PreRunE in key command paths.
  • Centralize reusable checks under internal/cmd/validation.
  • Promote daemon requirement checks in dvb to root PersistentPreRunE via command annotations.
  • Remove redundant manual required-flag checks where MarkFlagRequired already enforces them.
  • Keep CLI behavior/flags/output semantics unchanged except validation timing.

Main Changes

  • Added internal/cmd/validation:
    • mode validation
    • network validation
    • validator count/range validation
    • daemon connected requirement
  • devnet-builder command updates:
    • manage/deploy: added PreRunE validation and shared validators
    • core/init: added PreRunE validation and shared validators
    • manage/start: moved mode validation to PreRunE
    • manage/upgrade: moved mode/voting-period/resume-stage validation to PreRunE
  • dvb command updates:
    • added daemon-required annotation + root persistent check
    • removed repeated inline requireDaemon() checks from daemon-dependent subcommands
    • provision: added pre-run validation path for flag mode and centralized option validation
    • removed redundant manual --upgrade-name empty check in upgrade create (already covered by MarkFlagRequired)
  • .gitignore fix:
    • changed devnet-builder ignore rule to /devnet-builder to avoid ignoring cmd/devnet-builder/** source files.

Why

  • Invalid input now fails early (before service init/config/network-heavy paths).
  • Validation logic is now consistent and easier to test/review.
  • Daemon dependency enforcement is centralized instead of duplicated across many handlers.

Validation

Executed:

  • go test ./internal/cmd/validation/...
  • go test ./cmd/devnet-builder/commands/manage/...
  • go test ./cmd/devnet-builder/commands/core/...
  • go test ./cmd/dvb/...

Non-Goals

  • No new flags.
  • No CLI UX/contract changes beyond fail-fast timing.
  • No business logic/flow redesign outside validation placement and reuse.

Risk & Mitigation

  • Risk: subtle ordering regressions with Cobra hooks.
  • Mitigation: validation moved with minimal logic changes, error semantics preserved, and unit coverage added for shared validators and hook behavior.

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