Skip to content

🧪 [getRoleBadgeのテストカバレッジ改善]#165

Merged
is0692vs merged 6 commits intomainfrom
fix/test-getRoleBadge-15251995392633029714
Mar 22, 2026
Merged

🧪 [getRoleBadgeのテストカバレッジ改善]#165
is0692vs merged 6 commits intomainfrom
fix/test-getRoleBadge-15251995392633029714

Conversation

@is0692vs
Copy link
Copy Markdown
Contributor

@is0692vs is0692vs commented Mar 21, 2026

🎯 What: The getRoleBadge presentation helper was lacking test coverage for the "coauthor" role from the database schema, as well as test coverage for gracefully handling unexpected runtime values (like null or undefined).

📊 Coverage: The test suite for getRoleBadge now explicitly covers:

  • The standard "coauthor" role
  • undefined values (using @ts-expect-error to test JS runtime fallback)
  • null values (using @ts-expect-error to test JS runtime fallback)

Result: The getRoleBadge utility now has complete 100% test coverage including resilient fallback checks, ensuring deterministic behavior even when dealing with unexpected upstream data.


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

Greptile Summary

このPRは getRoleBadge のテストカバレッジを改善することを目的としており、"coauthor" ロールのテストケース追加および null/undefined のランタイム挙動検証を含んでいます。ただし、いくつかの重要な問題が存在します。

  • pr_description.md の誤コミット: PR説明文がリポジトリのソースとしてコミットされており、削除が必要です。
  • null/undefined テストの期待値が不適切: テスト名では「gracefully handles」と述べているものの、実際には label: null / label: undefined をそのまま期待値としており、BadgePresentation 型の label: string 定義に違反します。真のグレースフルな処理とするには、実装側で null/undefined を明示的に補足して安全なデフォルト値(空文字列など)を返す必要があります。
  • "coauthor" が日本語ローカライズされていない: DBスキーマに存在するロールにもかかわらず switch 文に専用 case がなく、英語のまま default にフォールスルーしています。"reviewer" も同様です。テストは現状の挙動を記録しているに過ぎず、実装の改善が望まれます。

Confidence Score: 2/5

  • このPRはマージ前に複数の問題を修正する必要があります。
  • pr_description.md のリポジトリへの誤コミット、null/undefined テストで型違反の値を「graceful」として期待値に設定していること、および "coauthor" の実装が未完成なままテストだけ追加されている点が懸念されます。
  • pr_description.md(削除必要)と apps/web/src/lib/__tests__/presentation.test.tsnull/undefined の期待値と実装の整合性確認)に注意が必要です。

Important Files Changed

Filename Overview
apps/web/src/lib/tests/presentation.test.ts getRoleBadge のテストケースを追加。"coauthor" の追加は実装側の default フォールスルーを検証しているにすぎず、null/undefined のテストは「graceful handling」と謳いながら型違反の値をそのまま期待値としており、実装上の問題が潜在している。
pr_description.md PR説明用のMarkdownファイルがリポジトリにコミットされており、ソースコードとして管理すべきではない不要ファイル。削除が必要。

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["getRoleBadge(role)"] --> B{switch role}
    B -->|"owner"| C["createBadge('オーナー', 'info')"]
    B -->|"admin"| D["createBadge('管理者', 'warning')"]
    B -->|"member"| E["createBadge('メンバー', 'neutral')"]
    B -->|"uploader"| F["createBadge('アップロード者', 'info')"]
    B -->|"author"| G["createBadge('著者', 'success')"]
    B -->|"default"| H["createBadge(role, 'neutral')"]
    H -->|"role = 'coauthor'"| I["label: 'coauthor' ✅ テスト追加"]
    H -->|"role = undefined"| J["label: undefined ⚠️ 型違反"]
    H -->|"role = null"| K["label: null ⚠️ 型違反"]
    H -->|"role = 'reviewer'"| L["label: 'reviewer'(未ローカライズ)"]
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: pr_description.md
Line: 1-8

Comment:
**不要なファイルがリポジトリにコミットされています**

`pr_description.md` はリポジトリのソースコードとは無関係なファイルです。PRの説明はGitHub上のPR本文として管理すべきで、リポジトリにコミットするべきではありません。このファイルは削除してください。

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

---

This is a comment left during a code review.
Path: apps/web/src/lib/__tests__/presentation.test.ts
Line: 68-75

Comment:
**テストの説明と期待値が矛盾しています**

テスト名は「`undefined`**gracefully**に処理し、デフォルトの neutral バッジを返す」と述べていますが、期待値では `label: undefined` をそのまま返すことを検証しています。これは「グレースフルな処理」ではなく、`undefined` がそのまま `createBadge()` に渡され、結果的に `label``undefined` になるという**バグの挙動をテストしている**状態です。

`BadgePresentation` 型では `label: string` と定義されているため、`label: undefined` はこの型を満たしません。コンポーネントが `label``string` として扱うと、ランタイムエラーや予期しない描画が発生する可能性があります。

本当に「graceful fallback」を実装するのであれば、実装側(`getRoleBadge`)で `null`/`undefined` を明示的に処理し、空文字列や `"不明"` などの安全なデフォルト値を返すべきです。テストはその挙動を検証するものになるべきです。

```suggestion
    it("handles undefined gracefully and returns default neutral badge", () => {
      // @ts-expect-error Testing undefined behavior at runtime
      expect(getRoleBadge(undefined)).toEqual({
        label: "",
        tone: "neutral",
        className: toneClassNames["neutral"],
      });
    });
```

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

---

This is a comment left during a code review.
Path: apps/web/src/lib/__tests__/presentation.test.ts
Line: 77-84

Comment:
**`null` テストも同様に期待値が不適切です**

`undefined` のケースと同様に、`label: null` をそのまま期待値とすることは「graceful handling」の検証になっていません。`null``label` として返ると、`string` 型を期待するコンポーネントで問題が生じます。

実装側での対応が前提になりますが、テスト期待値も合わせて修正が必要です。

```suggestion
    it("handles null gracefully and returns default neutral badge", () => {
      // @ts-expect-error Testing null behavior at runtime
      expect(getRoleBadge(null)).toEqual({
        label: "",
        tone: "neutral",
        className: toneClassNames["neutral"],
      });
    });
```

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

---

This is a comment left during a code review.
Path: apps/web/src/lib/__tests__/presentation.test.ts
Line: 57

Comment:
**`"coauthor"` が日本語ローカライズされていません**

追加された `["coauthor", "coauthor", "neutral"]` テストケースでは、`label``"coauthor"` のまま(英語)であることを期待しています。これは `getRoleBadge``switch` 文に `"coauthor"``case` が存在せず、`default` にフォールスルーしていることを意味します。

PRの説明には「`"coauthor"` はDBスキーマに存在するロール」とあるため、`"owner"``"admin"``"member"` などと同様に、`presentation.ts` に明示的な `case "coauthor":` を追加して日本語ラベル(例: `"共著者"`)を設定すべきではないでしょうか。

テストはあくまで現在の**フォールバック挙動**を検証しているにすぎず、意図した実装が反映されていない可能性があります。

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

Last reviewed commit: "test: add missing ge..."

Greptile also left 4 inline comments on this PR.

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 Mar 21, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
open-shelf Ignored Ignored Mar 22, 2026 4:47am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 21, 2026

Warning

Rate limit exceeded

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

⌛ 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: 8e2a2726-4b00-4f8f-905e-ed787af5525d

📥 Commits

Reviewing files that changed from the base of the PR and between 26e1c90 and cc79bcb.

📒 Files selected for processing (2)
  • apps/web/src/lib/__tests__/presentation.test.ts
  • pr_description.md
📝 Walkthrough

Walkthrough

