Skip to content

🧪 Add missing error handling test for fetchCommitDatesForTopRepos#351

Closed
is0692vs wants to merge 4 commits into
mainfrom
jules-12597517270863271554-566eb532
Closed

🧪 Add missing error handling test for fetchCommitDatesForTopRepos#351
is0692vs wants to merge 4 commits into
mainfrom
jules-12597517270863271554-566eb532

Conversation

@is0692vs

@is0692vs is0692vs commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

🎯 What: Added a missing error handling test case for the fetchCommitDatesForTopRepos batch query logic.

📊 Coverage: Covered the scenario where the inner graphql fetch actually throws an exception (e.g. simulating a network failure) instead of returning an API error response. This ensures the catch (error) block logs the exception and safely falls back to returning an empty array without crashing the entire fetchYearInReviewData request.

Result: Improved test reliability and ensured safe fallback paths are accurately exercised and verified by Vitest.


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

Greptile Summary

このPRは、fetchCommitDatesForTopRepos のバッチクエリが同期的な例外をスローした場合(ネットワーク障害のシミュレーション)に、catch (error) ブロックがエラーをログに残して空配列を返すフォールバック動作を正しくカバーするテストケースを追加します。

  • 既存テスト(HTTP 500 レスポンスを返すケース)を補完する形で、同期的な throw による例外スローパスを新たにカバーしている
  • expect.assertions(2) を先頭に配置することで、フォールバックパスが実際に通過したことをアサーションレベルで保証する設計になっている
  • ロガースパイのクリーンアップは finally ブロックで行われており、隣接する既存テストのパターンと一貫している

Confidence Score: 5/5

テストのみの変更で、実装コードへの影響はない。新規テストはフォールバックパスを正しく検証している。

変更はテストファイルのみで、実装コードへの変更はない。追加されたテストは fetchCommitDatesForTopRepos の catch ブロックを正しく網羅しており、expect.assertions(2) による保護も適切に配置されている。

特に注意が必要なファイルはない。

Important Files Changed

Filename Overview
src/lib/tests/githubYearInReview.test.ts fetchCommitDatesForTopRepos の例外スロー時フォールバックパスをカバーするテストを追加。expect.assertions(2) による保護も適切に設置されており、実装の catch ブロックと正しく対応している。

Reviews (3): Last reviewed commit: "🧪 Add missing error handling test for f..." | 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 6, 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)
github-user-summary Ignored Ignored Jul 8, 2026 6:29am

@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 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 3 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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 reviews.

How do review 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 refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a87ccc66-7c25-4f5f-a215-adb4d19f7571

📥 Commits

Reviewing files that changed from the base of the PR and between 05bc250 and b86ca03.

