Skip to content

Commit 6215701

Browse files
Fix pending user input option selection\n\nCo-authored-by: codex <codex@users.noreply.github.com>
1 parent 6a24126 commit 6215701

2 files changed

Lines changed: 76 additions & 10 deletions

File tree

apps/web/src/components/ChatView.browser.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3110,6 +3110,59 @@ describe("ChatView timeline estimator parity (full app)", () => {
31103110
}
31113111
});
31123112

3113+
it("submits pending user input after the final option selection resolves the draft answers", async () => {
3114+
const mounted = await mountChatView({
3115+
viewport: DEFAULT_VIEWPORT,
3116+
snapshot: createSnapshotWithPendingUserInput(),
3117+
resolveRpc: (body) => {
3118+
if (body._tag === ORCHESTRATION_WS_METHODS.dispatchCommand) {
3119+
return {
3120+
sequence: fixture.snapshot.snapshotSequence + 1,
3121+
};
3122+
}
3123+
return undefined;
3124+
},
3125+
});
3126+
3127+
try {
3128+
const firstOption = await waitForButtonContainingText("Tight");
3129+
firstOption.click();
3130+
3131+
const finalOption = await waitForButtonContainingText("Conservative");
3132+
finalOption.click();
3133+
3134+
await vi.waitFor(
3135+
() => {
3136+
const dispatchRequest = wsRequests.find(
3137+
(request) =>
3138+
request._tag === ORCHESTRATION_WS_METHODS.dispatchCommand &&
3139+
request.type === "thread.user-input.respond",
3140+
) as
3141+
| {
3142+
_tag: string;
3143+
type?: string;
3144+
requestId?: string;
3145+
answers?: Record<string, unknown>;
3146+
}
3147+
| undefined;
3148+
3149+
expect(dispatchRequest).toMatchObject({
3150+
_tag: ORCHESTRATION_WS_METHODS.dispatchCommand,
3151+
type: "thread.user-input.respond",
3152+
requestId: "req-browser-user-input",
3153+
answers: {
3154+
scope: "Tight",
3155+
risk: "Conservative",
3156+
},
3157+
});
3158+
},
3159+
{ timeout: 8_000, interval: 16 },
3160+
);
3161+
} finally {
3162+
await mounted.cleanup();
3163+
}
3164+
});
3165+
31133166
it("keeps plan follow-up footer actions fused and aligned after a real resize", async () => {
31143167
const mounted = await mountChatView({
31153168
viewport: WIDE_FOOTER_VIEWPORT,

apps/web/src/components/ChatView.tsx

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import {
7272
buildPendingUserInputAnswers,
7373
derivePendingUserInputProgress,
7474
setPendingUserInputCustomAnswer,
75+
togglePendingUserInputOptionSelection,
7576
type PendingUserInputDraftAnswer,
7677
} from "../pendingUserInput";
7778
import { selectThreadsAcrossEnvironments, useStore } from "../store";
@@ -3399,21 +3400,33 @@ export default function ChatView(props: ChatViewProps) {
33993400
if (!activePendingUserInput) {
34003401
return;
34013402
}
3402-
setPendingUserInputAnswersByRequestId((existing) => ({
3403-
...existing,
3404-
[activePendingUserInput.requestId]: {
3405-
...existing[activePendingUserInput.requestId],
3406-
[questionId]: {
3407-
selectedOptionLabel: optionLabel,
3408-
customAnswer: "",
3403+
setPendingUserInputAnswersByRequestId((existing) => {
3404+
const question =
3405+
(activePendingProgress?.activeQuestion?.id === questionId
3406+
? activePendingProgress.activeQuestion
3407+
: undefined) ??
3408+
activePendingUserInput.questions.find((entry) => entry.id === questionId);
3409+
if (!question) {
3410+
return existing;
3411+
}
3412+
3413+
return {
3414+
...existing,
3415+
[activePendingUserInput.requestId]: {
3416+
...existing[activePendingUserInput.requestId],
3417+
[questionId]: togglePendingUserInputOptionSelection(
3418+
question,
3419+
existing[activePendingUserInput.requestId]?.[questionId],
3420+
optionLabel,
3421+
),
34093422
},
3410-
},
3411-
}));
3423+
};
3424+
});
34123425
promptRef.current = "";
34133426
setComposerCursor(0);
34143427
setComposerTrigger(null);
34153428
},
3416-
[activePendingUserInput],
3429+
[activePendingProgress?.activeQuestion, activePendingUserInput],
34173430
);
34183431

34193432
const onChangeActivePendingUserInputCustomAnswer = useCallback(

0 commit comments

Comments
 (0)