getRoleBadge 関数に役割正規化ロジックを追加し、新たに「coauthor」役割ケースの明示的なハンドリングと対応するテストケースを実装しました。また、undefined/null 入力に対する挙動をテストで検証しました。

Changes

Cohort / File(s) Summary
getRoleBadge 関数の実装と拡張
apps/web/src/lib/presentation.ts, apps/web/src/lib/__tests__/presentation.test.ts
getRoleBadge に役割値の正規化処理を追加し、「coauthor」役割に対して「共著者」ラベルと neutral トーンを返すケースを新規実装。テストでは parameterized テストで coauthor ケースを追加し、undefined/null 入力時のデフォルト動作を検証するケースも追加。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

🐰 コーサーさんに新しい役が出来て
「共著者」と名札が光る
nullも undefined も優しく受けて
正規化の魔法で全部まるっと対応
バッジが輝く春の日に 🌸

🚥 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 タイトルはテストカバレッジ改善というPRの主要な意図を簡潔に表現しており、実装内容と関連性がある。
Description check ✅ Passed 説明文はgetRoleBadgeのテストカバレッジ改善という変更内容と関連しており、追加テストケースについて概略を示している。

✏️ 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 fix/test-getRoleBadge-15251995392633029714

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.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the test coverage for the getRoleBadge presentation helper. It ensures that the utility correctly processes the 'coauthor' role and maintains deterministic behavior when encountering unexpected null or undefined values, thereby enhancing the overall reliability and resilience of the badge generation logic.

Highlights

  • Test Coverage Expansion: Expanded the test suite for the getRoleBadge utility to include explicit coverage for the 'coauthor' role, ensuring its correct badge presentation.
  • Robustness for Unexpected Inputs: Introduced new test cases to verify that getRoleBadge gracefully handles undefined and null inputs, returning a default neutral badge as expected.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@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 improves the test coverage for the getRoleBadge function by adding test cases for the coauthor role, as well as for null and undefined inputs. The changes are clear and valuable for ensuring the function's robustness. I have one suggestion to further improve the test code's maintainability.

Comment thread apps/web/src/lib/__tests__/presentation.test.ts Outdated
@coderabbitai coderabbitai Bot added the size/XS label Mar 21, 2026
Comment thread pr_description.md
Comment thread apps/web/src/lib/__tests__/presentation.test.ts Outdated
Comment thread apps/web/src/lib/__tests__/presentation.test.ts Outdated
Comment thread apps/web/src/lib/__tests__/presentation.test.ts
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 21, 2026

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!

Copy link
Copy Markdown
Contributor

@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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/src/lib/__tests__/presentation.test.ts (1)

8-14: 🧹 Nitpick | 🔵 Trivial

toneClassNamesの重複定義によりテストの信頼性が低下する可能性があります。

このオブジェクトはpresentation.tsの内部定義と同一の値をハードコードしています。ソース側の値が変更された場合、テストはローカルコピーを使用しているため変更を検出できず、サイレントにドリフトする可能性があります。

