@@ -2648,6 +2648,75 @@ describe("Cline", () => {
26482648 updateSpy . mockRestore ( )
26492649 saveSpy . mockRestore ( )
26502650 } )
2651+
2652+ it ( "logs (instead of crashing) when updateClineMessage rejects from the ask() ignore-partial path" , async ( ) => {
2653+ // Pins the .catch arm on the fire-and-forget updateClineMessage call
2654+ // in ask() when a new partial ask arrives while the previous partial
2655+ // is still pending (AskIgnoredError path).
2656+ const boom = new Error ( "updateClineMessage boom" )
2657+ const updateSpy = vi . spyOn ( Task . prototype as any , "updateClineMessage" ) . mockImplementation ( async ( ) => {
2658+ throw boom
2659+ } )
2660+
2661+ const task = new Task ( {
2662+ provider : mockProvider ,
2663+ apiConfiguration : mockApiConfig ,
2664+ task : "test task" ,
2665+ startTask : false ,
2666+ } )
2667+
2668+ // Seed a prior partial ask so the isUpdatingPreviousPartial branch fires.
2669+ task . clineMessages . push ( {
2670+ ts : Date . now ( ) - 1 ,
2671+ type : "ask" ,
2672+ ask : "tool" ,
2673+ text : "partial" ,
2674+ partial : true ,
2675+ } )
2676+
2677+ // Sending a new partial of the same type triggers updateClineMessage
2678+ // then throws AskIgnoredError — catch it so the test doesn't fail.
2679+ await task . ask ( "tool" , "updated partial" , true ) . catch ( ( ) => { } )
2680+ await flushMicrotasks ( )
2681+
2682+ expect ( updateSpy ) . toHaveBeenCalled ( )
2683+ expect ( consoleErrorSpy ) . toHaveBeenCalledWith ( "[Task#ask] updateClineMessage failed:" , boom )
2684+ } )
2685+
2686+ it ( "logs (instead of crashing) when updateClineMessage rejects from handleWebviewAskResponse" , async ( ) => {
2687+ // Pins the .catch arm on the fire-and-forget updateClineMessage call
2688+ // in handleWebviewAskResponse when marking a tool ask as answered.
2689+ const boom = new Error ( "updateClineMessage boom" )
2690+ const updateSpy = vi . spyOn ( Task . prototype as any , "updateClineMessage" ) . mockImplementation ( async ( ) => {
2691+ throw boom
2692+ } )
2693+ vi . spyOn ( Task . prototype as any , "saveClineMessages" ) . mockResolvedValue ( undefined )
2694+
2695+ const task = new Task ( {
2696+ provider : mockProvider ,
2697+ apiConfiguration : mockApiConfig ,
2698+ task : "test task" ,
2699+ startTask : false ,
2700+ } )
2701+
2702+ // Seed an unanswered tool ask so the lastToolAskIndex branch fires.
2703+ task . clineMessages . push ( {
2704+ ts : Date . now ( ) - 1 ,
2705+ type : "ask" ,
2706+ ask : "tool" ,
2707+ text : "tool call" ,
2708+ partial : false ,
2709+ } )
2710+
2711+ task . handleWebviewAskResponse ( "yesButtonClicked" )
2712+ await flushMicrotasks ( )
2713+
2714+ expect ( updateSpy ) . toHaveBeenCalled ( )
2715+ expect ( consoleErrorSpy ) . toHaveBeenCalledWith (
2716+ "[Task#handleWebviewAskResponse] updateClineMessage failed:" ,
2717+ boom ,
2718+ )
2719+ } )
26512720 } )
26522721} )
26532722
0 commit comments