-
-
Notifications
You must be signed in to change notification settings - Fork 15
Fix Claude AskUserQuestion handling for multiple prompts #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
OpenSource03
merged 3 commits into
master
from
copilot/fix-claude-engine-multiple-answers
Mar 7, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { buildAskUserQuestionResult, getAskUserQuestionAnswer, getAskUserQuestionKey } from "./ask-user-question"; | ||
|
|
||
| describe("getAskUserQuestionKey", () => { | ||
| it("uses a fallback key when Claude questions do not provide ids", () => { | ||
| expect(getAskUserQuestionKey({ question: "First question?" }, 0)).toBe("question-0"); | ||
| expect(getAskUserQuestionKey({ question: "Second question?" }, 1)).toBe("question-1"); | ||
| }); | ||
|
|
||
| it("prefers the provided question id when available", () => { | ||
| expect(getAskUserQuestionKey({ id: "q-1", question: "First question?" }, 0)).toBe("q-1"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getAskUserQuestionAnswer", () => { | ||
| it("reads answers keyed by fallback question ids when Claude questions have no ids", () => { | ||
| const answer = getAskUserQuestionAnswer( | ||
| { question: "Second question?" }, | ||
| 1, | ||
| { | ||
| answersByQuestionId: { | ||
| "question-0": ["Alpha"], | ||
| "question-1": ["Beta"], | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| expect(answer).toBe("Beta"); | ||
| }); | ||
|
|
||
| it("reads answers keyed by question id", () => { | ||
| const answer = getAskUserQuestionAnswer( | ||
| { id: "q-1", question: "Pick one" }, | ||
| 0, | ||
OpenSource03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| answersByQuestionId: { | ||
| "q-1": ["Option A"], | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| expect(answer).toBe("Option A"); | ||
| }); | ||
|
|
||
| it("falls back to answers keyed by question text for Claude", () => { | ||
| const answer = getAskUserQuestionAnswer( | ||
| { question: "Second question?" }, | ||
| 1, | ||
| { | ||
| answers: { | ||
| "First question?": "Alpha", | ||
| "Second question?": "Beta", | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| expect(answer).toBe("Beta"); | ||
| }); | ||
|
|
||
| it("falls back to indexed answers when keys do not match", () => { | ||
| const answer = getAskUserQuestionAnswer( | ||
| { question: "Second question?" }, | ||
| 1, | ||
| { | ||
| answers: { | ||
| first: "Alpha", | ||
| second: "Beta", | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| expect(answer).toBe("Beta"); | ||
| }); | ||
|
|
||
| it("supports Codex-style structured answers", () => { | ||
| const answer = getAskUserQuestionAnswer( | ||
| { id: "q-2", question: "Choose many" }, | ||
| 0, | ||
| { | ||
| answersByQuestionId: { | ||
| "q-2": { answers: ["One", "Two"] }, | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| expect(answer).toBe("One, Two"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("buildAskUserQuestionResult", () => { | ||
| it("keeps answers separate for multiple Claude questions without ids", () => { | ||
| const result = buildAskUserQuestionResult( | ||
| [ | ||
| { question: "First question?" }, | ||
| { question: "Second question?" }, | ||
| ], | ||
| { | ||
| "question-0": new Set(["Alpha"]), | ||
| "question-1": new Set(["Beta"]), | ||
| }, | ||
| {}, | ||
| ); | ||
|
|
||
| expect(result).toEqual({ | ||
| answers: { | ||
| "First question?": "Alpha", | ||
| "Second question?": "Beta", | ||
| }, | ||
| answersByQuestionId: { | ||
| "question-0": ["Alpha"], | ||
| "question-1": ["Beta"], | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it("prefers free text over selected options for the matching question only", () => { | ||
| const result = buildAskUserQuestionResult( | ||
| [ | ||
| { question: "First question?" }, | ||
| { question: "Second question?" }, | ||
| ], | ||
| { | ||
| "question-0": new Set(["Alpha"]), | ||
| "question-1": new Set(["Beta"]), | ||
| }, | ||
| { | ||
| "question-1": "Custom answer", | ||
| }, | ||
| ); | ||
|
|
||
| expect(result).toEqual({ | ||
| answers: { | ||
| "First question?": "Alpha", | ||
| "Second question?": "Custom answer", | ||
| }, | ||
| answersByQuestionId: { | ||
| "question-0": ["Alpha"], | ||
| "question-1": ["Custom answer"], | ||
| }, | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Within this
questions.maprender, the wrapper useskey={q.question}. If two questions have the same text (or if text changes), React can reuse DOM/state incorrectly; with multi-question prompts it’s safer to key by a stable unique identifier (questionidwhen present, otherwise the same fallback key you use for answers/selections).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already applied in baeb516 — the renderer now uses
getAskUserQuestionKey(q, qi)instead ofq.question, so duplicate or changing question text will not reuse the wrong row state. I re-ran the targeted tests plus full test/build validation on the current branch before replying. Screenshot: https://github.com/user-attachments/assets/b5cffa90-81c9-45bf-8bf5-f8980d742722