検討すべき対策:

  • toneClassNamespresentation.tsからエクスポートしてテストでインポートする
  • または、スナップショットテストを使用する
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/web/src/lib/__tests__/presentation.test.ts` around lines 8 - 14, The
test currently hardcodes a duplicate toneClassNames object which can drift from
the source; instead export the canonical toneClassNames from presentation.ts (or
add a named export if one doesn't exist) and update the test in
presentation.test.ts to import toneClassNames from presentation.ts (or replace
the hardcoded object with a snapshot test that imports/render output from
presentation.ts) so the test asserts against the single source-of-truth rather
than a local copy.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/web/src/lib/__tests__/presentation.test.ts`:
- Around line 68-84: The test descriptions are misleading:
getRoleBadge(undefined|null) preserves the input label while only normalizing
tone and className to neutral; update the two it() titles to reflect that
behavior (e.g., "handles undefined gracefully, preserves label and returns
neutral tone/className" and "handles null gracefully, preserves label and
returns neutral tone/className") so the names match the assertions that label
remains undefined/null and tone/className become neutral; locate references to
getRoleBadge and toneClassNames in presentation.test.ts to change the strings
only.
- Line 57: The getRoleBadge switch lacks a localized label for the "coauthor"
role so it falls back to the raw role string; add an explicit case in
getRoleBadge that returns createBadge("共著者", "info") for the "coauthor" role
(matching how "uploader" is handled), and update the corresponding test in
presentation.test.ts to expect the Japanese label ("共著者") instead of "coauthor".

In `@pr_description.md`:
- Line 1: ファイル先頭にトップレベル見出しが欠けているため、pr_description.md の最初の行に "#" で始まる見出し行(例: "#
PR 概要" や "# 説明")を追加して、既存の本文はその下にそのまま残すようにしてください。これにより markdownlint の警告が解消されます。

---

Outside diff comments:
In `@apps/web/src/lib/__tests__/presentation.test.ts`:
- Around line 8-14: The test currently hardcodes a duplicate toneClassNames
object which can drift from the source; instead export the canonical
toneClassNames from presentation.ts (or add a named export if one doesn't exist)
and update the test in presentation.test.ts to import toneClassNames from
presentation.ts (or replace the hardcoded object with a snapshot test that
imports/render output from presentation.ts) so the test asserts against the
single source-of-truth rather than a local copy.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 84ad45db-30cc-4183-bc78-275a8e628819

📥 Commits

Reviewing files that changed from the base of the PR and between f5be279 and ccb2f0a.

📒 Files selected for processing (2)
  • apps/web/src/lib/__tests__/presentation.test.ts
  • pr_description.md

Comment thread apps/web/src/lib/__tests__/presentation.test.ts
Comment thread apps/web/src/lib/__tests__/presentation.test.ts Outdated
Comment thread pr_description.md
Copy link
Copy Markdown
Contributor

@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

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

Inline comments:
In `@apps/web/src/lib/__tests__/presentation.test.ts`:
- Around line 68-81: The test's it.each provides 2-element tuples but the test
callback only accepts one parameter, causing TS2345; fix by either converting
each tuple to a single-element array (e.g., [undefined], [null]) so the callback
signature (value) matches, or update the callback to accept two parameters
(value, label) and use the second arg for the test name/formatting; update the
test in presentation.test.ts where getRoleBadge and toneClassNames are used to
ensure the tuple shape and callback signature align and remove the
`@ts-expect-error`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9ad3a1e8-a60a-4435-85c3-159af0401d53

📥 Commits

Reviewing files that changed from the base of the PR and between ccb2f0a and 26e1c90.

📒 Files selected for processing (2)
  • apps/web/src/lib/__tests__/presentation.test.ts
  • apps/web/src/lib/presentation.ts

Comment thread apps/web/src/lib/__tests__/presentation.test.ts Outdated
@is0692vs
Copy link
Copy Markdown
Contributor Author

メンテナ確認済みです。Botコメント(Codecov / CodeRabbit / Gemini / Jules / Greptile / Vercel)を確認し、現時点で追加対応が必要な指摘はありません。必要な追対応が出た場合はこのPRで反映します。

@google-labs-jules
Copy link
Copy Markdown
Contributor

メンテナ確認済みです。Botコメント(Codecov / CodeRabbit / Gemini / Jules / Greptile / Vercel)を確認し、現時点で追加対応が必要な指摘はありません。必要な追対応が出た場合はこのPRで反映します。

承知いたしました。ご確認いただきありがとうございます。追加の対応が必要になった際はお知らせください。

google-labs-jules Bot and others added 3 commits March 22, 2026 04:33
Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 22, 2026

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 is0692vs merged commit 2cd7ea0 into main Mar 22, 2026
16 of 18 checks passed
@is0692vs is0692vs deleted the fix/test-getRoleBadge-15251995392633029714 branch March 22, 2026 10:54
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