test(worker,shared): unit tests for summarize, rate-limit, github-ip core logic (patch)#224
Merged
Merged
Conversation
本流の核心ロジックに単体テストを追加する。これまで OAuth と mcp-server クライアント契約に偏っていたカバレッジを是正し、webhook の payload 要約・ レート制限・IP 許可リストの純ロジックを既存ハーネスでカバーする。 - shared/summarize.ts: summarizeEvent の number/title/url フォールバック階層、 workflow_run 固有フィールドの type ゲート、空 payload の null 安全 - worker/rate-limit.ts: sliding window (webhook 300 / api 120)、窓リセット、 checkTenantQuota の 200/429/404 分岐、rateLimitResponse - worker/github-ip.ts: CIDR 一致判定の境界・/32・/0・IPv6 passthrough、 isGitHubWebhookIP の fallback 経路。テスト容易化のため ipMatchesCIDRs を export 新インフラ追加なし。既存の `tsx --test` で 34 本追加し全 47 本 pass。 Durable Object 層 (store/tenant) は Miniflare が要るため別 issue に分離。 Refs #223
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
github-webhook-mcp | 72d7c0d | Jun 21 2026, 04:03 AM |
liplus-lin-lay
commented
Jun 21, 2026
liplus-lin-lay
left a comment
Member
Author
There was a problem hiding this comment.
AI セルフレビュー (auto mode)
検証結果
npm test(worker): 47 pass / 0 fail(新規34本込み)。CI gatetestpass、CIgate pass、Workers Builds pass。wrangler deploy --dry-run: build 成功(github-ip.ts の export 追加が build を壊さないことを確認)。
妥当性(now: 問題なし)
- テストは実コードの分岐を反映:summarize の fallback 階層・workflow_run type ゲート、rate-limit の境界(300/120)・窓リセット・quota 200/429/404、github-ip の CIDR 境界/IPv6 passthrough。
- 決定性を確保:github-ip は global fetch を stub して FALLBACK 経路に固定(実ネット不使用)、rate-limit の窓リセットは Date.now を mock し finally で復元。
ipMatchesCIDRsの export は visibility のみ、ロジック不変。- ランタイム挙動の変更なし → patch 分類は妥当(observable impact 無し)。
留意(later: 別 issue)
store.ts/tenant.ts(Durable Object +ctx.storage.sql)、index.tsの fetch handler、verifyGitHubSignatureはtsx --testで実行不可。Miniflare(vitest-pool-workers)導入が要るため本 PR スコープ外。フォローアップ issue を起票予定。
受容済みトレードオフ (accepted)
summarize.test.tsをshared専用ハーネスではなくworker/testに配置。新インフラ回避のため(worker は summarize を実依存)。
self-review pass。auto mode に従い squash merge する。
This was referenced Jun 21, 2026
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.
Closes #223
概要
webhook 本流の核心ロジックに単体テストを追加。これまでテストは OAuth (
worker/oauth.ts) と mcp-server クライアント契約に偏っており、payload 要約・レート制限・IP 許可リストはテストの外だった。新インフラを足さず、既存ハーネス (tsx --test) で決定的にテストできる純ロジック層をカバーする。影響スコープ
worker/src/github-ip.tsに visibility 追加の export 1行。ランタイム挙動の変更なし。追加テスト(34本、全47本 pass)
worker/test/summarize.test.tsshared/summarize.tsworker/test/rate-limit.test.tsworker/rate-limit.tscheckTenantQuotaの 200/429/404 分岐、rateLimitResponseworker/test/github-ip.test.tsworker/github-ip.tsisGitHubWebhookIPの fallback 経路リファクタ
github-ip.tsの内部純関数ipMatchesCIDRsをexport(CIDR 演算を直接単体テストするため)。ロジック不変。スコープ外(別 issue 予定)
worker/src/store.ts/tenant.tsは Durable Object +ctx.storage.sqlでtsx --testでは実行不可。本格テストにはvitest-pool-workers(Miniflare) 導入=テストハーネス変更+workers-types ピン留めが必要なため分離する。確認
npm test(worker): 47 pass / 0 failnpx wrangler deploy --dry-run: build 成功