Skip to content

refactor: app hotspots testable patterns#104

Open
kangeunchan wants to merge 4 commits intoaltuslabsxyz:mainfrom
kangeunchan:refactor/app-hotspots-testable-patterns
Open

refactor: app hotspots testable patterns#104
kangeunchan wants to merge 4 commits intoaltuslabsxyz:mainfrom
kangeunchan:refactor/app-hotspots-testable-patterns

Conversation

@kangeunchan
Copy link
Collaborator

Summary

This PR refactors three high-complexity hotspots into explicit, testable patterns while preserving runtime behavior:

  1. Upgrade resumable execution → table-driven state machine
  2. Provisioning flow → pipeline step decomposition
  3. Daemon server initialization → builder pattern with centralized LIFO cleanup

It also includes dependency metadata updates in go.mod / go.sum for newly direct imports used by the refactor.

Scope

  • internal/application/upgrade/resumable_execute.go
  • internal/application/devnet/provision.go
  • internal/daemon/server/server.go
  • new tests for each refactored area

Key Changes

1) Upgrade resumable execution (state machine)

  • Replaced imperative switch/fallthrough flow with stage handler map + loop orchestration
  • Made stage transitions explicit and handler-level testable
  • Preserved terminal/error semantics and resume behavior

2) Provision use case (pipeline)

  • Decomposed ProvisionUseCase.Execute into step functions:
    • prepareMetadata
    • fetchGenesis
    • initializeKeysAndNodes
    • patchGenesis
    • persistState
  • Kept behavior equivalent while reducing control-flow density in Execute

3) Daemon server initialization (builder)

  • Introduced ServerBuilder with With* methods and Build()
  • Centralized construction cleanup in LIFO order
  • Aggregated cleanup errors via multierr

Tests Added

  • internal/application/upgrade/resumable_execute_state_machine_test.go
  • internal/application/devnet/provision_pipeline_test.go
  • internal/daemon/server/server_builder_test.go

Validation

  • go test ./internal/application/upgrade/...
  • go test ./internal/application/devnet/...
  • go test ./internal/daemon/server/...

Complexity / LOC (post-refactor)

  • executeWithGovResumable: CC=7, LOC=32
  • ProvisionUseCase.Execute: CC=5, LOC=22
  • server.New: CC=1, LOC=11

Compatibility

  • No CLI/API contract changes intended
  • No workflow semantic changes intended
  • Refactor focused on structure, testability, and review safety

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