Skip to content

🧪 [Testing] Add coverage for authHeaders SSR edge case#1035

Merged
is0692vs merged 3 commits into
stagingfrom
improve-api-helper-tests-5023596437525124151
Jun 29, 2026
Merged

🧪 [Testing] Add coverage for authHeaders SSR edge case#1035
is0692vs merged 3 commits into
stagingfrom
improve-api-helper-tests-5023596437525124151

Conversation

@is0692vs

@is0692vs is0692vs commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

🎯 What: Improved the test suite for the authHeaders utility function in apps/web/src/lib/api.ts by explicitly verifying its behavior when executed in a server-side rendering (SSR) environment.

📊 Coverage: Added a test that stubs the global window object to undefined (simulating SSR) to ensure authHeaders() correctly returns an empty object when window is not available, rather than attempting to access localStorage.

Result: The authHeaders function in api.ts is now covered by 100% of statements and branches. We can be confident it correctly guards against non-browser environments.


PR created automatically by Jules for task 5023596437525124151 started by @is0692vs

Greptile Summary

authHeaders ユーティリティの SSR エッジケース(window === undefined 環境)を検証するテストを追加し、ブランチカバレッジを 100% にする変更です。また、以前のレビューで指摘されたスタブのクリーンアップ漏れも beforeEach への vi.unstubAllGlobals() 追加で解消されています。

  • vi.stubGlobal("window", undefined) で SSR 環境をシミュレートし、authHeaders(){} を返すことを確認するテストを追加。
  • vi.unstubAllGlobals()beforeEach に移動することで、アサーション失敗時もスタブが確実にリセットされるよう修正。

Confidence Score: 5/5

テストのみの変更でプロダクションコードへの影響はなく、安全にマージできます。

変更はテストファイル1件のみで、新テストの内容・クリーンアップロジックともに正確です。vi.stubGlobal("window", undefined) で SSR を正しくシミュレートしており、beforeEach での vi.unstubAllGlobals() により状態の漏えいも防止されています。以前のレビュー指摘も本 PR で解消済みです。

特に注意が必要なファイルはありません。

Important Files Changed

Filename Overview
apps/web/src/lib/tests/api.test.ts SSR エッジケース用テストを追加し、vi.unstubAllGlobals()beforeEach へ移動することで以前の指摘も解消済み。変更内容は正確で安全。

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Test as テストケース
    participant BE as beforeEach
    participant VI as Vitest
    participant AH as authHeaders()

    Note over Test,AH: SSR エッジケーステスト(新規)
    Test->>VI: vi.stubGlobal("window", undefined)
    Test->>AH: authHeaders() を呼び出し
    AH->>AH: "typeof window !== "undefined" → false"
    AH-->>Test: "{} を返す"
    Test->>Test: "expect({}).toEqual({}) ✅"

    Note over BE,VI: 次のテスト前のクリーンアップ
    BE->>VI: vi.unstubAllGlobals()
    VI->>VI: window を復元
    BE->>VI: vi.restoreAllMocks()
    BE->>BE: localStorage.clear()
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Test as テストケース
    participant BE as beforeEach
    participant VI as Vitest
    participant AH as authHeaders()

    Note over Test,AH: SSR エッジケーステスト(新規)
    Test->>VI: vi.stubGlobal("window", undefined)
    Test->>AH: authHeaders() を呼び出し
    AH->>AH: "typeof window !== "undefined" → false"
    AH-->>Test: "{} を返す"
    Test->>Test: "expect({}).toEqual({}) ✅"

    Note over BE,VI: 次のテスト前のクリーンアップ
    BE->>VI: vi.unstubAllGlobals()
    VI->>VI: window を復元
    BE->>VI: vi.restoreAllMocks()
    BE->>BE: localStorage.clear()
Loading

Comments Outside Diff (1)

  1. apps/web/src/lib/__tests__/api.test.ts, line 5-8 (link)

    P2 beforeEachvi.unstubAllGlobals() を追加してスタブを確実にリセットし、テスト失敗時の状態漏えいを防ぎます。テストボディ末尾の手動呼び出しは不要になるので削除できます。

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: apps/web/src/lib/__tests__/api.test.ts
    Line: 5-8
    
    Comment:
    `beforeEach``vi.unstubAllGlobals()` を追加してスタブを確実にリセットし、テスト失敗時の状態漏えいを防ぎます。テストボディ末尾の手動呼び出しは不要になるので削除できます。
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (2): Last reviewed commit: "Merge remote-tracking branch 'origin/sta..." | Re-trigger Greptile

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Jun 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
open-shelf Ignored Ignored Jun 28, 2026 3:42pm

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@is0692vs, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 57 minutes and 29 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2783e3d5-0c1c-40d7-9ef3-27550f5a88fc

📥 Commits

Reviewing files that changed from the base of the PR and between c8bdf07 and afefd3f.

📒 Files selected for processing (1)
  • apps/web/src/lib/__tests__/api.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch improve-api-helper-tests-5023596437525124151

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds a new unit test to verify that 'authHeaders' returns an empty object when 'window' is undefined. The reviewer suggests wrapping the assertion in a try-finally block to ensure that 'vi.unstubAllGlobals()' is always executed, preventing potential test pollution if the assertion fails.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread apps/web/src/lib/__tests__/api.test.ts
Comment thread apps/web/src/lib/__tests__/api.test.ts
@github-actions
github-actions Bot changed the base branch from main to staging June 28, 2026 15:46
@github-actions

Copy link
Copy Markdown

このリポジトリでは staging 先行フローを採用しています。PR のターゲットを staging に変更しました。staging で動作確認後、stagingmain の PR を作成してください。

@codecov

codecov Bot commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

Deployment failed with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/hirokis-projects-afd618c7?upgradeToPro=build-rate-limit

@is0692vs

Copy link
Copy Markdown
Contributor Author

@greptile review

@is0692vs
is0692vs merged commit b64edbf into staging Jun 29, 2026
13 of 14 checks passed
@is0692vs
is0692vs deleted the improve-api-helper-tests-5023596437525124151 branch June 29, 2026 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant