Skip to content

feat: /api/score にZodスキーマ検証・JSON復旧・補正リトライを実装する#281

Open
keisato848 wants to merge 3 commits into
mainfrom
fix/264-score-zod-validation
Open

feat: /api/score にZodスキーマ検証・JSON復旧・補正リトライを実装する#281
keisato848 wants to merge 3 commits into
mainfrom
fix/264-score-zod-validation

Conversation

@keisato848

Copy link
Copy Markdown
Owner

概要

Issue #264 対応。/api/score のAI応答をZodでスキーマ検証し、JSON復旧・補正リトライを実装する。

変更内容

修正ファイル

  • �pps/web/app/api/score/route.ts: Zodスキーマ定義 + �xtractJson() + parseAndValidate() + �uildCorrectionPrompt() + callAi ヘルパー + Zodバリデーション + 最大1回補正リトライ
  • �pps/web/tests/api/score.test.ts: 4テストケース追加(コードフェンス付きJSON復旧・前後文付きJSON復旧・補正リトライ成功・補正リトライ失敗)

受け入れ基準チェック

  • 正常JSON、コードフェンス付きJSON、前後文付きJSONを採点結果として復旧できる
  • 必須フィールド欠落・型不一致はZodで検出できる
  • 再試行は最大1回で打ち切られる
  • /api/score の単体テストに成功・復旧・失敗ケースがある(20テスト、全パス)
  • エラー時に入力答案はUI上で保持される(route側では変更なし、既存の挙動を維持)

テスト

  • ユニットテスト全 64 ファイル・score.test.ts 20 テスト(旧16 + 新4)パス確認済み

px tsc --noEmit エラーなし

  • self-inspect R1〜R43 全クリア

Closes #264

Copilot AI review requested due to automatic review settings May 28, 2026 13:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Issue #264 対応として、/api/score の AI 応答パースに Zod スキーマ検証、コードフェンス/前後文からの JSON 抽出、補正プロンプトによる最大 1 回のリトライを導入します。AI 呼び出しは callAi ヘルパーへ抽出され、初回・リトライで共用されます。__tests__/api/score.test.ts に 4 ケース(フェンス復旧/前後文復旧/補正リトライ成功/補正リトライ失敗)が追加されています。

Changes:

  • ScoringResultSchema/RadarDataSchema を Zod で定義し、extractJson + parseAndValidate で復旧→検証
  • AI 呼び出しを callAi 関数へリファクタし、補正プロンプト buildCorrectionPrompt で 1 回だけリトライ
  • 復旧・補正パスを覆う 4 件のユニットテストを追加

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
apps/web/app/api/score/route.ts Zod スキーマ・JSON 抽出・補正リトライ実装、AI 呼び出しを callAi に共通化
apps/web/tests/api/score.test.ts フェンス復旧/前後文復旧/補正リトライ成功/失敗の 4 ケース追加

Comment thread apps/web/app/api/score/route.ts Outdated
Comment thread apps/web/app/api/score/route.ts
Comment thread apps/web/app/api/score/route.ts Outdated
@github-actions

github-actions Bot commented May 28, 2026

Copy link
Copy Markdown

✅ Staging デプロイ完了

項目
🌐 Staging URL Stagingで確認する
🌿 ブランチ fix/264-score-zod-validation
📝 コミット 288cdc9

⚠️ 複数PRが同時進行している場合は最後にデプロイされたPRが反映されています。
確認後は本PRのレビューを進めてください。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1] /api/score のAI応答をZodでスキーマ検証し、JSON復旧・再試行を実装する

2 participants