Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions cli/src/commands/__tests__/review-queue.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { afterEach, describe, expect, mock, test } from 'bun:test'

import { buildReviewPrompt } from '../prompt-builders'
import { routeUserPrompt } from '../router'
import { useChatStore } from '../../state/chat-store'

import type { RouterParams } from '../command-registry'

const createMockParams = (
overrides: Partial<RouterParams> = {},
): RouterParams => ({
agentMode: 'DEFAULT',
inputRef: { current: null },
inputValue: 'focus on the authentication flow',
isChainInProgressRef: { current: false },
isStreaming: false,
logoutMutation: {} as RouterParams['logoutMutation'],
streamMessageIdRef: { current: null },
addToQueue: mock(() => {}),
clearMessages: mock(() => {}),
saveToHistory: mock(() => {}),
scrollToLatest: mock(() => {}),
sendMessage: mock(async () => {}),
setCanProcessQueue: mock(() => {}),
setInputFocused: mock(() => {}),
setInputValue: mock(() => {}),
setIsAuthenticated: mock(() => {}),
setMessages: mock(() => {}),
setUser: mock(() => {}),
...overrides,
})

describe('custom review routing', () => {
afterEach(() => {
useChatStore.getState().reset()
})

test('queues a custom review while a response is in progress', async () => {
const attachment = {
kind: 'text' as const,
id: 'requirements',
content: 'Review the login requirements.',
preview: 'Review the login requirements.',
charCount: 32,
}
const addToQueue = mock(() => {})
const sendMessage = mock(async () => {})
useChatStore.setState({
inputMode: 'review',
pendingAttachments: [attachment],
})

const params = createMockParams({
addToQueue,
isStreaming: true,
sendMessage,
})

await routeUserPrompt(params)

expect(addToQueue).toHaveBeenCalledWith(
buildReviewPrompt('custom', params.inputValue),
[attachment],
)
expect(sendMessage).not.toHaveBeenCalled()
expect(useChatStore.getState().pendingAttachments).toEqual([])
})

test('sends a custom review immediately when idle', async () => {
const addToQueue = mock(() => {})
const sendMessage = mock(async () => {})
useChatStore.setState({ inputMode: 'review' })

const params = createMockParams({ addToQueue, sendMessage })

await routeUserPrompt(params)

expect(sendMessage).toHaveBeenCalledWith({
content: buildReviewPrompt('custom', params.inputValue),
agentMode: params.agentMode,
})
expect(addToQueue).not.toHaveBeenCalled()
})
})
13 changes: 12 additions & 1 deletion cli/src/commands/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,18 @@ export async function routeUserPrompt(
setInputFocused(true)
inputRef.current?.focus()

sendMessage({ content: buildReviewPrompt('custom', trimmed), agentMode })
const reviewPrompt = buildReviewPrompt('custom', trimmed)
if (
isStreaming ||
streamMessageIdRef.current ||
isChainInProgressRef.current
) {
const pendingAttachmentsForQueue = capturePendingAttachments()
addToQueue(reviewPrompt, pendingAttachmentsForQueue)
return
}

sendMessage({ content: reviewPrompt, agentMode })
setTimeout(() => {
scrollToLatest()
}, 0)
Expand Down
Loading