@@ -1795,6 +1795,99 @@ describe("Cline", () => {
17951795 // Verify cancelCurrentRequest was called
17961796 expect ( cancelSpy ) . toHaveBeenCalled ( )
17971797 } )
1798+ describe ( "abortSignal" , ( ) => {
1799+ it ( "should pass AbortController signal to createMessage metadata" , async ( ) => {
1800+ const task = new Task ( {
1801+ provider : mockProvider ,
1802+ apiConfiguration : mockApiConfig ,
1803+ task : "test task" ,
1804+ startTask : false ,
1805+ } )
1806+
1807+ // Mock the API stream response
1808+ const mockStream = {
1809+ async * [ Symbol . asyncIterator ] ( ) {
1810+ yield { type : "text" , text : "response" }
1811+ } ,
1812+ async next ( ) {
1813+ return { done : true , value : { type : "text" , text : "response" } }
1814+ } ,
1815+ async return ( ) {
1816+ return { done : true , value : undefined }
1817+ } ,
1818+ async throw ( e : any ) {
1819+ throw e
1820+ } ,
1821+ [ Symbol . asyncDispose ] : async ( ) => { } ,
1822+ } as AsyncGenerator < ApiStreamChunk >
1823+
1824+ const createMessageSpy = vi . spyOn ( task . api , "createMessage" ) . mockReturnValue ( mockStream )
1825+
1826+ task . apiConversationHistory = [
1827+ {
1828+ role : "user" as const ,
1829+ content : [ { type : "text" as const , text : "test message" } ] ,
1830+ ts : Date . now ( ) ,
1831+ } ,
1832+ ] as any
1833+
1834+ const iterator = task . attemptApiRequest ( 0 )
1835+ await iterator . next ( )
1836+
1837+ // Verify createMessage was called with metadata containing abortSignal
1838+ expect ( createMessageSpy ) . toHaveBeenCalled ( )
1839+ const [ , , metadata ] = createMessageSpy . mock . calls [ 0 ] !
1840+
1841+ expect ( metadata ) . toBeDefined ( )
1842+ expect ( metadata ! . abortSignal ) . toBeInstanceOf ( AbortSignal )
1843+ } )
1844+
1845+ it ( "should use the same AbortController signal as currentRequestAbortController" , async ( ) => {
1846+ const task = new Task ( {
1847+ provider : mockProvider ,
1848+ apiConfiguration : mockApiConfig ,
1849+ task : "test task" ,
1850+ startTask : false ,
1851+ } )
1852+
1853+ // Mock the API stream response
1854+ const mockStream = {
1855+ async * [ Symbol . asyncIterator ] ( ) {
1856+ yield { type : "text" , text : "response" }
1857+ } ,
1858+ async next ( ) {
1859+ return { done : true , value : { type : "text" , text : "response" } }
1860+ } ,
1861+ async return ( ) {
1862+ return { done : true , value : undefined }
1863+ } ,
1864+ async throw ( e : any ) {
1865+ throw e
1866+ } ,
1867+ [ Symbol . asyncDispose ] : async ( ) => { } ,
1868+ } as AsyncGenerator < ApiStreamChunk >
1869+
1870+ const createMessageSpy = vi . spyOn ( task . api , "createMessage" ) . mockReturnValue ( mockStream )
1871+
1872+ task . apiConversationHistory = [
1873+ {
1874+ role : "user" as const ,
1875+ content : [ { type : "text" as const , text : "test message" } ] ,
1876+ ts : Date . now ( ) ,
1877+ } ,
1878+ ] as any
1879+
1880+ const iterator = task . attemptApiRequest ( 0 )
1881+ await iterator . next ( )
1882+
1883+ // Get the signal from metadata
1884+ const [ , , metadata ] = createMessageSpy . mock . calls [ 0 ] !
1885+ const metadataSignal = metadata ! . abortSignal
1886+
1887+ // The signal in metadata should be the same as the one from currentRequestAbortController
1888+ expect ( metadataSignal ) . toBe ( task . currentRequestAbortController ! . signal )
1889+ } )
1890+ } )
17981891 } )
17991892 } )
18001893
0 commit comments