📒 Files selected for processing (23)
  • src/app/api/dashboard/stats/route.test.ts
  • src/app/api/dashboard/stats/route.ts
  • src/app/api/dashboard/year/route.test.ts
  • src/app/api/dashboard/year/route.ts
  • src/components/ContributionsCard.tsx
  • src/components/YearInReviewCarousel.test.tsx
  • src/components/YearInReviewCarousel.tsx
  • src/components/YearInReviewSlide.test.tsx
  • src/components/YearInReviewSlide.tsx
  • src/components/__tests__/ContributionsCard.test.tsx
  • src/hooks/__tests__/useDashboardData.test.tsx
  • src/lib/__tests__/auth.test.ts
  • src/lib/__tests__/github/fetchContributions.test.ts
  • src/lib/__tests__/githubYearInReview.test.ts
  • src/lib/__tests__/rateLimit.test.ts
  • src/lib/__tests__/validators.test.ts
  • src/lib/__tests__/yearInReviewUtils.test.ts
  • src/lib/auth.ts
  • src/lib/github.ts
  • src/lib/rateLimit.ts
  • src/lib/types.ts
  • src/lib/yearInReviewUtils.ts
  • vitest.setup.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jules-12597517270863271554-566eb532

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

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 test case to verify that the system falls back to an empty array and logs an error when fetchCommitDatesForTopRepos throws an exception. The reviewer suggested refactoring the mock implementation of mockFetch to be an async function with an explicit return type (Promise<Response>) instead of manually wrapping the responses in Promise.resolve, which improves type safety and readability.

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 on lines +222 to +260
mockFetch.mockImplementation((url: string | URL | Request) => {
const urlStr = typeof url === "string" ? url : url instanceof URL ? url.toString() : (url as Request).url;
if (urlStr.includes("/graphql")) {
callCount++;
if (callCount === 1) {
// combined query
return Promise.resolve(jsonResponse({
data: {
user: {
id: "MDQ6VXNlcjEyMzQ1",
contributionsCollection: {
totalCommitContributions: 10,
totalPullRequestContributions: 0,
totalIssueContributions: 0,
totalPullRequestReviewContributions: 0,
contributionCalendar: {
totalContributions: 10,
weeks: []
},
commitContributionsByRepository: [
{
repository: { owner: { login: "user1" }, name: "repo1" },
contributions: { totalCount: 10 }
}
],
pullRequestContributionsByRepository: [],
issueContributionsByRepository: []
}
}
}
}));
}
if (callCount === 2) {
// Fail the batch query by throwing an error directly
throw new Error("Simulated network failure for commit dates");
}
}
return Promise.resolve(jsonResponse([], 200));
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

According to our general rules, mock implementations returning Promises should be defined as async functions and have explicit return types to maintain type safety and readability.

Please update the mock implementation of mockFetch to be an async function returning Promise<Response> and return the responses directly instead of wrapping them in Promise.resolve.

        mockFetch.mockImplementation(async (url: string | URL | Request): Promise<Response> => {
            const urlStr = typeof url === "string" ? url : url instanceof URL ? url.toString() : (url as Request).url;
            if (urlStr.includes("/graphql")) {
                callCount++;
                if (callCount === 1) {
                    // combined query
                    return jsonResponse({
                        data: {
                            user: {
                                id: "MDQ6VXNlcjEyMzQ1",
                                contributionsCollection: {
                                    totalCommitContributions: 10,
                                    totalPullRequestContributions: 0,
                                    totalIssueContributions: 0,
                                    totalPullRequestReviewContributions: 0,
                                    contributionCalendar: { 
                                        totalContributions: 10,
                                        weeks: []
                                    },
                                    commitContributionsByRepository: [
                                        {
                                            repository: { owner: { login: "user1" }, name: "repo1" },
                                            contributions: { totalCount: 10 }
                                        }
                                    ],
                                    pullRequestContributionsByRepository: [],
                                    issueContributionsByRepository: []
                                }
                            }
                        }
                    });
                }
                if (callCount === 2) {
                    // Fail the batch query by throwing an error directly
                    throw new Error("Simulated network failure for commit dates");
                }
            }
            return jsonResponse([], 200);
        });
References
  1. In TypeScript, ensure functions and mock implementations have explicit return types and use async functions for mocks returning Promises to maintain type safety and readability.

@codecov

codecov Bot commented Jun 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread src/lib/__tests__/githubYearInReview.test.ts
Comment thread src/lib/__tests__/githubYearInReview.test.ts Outdated
@is0692vs

is0692vs commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@greptile review

@is0692vs

is0692vs commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@greptile review

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
@pull-request-size pull-request-size Bot added size/XL and removed size/M labels Jul 8, 2026
@is0692vs

is0692vs commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Closing because after updating with the latest main, this branch now contains many unrelated diffs, including auth and dashboard changes outside the intended fetchCommitDatesForTopRepos test. It no longer satisfies the safe-merge criteria for a narrow test PR.

@is0692vs is0692vs closed this Jul 8, 2026
@google-labs-jules

Copy link
Copy Markdown
Contributor

Closing because after updating with the latest main, this branch now contains many unrelated diffs, including auth and dashboard changes outside the intended fetchCommitDatesForTopRepos test. It no longer satisfies the safe-merge criteria for a narrow test PR.

Understood. Acknowledging that this work is now obsolete due to the unrelated diffs and stopping work on this task.

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