Skip to content

refactor: port status page migrate to SDK + RunContext#2

Merged
debidong merged 1 commit intomainfrom
feat/align-statuspage-migrate
Apr 20, 2026
Merged

refactor: port status page migrate to SDK + RunContext#2
debidong merged 1 commit intomainfrom
feat/align-statuspage-migrate

Conversation

@debidong
Copy link
Copy Markdown
Collaborator

Summary

Retires the CLI-local raw-HTTP transport introduced in #1 and routes the four status page migrate subcommands through flashduty-sdk@v0.7.0 and the existing RunContext / runCommand pattern. After this PR, 100% of the CLI flows through ctx.Client — no outlier transport.

Changes

SDK bump

  • github.com/flashcatcloud/flashduty-sdk v0.6.0 → v0.7.0 (adds status page migration methods)

Interface extension (internal/cli/root.go)
Four methods added to flashdutyClient:

  • StartStatusPageMigration
  • StartStatusPageEmailSubscriberMigration
  • GetStatusPageMigrationStatus
  • CancelStatusPageMigration

Command rewrite (internal/cli/status_page_migrate.go, −455 / +150)

  • Deleted: statusPageMigrationAPI, statusPageMigrationService, newStatusPageMigrationService, migrationEnvelope[T], local HTTP transport, manual sanitization helpers (sanitizeMigrationBody, redactAppKey, etc. — redundant now that SDK handles this), duplicate local types (migrationStartResult, migrationProgress, migrationJob).
  • Each RunE uses runCommand(cmd, args, func(ctx *RunContext) error {...}).
  • printMigrationStart / printMigrationStatus rewired from reading flagJSON / newPrinter() globals to ctx.JSON / ctx.Printer / ctx.Writer.

Test rewrite (internal/cli/status_page_migrate_test.go, −547 / +350)

  • Replaced httptest.NewServer transport tests with newClientFn mock-swap + execCommand tests matching command_test.go convention.
  • Wire-format coverage lives in flashduty-sdk's own tests — not duplicated here.
  • Added mock stubs for the 4 new interface methods in command_test.go.

Post-review fixes (two independent reviewers)

go-reviewer + Codex both reviewed the uncommitted diff. All flagged issues resolved:

  • Nil-guard mock methods so tests that override a subset of the migration methods fall back to mockClient instead of panicking.
  • Strengthened error assertion for unsupported source: now also asserts "atlassian" appears in the supported list — catches silent drift.
  • JSON contract preservation for cancel --json: emit both "command" (shipped by feat: add statuspage migration commands #1) and "next_command" (new canonical field) during a deprecation window.
  • Validation ordering fix: validateMigrationSource runs before runCommand, so an invalid --from fails with the source error before any client/auth work — matches feat: add statuspage migration commands #1 behavior. Added TestCommandStatusPageMigrate{Structure,EmailSubscribers}ValidatesBeforeClient to lock the ordering.

Compatibility

Command output and JSON schemas remain backwards-compatible with what #1 shipped:

  • Human output: identical text.
  • JSON output for structure / email-subscribers: unchanged.
  • JSON output for status: field names unchanged (maps directly to SDK's StatusPageMigrationJob).
  • JSON output for cancel: "command" field retained + new "next_command" field added (pure addition).

Test plan

  • go test -race -count=1 ./... green
  • go test -tags=e2e -count=1 ./e2e/... green (24.4s)
  • gofmt -l ., goimports -l ., go vet ./... clean
  • Coverage on changed commands: 80–100% (printMigrationStatus at 57% due to defensive write-error returns that can't be triggered against bytes.Buffer)
  • Two independent code reviews (go-reviewer agent + Codex)

Net

  • -660 lines of raw HTTP / service / duplicate types / manual sanitization
  • +400 lines of SDK-backed commands + focused mock-based tests
  • CLI is now architecturally uniform.

Replaces the CLI-local raw-HTTP transport introduced by #1 with the
flashduty-sdk v0.7.0 methods and routes the 4 migrate subcommands
through the RunContext / runCommand pattern used by every other
command.

Changes:
- Bump flashduty-sdk from v0.6.0 to v0.7.0 (adds status page migration
  methods).
- Extend flashdutyClient interface with StartStatusPageMigration,
  StartStatusPageEmailSubscriberMigration, GetStatusPageMigrationStatus,
  CancelStatusPageMigration.
- Add default mockClient stubs for the four new interface methods.
- Rewrite internal/cli/status_page_migrate.go (~590 lines to ~280):
  delete statusPageMigrationAPI, statusPageMigrationService, the
  CLI-local migration transport, manual sanitization, and duplicate
  local types. Each cobra command now uses runCommand(cmd, args,
  func(ctx *RunContext) error {...}) and delegates to ctx.Client.*.
  Print helpers rewired from flagJSON / newPrinter() globals to
  ctx.JSON / ctx.Printer / ctx.Writer.
- Rewrite internal/cli/status_page_migrate_test.go (387 lines to ~340):
  replace httptest-backed transport tests with newClientFn mock-swap
  tests using execCommand, matching the pattern established in
  command_test.go. One httptest-backed integration test per SDK method
  is not kept here because the flashduty-sdk repo owns wire-format
  tests now.

Post-review fixes (independent reviews from go-reviewer + Codex):
- Nil-guard mock methods so tests overriding a subset do not panic.
- Assert "atlassian" substring in the unsupported-source error so the
  supported list cannot silently drift.
- Emit both "command" (PR #1 schema) and "next_command" in cancel
  --json output to preserve the shipped JSON contract.
- Move validateMigrationSource before runCommand so an invalid --from
  fails with the source error before any client/auth work, matching
  PR #1 ordering. Add two tests locking the ordering.

Command output and JSON schemas remain compatible with PR #1. The
file internal/cli/status_page_migrate.go is no longer an architectural
outlier: 100% of the CLI now flows through ctx.Client.

Verification:
- go test -race -count=1 ./... green
- go test -tags=e2e ./e2e/... green (24.4s)
- gofmt, goimports, go vet clean
- Coverage on ported commands: 80-100%.
@debidong debidong merged commit 2fa6f65 into main Apr 20, 2026
12 checks passed
@debidong debidong deleted the feat/align-statuspage-migrate branch April 20, 2026 10:02
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