| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import {act, fireEvent, render, screen, waitFor, within} from '@testing-library/react'; |
| b69ab31 | | | 9 | import * as utils from 'shared/utils'; |
| b69ab31 | | | 10 | import App from '../App'; |
| b69ab31 | | | 11 | import {Internal} from '../Internal'; |
| b69ab31 | | | 12 | import {tracker} from '../analytics'; |
| b69ab31 | | | 13 | import {readAtom} from '../jotaiUtils'; |
| b69ab31 | | | 14 | import {operationList} from '../operationsState'; |
| b69ab31 | | | 15 | import {mostRecentSubscriptionIds} from '../serverAPIState'; |
| b69ab31 | | | 16 | import {CommitTreeListTestUtils} from '../testQueries'; |
| b69ab31 | | | 17 | import { |
| b69ab31 | | | 18 | closeCommitInfoSidebar, |
| b69ab31 | | | 19 | COMMIT, |
| b69ab31 | | | 20 | dragAndDropCommits, |
| b69ab31 | | | 21 | expectMessageSentToServer, |
| b69ab31 | | | 22 | expectYouAreHerePointAt, |
| b69ab31 | | | 23 | getLastMessageOfTypeSentToServer, |
| b69ab31 | | | 24 | resetTestMessages, |
| b69ab31 | | | 25 | simulateCommits, |
| b69ab31 | | | 26 | simulateMessageFromServer, |
| b69ab31 | | | 27 | simulateRepoConnected, |
| b69ab31 | | | 28 | TEST_COMMIT_HISTORY, |
| b69ab31 | | | 29 | } from '../testUtils'; |
| b69ab31 | | | 30 | |
| b69ab31 | | | 31 | const {clickGoto} = CommitTreeListTestUtils; |
| b69ab31 | | | 32 | |
| b69ab31 | | | 33 | const abortButton = () => screen.queryByTestId('abort-button'); |
| b69ab31 | | | 34 | |
| b69ab31 | | | 35 | describe('operations', () => { |
| b69ab31 | | | 36 | beforeEach(() => { |
| b69ab31 | | | 37 | jest.useFakeTimers(); |
| b69ab31 | | | 38 | resetTestMessages(); |
| b69ab31 | | | 39 | render(<App />); |
| b69ab31 | | | 40 | act(() => { |
| b69ab31 | | | 41 | closeCommitInfoSidebar(); |
| b69ab31 | | | 42 | expectMessageSentToServer({ |
| b69ab31 | | | 43 | type: 'subscribe', |
| b69ab31 | | | 44 | kind: 'smartlogCommits', |
| b69ab31 | | | 45 | subscriptionID: expect.anything(), |
| b69ab31 | | | 46 | }); |
| b69ab31 | | | 47 | simulateRepoConnected(); |
| b69ab31 | | | 48 | simulateCommits({ |
| b69ab31 | | | 49 | value: TEST_COMMIT_HISTORY, |
| b69ab31 | | | 50 | }); |
| b69ab31 | | | 51 | }); |
| b69ab31 | | | 52 | }); |
| b69ab31 | | | 53 | |
| b69ab31 | | | 54 | afterEach(() => { |
| b69ab31 | | | 55 | jest.useRealTimers(); |
| b69ab31 | | | 56 | }); |
| b69ab31 | | | 57 | |
| b69ab31 | | | 58 | it('shows running operation', async () => { |
| b69ab31 | | | 59 | await clickGoto('c'); |
| b69ab31 | | | 60 | |
| b69ab31 | | | 61 | expect( |
| b69ab31 | | | 62 | within(screen.getByTestId('progress-container')).getByText('sl goto --rev c'), |
| b69ab31 | | | 63 | ).toBeInTheDocument(); |
| b69ab31 | | | 64 | }); |
| b69ab31 | | | 65 | |
| b69ab31 | | | 66 | it('shows stdout from running command', async () => { |
| b69ab31 | | | 67 | await clickGoto('c'); |
| b69ab31 | | | 68 | const message = await waitFor(() => |
| b69ab31 | | | 69 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 70 | ); |
| b69ab31 | | | 71 | const id = message.operation.id; |
| b69ab31 | | | 72 | |
| b69ab31 | | | 73 | act(() => { |
| b69ab31 | | | 74 | simulateMessageFromServer({ |
| b69ab31 | | | 75 | type: 'operationProgress', |
| b69ab31 | | | 76 | id, |
| b69ab31 | | | 77 | kind: 'spawn', |
| b69ab31 | | | 78 | queue: [], |
| b69ab31 | | | 79 | }); |
| b69ab31 | | | 80 | |
| b69ab31 | | | 81 | simulateMessageFromServer({ |
| b69ab31 | | | 82 | type: 'operationProgress', |
| b69ab31 | | | 83 | id, |
| b69ab31 | | | 84 | kind: 'stdout', |
| b69ab31 | | | 85 | message: 'some progress...', |
| b69ab31 | | | 86 | }); |
| b69ab31 | | | 87 | }); |
| b69ab31 | | | 88 | |
| b69ab31 | | | 89 | expect(screen.queryByText('some progress...')).toBeInTheDocument(); |
| b69ab31 | | | 90 | |
| b69ab31 | | | 91 | act(() => { |
| b69ab31 | | | 92 | simulateMessageFromServer({ |
| b69ab31 | | | 93 | type: 'operationProgress', |
| b69ab31 | | | 94 | id, |
| b69ab31 | | | 95 | kind: 'stdout', |
| b69ab31 | | | 96 | message: 'another message', |
| b69ab31 | | | 97 | }); |
| b69ab31 | | | 98 | }); |
| b69ab31 | | | 99 | |
| b69ab31 | | | 100 | expect(screen.queryByText('another message', {exact: false})).toBeInTheDocument(); |
| b69ab31 | | | 101 | }); |
| b69ab31 | | | 102 | |
| b69ab31 | | | 103 | it('shows stderr from running command', async () => { |
| b69ab31 | | | 104 | await clickGoto('c'); |
| b69ab31 | | | 105 | const message = await waitFor(() => |
| b69ab31 | | | 106 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 107 | ); |
| b69ab31 | | | 108 | const id = message.operation.id; |
| b69ab31 | | | 109 | |
| b69ab31 | | | 110 | act(() => { |
| b69ab31 | | | 111 | simulateMessageFromServer({ |
| b69ab31 | | | 112 | type: 'operationProgress', |
| b69ab31 | | | 113 | id, |
| b69ab31 | | | 114 | kind: 'spawn', |
| b69ab31 | | | 115 | queue: [], |
| b69ab31 | | | 116 | }); |
| b69ab31 | | | 117 | |
| b69ab31 | | | 118 | simulateMessageFromServer({ |
| b69ab31 | | | 119 | type: 'operationProgress', |
| b69ab31 | | | 120 | id, |
| b69ab31 | | | 121 | kind: 'stderr', |
| b69ab31 | | | 122 | message: 'some progress...', |
| b69ab31 | | | 123 | }); |
| b69ab31 | | | 124 | }); |
| b69ab31 | | | 125 | |
| b69ab31 | | | 126 | expect(screen.queryByText('some progress...', {exact: false})).toBeInTheDocument(); |
| b69ab31 | | | 127 | |
| b69ab31 | | | 128 | act(() => { |
| b69ab31 | | | 129 | simulateMessageFromServer({ |
| b69ab31 | | | 130 | type: 'operationProgress', |
| b69ab31 | | | 131 | id, |
| b69ab31 | | | 132 | kind: 'stderr', |
| b69ab31 | | | 133 | message: 'another message', |
| b69ab31 | | | 134 | }); |
| b69ab31 | | | 135 | }); |
| b69ab31 | | | 136 | |
| b69ab31 | | | 137 | expect(screen.queryByText('another message', {exact: false})).toBeInTheDocument(); |
| b69ab31 | | | 138 | }); |
| b69ab31 | | | 139 | |
| b69ab31 | | | 140 | it('shows abort on long-running commands', async () => { |
| b69ab31 | | | 141 | await clickGoto('c'); |
| b69ab31 | | | 142 | expect(abortButton()).toBeNull(); |
| b69ab31 | | | 143 | |
| b69ab31 | | | 144 | act(() => { |
| b69ab31 | | | 145 | jest.advanceTimersByTime(600000); |
| b69ab31 | | | 146 | }); |
| b69ab31 | | | 147 | expect(abortButton()).toBeInTheDocument(); |
| b69ab31 | | | 148 | }); |
| b69ab31 | | | 149 | |
| b69ab31 | | | 150 | it('shows successful exit status', async () => { |
| b69ab31 | | | 151 | await clickGoto('c'); |
| b69ab31 | | | 152 | const message = await waitFor(() => |
| b69ab31 | | | 153 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 154 | ); |
| b69ab31 | | | 155 | const id = message.operation.id; |
| b69ab31 | | | 156 | |
| b69ab31 | | | 157 | act(() => { |
| b69ab31 | | | 158 | simulateMessageFromServer({ |
| b69ab31 | | | 159 | type: 'operationProgress', |
| b69ab31 | | | 160 | id, |
| b69ab31 | | | 161 | kind: 'spawn', |
| b69ab31 | | | 162 | queue: [], |
| b69ab31 | | | 163 | }); |
| b69ab31 | | | 164 | |
| b69ab31 | | | 165 | simulateMessageFromServer({ |
| b69ab31 | | | 166 | type: 'operationProgress', |
| b69ab31 | | | 167 | id, |
| b69ab31 | | | 168 | kind: 'exit', |
| b69ab31 | | | 169 | exitCode: 0, |
| b69ab31 | | | 170 | timestamp: 1234, |
| b69ab31 | | | 171 | }); |
| b69ab31 | | | 172 | }); |
| b69ab31 | | | 173 | |
| b69ab31 | | | 174 | expect(screen.queryByLabelText('Command exited successfully')).toBeInTheDocument(); |
| b69ab31 | | | 175 | expect( |
| b69ab31 | | | 176 | within(screen.getByTestId('progress-container')).getByText('sl goto --rev c'), |
| b69ab31 | | | 177 | ).toBeInTheDocument(); |
| b69ab31 | | | 178 | }); |
| b69ab31 | | | 179 | |
| b69ab31 | | | 180 | it('shows unsuccessful exit status', async () => { |
| b69ab31 | | | 181 | await clickGoto('c'); |
| b69ab31 | | | 182 | const message = await waitFor(() => |
| b69ab31 | | | 183 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 184 | ); |
| b69ab31 | | | 185 | const id = message.operation.id; |
| b69ab31 | | | 186 | |
| b69ab31 | | | 187 | act(() => { |
| b69ab31 | | | 188 | simulateMessageFromServer({ |
| b69ab31 | | | 189 | type: 'operationProgress', |
| b69ab31 | | | 190 | id, |
| b69ab31 | | | 191 | kind: 'spawn', |
| b69ab31 | | | 192 | queue: [], |
| b69ab31 | | | 193 | }); |
| b69ab31 | | | 194 | |
| b69ab31 | | | 195 | simulateMessageFromServer({ |
| b69ab31 | | | 196 | type: 'operationProgress', |
| b69ab31 | | | 197 | id, |
| b69ab31 | | | 198 | kind: 'exit', |
| b69ab31 | | | 199 | exitCode: -1, |
| b69ab31 | | | 200 | timestamp: 1234, |
| b69ab31 | | | 201 | }); |
| b69ab31 | | | 202 | }); |
| b69ab31 | | | 203 | |
| b69ab31 | | | 204 | expect(screen.queryByLabelText('Command exited unsuccessfully')).toBeInTheDocument(); |
| b69ab31 | | | 205 | expect( |
| b69ab31 | | | 206 | within(screen.getByTestId('progress-container')).getByText('sl goto --rev c'), |
| b69ab31 | | | 207 | ).toBeInTheDocument(); |
| b69ab31 | | | 208 | }); |
| b69ab31 | | | 209 | |
| b69ab31 | | | 210 | it('handles out of order exit messages', async () => { |
| b69ab31 | | | 211 | await clickGoto('c'); |
| b69ab31 | | | 212 | const message1 = await waitFor(() => |
| b69ab31 | | | 213 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 214 | ); |
| b69ab31 | | | 215 | const id1 = message1.operation.id; |
| b69ab31 | | | 216 | |
| b69ab31 | | | 217 | act(() => { |
| b69ab31 | | | 218 | simulateMessageFromServer({ |
| b69ab31 | | | 219 | type: 'operationProgress', |
| b69ab31 | | | 220 | id: id1, |
| b69ab31 | | | 221 | kind: 'spawn', |
| b69ab31 | | | 222 | queue: [], |
| b69ab31 | | | 223 | }); |
| b69ab31 | | | 224 | }); |
| b69ab31 | | | 225 | |
| b69ab31 | | | 226 | await clickGoto('d'); |
| b69ab31 | | | 227 | const message2 = await waitFor(() => |
| b69ab31 | | | 228 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 229 | ); |
| b69ab31 | | | 230 | const id2 = message2.operation.id; |
| b69ab31 | | | 231 | |
| b69ab31 | | | 232 | act(() => { |
| b69ab31 | | | 233 | simulateMessageFromServer({ |
| b69ab31 | | | 234 | type: 'operationProgress', |
| b69ab31 | | | 235 | id: id2, |
| b69ab31 | | | 236 | kind: 'spawn', |
| b69ab31 | | | 237 | queue: [], |
| b69ab31 | | | 238 | }); |
| b69ab31 | | | 239 | }); |
| b69ab31 | | | 240 | |
| b69ab31 | | | 241 | // get an exit for the SECOND operation before the first |
| b69ab31 | | | 242 | act(() => { |
| b69ab31 | | | 243 | simulateMessageFromServer({ |
| b69ab31 | | | 244 | type: 'operationProgress', |
| b69ab31 | | | 245 | id: id2, |
| b69ab31 | | | 246 | kind: 'exit', |
| b69ab31 | | | 247 | exitCode: 0, |
| b69ab31 | | | 248 | timestamp: 1234, |
| b69ab31 | | | 249 | }); |
| b69ab31 | | | 250 | }); |
| b69ab31 | | | 251 | |
| b69ab31 | | | 252 | // but then get the first |
| b69ab31 | | | 253 | act(() => { |
| b69ab31 | | | 254 | simulateMessageFromServer({ |
| b69ab31 | | | 255 | type: 'operationProgress', |
| b69ab31 | | | 256 | id: id1, |
| b69ab31 | | | 257 | kind: 'exit', |
| b69ab31 | | | 258 | exitCode: 0, |
| b69ab31 | | | 259 | timestamp: 1234, |
| b69ab31 | | | 260 | }); |
| b69ab31 | | | 261 | }); |
| b69ab31 | | | 262 | |
| b69ab31 | | | 263 | // This test is a bit bad: we directly read the jotai state instead of asserting on the UI state. |
| b69ab31 | | | 264 | // This is to make sure our state is correct, and isn't represented in the UI in an obvious way. |
| b69ab31 | | | 265 | const opList = readAtom(operationList); |
| b69ab31 | | | 266 | |
| b69ab31 | | | 267 | expect(opList.currentOperation).toEqual( |
| b69ab31 | | | 268 | expect.objectContaining({ |
| b69ab31 | | | 269 | operation: expect.objectContaining({id: id2}), |
| b69ab31 | | | 270 | exitCode: 0, |
| b69ab31 | | | 271 | }), |
| b69ab31 | | | 272 | ); |
| b69ab31 | | | 273 | expect(opList.operationHistory).toEqual([ |
| b69ab31 | | | 274 | expect.objectContaining({ |
| b69ab31 | | | 275 | operation: expect.objectContaining({id: id1}), |
| b69ab31 | | | 276 | exitCode: 0, // we marked it as exited even though they came out of order |
| b69ab31 | | | 277 | }), |
| b69ab31 | | | 278 | ]); |
| b69ab31 | | | 279 | |
| b69ab31 | | | 280 | if (Internal.sendAnalyticsDataToServer != null) { |
| b69ab31 | | | 281 | expectMessageSentToServer({ |
| b69ab31 | | | 282 | type: 'track', |
| b69ab31 | | | 283 | data: expect.objectContaining({ |
| b69ab31 | | | 284 | eventName: 'ExitMessageOutOfOrder', |
| b69ab31 | | | 285 | }), |
| b69ab31 | | | 286 | }); |
| b69ab31 | | | 287 | } |
| b69ab31 | | | 288 | }); |
| b69ab31 | | | 289 | |
| b69ab31 | | | 290 | it('reacts to abort', async () => { |
| b69ab31 | | | 291 | await clickGoto('c'); |
| b69ab31 | | | 292 | const message = await waitFor(() => |
| b69ab31 | | | 293 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 294 | ); |
| b69ab31 | | | 295 | const id = message.operation.id; |
| b69ab31 | | | 296 | |
| b69ab31 | | | 297 | act(() => { |
| b69ab31 | | | 298 | jest.advanceTimersByTime(600000); |
| b69ab31 | | | 299 | }); |
| b69ab31 | | | 300 | |
| b69ab31 | | | 301 | // Start abort |
| b69ab31 | | | 302 | fireEvent.click(abortButton() as Element); |
| b69ab31 | | | 303 | |
| b69ab31 | | | 304 | // During abort |
| b69ab31 | | | 305 | expect(abortButton()).toBeDisabled(); |
| b69ab31 | | | 306 | |
| b69ab31 | | | 307 | // After abort (process exit) |
| b69ab31 | | | 308 | act(() => { |
| b69ab31 | | | 309 | simulateMessageFromServer({ |
| b69ab31 | | | 310 | type: 'operationProgress', |
| b69ab31 | | | 311 | id, |
| b69ab31 | | | 312 | kind: 'exit', |
| b69ab31 | | | 313 | exitCode: 130, |
| b69ab31 | | | 314 | timestamp: 1234, |
| b69ab31 | | | 315 | }); |
| b69ab31 | | | 316 | }); |
| b69ab31 | | | 317 | expect(abortButton()).toBeNull(); |
| b69ab31 | | | 318 | expect(screen.queryByLabelText('Command aborted')).toBeInTheDocument(); |
| b69ab31 | | | 319 | }); |
| b69ab31 | | | 320 | |
| b69ab31 | | | 321 | describe('queued commands', () => { |
| b69ab31 | | | 322 | it('optimistically shows queued commands', async () => { |
| b69ab31 | | | 323 | await clickGoto('c'); |
| b69ab31 | | | 324 | const message1 = await waitFor(() => |
| b69ab31 | | | 325 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 326 | ); |
| b69ab31 | | | 327 | const id1 = message1.operation.id; |
| b69ab31 | | | 328 | |
| b69ab31 | | | 329 | act(() => { |
| b69ab31 | | | 330 | simulateMessageFromServer({ |
| b69ab31 | | | 331 | type: 'operationProgress', |
| b69ab31 | | | 332 | id: id1, |
| b69ab31 | | | 333 | kind: 'spawn', |
| b69ab31 | | | 334 | queue: [], |
| b69ab31 | | | 335 | }); |
| b69ab31 | | | 336 | }); |
| b69ab31 | | | 337 | |
| b69ab31 | | | 338 | await clickGoto('a'); |
| b69ab31 | | | 339 | await clickGoto('b'); |
| b69ab31 | | | 340 | |
| b69ab31 | | | 341 | expect( |
| b69ab31 | | | 342 | within(screen.getByTestId('queued-commands')).getByText('sl goto --rev a'), |
| b69ab31 | | | 343 | ).toBeInTheDocument(); |
| b69ab31 | | | 344 | expect( |
| b69ab31 | | | 345 | within(screen.getByTestId('queued-commands')).getByText('sl goto --rev b'), |
| b69ab31 | | | 346 | ).toBeInTheDocument(); |
| b69ab31 | | | 347 | }); |
| b69ab31 | | | 348 | |
| b69ab31 | | | 349 | it('dequeues when the server starts the next command', async () => { |
| b69ab31 | | | 350 | await clickGoto('c'); |
| b69ab31 | | | 351 | const message1 = await waitFor(() => |
| b69ab31 | | | 352 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 353 | ); |
| b69ab31 | | | 354 | const id1 = message1.operation.id; |
| b69ab31 | | | 355 | |
| b69ab31 | | | 356 | act(() => { |
| b69ab31 | | | 357 | simulateMessageFromServer({ |
| b69ab31 | | | 358 | type: 'operationProgress', |
| b69ab31 | | | 359 | id: id1, |
| b69ab31 | | | 360 | kind: 'spawn', |
| b69ab31 | | | 361 | queue: [], |
| b69ab31 | | | 362 | }); |
| b69ab31 | | | 363 | }); |
| b69ab31 | | | 364 | |
| b69ab31 | | | 365 | await clickGoto('a'); |
| b69ab31 | | | 366 | const message2 = await waitFor(() => |
| b69ab31 | | | 367 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 368 | ); |
| b69ab31 | | | 369 | const id2 = message2.operation.id; |
| b69ab31 | | | 370 | |
| b69ab31 | | | 371 | expect( |
| b69ab31 | | | 372 | within(screen.getByTestId('queued-commands')).getByText('sl goto --rev a'), |
| b69ab31 | | | 373 | ).toBeInTheDocument(); |
| b69ab31 | | | 374 | |
| b69ab31 | | | 375 | act(() => { |
| b69ab31 | | | 376 | simulateMessageFromServer({ |
| b69ab31 | | | 377 | type: 'operationProgress', |
| b69ab31 | | | 378 | id: id2, |
| b69ab31 | | | 379 | kind: 'spawn', |
| b69ab31 | | | 380 | queue: [], |
| b69ab31 | | | 381 | }); |
| b69ab31 | | | 382 | }); |
| b69ab31 | | | 383 | |
| b69ab31 | | | 384 | expect(screen.queryByTestId('queued-commands')).not.toBeInTheDocument(); |
| b69ab31 | | | 385 | }); |
| b69ab31 | | | 386 | |
| b69ab31 | | | 387 | it('takes queued command info from server', async () => { |
| b69ab31 | | | 388 | await clickGoto('c'); |
| b69ab31 | | | 389 | const message1 = await waitFor(() => |
| b69ab31 | | | 390 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 391 | ); |
| b69ab31 | | | 392 | const id1 = message1.operation.id; |
| b69ab31 | | | 393 | |
| b69ab31 | | | 394 | act(() => { |
| b69ab31 | | | 395 | simulateMessageFromServer({ |
| b69ab31 | | | 396 | type: 'operationProgress', |
| b69ab31 | | | 397 | id: id1, |
| b69ab31 | | | 398 | kind: 'spawn', |
| b69ab31 | | | 399 | queue: [], |
| b69ab31 | | | 400 | }); |
| b69ab31 | | | 401 | }); |
| b69ab31 | | | 402 | |
| b69ab31 | | | 403 | await clickGoto('a'); |
| b69ab31 | | | 404 | const message2 = await waitFor(() => |
| b69ab31 | | | 405 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 406 | ); |
| b69ab31 | | | 407 | const id2 = message2.operation.id; |
| b69ab31 | | | 408 | |
| b69ab31 | | | 409 | await clickGoto('b'); |
| b69ab31 | | | 410 | const message3 = await waitFor(() => |
| b69ab31 | | | 411 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 412 | ); |
| b69ab31 | | | 413 | const id3 = message3.operation.id; |
| b69ab31 | | | 414 | |
| b69ab31 | | | 415 | act(() => { |
| b69ab31 | | | 416 | simulateMessageFromServer({ |
| b69ab31 | | | 417 | type: 'operationProgress', |
| b69ab31 | | | 418 | id: id1, |
| b69ab31 | | | 419 | kind: 'exit', |
| b69ab31 | | | 420 | exitCode: 0, |
| b69ab31 | | | 421 | timestamp: 1234, |
| b69ab31 | | | 422 | }); |
| b69ab31 | | | 423 | simulateMessageFromServer({ |
| b69ab31 | | | 424 | type: 'operationProgress', |
| b69ab31 | | | 425 | id: id2, |
| b69ab31 | | | 426 | kind: 'spawn', |
| b69ab31 | | | 427 | queue: [id3], |
| b69ab31 | | | 428 | }); |
| b69ab31 | | | 429 | }); |
| b69ab31 | | | 430 | |
| b69ab31 | | | 431 | expect( |
| b69ab31 | | | 432 | within(screen.getByTestId('queued-commands')).getByText('sl goto --rev b'), |
| b69ab31 | | | 433 | ).toBeInTheDocument(); |
| b69ab31 | | | 434 | expect( |
| b69ab31 | | | 435 | within(screen.getByTestId('queued-commands')).queryByText('sl goto --rev a'), |
| b69ab31 | | | 436 | ).not.toBeInTheDocument(); |
| b69ab31 | | | 437 | }); |
| b69ab31 | | | 438 | |
| b69ab31 | | | 439 | it('error running command cancels queued commands', async () => { |
| b69ab31 | | | 440 | await clickGoto('c'); |
| b69ab31 | | | 441 | const message1 = await waitFor(() => |
| b69ab31 | | | 442 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 443 | ); |
| b69ab31 | | | 444 | const id1 = message1.operation.id; |
| b69ab31 | | | 445 | |
| b69ab31 | | | 446 | act(() => { |
| b69ab31 | | | 447 | simulateMessageFromServer({ |
| b69ab31 | | | 448 | type: 'operationProgress', |
| b69ab31 | | | 449 | id: id1, |
| b69ab31 | | | 450 | kind: 'spawn', |
| b69ab31 | | | 451 | queue: [], |
| b69ab31 | | | 452 | }); |
| b69ab31 | | | 453 | }); |
| b69ab31 | | | 454 | |
| b69ab31 | | | 455 | await clickGoto('a'); |
| b69ab31 | | | 456 | await clickGoto('b'); |
| b69ab31 | | | 457 | |
| b69ab31 | | | 458 | expect(screen.queryByTestId('queued-commands')).toBeInTheDocument(); |
| b69ab31 | | | 459 | expect(screen.queryByText('Next to run')).toBeInTheDocument(); |
| b69ab31 | | | 460 | act(() => { |
| b69ab31 | | | 461 | // original goto fails |
| b69ab31 | | | 462 | simulateMessageFromServer({ |
| b69ab31 | | | 463 | type: 'operationProgress', |
| b69ab31 | | | 464 | id: id1, |
| b69ab31 | | | 465 | kind: 'exit', |
| b69ab31 | | | 466 | exitCode: -1, |
| b69ab31 | | | 467 | timestamp: 1234, |
| b69ab31 | | | 468 | }); |
| b69ab31 | | | 469 | }); |
| b69ab31 | | | 470 | expect(screen.getByTestId('cancelled-queued-commands')).toBeInTheDocument(); |
| b69ab31 | | | 471 | expect(screen.queryByText('Next to run')).not.toBeInTheDocument(); |
| b69ab31 | | | 472 | }); |
| b69ab31 | | | 473 | |
| b69ab31 | | | 474 | it('force clears optimistic state after fetching after an operation has finished', async () => { |
| b69ab31 | | | 475 | jest.spyOn(tracker, 'track').mockImplementation(() => null); |
| b69ab31 | | | 476 | const commitsBeforeOperations = { |
| b69ab31 | | | 477 | value: [ |
| b69ab31 | | | 478 | COMMIT('e', 'Commit E', 'd', {isDot: true}), |
| b69ab31 | | | 479 | COMMIT('d', 'Commit D', 'c'), |
| b69ab31 | | | 480 | COMMIT('c', 'Commit C', 'b'), |
| b69ab31 | | | 481 | COMMIT('b', 'Commit B', 'a'), |
| b69ab31 | | | 482 | COMMIT('a', 'Commit A', '1'), |
| b69ab31 | | | 483 | COMMIT('1', 'public', '0', {phase: 'public'}), |
| b69ab31 | | | 484 | ], |
| b69ab31 | | | 485 | }; |
| b69ab31 | | | 486 | const commitsAfterOperations = { |
| b69ab31 | | | 487 | value: [ |
| b69ab31 | | | 488 | COMMIT('e2', 'Commit E', 'd2'), |
| b69ab31 | | | 489 | COMMIT('d2', 'Commit D', 'c2', {isDot: true}), // goto |
| b69ab31 | | | 490 | COMMIT('c2', 'Commit C', 'a'), // rebased |
| b69ab31 | | | 491 | COMMIT('b', 'Commit B', 'a'), |
| b69ab31 | | | 492 | COMMIT('a', 'Commit A', '1'), |
| b69ab31 | | | 493 | COMMIT('1', 'public', '0', {phase: 'public'}), |
| b69ab31 | | | 494 | ], |
| b69ab31 | | | 495 | }; |
| b69ab31 | | | 496 | |
| b69ab31 | | | 497 | act(() => |
| b69ab31 | | | 498 | simulateMessageFromServer({ |
| b69ab31 | | | 499 | type: 'subscriptionResult', |
| b69ab31 | | | 500 | kind: 'smartlogCommits', |
| b69ab31 | | | 501 | subscriptionID: mostRecentSubscriptionIds.smartlogCommits, |
| b69ab31 | | | 502 | data: { |
| b69ab31 | | | 503 | fetchStartTimestamp: 1, |
| b69ab31 | | | 504 | fetchCompletedTimestamp: 2, |
| b69ab31 | | | 505 | commits: commitsBeforeOperations, |
| b69ab31 | | | 506 | }, |
| b69ab31 | | | 507 | }), |
| b69ab31 | | | 508 | ); |
| b69ab31 | | | 509 | |
| b69ab31 | | | 510 | // 100 200 300 400 500 600 700 |
| b69ab31 | | | 511 | // |--------|--------|--------|--------|--------|--------| |
| b69ab31 | | | 512 | // <----- rebase ----> |
| b69ab31 | | | 513 | // ...................<----- goto -----> |
| b69ab31 | | | 514 | // <----fetch1---> (no effect) |
| b69ab31 | | | 515 | // <---fetch2--> (clears optimistic state) |
| b69ab31 | | | 516 | |
| b69ab31 | | | 517 | // t=100 simulate spawn rebase [c-d-e(YouAreHere)] -> a |
| b69ab31 | | | 518 | // t=200 simulate queue goto 'd' (successor: 'd2') |
| b69ab31 | | | 519 | // t=300 simulate exit rebase (success) |
| b69ab31 | | | 520 | // t=400 simulate spawn goto |
| b69ab31 | | | 521 | // t=500 simulate exit goto (success) |
| b69ab31 | | | 522 | // no "commitsAfterOperations" state received |
| b69ab31 | | | 523 | // expect optimistic "You are here" to be on the old 'e' |
| b69ab31 | | | 524 | // t=600 simulate new commits fetch started @ t=450, with new head |
| b69ab31 | | | 525 | // no effect |
| b69ab31 | | | 526 | // t=700 simulate new commits fetch started @ t=550, with new head |
| b69ab31 | | | 527 | // BEFORE: Optimistic state wouldn't resolve, so "You were here..." would stick |
| b69ab31 | | | 528 | // AFTER: Optimistic state forced to resolve, so "You were here..." is gone |
| b69ab31 | | | 529 | |
| b69ab31 | | | 530 | dragAndDropCommits('c', 'a'); |
| b69ab31 | | | 531 | fireEvent.click(screen.getByText('Run Rebase')); |
| b69ab31 | | | 532 | await waitFor(() => { |
| b69ab31 | | | 533 | expect(screen.getByText('rebasing...')).toBeInTheDocument(); |
| b69ab31 | | | 534 | }); |
| b69ab31 | | | 535 | |
| b69ab31 | | | 536 | // Get the rebase operation ID |
| b69ab31 | | | 537 | const rebaseMessage = await waitFor(() => |
| b69ab31 | | | 538 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 539 | ); |
| b69ab31 | | | 540 | const rebaseId = rebaseMessage.operation.id; |
| b69ab31 | | | 541 | |
| b69ab31 | | | 542 | await clickGoto('d'); // checkout d, which is now optimistic from the rebase, since it'll actually become d2. |
| b69ab31 | | | 543 | |
| b69ab31 | | | 544 | // Get the goto operation ID |
| b69ab31 | | | 545 | const gotoMessage = await waitFor(() => |
| b69ab31 | | | 546 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 547 | ); |
| b69ab31 | | | 548 | const gotoId = gotoMessage.operation.id; |
| b69ab31 | | | 549 | |
| b69ab31 | | | 550 | act(() => |
| b69ab31 | | | 551 | simulateMessageFromServer({ |
| b69ab31 | | | 552 | type: 'operationProgress', |
| b69ab31 | | | 553 | id: rebaseId, |
| b69ab31 | | | 554 | kind: 'spawn', |
| b69ab31 | | | 555 | queue: [], |
| b69ab31 | | | 556 | }), |
| b69ab31 | | | 557 | ); |
| b69ab31 | | | 558 | act(() => |
| b69ab31 | | | 559 | simulateMessageFromServer({ |
| b69ab31 | | | 560 | type: 'operationProgress', |
| b69ab31 | | | 561 | id: gotoId, |
| b69ab31 | | | 562 | kind: 'queue', |
| b69ab31 | | | 563 | queue: [gotoId], |
| b69ab31 | | | 564 | }), |
| b69ab31 | | | 565 | ); |
| b69ab31 | | | 566 | act(() => |
| b69ab31 | | | 567 | simulateMessageFromServer({ |
| b69ab31 | | | 568 | type: 'operationProgress', |
| b69ab31 | | | 569 | id: rebaseId, |
| b69ab31 | | | 570 | kind: 'exit', |
| b69ab31 | | | 571 | exitCode: 0, |
| b69ab31 | | | 572 | timestamp: 300, |
| b69ab31 | | | 573 | }), |
| b69ab31 | | | 574 | ); |
| b69ab31 | | | 575 | act(() => |
| b69ab31 | | | 576 | simulateMessageFromServer({ |
| b69ab31 | | | 577 | type: 'operationProgress', |
| b69ab31 | | | 578 | id: gotoId, |
| b69ab31 | | | 579 | kind: 'spawn', |
| b69ab31 | | | 580 | queue: [], |
| b69ab31 | | | 581 | }), |
| b69ab31 | | | 582 | ); |
| b69ab31 | | | 583 | act(() => |
| b69ab31 | | | 584 | simulateMessageFromServer({ |
| b69ab31 | | | 585 | type: 'operationProgress', |
| b69ab31 | | | 586 | id: gotoId, |
| b69ab31 | | | 587 | kind: 'exit', |
| b69ab31 | | | 588 | exitCode: 0, |
| b69ab31 | | | 589 | timestamp: 500, |
| b69ab31 | | | 590 | }), |
| b69ab31 | | | 591 | ); |
| b69ab31 | | | 592 | act(() => |
| b69ab31 | | | 593 | simulateMessageFromServer({ |
| b69ab31 | | | 594 | type: 'operationProgress', |
| b69ab31 | | | 595 | id: gotoId, |
| b69ab31 | | | 596 | kind: 'exit', |
| b69ab31 | | | 597 | exitCode: 0, |
| b69ab31 | | | 598 | timestamp: 500, |
| b69ab31 | | | 599 | }), |
| b69ab31 | | | 600 | ); |
| b69ab31 | | | 601 | |
| b69ab31 | | | 602 | act(() => |
| b69ab31 | | | 603 | simulateMessageFromServer({ |
| b69ab31 | | | 604 | type: 'subscriptionResult', |
| b69ab31 | | | 605 | kind: 'smartlogCommits', |
| b69ab31 | | | 606 | subscriptionID: mostRecentSubscriptionIds.smartlogCommits, |
| b69ab31 | | | 607 | data: { |
| b69ab31 | | | 608 | commits: commitsBeforeOperations, // not observed the new head |
| b69ab31 | | | 609 | fetchStartTimestamp: 400, // before goto finished |
| b69ab31 | | | 610 | fetchCompletedTimestamp: 450, |
| b69ab31 | | | 611 | }, |
| b69ab31 | | | 612 | }), |
| b69ab31 | | | 613 | ); |
| b69ab31 | | | 614 | |
| b69ab31 | | | 615 | // this latest fetch started before the goto finished, so we don't know that it has all the information |
| b69ab31 | | | 616 | // included. So the optimistic state remains (goto 'd'). |
| b69ab31 | | | 617 | expectYouAreHerePointAt('d'); |
| b69ab31 | | | 618 | |
| b69ab31 | | | 619 | act(() => |
| b69ab31 | | | 620 | simulateMessageFromServer({ |
| b69ab31 | | | 621 | type: 'subscriptionResult', |
| b69ab31 | | | 622 | kind: 'smartlogCommits', |
| b69ab31 | | | 623 | subscriptionID: mostRecentSubscriptionIds.smartlogCommits, |
| b69ab31 | | | 624 | data: { |
| b69ab31 | | | 625 | commits: commitsAfterOperations, // observed the new head |
| b69ab31 | | | 626 | fetchStartTimestamp: 400, // before goto finished |
| b69ab31 | | | 627 | fetchCompletedTimestamp: 450, |
| b69ab31 | | | 628 | }, |
| b69ab31 | | | 629 | }), |
| b69ab31 | | | 630 | ); |
| b69ab31 | | | 631 | |
| b69ab31 | | | 632 | // However, even if the latest fetch started before the goto finished, |
| b69ab31 | | | 633 | // if "goto" saw that head = the new commit, the optimistic state is a |
| b69ab31 | | | 634 | // no-op (does not update 'd2' from the smartlog head back to 'd'). |
| b69ab31 | | | 635 | expectYouAreHerePointAt('d2'); |
| b69ab31 | | | 636 | |
| b69ab31 | | | 637 | act(() => |
| b69ab31 | | | 638 | simulateMessageFromServer({ |
| b69ab31 | | | 639 | type: 'subscriptionResult', |
| b69ab31 | | | 640 | kind: 'smartlogCommits', |
| b69ab31 | | | 641 | subscriptionID: mostRecentSubscriptionIds.smartlogCommits, |
| b69ab31 | | | 642 | data: { |
| b69ab31 | | | 643 | commits: commitsBeforeOperations, // intentionally "incorrect" to test the force clear out |
| b69ab31 | | | 644 | fetchStartTimestamp: 550, // after goto finished |
| b69ab31 | | | 645 | fetchCompletedTimestamp: 600, |
| b69ab31 | | | 646 | }, |
| b69ab31 | | | 647 | }), |
| b69ab31 | | | 648 | ); |
| b69ab31 | | | 649 | |
| b69ab31 | | | 650 | // This latest fetch started AFTER the goto finished, so we can be sure |
| b69ab31 | | | 651 | // it accounts for that operation. |
| b69ab31 | | | 652 | // So the optimistic state should be cleared out, even though we didn't |
| b69ab31 | | | 653 | // detect that the optimistic state should have resolved according to the applier. |
| b69ab31 | | | 654 | // (does not update 'e' from the smartlog head to 'd') |
| b69ab31 | | | 655 | expectYouAreHerePointAt('e'); |
| b69ab31 | | | 656 | }); |
| b69ab31 | | | 657 | }); |
| b69ab31 | | | 658 | |
| b69ab31 | | | 659 | describe('progress messages', () => { |
| b69ab31 | | | 660 | it('shows progress messages', async () => { |
| b69ab31 | | | 661 | await clickGoto('c'); |
| b69ab31 | | | 662 | const message = await waitFor(() => |
| b69ab31 | | | 663 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 664 | ); |
| b69ab31 | | | 665 | const id = message.operation.id; |
| b69ab31 | | | 666 | |
| b69ab31 | | | 667 | act(() => { |
| b69ab31 | | | 668 | simulateMessageFromServer({ |
| b69ab31 | | | 669 | type: 'operationProgress', |
| b69ab31 | | | 670 | id, |
| b69ab31 | | | 671 | kind: 'spawn', |
| b69ab31 | | | 672 | queue: [], |
| b69ab31 | | | 673 | }); |
| b69ab31 | | | 674 | |
| b69ab31 | | | 675 | simulateMessageFromServer({ |
| b69ab31 | | | 676 | type: 'operationProgress', |
| b69ab31 | | | 677 | id, |
| b69ab31 | | | 678 | kind: 'progress', |
| b69ab31 | | | 679 | progress: {message: 'doing the thing', progress: 3, progressTotal: 7}, |
| b69ab31 | | | 680 | }); |
| b69ab31 | | | 681 | }); |
| b69ab31 | | | 682 | |
| b69ab31 | | | 683 | expect( |
| b69ab31 | | | 684 | within(screen.getByTestId('progress-container')).getByText('doing the thing'), |
| b69ab31 | | | 685 | ).toBeInTheDocument(); |
| b69ab31 | | | 686 | }); |
| b69ab31 | | | 687 | |
| b69ab31 | | | 688 | it('hide progress on new stdout', async () => { |
| b69ab31 | | | 689 | await clickGoto('c'); |
| b69ab31 | | | 690 | const message = await waitFor(() => |
| b69ab31 | | | 691 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 692 | ); |
| b69ab31 | | | 693 | const id = message.operation.id; |
| b69ab31 | | | 694 | |
| b69ab31 | | | 695 | act(() => { |
| b69ab31 | | | 696 | simulateMessageFromServer({ |
| b69ab31 | | | 697 | type: 'operationProgress', |
| b69ab31 | | | 698 | id, |
| b69ab31 | | | 699 | kind: 'spawn', |
| b69ab31 | | | 700 | queue: [], |
| b69ab31 | | | 701 | }); |
| b69ab31 | | | 702 | |
| b69ab31 | | | 703 | simulateMessageFromServer({ |
| b69ab31 | | | 704 | type: 'operationProgress', |
| b69ab31 | | | 705 | id, |
| b69ab31 | | | 706 | kind: 'progress', |
| b69ab31 | | | 707 | progress: {message: 'doing the thing'}, |
| b69ab31 | | | 708 | }); |
| b69ab31 | | | 709 | }); |
| b69ab31 | | | 710 | |
| b69ab31 | | | 711 | expect( |
| b69ab31 | | | 712 | within(screen.getByTestId('progress-container')).getByText('doing the thing'), |
| b69ab31 | | | 713 | ).toBeInTheDocument(); |
| b69ab31 | | | 714 | |
| b69ab31 | | | 715 | act(() => { |
| b69ab31 | | | 716 | simulateMessageFromServer({ |
| b69ab31 | | | 717 | type: 'operationProgress', |
| b69ab31 | | | 718 | id, |
| b69ab31 | | | 719 | kind: 'stdout', |
| b69ab31 | | | 720 | message: 'hello', |
| b69ab31 | | | 721 | }); |
| b69ab31 | | | 722 | }); |
| b69ab31 | | | 723 | |
| b69ab31 | | | 724 | expect( |
| b69ab31 | | | 725 | within(screen.getByTestId('progress-container')).queryByText('doing the thing'), |
| b69ab31 | | | 726 | ).not.toBeInTheDocument(); |
| b69ab31 | | | 727 | expect( |
| b69ab31 | | | 728 | within(screen.getByTestId('progress-container')).getByText('hello'), |
| b69ab31 | | | 729 | ).toBeInTheDocument(); |
| b69ab31 | | | 730 | }); |
| b69ab31 | | | 731 | }); |
| b69ab31 | | | 732 | |
| b69ab31 | | | 733 | describe('inline progress', () => { |
| b69ab31 | | | 734 | it('shows progress messages next to commits', async () => { |
| b69ab31 | | | 735 | await clickGoto('c'); |
| b69ab31 | | | 736 | const message = await waitFor(() => |
| b69ab31 | | | 737 | utils.nullthrows(getLastMessageOfTypeSentToServer('runOperation')), |
| b69ab31 | | | 738 | ); |
| b69ab31 | | | 739 | const id = message.operation.id; |
| b69ab31 | | | 740 | |
| b69ab31 | | | 741 | act(() => { |
| b69ab31 | | | 742 | simulateMessageFromServer({ |
| b69ab31 | | | 743 | type: 'operationProgress', |
| b69ab31 | | | 744 | id, |
| b69ab31 | | | 745 | kind: 'spawn', |
| b69ab31 | | | 746 | queue: [], |
| b69ab31 | | | 747 | }); |
| b69ab31 | | | 748 | |
| b69ab31 | | | 749 | simulateMessageFromServer({ |
| b69ab31 | | | 750 | type: 'operationProgress', |
| b69ab31 | | | 751 | id, |
| b69ab31 | | | 752 | kind: 'inlineProgress', |
| b69ab31 | | | 753 | hash: 'c', |
| b69ab31 | | | 754 | message: 'going...', // not a real thing for goto operation, but we support arbitrary progress |
| b69ab31 | | | 755 | }); |
| b69ab31 | | | 756 | }); |
| b69ab31 | | | 757 | |
| b69ab31 | | | 758 | expect( |
| b69ab31 | | | 759 | within(screen.getByTestId('commit-tree-root')).getByText('going...'), |
| b69ab31 | | | 760 | ).toBeInTheDocument(); |
| b69ab31 | | | 761 | }); |
| b69ab31 | | | 762 | }); |
| b69ab31 | | | 763 | }); |