@@ -208,6 +208,49 @@ describe("TaskRunEventStreamSender", () => {
208208 expect ( lastCall [ 0 ] ) . not . toContain ( "/api/projects/" ) ;
209209 } ) ;
210210
211+ it ( "uses a short stream window for agent-proxy ingest so buffered uploads commit live events" , async ( ) => {
212+ vi . useFakeTimers ( ) ;
213+ try {
214+ const requestBodies : string [ ] = [ ] ;
215+ let activeStreamClosed = false ;
216+ const fetchMock = vi . fn (
217+ async ( _url : string | URL | Request , init ?: RequestInit ) => {
218+ if ( ! init ?. body || typeof init . body === "string" ) {
219+ return responseForBody ( await readRequestBody ( init ) ) ;
220+ }
221+
222+ const body = await readRequestBody ( init ) ;
223+ activeStreamClosed = true ;
224+ requestBodies . push ( body ) ;
225+ return responseForBody ( body ) ;
226+ } ,
227+ ) ;
228+ vi . stubGlobal ( "fetch" , fetchMock ) ;
229+
230+ const sender = createSender ( {
231+ eventIngestBaseUrl : "http://agent-proxy:8003/" ,
232+ } ) ;
233+
234+ sender . enqueue ( {
235+ type : "notification" ,
236+ notification : { method : "first" } ,
237+ } ) ;
238+ await vi . advanceTimersByTimeAsync ( 0 ) ;
239+
240+ expect ( fetchMock ) . toHaveBeenCalledTimes ( 2 ) ;
241+ expect ( activeStreamClosed ) . toBe ( false ) ;
242+
243+ await vi . advanceTimersByTimeAsync ( 1_000 ) ;
244+
245+ expect ( activeStreamClosed ) . toBe ( true ) ;
246+ expect ( eventSequences ( requestBodies [ 0 ] ) ) . toEqual ( [ 1 ] ) ;
247+
248+ await sender . stop ( ) ;
249+ } finally {
250+ vi . useRealTimers ( ) ;
251+ }
252+ } ) ;
253+
211254 it ( "keeps the active ingest request open across scheduled flushes" , async ( ) => {
212255 const requestBodies : string [ ] = [ ] ;
213256 let activeStreamClosed = false ;
0 commit comments