Skip to content

test(api): align slug validation messaging#142

Merged
is0692vs merged 2 commits intomainfrom
split/pr138-slug-validation
Mar 18, 2026
Merged

test(api): align slug validation messaging#142
is0692vs merged 2 commits intomainfrom
split/pr138-slug-validation

Conversation

@is0692vs
Copy link
Contributor

@is0692vs is0692vs commented Mar 17, 2026

Summary

  • align validateSlug length messaging with the existing en-dash expectation
  • add focused tests for leading and trailing hyphen rejection

Validation

  • npm run --workspace apps/api test -- src/utils/tests/validation.test.ts

Split out of #138 to keep this tiny validation tweak reviewable on its own.

Greptile Summary

このPRは validateSlug のエラーメッセージを2点改善しています。①長さエラーのハイフン(-)をエンダッシュ()に統一、②先頭・末尾がハイフンのスラグに対して、従来は誤解を招く "character set" エラーを返していた箇所を専用メッセージ "slug must not start or end with a hyphen" に置き換え、それに対応するテストを追加しています。

  • validation.ts: "slug must be 3-40 characters""slug must be 3–40 characters"(エンダッシュ統一)
  • validation.ts: SLUG_RE チェックの前に s.startsWith("-") || s.endsWith("-") の明示的ガードを追加し、より具体的なエラーメッセージを返すように修正
  • validation.test.ts: 長さバリデーションのテスト期待値をエンダッシュに更新
  • validation.test.ts: "rejects leading/trailing hyphens" テストを新規追加("-invalid" / "invalid-" の2ケース)

SLUG_RE (/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/) は元々先頭・末尾ハイフンを拒否できていましたが、新しいチェックを前に置くことで より具体的なエラーメッセージ を提供できるようになっており、意図的かつ正しい設計変更です。チェックの順序・ロジックに問題はありません。

Confidence Score: 5/5

  • 変更は最小限かつ正確で、既存の挙動を壊すリスクはありません。安心してマージできます。
  • 変更範囲が小さく(2ファイル、計10行)、エラーメッセージ文字列の修正と新規テストの追加のみ。ロジックの正確性は手動トレースでも確認済みで、テストがその挙動を正しくカバーしています。
  • 特に注意が必要なファイルはありません。

Important Files Changed

Filename Overview
apps/api/src/utils/validation.ts エラーメッセージのハイフンをエンダッシュ(–)に変更し、先頭・末尾ハイフン向けの明示的なチェックを SLUG_RE 前に追加。ロジック的に正しく、SLUG_RE との重複は意図的なメッセージ改善のため。
apps/api/src/utils/tests/validation.test.ts 長さエラーメッセージをエンダッシュに揃え、先頭・末尾ハイフン拒否の新テスト("-invalid" / "invalid-")を追加。既存テストとの整合性も取れている。

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A([validateSlug 呼び出し]) --> B{typeof slug === 'string'?}
    B -- No --> E1["❌ 'slug is required'"]
    B -- Yes --> C[trim + toLowerCase]
    C --> D{length < 3 または > 40?}
    D -- Yes --> E2["❌ 'slug must be 3–40 characters'"]
    D -- No --> F{先頭または末尾が '-' ?}
    F -- Yes --> E3["❌ 'slug must not start or end with a hyphen' 🆕"]
    F -- No --> G{SLUG_RE に一致?}
    G -- No --> E4["❌ 'slug must contain only lowercase letters, numbers, and hyphens'"]
    G -- Yes --> H{'--' を含む?}
    H -- Yes --> E5["❌ 'slug must not contain consecutive hyphens'"]
    H -- No --> OK(["✅ null(有効)"])

    style E3 fill:#d4edda,stroke:#28a745
    style F fill:#d4edda,stroke:#28a745
Loading

Last reviewed commit: ee7b03d

@vercel
Copy link

vercel bot commented Mar 17, 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

@gemini-code-assist
Copy link
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 refines the API's slug validation logic and its corresponding test suite. It ensures that error messages for slug length are consistent with expected formatting and expands test coverage to explicitly validate the rejection of slugs that start or end with hyphens, improving the robustness of the validation process.

Highlights

  • Slug Validation Messaging: The error message for slug length validation was updated to use an en-dash (–) instead of a hyphen (-) for consistency with existing expectations.
  • Slug Validation Tests: New focused tests were added to specifically cover the rejection of slugs with leading or trailing hyphens, enhancing test coverage for edge cases.
Changelog
  • apps/api/src/utils/tests/validation.test.ts
    • Updated the expected error message for slug length validation tests to use an en-dash.
    • Added new test cases to verify that slugs with leading or trailing hyphens are correctly rejected.
  • apps/api/src/utils/validation.ts
    • Modified the slug length validation error message to use an en-dash (–) for improved consistency.
Activity
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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
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 correctly aligns the slug validation messaging to use an en-dash and adds new tests for rejecting leading and trailing hyphens. The changes are good, but I have one suggestion to improve the user experience by providing a more specific error message for the newly tested validation case, ensuring it adheres to our English-only API error message standard.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 17, 2026

📝 Walkthrough

ウォークスルー

スラッグ検証のエラーメッセージをハイフン(3-40文字)からエンダッシュ(3–40文字)に変更し、対応するテストケースを更新しました。先頭または末尾のハイフン拒否を検証する新しいテストも追加されています。

変更内容

コホート / ファイル 概要
検証ロジック
apps/api/src/utils/validation.ts
エラーメッセージ内のハイフンをエンダッシュに変更(「3–40文字」)。
テストスイート
apps/api/src/utils/__tests__/validation.test.ts
エンダッシュを含む新しいエラーメッセージを期待するようにテストを更新。先頭・末尾のハイフン拒否を検証する新しいテストケースを追加。

コード評価の推定負荷

🎯 1 (Trivial) | ⏱️ ~3分

🐰 ハイフンからエンダッシュへ、
ちょっぴりの変更で気品が増し、
テストも確認、しっかり整備、
バリデーション、より美しく磨かれたり。

🚥 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 PRの説明はchangesetの内容に関連しており、validateSlugのエラーメッセージの改善とテストの追加について適切に説明されている。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch split/pr138-slug-validation
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@vercel
Copy link

vercel bot commented Mar 17, 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 17, 2026 0:20am

@is0692vs is0692vs merged commit e2fb7f0 into main Mar 18, 2026
19 checks passed
@is0692vs is0692vs deleted the split/pr138-slug-validation branch March 18, 2026 01:19
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