Fix question prompt not rendering for active session (#325)

* Fix question prompt not rendering for active session

currentQuestion was the first pending question globally across all
sessions. When another session had the first question in the flat list,
the QuestionPrompt would not render for the session being viewed even
though it had its own pending question.

Add getForSession() to the questions context and use it in
SessionDetail to look up questions scoped to the current session.

* test(frontend): cover session-scoped question prompt resolution

The SessionDetail useQuestions mocks did not expose getForSession, so
every page test threw on the new session-scoped lookup. Add it to each
mock and lock in the behaviour with regression coverage: the context
helper resolves questions per session while another session owns the
global current question, and SessionDetail renders the prompt for the
session being viewed.

---------

Co-authored-by: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com>
This commit is contained in:
Alexander DrewekeandChris Scott authored and GitHub committed 2026-07-28 19:32:45 -04:00
1 parent 6cc50a02ed
commit eac09090c6
8 files changed
+313 -3

No files matched your search

+21 -1
View File
@@ -94,7 +94,7 @@ const pendingPermission: PermissionRequest = {
}
function Harness() {
const { current, pendingCount, syncForSession, navigateToCurrent, reject, reply } = useQuestions()
const { current, pendingCount, syncForSession, navigateToCurrent, reject, reply, getForSession } = useQuestions()
const permissions = usePermissions()
const permissionForCall = permissions.getForCallID('call-1', 'session-1')
const location = useLocation()
@@ -103,6 +103,9 @@ function Harness() {
<div>
<div data-testid="count">{pendingCount}</div>
<div data-testid="current">{current?.id ?? 'none'}</div>
<div data-testid="for-session-1">{getForSession('session-1')?.id ?? 'none'}</div>
<div data-testid="for-session-2">{getForSession('session-2')?.id ?? 'none'}</div>
<div data-testid="for-session-unknown">{getForSession('session-unknown')?.id ?? 'none'}</div>
<div data-testid="permission-count">{permissions.pendingCount}</div>
<div data-testid="permission-current">{permissions.current?.id ?? 'none'}</div>
<div data-testid="permission-call">{permissionForCall?.id ?? 'none'}</div>
@@ -239,6 +242,23 @@ describe('EventProvider questions', () => {
})
})
it('resolves pending questions per session independently of the global current', async () => {
mocks.listPendingQuestions.mockResolvedValue([pendingQuestion, secondPendingQuestion])
render(<Harness />, { wrapper: createWrapper() })
await userEvent.click(screen.getByRole('button', { name: 'Sync' }))
await waitFor(() => {
expect(screen.getByTestId('count')).toHaveTextContent('2')
})
expect(screen.getByTestId('current')).toHaveTextContent('question-1')
expect(screen.getByTestId('for-session-1')).toHaveTextContent('question-1')
expect(screen.getByTestId('for-session-2')).toHaveTextContent('question-2')
expect(screen.getByTestId('for-session-unknown')).toHaveTextContent('none')
})
it('reconciles stale pending questions after reconnect', async () => {
mocks.listRepos.mockResolvedValue([{ id: 123, fullPath: '/repo' }])
mocks.listPendingQuestions
+7
View File
@@ -158,6 +158,7 @@ interface EventContextValue {
reject: (requestID: string) => Promise<void>
dismiss: (requestID: string, sessionID?: string) => void
getForCallID: (callID: string, sessionID: string) => QuestionRequest | null
getForSession: (sessionID: string) => QuestionRequest | null
hasForSession: (sessionID: string) => boolean
navigateToCurrent: () => void
syncForSession: (directory: string, sessionID: string) => Promise<void>
@@ -404,6 +405,10 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
return (permissionsBySession[sessionID]?.length ?? 0) > 0
}, [permissionsBySession])
const getQuestionForSession = useCallback((sessionID: string): QuestionRequest | null => {
return questionsBySession[sessionID]?.[0] ?? null
}, [questionsBySession])
const hasQuestionsForSession = useCallback((sessionID: string): boolean => {
return (questionsBySession[sessionID]?.length ?? 0) > 0
}, [questionsBySession])
@@ -597,6 +602,7 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
reject: rejectQuestion,
dismiss: removeQuestion,
getForCallID: getQuestionForCallID,
getForSession: getQuestionForSession,
hasForSession: hasQuestionsForSession,
navigateToCurrent: navigateToCurrentQuestion,
syncForSession: syncQuestionsForSession,
@@ -622,6 +628,7 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
rejectQuestion,
removeQuestion,
getQuestionForCallID,
getQuestionForSession,
hasQuestionsForSession,
navigateToCurrentQuestion,
syncQuestionsForSession,