Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .claude/commands/check-coverage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# check-coverage

## 目的

テストカバレッジが全リポジトリ70%以上、クリティカルパス100%の基準を満たしているか確認する。カバレッジの詳細レポートを生成し、改善点を特定。

## 実行手順

1. **カバレッジの測定**
```bash
# カバレッジ付きでテストを実行
npm run test -- --coverage
```

2. **カバレッジサマリの確認**
```bash
# コンソールでサマリを表示
npm run coverage:summary
```

3. **詳細レポートの生成**
```bash
# HTMLレポートを生成
npm run coverage:html

# レポートの場所を表示
echo "Coverage report: ./coverage/lcov-report/index.html"
```

4. **クリティカルパスの確認**
```bash
# クリティカルパスのリストを確認
echo "クリティカルパス:"
echo "- 認証/認可関連機能"
echo "- 決済処理"
echo "- セキュリティ関連機能"
echo "- データの保存/削除処理"
echo "- エラーハンドリング"
```

5. **カバレッジが低いファイルの特定**
```bash
# カバレッジが50%未満のファイルをリスト
npm run coverage:low-files
```

6. **カバレッジレポートのCI用出力**
```bash
# CI用のJUnit形式で出力
npm run coverage:ci
```

7. **カバレッジ履歴の確認**
```bash
# 過去のカバレッジと比較
git show HEAD~1:coverage/coverage-summary.json 2>/dev/null || echo "履歴なし"
```

## 成功基準

- ✅ 全体のラインカバレッジが70%以上
- ✅ ブランチカバレッジが60%以上
- ✅ 関数カバレッジが65%以上
- ✅ クリティカルパスのカバレッジが100%
- ✅ カバレッジレポートが正常に生成される

## トラブルシューティング

### カバレッジが基準を満たさない場合
1. HTMLレポートで未カバーのコードを確認
2. 優先度順にテストを追加:
- クリティカルパス > ビジネスロジック > ユーティリティ
3. テストが難しいコードはリファクタリングを検討

### カバレッジが測定されない場合
1. `jest.config.js` またはテスト設定を確認
2. `collectCoverageFrom` の設定を確認
3. テストが実行されているか確認

### クリティカルパスの特定が難しい場合
1. ビジネス要件を確認
2. セキュリティチームと連携
3. リスクアセスメントを実施
4. `.critical-paths.json` ファイルで明示的に定義

### カバレッジの向上方法
1. TDDを徹底(テストファースト)
2. モックを活用して依存関係を分離
3. エッジケースのテストを追加
4. カバレッジ目標を段階的に設定(60% → 70% → 80%)
122 changes: 122 additions & 0 deletions .claude/commands/fix-ci.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# fix-ci

## 目的

CI失敗時の対応手順を提供し、24時間以内修正ルールを遵守する。CI Red → Slack #ci-alerts → 24h以内修正 or Owner Escalateのフローを実行。

## 実行手順

1. **CIエラーの特定**
```bash
# GitHub Actionsのログを確認
gh run list --limit 5
gh run view <run-id>

# 失敗したジョブの詳細を確認
gh run view <run-id> --log-failed
```

2. **エラータイプの分類**
```bash
echo "エラータイプを確認:"
echo "1. テスト失敗"
echo "2. Lintエラー"
echo "3. ビルドエラー"
echo "4. セキュリティ/脆弱性"
echo "5. デプロイ失敗"
```

3. **ローカルでの再現**
```bash
# CI環境と同じコマンドを実行
npm ci
npm run test:all
npm run quality:check
npm run build
```
Comment on lines +32 to +36

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Package-manager inconsistency (pnpm vs npm)

Earlier docs recommend pnpm; this section uses npm ci. Mixing tools can create divergent lockfiles and caches. Standardise on one (or note both variants).

🤖 Prompt for AI Agents
In .claude/commands/fix-ci.md around lines 32 to 36, the commands use `npm ci`
while earlier documentation recommends `pnpm`, causing inconsistency. Update
this section to use `pnpm install` or the equivalent pnpm commands consistently,
or clearly note both npm and pnpm variants to avoid divergent lockfiles and
caches.


4. **修正の実施**

### テスト失敗の場合
```bash
# 失敗したテストを特定
npm run test -- --verbose
# 修正後、再度テスト
npm run test -- --watch
```

### Lintエラーの場合
```bash
# 自動修正を試す
npm run lint -- --fix
npm run format:fix
```

### ビルドエラーの場合
```bash
# キャッシュをクリア
rm -rf node_modules package-lock.json
npm install
npm run build
```

### セキュリティ問題の場合
```bash
# 脆弱性を修正
npm audit fix
# 強制的に修正(注意が必要)
npm audit fix --force
```

5. **修正の確認とプッシュ**
```bash
# ローカルでCIと同じチェックを実行
npm run ci:check

# 修正をコミット
git add .
git commit -m "fix: CIエラーを修正 (#<issue-number>)"

# プッシュ
git push
```

6. **CIの再実行を確認**
```bash
# CIがグリーンになるまでモニタリング
gh run watch
```

7. **対応完了の報告**
```bash
# Slack #ci-alertsへの報告テンプレート
echo "CI修正完了報告:"
echo "- エラー: <エラー内容>"
echo "- 原因: <原因>"
echo "- 対応: <対応内容>"
echo "- PR: #<PR番号>"
```

## 成功基準

- ✅ CIがグリーンになる
- ✅ 24時間以内に修正完了
- ✅ Slack #ci-alertsに報告済み
- ✅ 根本原因が特定され、再発防止策が実施される

## トラブルシューティング

### 24時間以内に修正できない場合
1. Ownerにエスカレーション
2. 一時的なワークアラウンドを検討
3. RevertしてCIをグリーンにし、後日修正

### ローカルで再現しない場合
1. CI環境との差分を確認(Nodeバージョン、環境変数等)
2. DockerでCI環境を再現
3. CIのキャッシュをクリア

### 繰り返しCIが失敗する場合
1. Flakyテストの可能性を確認
2. テストの安定性を改善(タイムアウト設定、非同期処理の改善)
3. CIパイプラインのリトライ設定を追加
Loading