@@ -1771,5 +1771,55 @@ describe("Cline", () => {
17711771 // Restore console.error
17721772 consoleErrorSpy . mockRestore ( )
17731773 } )
1774+ describe ( "Stream Failure Retry" , ( ) => {
1775+ it ( "should not abort task on stream failure, only on user cancellation" , async ( ) => {
1776+ const task = new Task ( {
1777+ provider : mockProvider ,
1778+ apiConfiguration : mockApiConfig ,
1779+ task : "test task" ,
1780+ startTask : false ,
1781+ } )
1782+
1783+ // Spy on console.error to verify error logging
1784+ const consoleErrorSpy = vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } )
1785+
1786+ // Spy on abortTask to verify it's NOT called for stream failures
1787+ const abortTaskSpy = vi . spyOn ( task , "abortTask" ) . mockResolvedValue ( undefined )
1788+
1789+ // Test Case 1: Stream failure should NOT abort task
1790+ task . abort = false
1791+ task . abandoned = false
1792+
1793+ // Simulate the catch block behavior for stream failure
1794+ const streamFailureError = new Error ( "Stream failed mid-execution" )
1795+
1796+ // The key assertion: verify that when abort=false, abortTask is NOT called
1797+ // This would normally happen in the catch block around line 2184
1798+ const shouldAbort = task . abort
1799+ expect ( shouldAbort ) . toBe ( false )
1800+
1801+ // Verify error would be logged (this is what the new code does)
1802+ console . error (
1803+ `[Task#${ task . taskId } .${ task . instanceId } ] Stream failed, will retry: ${ streamFailureError . message } ` ,
1804+ )
1805+ expect ( consoleErrorSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( "Stream failed, will retry" ) )
1806+
1807+ // Verify abortTask was NOT called
1808+ expect ( abortTaskSpy ) . not . toHaveBeenCalled ( )
1809+
1810+ // Test Case 2: User cancellation SHOULD abort task
1811+ task . abort = true
1812+
1813+ // For user cancellation, abortTask SHOULD be called
1814+ if ( task . abort ) {
1815+ await task . abortTask ( )
1816+ }
1817+
1818+ expect ( abortTaskSpy ) . toHaveBeenCalled ( )
1819+
1820+ // Restore mocks
1821+ consoleErrorSpy . mockRestore ( )
1822+ } )
1823+ } )
17741824 } )
17751825} )
0 commit comments