Skip to content

🧪 [テスト追加] fetchActivityのエラーパスと早期終了のテストカバレッジ向上#174

Open
is0692vs wants to merge 3 commits intomainfrom
jules-7731857770113037880-16ef4aaa
Open

🧪 [テスト追加] fetchActivityのエラーパスと早期終了のテストカバレッジ向上#174
is0692vs wants to merge 3 commits intomainfrom
jules-7731857770113037880-16ef4aaa

Conversation

@is0692vs
Copy link
Copy Markdown
Contributor

@is0692vs is0692vs commented Apr 17, 2026

🎯 What: fetchActivity 関数における以下の未テストパスをカバーしました。

  • events.length < 100 で早期に break するシナリオ。
  • events.length >= 100 で次のページの取得に進むシナリオ。
  • UserNotFoundError および RateLimitError 以外の例外が発生した際に、ループを抜けて処理を継続するエラーハンドリングのシナリオ。

📊 Coverage:
以下のシナリオを追加し、該当処理の全分岐をカバーしました:

  1. 100件以上のイベントがある場合: 次のページも適切に取得されることを確認するテスト。
  2. 100件未満のイベントがある場合: 早期に break し、不要なページへのリクエストを行わないことを確認するテスト。
  3. 500等のAPIエラーが発生した場合 (最初のページ): 早期終了し、空のイベント配列とイベント内訳が返されることを確認するテスト。
  4. 一般的なエラーが発生した場合: UserNotFoundError または RateLimitError 以外のエラーがスローされた際に、fetchActivity がそれをキャッチしてループを抜け、フォールバックとして結果(空データなど)を正しく返すことを確認するテスト。

Result:
src/lib/github.ts:647 周辺の fetchEvents パスおよびエラー時の break ステートメントが完全にテストされるようになり、テストカバレッジの向上とコードの信頼性強化に貢献しました。


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

Greptile Summary

このPRは fetchActivity のエラーパス・早期終了・ページネーション分岐をカバーする4つのテストを追加しています。しかし、テストファイルの生成に使われた7つの一時的なJavaScriptスクリプト(append.jsappend_events.js 等)がリポジトリルートに残ったままコミットされており、マージ前に削除が必要です。

  • テストファイルを文字列置換で書き換えた副作用で、2つのテストが describe(\"Error handling\") ブロックの外に誤配置されています
  • 135〜146行目と177〜185行目のエラーテストはほぼ同一シナリオの重複です

Confidence Score: 4/5

開発用スクリプト7ファイルを削除し、テスト構造を修正すればマージ可能です。

リポジトリルートに残った一時スクリプト群(P1)がそのままマージされることで不要なファイルが本番コードに混入するため、スコアを4としました。テストロジック自体は概ね正しく、P2の構造・重複問題はマージをブロックしません。

リポジトリルートの7つのJSスクリプトファイル(append.js、append_events.js、append_more.js、fix_file.js、fix_test.js、get_coverage.js、req.js)を削除する必要があります。

Important Files Changed

Filename Overview
src/lib/tests/github/fetchActivity.test.ts 4つの新規テストを追加。2つがdescribe("Error handling")外に誤配置され、2つのエラーテストが実質的に重複している。
append.js テストファイルを文字列置換で書き換えるための一時的なスクリプト。リポジトリに含めるべきではない開発成果物。
append_events.js テストファイルを文字列置換で書き換えるための一時的なスクリプト。リポジトリに含めるべきではない開発成果物。
fix_file.js テストファイルを書き換えるための一時的なスクリプト。リポジトリに含めるべきではない開発成果物。
get_coverage.js async関数を定義しているが呼び出しがなく不完全。リポジトリに含めるべきではない開発成果物。
req.js ログ出力のみのプレースホルダースクリプト。リポジトリに含めるべきではない開発成果物。

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[fetchActivity 開始] --> B[pages 1-2-3 のPromiseを並行生成]
    B --> C{page Promiseをawait}
    C -->|成功| D{events.length < 100?}
    D -->|true| E[break → 早期終了]
    D -->|false| C
    C -->|エラー| F{UserNotFoundError\nまたは RateLimitError?}
    F -->|true| G[再スロー → 呼び出し元へ伝播]
    F -->|false 一般エラー| H[break → 早期終了]
    E --> I[ヒートマップ・イベント集計]
    H --> I
    C -->|全ページ完了| I
    I --> J[ActivityData を返す]
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: append.js
Line: 1-18

Comment:
**開発用スクリプトが誤ってコミットされている**

`append.js``append_events.js``append_more.js``fix_file.js``fix_test.js``get_coverage.js``req.js` の7ファイルはテストファイルをプログラム的に書き換えるために使われた一時的なスクリプトです。これらは開発の成果物であり、リポジトリのルートに含めるべきではありません。`main` ブランチにマージされる前にすべて削除してください。

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/lib/__tests__/github/fetchActivity.test.ts
Line: 164-185

Comment:
**テストが正しい `describe` ブロックの外に配置されている**

164〜175行目の「100件以上」テストおよび177〜185行目の「エラーが UserNotFoundError や RateLimitError 以外の場合」テストは、`describe("Error handling")` ブロック(162行目で閉じられる)の外に置かれています。特にエラーハンドリングのテストは `describe("Error handling")` の中に入れるべきです。スクリプトでの文字列置換による追記が原因で、テスト構造が意図せず壊れています。

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/lib/__tests__/github/fetchActivity.test.ts
Line: 135-146

Comment:
**重複したエラーテストが存在する**

135〜146行目「1ページ目で例外がスローされた場合(エラーインスタンス以外)」と177〜185行目「エラーが UserNotFoundError や RateLimitError 以外の場合」は、どちらも `new Error(...)` を1ページ目でリジェクトして `totalEvents === 0` を確認するほぼ同一のシナリオです。一方を削除してください。

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/lib/__tests__/github/fetchActivity.test.ts
Line: 150

Comment:
**未使用変数 `i` がある**

`Array.from` のコールバック引数 `i` は宣言されていますが使われていません。165行目も同様です。

```suggestion
      const events = Array.from({ length: 99 }, (_) => ({ type: "PushEvent", created_at: "2024-01-15T10:30:00Z" }));
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "🧪 fetchActivityのエラーパスと早期終了のテスト追加" | Re-trigger Greptile

Greptile also left 4 inline comments on this PR.

Context used:

  • Context used - 日本語で!!! (source)

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
Copy link
Copy Markdown

vercel bot commented Apr 17, 2026

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

Project Deployment Actions Updated (UTC)
github-user-summary Ready Ready Preview, Comment Apr 17, 2026 8:46am

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 17, 2026

Warning

Rate limit exceeded

@is0692vs has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 18 minutes and 17 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 18 minutes and 17 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 02a8d862-f697-4df4-993c-b0889261bd01

📥 Commits

Reviewing files that changed from the base of the PR and between 39f1a59 and 9627fcd.

📒 Files selected for processing (1)
  • src/lib/__tests__/github/fetchActivity.test.ts
📝 Walkthrough

Walkthrough

このプルリクエストは、fetchActivity関数のペジネーション処理とエラーハンドリング動作を検証するための5つの新しいJestテストケースをsrc/lib/__tests__/github/fetchActivity.test.tsに追加しています。また、テストファイル操作を行う複数の補助スクリプト(append、fix、coverage関連)も含まれています。

Changes

Cohort / File(s) Summary
テスト補助スクリプト
append.js, append_events.js, append_more.js, fix_file.js, fix_test.js, get_coverage.js, req.js
fetchActivity テストファイルを動的に操作・拡張するためのNode.jsユーティリティスクリプト。テストケースの追加、ファイルの読み込み、ログ出力などを実行します。
メインテストファイル更新
src/lib/__tests__/github/fetchActivity.test.ts
HTTPエラー(500)、未型付けエラー、ペジネーション境界値(100イベント)、エラーリトライ動作に関する5つの新しいテストケースを追加。ページネーション継続・停止条件やエラーレジリエンス機能をカバーします。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 百の境を越えるるとき、
ページは進むもその先に、
エラーの波も優しく受け止め、
テストの光が道を照らす✨
バグなき未来へ、飛び出そう!

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Title check ✅ Passed プルリクエストのタイトルは fetchActivity のエラーパスと早期終了のテストカバレッジ向上に関するもので、変更内容と一致しています。
Description check ✅ Passed プルリクエストの説明は追加されたテストシナリオ、カバレッジの詳細、および結果について具体的に説明しており、変更内容と十分に関連しています。

✏️ 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 jules-7731857770113037880-16ef4aaa

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 and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

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

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 several test cases to src/lib/__tests__/github/fetchActivity.test.ts to improve coverage for error handling, pagination, and early exit scenarios. It also includes several temporary script files in the root directory that appear to have been used for generating these changes. Feedback focuses on correcting a mismatch between a test's description and its implementation regarding error types, removing redundant test cases to improve maintainability, and cleaning up the repository by deleting the unnecessary script files.

Comment thread src/lib/__tests__/github/fetchActivity.test.ts
Comment thread src/lib/__tests__/github/fetchActivity.test.ts
Comment thread append.js Outdated
Comment thread append.js Outdated
Comment thread src/lib/__tests__/github/fetchActivity.test.ts
Comment thread src/lib/__tests__/github/fetchActivity.test.ts
Comment thread src/lib/__tests__/github/fetchActivity.test.ts Outdated
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: 9

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@append_events.js`:
- Around line 1-18: Delete the helper script append_events.js entirely (it's no
longer needed and breaks test structure) and revert any edits it made to
src/lib/__tests__/github/fetchActivity.test.ts; then open fetchActivity.test.ts
and move the appended it("100件以上のイベントがある場合、次のページも取得する") block so it sits inside
the describe("Error handling") group (preserve its mockFetch setup and
assertions), and finally remove the linting issue by replacing the top-level
require('fs') with an ES import or otherwise fix the require() usage in
append_events.js before deletion (preferably just delete the file to eliminate
the lint error).

In `@append_more.js`:
- Around line 1-18: append_more.js is a one-shot test-injection script that must
not be committed; delete this file (and any other similar scripts like
append_events.js) from the repository, remove any CI/run references to it, and
ensure the intended test was committed directly into
src/lib/__tests__/github/fetchActivity.test.ts instead; do not replace it with a
runtime script using require/fs (avoid the use of require/import in committed
scripts to satisfy `@typescript-eslint/no-require-imports`), and remove any code
that relies on the fragile regex replace pattern (newContent = content.replace(/
\}\);\n  \}\);\n\}\);/, ...)) so the test file structure isn’t mutated at
runtime.

In `@append.js`:
- Around line 1-18: Remove the disposable Node script append.js that uses
require() and file-manipulation (symbols: fs, readFileSync, writeFileSync,
content, toAppend, newContent) from the commit and repository; delete the file
entirely so the ESLint rule `@typescript-eslint/no-require-imports` no longer
fails in CI and rely on the already-applied changes in
src/lib/__tests__/github/fetchActivity.test.ts instead.

In `@fix_file.js`:
- Around line 1-17: This throwaway script (uses require('fs'), fs.readFileSync,
fs.writeFileSync and content.replace(...)) should be removed because it mutates
src/lib/__tests__/github/fetchActivity.test.ts incorrectly (placing
additionalTest outside the intended describe block) and also causes lint
failures via require(); delete this file from the repo (or if you must keep it
temporarily, revert the test file to its original content and remove/replace
require('fs') with import fs from 'fs' and stop using the regex insertion via
content.replace to avoid corrupting describe scopes).

In `@fix_test.js`:
- Around line 1-6: The file fix_test.js is just a leftover memo that reads a
test file but makes no changes and creates unused/ lint-flagged artifacts
(require('fs') and the content variable); remove this file from the repository
(or if you need to preserve the note, move the text into the PR
description/commit message and delete fix_test.js) and ensure there are no
references to content or require('fs') left in the codebase.

In `@get_coverage.js`:
- Around line 1-6: このファイルは開発用の一時スクリプトなのでコミットから削除するか(推奨)リポジトリの無視対象へ移動してください:
get_coverage.js を削除、または .gitignore 配下の別ディレクトリへ移し、もし残す必要があるなら require('fs')
の未使用削除と test 関数(および動的 import('./src/lib/github.ts') と fetchActivity の
console.log)を実行しない状態でコミットしないようにしてください。

In `@req.js`:
- Around line 1-6: Remove this dev-only one-shot debug script from the PR:
delete req.js (which contains the unused require('fs') and the test() function
that only logs "Ready for plan review.") because it is unrelated to
production/test logic and violates the `@typescript-eslint/no-require-imports`
rule; also remove the other listed temporary scripts (get_coverage.js,
append.js, append_more.js, append_events.js, fix_test.js, fix_file.js) from the
commit so CI linting and repository cleanliness are preserved.

In `@src/lib/__tests__/github/fetchActivity.test.ts`:
- Around line 148-161: The test comment is misleading: update the inline comment
in the test (the block around the it("100件未満のイベントがある場合、breakする", ...)) to state
that fetchActivity issues restGet/fetch requests for pages = [1,2,3] in
parallel, so mockFetch will be invoked three times even though the for...of
awaiting loop inside fetchActivity (function fetchActivity) will break early
when events.length < 100; keep the assertion expecting totalEvents === 99 but
change the explanatory comment to reflect parallel request behavior and the
subsequent early break during sequential awaiting.
- Around line 162-186: Two tests ("100件以上のイベントがある場合、次のページも取得する" and the generic
error test) were placed outside the describe("Error handling") block; move both
it(...) blocks so they are nested inside the existing describe("Error handling")
group that surrounds the other error tests. Also remove or merge the generic
Error test (the one that mocks mockRejectedValueOnce(new Error("Generic error"))
and expects totalEvents === 0) with the existing similar test that handles
"1ページ目で例外がスローされた場合(エラーインスタンス以外)、breakして処理を継続する" to avoid duplication — keep a
single it(...) under describe("Error handling") that asserts fetchActivity
(function fetchActivity) breaks on a generic Error and results in totalEvents
=== 0, and ensure the pagination test (100 events -> fetch next page) remains
inside the appropriate describe block.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 447f353f-d985-4946-a26b-62e03ed3b474

📥 Commits

Reviewing files that changed from the base of the PR and between 3be157d and 39f1a59.

📒 Files selected for processing (8)
  • append.js
  • append_events.js
  • append_more.js
  • fix_file.js
  • fix_test.js
  • get_coverage.js
  • req.js
  • src/lib/__tests__/github/fetchActivity.test.ts

Comment thread append_events.js Outdated
Comment thread append_more.js Outdated
Comment thread append.js Outdated
Comment thread fix_file.js Outdated
Comment thread fix_test.js Outdated
Comment thread get_coverage.js Outdated
Comment thread req.js Outdated
Comment thread src/lib/__tests__/github/fetchActivity.test.ts
Comment thread src/lib/__tests__/github/fetchActivity.test.ts
Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
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