Skip to content

test(vercel-basic-auth): vitest でテストを追加#20

Merged
amotarao merged 7 commits intomainfrom
feature/vercel-basic-auth-tests
Mar 26, 2026
Merged

test(vercel-basic-auth): vitest でテストを追加#20
amotarao merged 7 commits intomainfrom
feature/vercel-basic-auth-tests

Conversation

@amotarao
Copy link
Copy Markdown
Member

@amotarao amotarao commented Mar 26, 2026

概要

vercel-basic-auth パッケージに vitest を使ったテストを追加します。

  • vitest を devDependency として追加
  • test / test:run スクリプトを追加
  • src/index.test.ts を作成し、12テストケースを実装
    • NODE_ENV=development 時の挙動 (dev オプション)
    • Vercel 環境 (VERCEL=1) での vercelEnvTarget 各パターン
    • Authorization ヘッダーのバリデーション (なし・不正・認証失敗・成功)
  • CI ワークフローを format-check.yml から ci.yml に統合し、テストを追加

Closes #17

Summary by CodeRabbit

  • Tests

    • basicAuth の包括的なテストスイートを追加し、認証ヘッダー解析・環境別の振る舞い・成功/失敗ケースを網羅。
  • Chores

    • テスト実行用スクリプトと開発依存を追加し、ローカルおよび CI でのテスト実行を可能にした。
    • パッチリリースを記録する変更セットを追加。
    • CI ワークフローを整理し、フォーマットチェック後にテストが実行されるように更新。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1fc2a0f0-c459-4f18-b203-57d88e14ecd5

📥 Commits

Reviewing files that changed from the base of the PR and between 344b2bf and b511ac6.

📒 Files selected for processing (2)
  • .github/workflows/ci.yml
  • packages/vercel-basic-auth/package.json
✅ Files skipped from review due to trivial changes (2)
  • packages/vercel-basic-auth/package.json
  • .github/workflows/ci.yml

Walkthrough

packages/vercel-basic-auth に Vitest ベースのテストを追加し、package.json にテストスクリプトと vitestdevDependencies に追加しました。CI ワークフローにテスト実行ステップを追加し、Changeset を作成しています。

Changes

Cohort / File(s) Summary
Package Configuration
packages/vercel-basic-auth/package.json
devDependenciesvitest@^4.1.1 を追加し、scriptstest/test:run を追加。build スクリプトの細かな表記差分。
Test Suite
packages/vercel-basic-auth/src/index.test.ts
新規 Vitest テストファイルを追加(約121行)。NODE_ENV/VERCEL/VERCEL_ENV による環境ゲーティングと、Authorization ヘッダーの欠落・不正・認証成功/失敗パターンを網羅。
CI Workflow
.github/workflows/ci.yml
ワークフロー名とジョブ名を変更(Format Check → CI)、フォーマットチェック後に pnpm -r run test:run を実行するステップを追加。
Changeset
.changeset/vercel-basic-auth-add-tests.md
テスト追加を記載したパッチ用 Changeset を追加。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • akameco

Poem

🐇 テストの朝に跳ねるよ
期待値を抱えて、ヘッダを確かめる
環境を整えて、扉をノックする
Vitest の光で不具合を照らすよ
合格のご褒美はにんじん一つ 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトルは「test(vercel-basic-auth): vitest でテストを追加」で、変更内容(vitest を使ったテスト追加)を明確に要約しており、主要な変更を適切に反映しています。
Linked Issues check ✅ Passed リンクされたissue #17は「vercel-basic-auth: テスト追加」であり、本PRはvitest を使った包括的なテストスイート(12テストケース)を実装し、NODE_ENV、Vercel環境、Authorizationヘッダーの各ケースをカバーしており、要件を満たしています。
Out of Scope Changes check ✅ Passed すべての変更はテスト追加に関連しており、package.jsonへのvitest依存追加、テストファイル作成、CIワークフロー更新、changesetファイルは全てスコープ内の範囲です。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/vercel-basic-auth-tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/vercel-basic-auth/src/index.test.ts (1)

75-111: 認証スキーム不一致(Bearer など)の拒否ケースも追加したいです。

Authorization の値検証として、Basic 以外のスキームを 401 にするテストを追加すると回帰検知が強くなります。

追加例
 describe("認証ヘッダーのバリデーション", () => {
+  it("Authorization スキームが Basic 以外のとき 401 を返す", () => {
+    const req = makeRequest(`Bearer ${btoa(`${USERNAME}:${PASSWORD}`)}`);
+    const res = basicAuth(req, { username: USERNAME, password: PASSWORD });
+    expect(res?.status).toBe(401);
+  });
+
   it("Authorization ヘッダーなしのとき 401 を返す", () => {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/vercel-basic-auth/src/index.test.ts` around lines 75 - 111, Add a
new test case that verifies basicAuth rejects non-"Basic" schemes (e.g., "Bearer
abc123") by returning 401 and setting WWW-Authenticate to "Basic"; create a
request using makeRequest("Bearer abc123") (or similar) and call basicAuth(req,
{ username: USERNAME, password: PASSWORD }) and assert res?.status === 401 and
res?.headers.get("WWW-Authenticate") === "Basic" to ensure scheme mismatch is
covered alongside the existing makeBasicAuthHeader/USERNAME/PASSWORD tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/vercel-basic-auth/src/index.test.ts`:
- Around line 20-24: The afterEach currently deletes process.env.NODE_ENV,
process.env.VERCEL and process.env.VERCEL_ENV which can break other tests;
instead capture their original values before tests run (e.g. in a beforeEach or
at top of the test file) and restore them in afterEach by assigning back the
saved values (use undefined-check to delete only if originally undefined).
Update the afterEach handler and add a snapshot variable (e.g. originalNodeEnv,
originalVercel, originalVercelEnv) to perform safe restoration rather than
unconditional deletion.

---

Nitpick comments:
In `@packages/vercel-basic-auth/src/index.test.ts`:
- Around line 75-111: Add a new test case that verifies basicAuth rejects
non-"Basic" schemes (e.g., "Bearer abc123") by returning 401 and setting
WWW-Authenticate to "Basic"; create a request using makeRequest("Bearer abc123")
(or similar) and call basicAuth(req, { username: USERNAME, password: PASSWORD })
and assert res?.status === 401 and res?.headers.get("WWW-Authenticate") ===
"Basic" to ensure scheme mismatch is covered alongside the existing
makeBasicAuthHeader/USERNAME/PASSWORD tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 46a16055-b0be-484c-b5ce-b691231dd422

📥 Commits

Reviewing files that changed from the base of the PR and between bf05712 and 2bd5fab.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • packages/vercel-basic-auth/package.json
  • packages/vercel-basic-auth/src/index.test.ts

Comment thread packages/vercel-basic-auth/src/index.test.ts
amotarao and others added 3 commits March 26, 2026 09:11
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@amotarao amotarao requested a review from akameco March 26, 2026 00:15
amotarao and others added 3 commits March 26, 2026 09:20
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@amotarao amotarao requested a review from iromonek39 March 26, 2026 00:39
Copy link
Copy Markdown

@akameco akameco left a comment

Choose a reason for hiding this comment

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

LGTM

@akameco akameco removed the request for review from iromonek39 March 26, 2026 02:28
@amotarao amotarao merged commit 816bb27 into main Mar 26, 2026
2 checks passed
@amotarao amotarao deleted the feature/vercel-basic-auth-tests branch March 26, 2026 02:52
@github-actions github-actions Bot mentioned this pull request Mar 26, 2026
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.

vercel-basic-auth: テスト追加

2 participants