Skip to content

Commit 7c073ef

Browse files
test(web): cover expired questions and thread chips returning to the thread draft
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 65bf16d commit 7c073ef

1 file changed

Lines changed: 48 additions & 31 deletions

File tree

‎apps/web/src/components/chat/ComposerPendingUserInputPanel.navigation.browser.test.tsx‎

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ vi.mock(import("../ChatMarkdown"), async (importOriginal) => ({
1616

1717
import { act, fakeTimers, render } from "../../../test/render";
1818
import { DraftId, useComposerDraftStore } from "../../composerDraftStore";
19+
import { formatInlineContextReference } from "../../lib/composerContextReferences";
20+
import { threadContextRecord, threadContextReference } from "../../lib/composerContextRecords";
21+
import { questionAttachmentDraftId } from "../../questionAttachments";
1922
import { makeThreadProjectionFixture } from "../../test-fixtures";
2023
import { usePendingThreadRequests } from "./usePendingThreadRequests";
2124

@@ -186,38 +189,52 @@ it("isolates drafts by environment, thread and request and discards only resolve
186189
}
187190
});
188191

189-
it("keeps a typed answer in the thread draft when the question is cancelled by Stop", async () => {
190-
using _timers = fakeTimers();
191-
const environmentId = EnvironmentId.make("stop-environment");
192-
const projection = questionProjection(threadRef.threadId, ["first"]);
193-
const answer = "Purple please. This typed question answer must survive Stop.";
194-
const draftTarget = { environmentId, threadId: threadRef.threadId };
195-
useComposerDraftStore.getState().setPrompt(draftTarget, "Earlier draft");
196-
await using screen = await render(
197-
<PendingRequestsProbe environmentId={environmentId} projection={projection} />,
198-
);
199-
await act(() => requests.onChangeActivePendingUserInputCustomAnswer("question-0", answer));
200-
expect(requests.activePendingDraftAnswers["question-0"]?.customAnswer).toBe(answer);
192+
// Stop cancels an open question; a provider timeout expires it. Neither sends the answer.
193+
it.each(["cancelled", "expired"] as const)(
194+
"keeps a typed answer and its thread chips in the thread draft when the question is %s",
195+
async (status) => {
196+
using _timers = fakeTimers();
197+
const environmentId = EnvironmentId.make(`${status}-environment`);
198+
const projection = questionProjection(threadRef.threadId, ["first"]);
199+
const reference = threadContextRecord(
200+
{ environmentId, threadId: ThreadId.make("reference-thread") },
201+
"Reference work",
202+
);
203+
const answer = `Purple please, like ${formatInlineContextReference(threadContextReference(reference))}`;
204+
const draftTarget = { environmentId, threadId: threadRef.threadId };
205+
useComposerDraftStore.getState().setPrompt(draftTarget, "Earlier draft");
206+
useComposerDraftStore
207+
.getState()
208+
.setThreadContexts(
209+
questionAttachmentDraftId(environmentId, threadRef.threadId, "first", "question-0"),
210+
[reference],
211+
);
212+
await using screen = await render(
213+
<PendingRequestsProbe environmentId={environmentId} projection={projection} />,
214+
);
215+
await act(() => requests.onChangeActivePendingUserInputCustomAnswer("question-0", answer));
216+
expect(requests.activePendingDraftAnswers["question-0"]?.customAnswer).toBe(answer);
201217

202-
// Stop interrupts the turn, which cancels its open question without an answer.
203-
await screen.rerender(
204-
<PendingRequestsProbe
205-
environmentId={environmentId}
206-
projection={{
207-
...projection,
208-
runtimeRequests: projection.runtimeRequests.map((request) => ({
209-
...request,
210-
status: "cancelled",
211-
resolvedAt: projection.updatedAt,
212-
})),
213-
}}
214-
/>,
215-
);
216-
expect(requests.activePendingUserInput).toBeNull();
217-
expect(useComposerDraftStore.getState().getComposerDraft(draftTarget)?.prompt).toBe(
218-
`Earlier draft\n\n${answer}`,
219-
);
220-
});
218+
await screen.rerender(
219+
<PendingRequestsProbe
220+
environmentId={environmentId}
221+
projection={{
222+
...projection,
223+
runtimeRequests: projection.runtimeRequests.map((request) => ({
224+
...request,
225+
status,
226+
resolvedAt: projection.updatedAt,
227+
})),
228+
}}
229+
/>,
230+
);
231+
expect(requests.activePendingUserInput).toBeNull();
232+
expect(useComposerDraftStore.getState().getComposerDraft(draftTarget)).toMatchObject({
233+
prompt: `Earlier draft\n\n${answer}`,
234+
threadContexts: [reference],
235+
});
236+
},
237+
);
221238

222239
it("does not return an answer to the thread draft once the question is resolved", async () => {
223240
using _timers = fakeTimers();

0 commit comments

Comments
 (0)