fix(#287): promptCheck再検証失敗時のフォールバック不備修正#290
Merged
Conversation
…ponse API When promptCheck re-verification fails (capture error), the API now falls back to body.promptType and body.defaultOptionNumber to determine whether cursor-key navigation should be used for Claude Code multiple-choice prompts. This prevents the bug where a failed re-verification causes multiple_choice prompts to be sent as plain text instead of cursor keys. - route.ts: Accept optional promptType/defaultOptionNumber in request body; use as fallback when promptCheck is null - WorktreeDetailRefactored.tsx: Include promptType and defaultOptionNumber in handlePromptRespond request body from state.prompt.data - useAutoYes.ts: Include promptType and defaultOptionNumber in auto-response request body to prevent same bug in auto-yes path - Tests: Add 6 unit tests for fallback behavior, 6 tests for useAutoYes hook, and 2 integration tests for request body validation Resolves #287 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ve coverage Extract duplicated prompt-response request body construction logic from useAutoYes hook and WorktreeDetailRefactored into shared buildPromptResponseBody() utility (DRY principle). Extract buildNavigationKeys() helper in route.ts to eliminate duplicated cursor offset-to-direction-keys logic between multi-select and single-select code paths. Add CHECKBOX_OPTION_PATTERN constant to replace inline regex duplication for checkbox-style option detection. Add comprehensive tests for previously uncovered paths: - Session not running error (400) - Multi-select checkbox prompt navigation - sendKeys/sendSpecialKeys error handling (500) - Malformed JSON body (outer catch) - Non-Error thrown from sendKeys Quality Metrics: - route.ts Lines: 73.84% -> 100% - route.ts Branches: 69.04% -> 92.1% - route.ts Functions: 80% -> 100% - ESLint errors: 0 -> 0 - TypeScript errors: 0 -> 0 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…orts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The fallback condition `(promptCheck === null && bodyPromptType === 'multiple_choice')` only covered the case when promptCheck was null. When promptCheck was non-null but its type was not 'multiple_choice' (e.g., 'yes_no'), the fallback did not activate, causing cursor-key navigation to be skipped. Simplified the condition to `|| bodyPromptType === 'multiple_choice'` which correctly falls back in all cases where promptCheck does not provide multiple_choice data. Added 2 new test cases for the type mismatch and undefined promptData scenarios. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
buildPromptResponseBody()共通ユーティリティを抽出し、useAutoYes/WorktreeDetailRefactoredのリクエストボディ構築ロジックをDRY化isClaudeMultiChoiceのフォールバック条件を拡張。promptCheck === nullのみだった条件をbodyPromptType === 'multiple_choice'に簡略化し、promptCheckが非nullでもタイプ不一致時にフォールバックが発動するよう修正Bug1 修正詳細
根本原因:
captureSessionOutput()が成功してもdetectPrompt()がタイミングやターミナル出力の部分レンダリングによりmultiple_choice以外のタイプを返す場合、promptCheckが非nullのためフォールバックが発動しなかった。変更前 (route.ts L125):
変更後:
Changes
src/app/api/worktrees/[id]/prompt-response/route.ts: フォールバック条件拡張、buildNavigationKeys()/CHECKBOX_OPTION_PATTERN抽出src/lib/prompt-response-body-builder.ts: リクエストボディ構築の共通ユーティリティ(新規)src/components/worktree/WorktreeDetailRefactored.tsx: handlePromptRespondでpromptType/defaultOptionNumberを送信src/hooks/useAutoYes.ts: Auto-YesパスでpromptType/defaultOptionNumberを送信tests/unit/api/prompt-response-verification.test.ts: Bug1テストケース追加(21テスト全パス)Test plan
Closes #287
🤖 Generated with Claude Code