Skip to content

test(oauth): device flow integration tests + docs migration (#202)#206

Merged
liplus-lin-lay merged 1 commit into
mainfrom
198-oauth-device-flow
Apr 20, 2026
Merged

test(oauth): device flow integration tests + docs migration (#202)#206
liplus-lin-lay merged 1 commit into
mainfrom
198-oauth-device-flow

Conversation

@liplus-lin-lay
Copy link
Copy Markdown
Member

Closes #202

Device flow 移行 (#198) の Step 4。Worker 側 OAuth エンドポイントは自動統合テストで網羅し、README/docs を device flow 前提に書き換え。既存 user migration と onboarding を 3rd party でも追えるようにした。

自動テスト (CI で実行)

Worker 側 (worker/test/oauth.test.ts, 10 tests)

  • /oauth/authorize + /oauth/callback は 410 Gone
  • /.well-known/oauth-authorization-server メタデータが device_code + refresh_token を広告
  • 公開 client 発行 (secret なし) の dynamic registration
  • device_authorization → authorization_pending → 承認 → token 発行の happy path
  • 未承認 / 不正 Bearer の 401 検証
  • refresh token rotation: 旧 access_token も旧 refresh_token も invalidate される
  • process 再起動後も同じ access_token が KV 経由で validate できる (accessibleAccountIds が user + org でマージ)
  • GitHub App で device flow 未有効の場合に 503 を返す (silent auth loop を避ける)

Client 側 (mcp-server/test/migration.test.mjs, 5 tests)

  • 旧 tokens ファイル (flow marker 無し) は load 時に reject される
  • device flow tokens ファイル (flow="device") は受理される
  • 不正形式は全て inactive 扱い
  • 旧ファイル削除 → device flow ファイル書き出しの round-trip
  • client 登録の grant_types 判定 (device_code 必須)

クライアント側のフルな E2E (実ブラウザで user_code 入力) は手動確認に残す。Worker 側とクライアント側の contract は KV/ファイルレイヤーで automated に cover してある。

ドキュメント更新

  • docs/installation.md + .ja.md: GitHub App 作成手順で "Enable Device Flow" チェックボックスの ON を必須として明示、Callback URL を削除、シークレット設定から Client Secret を optional 扱いへ降格、troubleshooting に 503 device_flow_disabled / 410 Gone / stderr device code 未表示 / legacy token 削除の項目を追加
  • docs/installation.md + .ja.md: MCP クライアント設定の先頭に「初回認証(OAuth Device Flow)」セクションを追加し、Claude Code ログに流れる stderr サンプルを掲載
  • mcp-server/README.md (npm package landing): "browser-based localhost callback" 記述を device flow に差し替え、migration ノート + "Enable Device Flow" 誘導を追加、authentication flow の 8 ステップ再記述、troubleshooting を device flow 用に更新

CI

  • .github/workflows/ci.ymlmcp-serverworker 両方の test ステップを追加。worker/npm ci 時点で tsx devDep が入るので tests が動く。

Master の手動確認待ち (release 前の gate)

以下は実ブラウザで https://github.com/login/device に user_code を入力する必要があり、CI では実行していません:

  • existing user migration: ~/.github-webhook-mcp/oauth-tokens.json を v0.10.x 時代のものに戻した状態で新 mcp-server を起動 → stderr に legacy 移行通知が出る → device code を入力 → 再認証完了 → 旧ファイルが置換されていること
  • new user onboarding: Claude Code の fresh profile (~/.github-webhook-mcp/ 空) から起動 → stderr に user_code が出る → https://github.com/login/device で入力 → get_pending_status が応答する
  • 並行 Claude Code instance: 2 つのセッションを同時起動し、両方で tool 呼び出しを発行 → race condition なしに両方が OAuth を完結できる
  • process 再起動後の token 維持: 認証済状態で Claude Code process を kill → 再起動 → 再認証なしに get_pending_status が通る
  • WebSocket channel 通知: Claude Code CLI で --dangerously-load-development-channels server:github-webhook-mcp 起動 → 実 PR へ comment → channel 通知が届く
  • self-hosting README 再検証: 3rd party user の視点で docs/installation.md の手順通り GitHub App を作成 → "Enable Device Flow" 有効化漏れがないか確認 (503 が返る) → 有効化後に再試行で成功

release は CD green + Master の上記手動検証 pass を gate としてください。

Part of #198

Add integration tests that verify the Worker's bespoke OAuth device-flow
implementation (worker/test/oauth.test.ts) covering legacy 410 Gone
endpoints, metadata, dynamic registration, device authorization + token
exchange, refresh rotation invalidating prior tokens, process-restart
token persistence, and the 503 response when the upstream GitHub App
has device flow disabled. Add client-side migration contract tests
(mcp-server/test/migration.test.mjs) that lock in the tokens-file flow
marker convention used to detect legacy pre-v0.11.0 files.

Refresh README and docs/installation (EN/JA) for device flow: remove
stale Callback URL guidance, document the "Enable Device Flow" toggle
on the GitHub App, describe the stderr user_code prompt the MCP client
surfaces, and add migration + troubleshooting entries for the
`/oauth/authorize` 410 Gone transition.

Wire both test suites into CI so every PR exercises the flow.

device flow 移行 (#198) の Step 4。Worker 側は自動統合テストで covered、
クライアント側の実ブラウザ承認を伴うシナリオは Master の実機確認待ち。

Closes #202
Part of #198
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
github-webhook-mcp 68a2a0c Apr 20 2026, 06:16 AM

@liplus-lin-lay liplus-lin-lay merged commit c77a1a9 into main Apr 20, 2026
3 checks passed
@liplus-lin-lay liplus-lin-lay deleted the 198-oauth-device-flow branch April 20, 2026 06:18
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.

test: device flow migration + onboarding integration check

1 participant