diff --git a/frontend/src/components/session/ChangesWalkthroughSheet.test.tsx b/frontend/src/components/session/ChangesWalkthroughSheet.test.tsx index 5afbab7d..d66eb137 100644 --- a/frontend/src/components/session/ChangesWalkthroughSheet.test.tsx +++ b/frontend/src/components/session/ChangesWalkthroughSheet.test.tsx @@ -142,7 +142,7 @@ describe('ChangesWalkthroughSheet', () => { expect(await screen.findByText('Stop 1 of 2')).toBeInTheDocument() }) - it('shows the stale warning and regenerates', async () => { + it('updates a stale walkthrough incrementally', async () => { const user = userEvent.setup() mocks.getChangeWalkthrough.mockResolvedValue(state({ stale: true, currentDiffHash: 'hash-2' })) mocks.generateChangeWalkthrough.mockResolvedValue(state({ generating: true })) @@ -152,10 +152,10 @@ describe('ChangesWalkthroughSheet', () => { await screen.findByText('Changes have been updated since this walkthrough was generated'), ).toBeInTheDocument() - await user.click(screen.getByRole('button', { name: 'Regenerate' })) + await user.click(screen.getByRole('button', { name: 'Update walkthrough' })) await waitFor(() => { - expect(mocks.generateChangeWalkthrough).toHaveBeenCalledWith('ses_1', { regenerate: true }) + expect(mocks.generateChangeWalkthrough).toHaveBeenCalledWith('ses_1', {}) }) }) @@ -181,6 +181,50 @@ describe('ChangesWalkthroughSheet', () => { expect(screen.queryByRole('button', { name: 'Generate walkthrough' })).not.toBeInTheDocument() }) + it('renders ready and pending stops while generating', async () => { + mocks.getChangeWalkthrough.mockResolvedValue( + state({ + generating: true, + walkthrough: { + ...walkthrough, + stops: [ + { ...walkthrough.stops[0], status: 'ready' }, + { ...walkthrough.stops[1], status: 'pending', explanation: '' }, + ], + }, + }), + ) + renderSheet() + + expect(await screen.findByText('Introduces the greeting helper.')).toBeInTheDocument() + expect(screen.getByText(/1 of 2 stops explained/)).toBeInTheDocument() + expect(screen.getByLabelText('Explaining')).toBeInTheDocument() + }) + + it('retries unexplained stops', async () => { + const user = userEvent.setup() + mocks.getChangeWalkthrough.mockResolvedValue( + state({ + walkthrough: { + ...walkthrough, + stops: [ + { ...walkthrough.stops[0], status: 'failed', explanation: '' }, + { ...walkthrough.stops[1], status: 'ready' }, + ], + }, + }), + ) + mocks.generateChangeWalkthrough.mockResolvedValue(state({ generating: true })) + renderSheet() + + expect(await screen.findByText('This stop could not be explained.')).toBeInTheDocument() + await user.click(screen.getByRole('button', { name: 'Retry unexplained stops' })) + + await waitFor(() => { + expect(mocks.generateChangeWalkthrough).toHaveBeenCalledWith('ses_1', {}) + }) + }) + it('renders a generation failure recorded by the server', async () => { mocks.getChangeWalkthrough.mockResolvedValue( state({ diff --git a/frontend/src/components/session/ChangesWalkthroughSheet.tsx b/frontend/src/components/session/ChangesWalkthroughSheet.tsx index 7b7caebb..3df7ce7f 100644 --- a/frontend/src/components/session/ChangesWalkthroughSheet.tsx +++ b/frontend/src/components/session/ChangesWalkthroughSheet.tsx @@ -85,6 +85,7 @@ interface ChangesWalkthroughContextValue { selectedHunks: WalkthroughHunk[] selectStop: (index: number) => void detailRef: RefObject + failedStopCount: number } const ChangesWalkthroughContext = createContext(null) @@ -132,6 +133,10 @@ export function ChangesWalkthroughProvider({ sessionId, active, children }: Chan .map((id) => hunksById.get(id)) .filter((hunk): hunk is WalkthroughHunk => hunk !== undefined) + const failedStopCount = stops.filter( + (stop) => stop.status === 'failed' || (stop.status === 'pending' && !generating), + ).length + const selectStop = useCallback((index: number) => { setStopIndex(index) detailRef.current?.scrollIntoView?.({ block: 'start', behavior: 'smooth' }) @@ -152,6 +157,7 @@ export function ChangesWalkthroughProvider({ sessionId, active, children }: Chan selectedHunks, selectStop, detailRef, + failedStopCount, } return {children} @@ -219,15 +225,17 @@ export const ChangesWalkthroughView = memo(function ChangesWalkthroughView() { error, contextLimitFiles, generate, - regenerate, stops, stopIndex, selectedStop, selectedHunks, selectStop, detailRef, + failedStopCount, } = useChangesWalkthrough() + const readyStopCount = stops.filter((stop) => stop.status === 'ready').length + return (
{error ? ( @@ -240,7 +248,11 @@ export const ChangesWalkthroughView = memo(function ChangesWalkthroughView() { {generating ? (
- Generating walkthrough… this can take a minute or two. + + {walkthrough && stops.length > 0 + ? `Generating walkthrough… ${readyStopCount} of ${stops.length} stops explained` + : 'Generating walkthrough… this can take a minute or two.'} +
) : null} @@ -264,9 +276,18 @@ export const ChangesWalkthroughView = memo(function ChangesWalkthroughView() {

Changes have been updated since this walkthrough was generated

- +
+ ) : null} + + {failedStopCount > 0 && !generating ? ( +
+

Some stops could not be explained

+
) : null} @@ -288,7 +309,16 @@ export const ChangesWalkthroughView = memo(function ChangesWalkthroughView() { : 'text-muted-foreground hover:bg-accent/20', )} > - {index + 1}. {stop.title} + + + {index + 1}. {stop.title} + + {stop.status === 'pending' && generating ? ( + + ) : stop.status === 'failed' || stop.status === 'pending' ? ( + not explained + ) : null} + ))} @@ -300,7 +330,13 @@ export const ChangesWalkthroughView = memo(function ChangesWalkthroughView() {

{stopIndex + 1}. {selectedStop.title}

- + {selectedStop.status === 'ready' ? ( + + ) : ( +

+ {generating ? 'Explaining this stop…' : 'This stop could not be explained.'} +

+ )} {selectedHunks.map((hunk) => (