@@ -1807,16 +1807,6 @@ describe("TaskDiffViewer", () => {
18071807 expect ( screen . getByRole ( "button" , { name : "Copy to Clipboard" } ) ) . toHaveClass ( "w-full" ) ;
18081808 expect ( screen . getByRole ( "button" , { name : "Send to Agent" } ) ) . toBeEnabled ( ) ;
18091809
1810- await user . click ( screen . getByRole ( "button" , { name : "Send to Agent" } ) ) ;
1811- await waitFor ( ( ) => {
1812- expect ( api . request . sendAgentMessageNow ) . toHaveBeenCalledWith ( {
1813- taskId : "t1" ,
1814- projectId : "p1" ,
1815- text : expect . stringContaining ( `<comment>${ longComment } </comment>` ) ,
1816- } ) ;
1817- } ) ;
1818- expect ( screen . getByRole ( "button" , { name : "Sent" } ) ) . toBeInTheDocument ( ) ;
1819-
18201810 await user . click ( screen . getByRole ( "button" , { name : "Comment 1" } ) ) ;
18211811 await waitFor ( ( ) => {
18221812 expect ( scrollIntoViewMock ) . toHaveBeenCalled ( ) ;
@@ -2477,6 +2467,56 @@ describe("TaskDiffViewer", () => {
24772467 expect ( localStorage . getItem ( reviewKey ) ) . toBeNull ( ) ;
24782468 } ) ;
24792469
2470+ it ( "clears the review after a successful send, and keeps it when the send fails" , async ( ) => {
2471+ const user = userEvent . setup ( ) ;
2472+ const reviewKey = "dev3-inline-diff-review-v1:t1" ;
2473+ const showConfirm = vi . mocked ( confirm ) ;
2474+ vi . mocked ( api . request . sendAgentMessageNow ) . mockRejectedValueOnce ( new Error ( "no agent" ) ) ;
2475+
2476+ render (
2477+ < I18nProvider >
2478+ < TaskDiffViewer
2479+ task = { task }
2480+ project = { project }
2481+ request = { { mode : "branch" , compareRef : "origin/main" , compareLabel : "origin/main" } }
2482+ onBack = { vi . fn ( ) }
2483+ />
2484+ </ I18nProvider > ,
2485+ ) ;
2486+
2487+ const diffs = await screen . findAllByTestId ( "mock-diff" ) ;
2488+ await user . click ( within ( diffs [ 0 ] ) . getByRole ( "button" , { name : "Open inline comment composer" } ) ) ;
2489+ await user . type ( screen . getByPlaceholderText ( "Leave a comment on this line..." ) , "send me" ) ;
2490+ await user . click ( screen . getByRole ( "button" , { name : "Add comment" } ) ) ;
2491+
2492+ await waitFor ( ( ) => {
2493+ expect ( localStorage . getItem ( reviewKey ) ) . toContain ( "send me" ) ;
2494+ } ) ;
2495+
2496+ // Failed send: the comments must survive so the reviewer can retry.
2497+ await user . click ( screen . getByTestId ( "review-send-button" ) ) ;
2498+ await waitFor ( ( ) => {
2499+ expect ( api . request . sendAgentMessageNow ) . toHaveBeenCalledWith ( {
2500+ taskId : "t1" ,
2501+ projectId : "p1" ,
2502+ text : expect . stringContaining ( "<comment>send me</comment>" ) ,
2503+ } ) ;
2504+ } ) ;
2505+ expect ( screen . getAllByText ( "send me" ) . length ) . toBeGreaterThan ( 0 ) ;
2506+ expect ( localStorage . getItem ( reviewKey ) ) . toContain ( "send me" ) ;
2507+
2508+ // Successful send: comments are delivered, so they clear without a confirm.
2509+ vi . mocked ( api . request . sendAgentMessageNow ) . mockResolvedValueOnce ( undefined as never ) ;
2510+ await user . click ( screen . getByTestId ( "review-send-button" ) ) ;
2511+
2512+ await waitFor ( ( ) => {
2513+ expect ( screen . queryAllByText ( "send me" ) ) . toHaveLength ( 0 ) ;
2514+ } ) ;
2515+ expect ( showConfirm ) . not . toHaveBeenCalled ( ) ;
2516+ expect ( screen . queryByTestId ( "review-reset-button" ) ) . not . toBeInTheDocument ( ) ;
2517+ expect ( localStorage . getItem ( reviewKey ) ) . toBeNull ( ) ;
2518+ } ) ;
2519+
24802520 it ( "still saves new comments when the existing localStorage entry is corrupt JSON" , async ( ) => {
24812521 const user = userEvent . setup ( ) ;
24822522 const reviewKey = "dev3-inline-diff-review-v1:t1" ;
0 commit comments