Skip to content

[refactor] Refactor manage upgrade/deploy commands into modular, testable steps #101

@kangeunchan

Description

@kangeunchan

Enhancement Description

Decompose runUpgrade and runDeploy into small, testable steps to reduce complexity and review risk for critical workflows.

Background

The two primary command entry points (runUpgrade and runDeploy) have grown into monolithic functions (400+/320+ LOC, CC 61/51). They mix validation, configuration resolution, signal handling, and execution logic, making isolated testing and safe review difficult.

Scope

Decompose runUpgrade

Files: cmd/devnet-builder/commands/manage/upgrade.go

  • Extract: setupSignalHandling
  • Extract: resolveUpgradeConfig (including validation)
  • Extract: resolveBinarySource (docker image vs local path)
  • Extract: resolveGovernanceParams
  • Extract: executeUpgrade
  • Extract: reportResults

Decompose runDeploy

Files: cmd/devnet-builder/commands/manage/deploy.go

  • Extract: resolveDeployConfig (including validation)
  • Extract: prepareDeployInputs (image/binary selection)
  • Extract: executeDeployment (separate Docker vs Local strategy)

Non-Goals

  • Reworking upgrade/deploy business logic semantics
  • Changing user-facing flags or command UX as part of decomposition
  • Major architecture changes beyond the command packages

Risks and Open Questions

  • Refactors in critical workflows can introduce subtle behavior regressions
  • Helper function boundaries must preserve existing side effects and error semantics
  • Need agreement on the complexity measurement tool/threshold used in CI (if any)

Validation Plan

Unit and Integration Checks

  • go test ./... (or scoped packages) with mocks for extracted helpers
  • Complexity/LOC measurement before/after (tool output or script logs)
  • Unit tests for at least 5 extracted helpers per command

End-to-End Checks

  • Run upgrade workflow against an existing devnet (smoke)
  • Run deploy workflow in both docker and local modes (smoke)
  • Verify invalid inputs fail without reaching execution logic

Evidence Required in Issue Updates

  • Complexity report snippets (before/after) for runUpgrade and runDeploy
  • Test output showing added unit tests for extracted helpers
  • Smoke run logs for deploy/upgrade (key steps and final success)

Acceptance Criteria

  • runUpgrade cyclomatic complexity reduced to ≤ 20 and LOC < 150
  • runDeploy cyclomatic complexity reduced to ≤ 20 and LOC < 150
  • At least 5 helper functions per command have unit tests
  • End-to-end regression/smoke tests pass

Deliverables

  • PR(s) that introduce helper functions and reduce complexity without behavior change
  • Added/updated unit tests covering extracted steps
  • Notes describing functional equivalence and any intentional micro-changes

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions