Skip to content

🧪 [testing improvement] 100% test coverage for yearInReviewUtils#182

Open
is0692vs wants to merge 2 commits intomainfrom
test-year-in-review-utils-12914753485959745825
Open

🧪 [testing improvement] 100% test coverage for yearInReviewUtils#182
is0692vs wants to merge 2 commits intomainfrom
test-year-in-review-utils-12914753485959745825

Conversation

@is0692vs
Copy link
Copy Markdown
Contributor

@is0692vs is0692vs commented Apr 18, 2026

🎯 What: Testing gaps in yearInReviewUtils module. Specifically, adding edge-case validations inside the 'buildHourlyHeatmapFromCommitDates' loop logic to hit branching exceptions correctly.
📊 Coverage: We added unparseable string scenarios, cache fallback misses, unparseable hour parsing, and timezone parsing condition blocks.
Result: 100% total statement, branching, and line coverage.


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

Greptile Summary

このPRは buildHourlyHeatmapFromCommitDates のブランチカバレッジ向上を目的としたテスト追加で、実装コードへの変更はありません。

  • P1: it(\"hits the fast path with a length 20 string\", ...) ブロック(行 224–233)が describe の閉じ括弧の外側に誤って配置されており、テストグルーピングが崩れています。テスト名も実際の挙動(fallback path, 24文字文字列)と矛盾しているため、修正が必要です。

Confidence Score: 4/5

プロダクションコードへの変更はなく安全だが、テストファイルに構造的なバグ(orphaned it ブロック)がありマージ前の修正が推奨される。

P1 の問題が1件あります:最後の it ブロックが describe 外に配置されており、テスト名も実態と異なります。実装コードは変更されておらず本番リスクはゼロですが、テストの意図が不明確になっており、将来の保守で混乱を招く可能性があるため 4/5 とします。

src/lib/tests/yearInReviewUtils.test.ts — 行 224-233 の orphaned it ブロックの修正が必要

Important Files Changed

Filename Overview
src/lib/tests/yearInReviewUtils.test.ts エッジケースを対象とした新しいテストブロックを追加しているが、最後の it ブロックが describe の外側に誤って配置されており、テスト名も誤り(fast path と書いてあるが実際は fallback をテスト)。一部のテストが実装詳細依存の脆弱なモックを使用している。

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Loop over commitDates] --> B{Fast path check}
    B -->|No| F[new Date fallback]
    B -->|Yes| C[Get datePart, check cache]
    C --> D{Cache hit?}
    D -->|Miss| E[Parse date part]
    E --> G{Valid date?}
    G -->|No| H[new Date full string]
    H --> I{Valid?}
    I -->|No| Skip1[Skip]
    I -->|Yes| K[Update heatmap]
    G -->|Yes| J[Cache day value]
    D -->|Hit| J
    J --> L[Parse hour h1 and h2]
    L --> M{Hour digits valid 0-9?}
    M -->|No| F
    M -->|Yes| N{Ends with Z or length 20 or length 24 .000Z?}
    N -->|Yes| O[Fast path update heatmap]
    N -->|No| F
    F --> P{Valid date?}
    P -->|No| Skip2[Skip]
    P -->|Yes| Q[Update heatmap]
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/lib/__tests__/yearInReviewUtils.test.ts
Line: 224-233

Comment:
**`it` ブロックが `describe` の外に配置されている**

このテストブロック(行 224–233)は `describe("buildHourlyHeatmapFromCommitDates - edge cases", ...)``});` 閉じ括弧(行 222)の**外側**に書かれています。インデント(4スペース)から `describe` 内に入れるつもりだったことは分かりますが、実際はトップレベルの `it` になっています。Vitest はトップレベル `it` を実行しますが、テストのグルーピングが崩れており、意図した構造ではありません。

さらにテスト名も誤りです。「hits the fast path with a length 20 string」と書かれていますが、実際に使っているのは **24文字**の文字列 `"2023-01-01T10:00:00.123+"` であり、fast path ではなく **fallback path** をテストしています。コメント内の `// Wait, "2023-01-01T10:00:00Z" is 20 chars long.` という記述からも開発者が混乱していたことが読み取れます。

このブロックを `describe("buildHourlyHeatmapFromCommitDates - edge cases", ...)` の閉じ括弧の**内側**に移動し、テスト名とコメントを正確なものに修正してください。

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__/yearInReviewUtils.test.ts
Line: 179-188

Comment:
**モックオブジェクトが実装詳細に強く依存している**

`as unknown as string` で型システムを回避したオブジェクトを渡すアプローチは、`buildHourlyHeatmapFromCommitDates` の内部実装(`.length``[10]``.slice()``new Date(dateString)``.toString()` を呼ぶ等)に強く依存しています。同様の構造が 201–211 行目にも存在します。

実装リファクタリング時にこれらのテストが意図しない形でサイレントに壊れる可能性があります。実際の分岐を通したいなら、実装の内部詳細に依存しないような実際の文字列入力を用いるほうが保守性が高まります。

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

Reviews (1): Last reviewed commit: "🧪 100% test coverage for yearInReviewUt..." | Re-trigger Greptile

Greptile also left 2 inline comments on this PR.

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 18, 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 18, 2026 3:26am

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 18, 2026

Warning

Rate limit exceeded

@is0692vs has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 4 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 2 minutes and 4 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: 484472c9-be0a-4ea4-bbba-f6a2af3c10dd

📥 Commits

Reviewing files that changed from the base of the PR and between 01716f7 and 05f73fb.

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

Walkthrough

yearInReviewUtils.test.tsファイルにbuildHourlyHeatmapFromCommitDatesの新しいエッジケーステスト群が追加されました。キャッシュ解析でのNaN発生、時間成分の解析不可、タイムゾーンオフセット処理など、複数の境界条件をカバーするテストケースが含まれています。

Changes

Cohort / File(s) Summary
buildHourlyHeatmapFromCommitDates エッジケーステスト
src/lib/__tests__/yearInReviewUtils.test.ts
キャッシュ/高速解析がNaNを返す場合、時間成分が解析不可の場合、日付は有効だが時間が解析不可の場合、両方の解析が無効な場合、タイムゾーンオフセット処理がフォールバック条件を満たさない場合、および長さ20の文字列に基づく高速パスの実行についてのエッジケーステストを新規追加。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 キャッシュとフォールバック、時間ずれ
エッジを捕まえて、テスト輝く
二十文字の高速道、ホップで検証
🌙 タイムゾーン越えて、真実の時刻へ
テスト群これぞ、品質の証✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly refers to improving test coverage for yearInReviewUtils, which aligns with the changeset that adds new test cases for the module.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description clearly relates to the changeset - it describes adding tests for buildHourlyHeatmapFromCommitDates edge cases to achieve 100% coverage.

✏️ 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 test-year-in-review-utils-12914753485959745825

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 18, 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 edge-case tests for the buildHourlyHeatmapFromCommitDates utility to verify fallback parsing and timezone handling. A structural issue was identified where a test case was placed outside the describe block due to a misplaced brace, and the test's description and internal comments were noted as misleading or requiring cleanup.

Comment on lines +222 to +233
});

it("hits the fast path with a length 20 string", () => {
// e.g. "2023-01-01T10:00:00Z" is length 20!
// Wait, "2023-01-01T10:00:00Z" is 20 chars long.
// Let's make sure we test length === 24 without ending in .000Z
const commitDates = [
"2023-01-01T10:00:00.123+", // length 24
];
const heatmap = buildHourlyHeatmapFromCommitDates(commitDates);
expect(heatmap[0][10]).toBe(0); // wait, it falls back to new Date() which will be NaN so it's ignored
});
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

The test case starting on line 224 is defined outside of the describe block due to the misplaced closing brace on line 222. Additionally, the test description "hits the fast path with a length 20 string" is misleading because the test actually uses a string of length 24 and verifies that it correctly falls back to the standard parsing logic (resulting in 0 commits because the string is invalid). The internal comments also appear to be development notes that should be cleaned up.

    it("falls back to full date parsing when length is 24 but does not end with .000Z", () => {
        const commitDates = [
            "2023-01-01T10:00:00.123+", // length 24
        ];
        const heatmap = buildHourlyHeatmapFromCommitDates(commitDates);
        expect(heatmap[0][10]).toBe(0);
    });
});

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: 2

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

Inline comments:
In `@src/lib/__tests__/yearInReviewUtils.test.ts`:
- Around line 196-199: The test description mismatches its behavior: the spec in
the it(...) claims to verify fallback parsing for unparseable hour data, but the
input "2023-01-01T10:00:00.1234Z" has a parseable hour and triggers the
fast-path; update the test to either (A) rename the test case to describe that
it verifies the fast-path accepts non-25-length UTC strings (e.g., change the it
string to mention "accepts non-25-length Z-terminated timestamps on fast-path")
or (B) change the input to an actually unparseable-hour string so the fallback
path runs; locate the test using the identifier
buildHourlyHeatmapFromCommitDates in src/lib/__tests__/yearInReviewUtils.test.ts
and modify the it(...) description or the input accordingly so the name matches
the asserted behavior.
- Around line 222-233: The test "it('hits the fast path with a length 20
string')" is accidentally located outside the enclosing describe block and its
input string does not match the test name (the string is length 24 and ends with
'+', so it does not hit the fast path in buildHourlyHeatmapFromCommitDates);
move this it(...) back inside the appropriate describe (the one for
buildHourlyHeatmapFromCommitDates - edge cases) and either change the test name
and assertion to reflect that you're testing a non-fast-path 24-char string that
falls back to new Date(), or change the commitDates value to a true fast-path
example (e.g., a 20-char "YYYY-MM-DDTHH:MM:SSZ" or a 24-char ending with
".000Z") so the test name, input, and expected behavior align.
🪄 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: d2dcd50e-118c-465b-be38-062e19c5083a

📥 Commits

Reviewing files that changed from the base of the PR and between 360cec8 and 01716f7.

📒 Files selected for processing (1)
  • src/lib/__tests__/yearInReviewUtils.test.ts

Comment thread src/lib/__tests__/yearInReviewUtils.test.ts
Comment thread src/lib/__tests__/yearInReviewUtils.test.ts Outdated
Comment on lines +224 to +233
it("hits the fast path with a length 20 string", () => {
// e.g. "2023-01-01T10:00:00Z" is length 20!
// Wait, "2023-01-01T10:00:00Z" is 20 chars long.
// Let's make sure we test length === 24 without ending in .000Z
const commitDates = [
"2023-01-01T10:00:00.123+", // length 24
];
const heatmap = buildHourlyHeatmapFromCommitDates(commitDates);
expect(heatmap[0][10]).toBe(0); // wait, it falls back to new Date() which will be NaN so it's ignored
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 it ブロックが describe の外に配置されている

このテストブロック(行 224–233)は describe("buildHourlyHeatmapFromCommitDates - edge cases", ...)}); 閉じ括弧(行 222)の外側に書かれています。インデント(4スペース)から describe 内に入れるつもりだったことは分かりますが、実際はトップレベルの it になっています。Vitest はトップレベル it を実行しますが、テストのグルーピングが崩れており、意図した構造ではありません。

さらにテスト名も誤りです。「hits the fast path with a length 20 string」と書かれていますが、実際に使っているのは 24文字の文字列 "2023-01-01T10:00:00.123+" であり、fast path ではなく fallback path をテストしています。コメント内の // Wait, "2023-01-01T10:00:00Z" is 20 chars long. という記述からも開発者が混乱していたことが読み取れます。

このブロックを describe("buildHourlyHeatmapFromCommitDates - edge cases", ...) の閉じ括弧の内側に移動し、テスト名とコメントを正確なものに修正してください。

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/lib/__tests__/yearInReviewUtils.test.ts
Line: 224-233

Comment:
**`it` ブロックが `describe` の外に配置されている**

このテストブロック(行 224–233)は `describe("buildHourlyHeatmapFromCommitDates - edge cases", ...)``});` 閉じ括弧(行 222)の**外側**に書かれています。インデント(4スペース)から `describe` 内に入れるつもりだったことは分かりますが、実際はトップレベルの `it` になっています。Vitest はトップレベル `it` を実行しますが、テストのグルーピングが崩れており、意図した構造ではありません。

さらにテスト名も誤りです。「hits the fast path with a length 20 string」と書かれていますが、実際に使っているのは **24文字**の文字列 `"2023-01-01T10:00:00.123+"` であり、fast path ではなく **fallback path** をテストしています。コメント内の `// Wait, "2023-01-01T10:00:00Z" is 20 chars long.` という記述からも開発者が混乱していたことが読み取れます。

このブロックを `describe("buildHourlyHeatmapFromCommitDates - edge cases", ...)` の閉じ括弧の**内側**に移動し、テスト名とコメントを正確なものに修正してください。

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

Comment on lines +179 to +188
it("falls back to full date parsing if cached day parsing results in NaN but full date is parseable", () => {
const mockDateStr = {
length: 19,
10: "T",
slice: () => "invalid___",
toString: () => "2023-01-01T10:00:00Z"
} as unknown as string;
const heatmap = buildHourlyHeatmapFromCommitDates([mockDateStr]);
expect(heatmap[0][10]).toBe(1);
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 モックオブジェクトが実装詳細に強く依存している

as unknown as string で型システムを回避したオブジェクトを渡すアプローチは、buildHourlyHeatmapFromCommitDates の内部実装(.length[10].slice()new Date(dateString).toString() を呼ぶ等)に強く依存しています。同様の構造が 201–211 行目にも存在します。

実装リファクタリング時にこれらのテストが意図しない形でサイレントに壊れる可能性があります。実際の分岐を通したいなら、実装の内部詳細に依存しないような実際の文字列入力を用いるほうが保守性が高まります。

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/lib/__tests__/yearInReviewUtils.test.ts
Line: 179-188

Comment:
**モックオブジェクトが実装詳細に強く依存している**

`as unknown as string` で型システムを回避したオブジェクトを渡すアプローチは、`buildHourlyHeatmapFromCommitDates` の内部実装(`.length``[10]``.slice()``new Date(dateString)``.toString()` を呼ぶ等)に強く依存しています。同様の構造が 201–211 行目にも存在します。

実装リファクタリング時にこれらのテストが意図しない形でサイレントに壊れる可能性があります。実際の分岐を通したいなら、実装の内部詳細に依存しないような実際の文字列入力を用いるほうが保守性が高まります。

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

Moved improperly placed 'it' block inside its corresponding 'describe' block.
Updated tests descriptions to accurately reflect the length and behavior of the fast-path vs fallback logic. Added explanations for edge cases using object mocks.

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