Skip to content

test: vitest unit suite for binding-independent surfaces (test-leg slice 1)#168

Merged
liplus-lin-lay merged 1 commit into
mainfrom
165-test-restore-ci-test-leg-behavioral-coverage-for-high-risk-surfaces
Jun 21, 2026
Merged

test: vitest unit suite for binding-independent surfaces (test-leg slice 1)#168
liplus-lin-lay merged 1 commit into
mainfrom
165-test-restore-ci-test-leg-behavioral-coverage-for-high-risk-surfaces

Conversation

@liplus-lin-lay

Copy link
Copy Markdown
Member

概要

#165(テスト脚の復元)の最初の一枚。Cloudflare Workers バインディング(D1/Vectorize/AI)非依存で node 上で回せるロジックに限定して、最小の unit テストを敷いた。harness 選定(@cloudflare/vitest-pool-workers か miniflare)はバインディング依存テスト用の判断で、本 PR はそれを待たず進められる範囲。

追加

  • vitest を devDependency に追加。npm test(= vitest run)を CI(ci.yml の test ジョブ)へ組み込み。
  • テスト 38 件 / 5 ファイル:
    • vector-id — 決定性・サーフェス別 prefix・64 byte 上限・NUL 結合の衝突耐性(known-answer ベクトル)
    • hashcomputeBodyHash / sha256Hex / base64UrlEncode(known-answer)+ embedding 入力の truncation・null 処理
    • ingest-filterisBotSender[bot] suffix)/ isBodyTooShort(floor=10 の境界)
    • ftstoRankMap + reciprocalRankFusion(RRF 公式 1/(k+rank)、k、contributions の null、降順ソート)
    • webhookverifyGitHubSignature を GitHub 公式の HMAC サンプルベクトルで検証

副産物(このPRでは直さない)

影響範囲

  • src/ の Worker 本体コードは無変更(テスト・CI・package のみ)。npm 公開パッケージ(mcp-server/)は不変。
  • 挙動変更なし → patch 相当。ただし CI 構成(vitest 追加)が変わるため、リリース要否・種別は Master 判断。

残(#165 に残置)

  • バインディング依存サーフェス(store/D1、oauth フロー全体、webhook ルーティング)は harness 選定後。proxy 側(mcp-server)の PKCE も別スライス。

Refs #165

Restore the missing CI test leg (#165), first slice: the surfaces that run
without Cloudflare Workers bindings, so no test-harness decision is needed yet.

Adds vitest + `npm test`, wires it into CI, and covers:
- vector-id: determinism, per-surface prefix, 64-byte cap, NUL-join collision
  resistance (known-answer vectors)
- hash: computeBodyHash / sha256Hex / base64UrlEncode (known-answer) + truncation
- ingest-filter: isBotSender / isBodyTooShort boundaries
- fts: toRankMap + reciprocalRankFusion (exact RRF scores, k, contributions, order)
- webhook: verifyGitHubSignature against GitHub's published HMAC example vector

While writing these, the signature check was found to use a non-constant-time
comparison -> filed #167. Binding-dependent surfaces (D1/Vectorize/AI) remain in
#165, gated on the harness choice.

バインディング非依存のロジックに最小のテスト脚を敷いた。仕様書はあるのに照合する
ものが無い状態を埋める最初の一枚で、known-answer ベクトルで公式を pin している。

Refs #165
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 21, 2026

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-rag-mcp c1cb3ad Jun 21 2026, 01:05 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 セルフレビュー (auto mode)

  • ✅ CI 全 green(test = vitest 38 件 + schema-drift + tsc --noEmit + wrangler dry-run / Workers Builds)。ローカルでも同一シーケンスを事前確認済み。
  • src/ の Worker 本体コードは無変更。差分はテスト 5 ファイル + ci.ymlnpm test 追加)+ package.json/lock(vitest devDep)のみ。挙動変更なし。
  • ✅ known-answer は外部オラクル(GitHub 公式 HMAC サンプル、独立計算した sha256 / base64url)で pin。実装ミラーではないので tautological ではない。
  • ✅ harness 選定を要する範囲には踏み込んでいない(バインディング非依存に限定)。#165 の残スコープは本文に明記。
  • ⚠️ プロセス上の自己訂正: vector-id 区切りを当初 space と誤読し #166 を起票 → byte レベル確認で NUL(正しい) と判明、#166 をクローズし、テストを正の衝突耐性テストへ修正。known-answer テストの失敗が誤読を即座に捕捉した。誤りは残さず是正済み。
  • リリース種別: 本体無変更で patch 相当。ただし CI に vitest が増えるため、リリース要否・種別は Master 判断(本 PR では release しない)。

self-review pass。auto mode のため squash merge を実行。#165 は残スコープのため open 継続。

@liplus-lin-lay liplus-lin-lay merged commit d31122a into main Jun 21, 2026
3 checks passed
@liplus-lin-lay liplus-lin-lay deleted the 165-test-restore-ci-test-leg-behavioral-coverage-for-high-risk-surfaces branch June 21, 2026 00:35
@liplus-lin-lay liplus-lin-lay restored the 165-test-restore-ci-test-leg-behavioral-coverage-for-high-risk-surfaces branch June 21, 2026 01:04
@liplus-lin-lay liplus-lin-lay deleted the 165-test-restore-ci-test-leg-behavioral-coverage-for-high-risk-surfaces branch June 21, 2026 01:07
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: restore CI test leg — behavioral coverage for high-risk surfaces

1 participant