Skip to content

test(worker): Durable Object layer tests via vitest-pool-workers (patch)#226

Merged
liplus-lin-lay merged 1 commit into
mainfrom
225-do-layer-tests
Jun 21, 2026
Merged

test(worker): Durable Object layer tests via vitest-pool-workers (patch)#226
liplus-lin-lay merged 1 commit into
mainfrom
225-do-layer-tests

Conversation

@liplus-lin-lay

Copy link
Copy Markdown
Member

Closes #225

概要

#223/#224 で純ロジック層をカバーした続き。残っていた Durable Object 層(store.ts / tenant.tsctx.storage.sql 使用)を @cloudflare/vitest-pool-workers(Miniflare) で本格的にテストする。実証済みの姉妹リポジトリ github-rag-mcp のパターンを移植した。

影響スコープ

  • テスト追加+テスト基盤導入のみ。worker/src/*.ts のロジック変更なし(新規 test-do-entry.ts のみ追加)。
  • ユーザー/システムから観測可能なランタイム変更なし → patch。

変更

ファイル 役割
vitest.workers.config.ts vitest 4 cloudflareTest()+cloudflarePool()、両 DO を useSQLite で bind、include test/workers/**
src/test-do-entry.ts DO 2クラスだけ re-export する最小エントリ
test/test-env.d.ts cloudflare:test の ProvidedEnv 型拡張
test/workers/store.test.ts WebhookStore: ingest / pending-status / pending-events / webhook-events / event / mark-processed
test/workers/tenant.test.ts TenantRegistry: installation resolve/created/deleted、quota check(atomic)/increment/decrement 境界
package.json devDeps 追加、workers-types を 4.20260404.1 にピン留め+overrides、test script 二段化

ハーネス方針

既存の tsx --test(47本)は無変更で温存、DO テストは test/workers/ 配下に分離。npm test = tsx --test test/*.test.ts && vitest run --config vitest.workers.config.ts。workers-types のピン留めは vitest-pool-workers の型 bump 地雷対策(rag-mcp と同手法)。

確認

  • npm test: tsx 47 pass / vitest workers 25 pass、計72本。
  • wrangler deploy --dry-run: build 成功。

Add Miniflare-backed tests for the two SQLite Durable Objects (WebhookStore,
TenantRegistry) that cannot run under the existing tsx --test harness because
they depend on ctx.storage.sql. Introduce @cloudflare/vitest-pool-workers
scoped only to these DO tests; the existing tsx pure-logic/oauth suite is left
untouched.

New test/workers/store.test.ts and test/workers/tenant.test.ts drive each DO
through its fetch routes (HTTP-style, not public methods), using a unique
idFromName per test for storage isolation. test-do-entry.ts re-exports only the
two DO classes so the full worker graph and OAuth KV are never bound. The
@cloudflare/workers-types pin + overrides block prevents a transitive bump from
breaking existing src types. The test script chains both suites.

tsx --test glob stays top-level (test/*.test.ts) so it does not pick up the new
test/workers/ files; the vitest workers config includes test/workers/**/*.test.ts.

二つの SQLite Durable Object は ctx.storage.sql に依存し既存ハーネスで動かせないため、
DO テストに限定して vitest-pool-workers を導入した。

Refs #225
@liplus-lin-lay liplus-lin-lay added this to the v0.11.7 milestone Jun 21, 2026
@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 5ee8475 Jun 21 2026, 04:43 AM

@liplus-lin-lay liplus-lin-lay left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI self-review (auto mode / 引き継ぎセッション)

前セッションが PR 作成+CI green で停止していたため引き継ぎ。self-review を実施。

コード

  • 純テスト追加(7ファイル)。worker/src/*.ts のロジック変更なし、新規 test-do-entry.ts は DO 2クラスの最小 re-export のみ。
  • WebhookStore: ingest 冪等性(INSERT OR REPLACE) / pending-status 集計 / pending-events newest-first・limit・processed 除外 / webhook-events full payload / event 404・400 / mark-processed をカバー。
  • TenantRegistry: installation resolve・created・deleted(has_other 判定) / quota-check の 429 ゲート+atomic increment / increment over_limit / decrement 0クランプ / unknown route をカバー。
  • workers-types ピン留め+overrides($ref) は姉妹リポ github-rag-mcp で実証済みの型 bump 地雷対策と同手法。test-env.d.ts の手書き ambient 宣言も同方針で整合。

分類

  • patch 妥当。ユーザー/システム観測可能なランタイム変更なし(テスト基盤+テストのみ)。

ゲート

  • issue #225 が予約していた「新インフラ導入の Master 確認」ゲートについて Master の承認(go-sign)を取得済み。導入是非クリア。

CI

  • CI / test / Workers Builds 3本 pass。tsx 47 + vitest workers 25 = 72本 green、wrangler dry-run 通過。

→ approve 相当。squash merge へ。

@liplus-lin-lay liplus-lin-lay merged commit 079c0b5 into main Jun 21, 2026
3 checks passed
@liplus-lin-lay liplus-lin-lay deleted the 225-do-layer-tests branch June 21, 2026 05:05
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(worker): Durable Object layer tests (store, tenant) via Miniflare

1 participant