@@ -16,6 +16,9 @@ vi.mock(import("../ChatMarkdown"), async (importOriginal) => ({
1616
1717import { act , fakeTimers , render } from "../../../test/render" ;
1818import { DraftId , useComposerDraftStore } from "../../composerDraftStore" ;
19+ import { formatInlineContextReference } from "../../lib/composerContextReferences" ;
20+ import { threadContextRecord , threadContextReference } from "../../lib/composerContextRecords" ;
21+ import { questionAttachmentDraftId } from "../../questionAttachments" ;
1922import { makeThreadProjectionFixture } from "../../test-fixtures" ;
2023import { 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
222239it ( "does not return an answer to the thread draft once the question is resolved" , async ( ) => {
223240 using _timers = fakeTimers ( ) ;
0 commit comments