Skip to content

refactor(digitalocean): extract 3 helpers from 260-line tryDoOAuth#3344

Open
la14-1 wants to merge 1 commit intomainfrom
refactor/extract-do-oauth-helpers
Open

refactor(digitalocean): extract 3 helpers from 260-line tryDoOAuth#3344
la14-1 wants to merge 1 commit intomainfrom
refactor/extract-do-oauth-helpers

Conversation

@la14-1
Copy link
Copy Markdown
Member

@la14-1 la14-1 commented Apr 23, 2026

Why: tryDoOAuth() was 260 lines with 4 distinct responsibilities (connectivity check, HTTP callback server, terminal I/O wait loop, token exchange) — extracting reduces cognitive load and makes each piece independently testable.

Changes

Split tryDoOAuth() in packages/cli/src/digitalocean/digitalocean.ts into 3 focused helpers:

  • startOAuthCallbackServer(csrfState) — Starts Bun.serve on localhost, scanning ports 5190-5199. Returns the server, actual port, and a shared OAuthCallbackState object that the callback handler mutates.
  • waitForOAuthCallback(cbState, server) — Handles the initial 120s polling timeout, non-interactive timeout, and extended interactive wait with raw-mode Escape-key detection. Returns a discriminated outcome: "code" | "denied" | "manual" | "timeout".
  • exchangeOAuthCode(code, redirectUri) — POSTs to the DigitalOcean token endpoint and persists the access/refresh tokens.

tryDoOAuth() is now a ~45-line orchestrator that checks connectivity, delegates to each helper, and maps outcomes to return values.

Verification

  • bunx @biomejs/biome check src/ — 0 errors (193 files)
  • bun test — 2106 pass, 2 fail (same 2 pre-existing failures on main)
  • DigitalOcean-specific tests (digitalocean*.test.ts) — 9 pass, 0 fail

-- spawn-refactor/complexity-hunter

@la14-1 la14-1 marked this pull request as ready for review April 23, 2026 03:13
@la14-1 la14-1 force-pushed the refactor/extract-do-oauth-helpers branch from 24e7f5e to e7c01f1 Compare April 25, 2026 08:21
@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented Apr 25, 2026

Rebased onto main to resolve merge conflicts (package.json version bump).

-- refactor/pr-maintainer

@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented Apr 25, 2026

Fixed CI: removed duplicate "version" key in packages/cli/package.json that was introduced during the rebase. bun install was failing with Duplicate key "version" in object literal. CI should pass now.

-- refactor/pr-maintainer

@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented Apr 26, 2026

This PR has been open for 3+ days with all CI checks passing (ShellCheck, Mock Tests, Biome Lint, Unit Tests, macOS Compatibility — all SUCCESS). It is mergeable with no conflicts.

Requesting human review when convenient.

-- refactor/pr-maintainer

@la14-1 la14-1 force-pushed the refactor/extract-do-oauth-helpers branch from bcceb9b to 91e0747 Compare April 29, 2026 06:48
@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented Apr 29, 2026

Rebased onto main (dropped the now-redundant duplicate-version-key fix commit). Branch is clean with 1 commit. Awaiting human review.

-- refactor/pr-maintainer

@la14-1 la14-1 force-pushed the refactor/extract-do-oauth-helpers branch from 91e0747 to 7bf77b9 Compare April 30, 2026 05:08
@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented May 3, 2026

This PR is ready for review. All CI checks pass and there are no merge conflicts.

-- refactor/pr-maintainer

Split tryDoOAuth() into focused helpers:
- startOAuthCallbackServer(): HTTP server setup + port scanning
- waitForOAuthCallback(): 120s timeout + extended wait + escape-key
- exchangeOAuthCode(): authorization code → access token exchange

tryDoOAuth() is now a 45-line orchestrator that delegates to each.

Agent: complexity-hunter
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@la14-1 la14-1 force-pushed the refactor/extract-do-oauth-helpers branch from 7bf77b9 to ec044e6 Compare May 3, 2026 14:19
@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented May 3, 2026

Rebased onto main (was 4 commits behind). Clean rebase, no conflicts.

-- refactor/pr-maintainer

@la14-1
Copy link
Copy Markdown
Member Author

la14-1 commented May 4, 2026

Verified in worktree: tests pass (2236/2238, same 2 pre-existing failures as main), lint clean (biome 0 errors). PR is mergeable and ready for review.

-- refactor/pr-maintainer

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.

2 participants