refactor: port status page migrate to SDK + RunContext#2
Merged
Conversation
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%.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Retires the CLI-local raw-HTTP transport introduced in #1 and routes the four status page migrate subcommands through
flashduty-sdk@v0.7.0and the existingRunContext/runCommandpattern. After this PR, 100% of the CLI flows throughctx.Client— no outlier transport.Changes
SDK bump
github.com/flashcatcloud/flashduty-sdkv0.6.0 → v0.7.0 (adds status page migration methods)Interface extension (
internal/cli/root.go)Four methods added to
flashdutyClient:StartStatusPageMigrationStartStatusPageEmailSubscriberMigrationGetStatusPageMigrationStatusCancelStatusPageMigrationCommand rewrite (
internal/cli/status_page_migrate.go, −455 / +150)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).RunEusesrunCommand(cmd, args, func(ctx *RunContext) error {...}).printMigrationStart/printMigrationStatusrewired from readingflagJSON/newPrinter()globals toctx.JSON/ctx.Printer/ctx.Writer.Test rewrite (
internal/cli/status_page_migrate_test.go, −547 / +350)httptest.NewServertransport tests withnewClientFnmock-swap +execCommandtests matchingcommand_test.goconvention.flashduty-sdk's own tests — not duplicated here.command_test.go.Post-review fixes (two independent reviewers)
go-reviewer + Codex both reviewed the uncommitted diff. All flagged issues resolved:
mockClientinstead of panicking."atlassian"appears in the supported list — catches silent drift.cancel --json: emit both"command"(shipped by feat: add statuspage migration commands #1) and"next_command"(new canonical field) during a deprecation window.validateMigrationSourceruns beforerunCommand, so an invalid--fromfails with the source error before any client/auth work — matches feat: add statuspage migration commands #1 behavior. AddedTestCommandStatusPageMigrate{Structure,EmailSubscribers}ValidatesBeforeClientto lock the ordering.Compatibility
Command output and JSON schemas remain backwards-compatible with what #1 shipped:
structure/email-subscribers: unchanged.status: field names unchanged (maps directly to SDK'sStatusPageMigrationJob).cancel:"command"field retained + new"next_command"field added (pure addition).Test plan
go test -race -count=1 ./...greengo test -tags=e2e -count=1 ./e2e/...green (24.4s)gofmt -l .,goimports -l .,go vet ./...cleanprintMigrationStatusat 57% due to defensive write-error returns that can't be triggered againstbytes.Buffer)Net
-660lines of raw HTTP / service / duplicate types / manual sanitization+400lines of SDK-backed commands + focused mock-based tests