Skip to content

The agent that grows with you

fix(desktop): satisfy eslint and the late-result surface in quick-entry tests

Brooklyn Nicholson7e3e13573ad2
diff --git a/apps/desktop/src/app/chat/session-tile-actions.test.ts b/apps/desktop/src/app/chat/session-tile-actions.test.ts
index 76837bed3cd..d9d0c67b302 100644
--- a/apps/desktop/src/app/chat/session-tile-actions.test.ts
+++ b/apps/desktop/src/app/chat/session-tile-actions.test.ts
@@ -327,7 +327,7 @@ describe('useSessionTileActions reloadFromMessage failed-submit rollback (#95745
executeSlash: vi.fn(async () => undefined),
interruptSession: vi.fn(async () => undefined),
resumeTile,
- submitToSession: vi.fn(async () => undefined),
+ submitToSession: vi.fn(async () => ({ runtimeSessionId: RUNTIME_SESSION_ID, storedSessionId: null })),
updateSession: vi.fn((_runtimeId, updater) => {
const current = $sessionStates.get()[RUNTIME_SESSION_ID]
diff --git a/apps/desktop/src/app/contrib/hooks/use-quick-entry-bridge.test.ts b/apps/desktop/src/app/contrib/hooks/use-quick-entry-bridge.test.ts
index c7b49f75bdb..6f310bc5eea 100644
--- a/apps/desktop/src/app/contrib/hooks/use-quick-entry-bridge.test.ts
+++ b/apps/desktop/src/app/contrib/hooks/use-quick-entry-bridge.test.ts
@@ -1,9 +1,12 @@
import { act, createElement } from 'react'
import { createRoot, type Root } from 'react-dom/client'
import { afterEach, describe, expect, it, vi } from 'vitest'
-import { useQuickEntryBridge, quickEntrySubmitAck } from './use-quick-entry-bridge'
+
+import type * as QuickEntryModule from '@/store/quick-entry'
import { sessionTileDelegate } from '@/store/session-states'
+import { quickEntrySubmitAck, useQuickEntryBridge } from './use-quick-entry-bridge'
+
const registeredSubmitHandler = vi.hoisted(() => ({
current: null as ((payload: { correlationId: string; target: string; text: string }) => void) | null
}))
@@ -12,7 +15,7 @@ type SubmitTextForBridge = Parameters<typeof useQuickEntryBridge>[0]['submitText
type SubmitTextToNewSessionForBridge = Parameters<typeof useQuickEntryBridge>[0]['submitTextToNewSession']
vi.mock('@/store/quick-entry', async importOriginal => {
- const actual = await importOriginal<typeof import('@/store/quick-entry')>()
+ const actual = await importOriginal<typeof QuickEntryModule>()
return {
...actual,
@@ -97,8 +100,10 @@ describe('useQuickEntryBridge', () => {
const submitText = vi.fn(async (text: string, options?: Parameters<SubmitTextForBridge>[1]) => {
options?.onAccepted?.({ runtimeSessionId: 'rt-current-1', storedSessionId: 'st-current-1' })
expect(text).toBe('Send to current chat')
+
return true
})
+
const { container, submit } = await renderBridge(submitText)
await act(async () => {
@@ -118,10 +123,12 @@ describe('useQuickEntryBridge', () => {
it('passes the correlation id as the new-session pin owner', async () => {
const correlationId = 'new-submit-correlation'
const ackSubmit = vi.fn()
+
const submitTextToNewSession = vi.fn(async () => ({
runtimeSessionId: 'runtime-new',
sessionId: 'stored-new'
}))
+
window.hermesDesktop = {
quickEntry: {
ackSubmit,
@@ -240,10 +247,12 @@ describe('useQuickEntryBridge', () => {
} as unknown as typeof window.hermesDesktop
const resumeTile = vi.fn(async () => 'runtime-session-1')
+
const submitToSession = vi.fn(async () => ({
runtimeSessionId: 'runtime-session-1',
storedSessionId: 'stored-session-1'
}))
+
vi.mocked(sessionTileDelegate).mockReturnValue({
resumeTile,
submitToSession
@@ -284,10 +293,12 @@ describe('useQuickEntryBridge', () => {
} as unknown as typeof window.hermesDesktop
const resumeTile = vi.fn(async () => 'runtime-session-before-recovery')
+
const submitToSession = vi.fn(async () => ({
runtimeSessionId: 'runtime-session-recovered',
storedSessionId: 'stored-session-1'
}))
+
vi.mocked(sessionTileDelegate).mockReturnValue({
resumeTile,
submitToSession
@@ -320,10 +331,12 @@ describe('useQuickEntryBridge', () => {
} as unknown as typeof window.hermesDesktop
const resumeTile = vi.fn(async () => 'runtime-session-1')
+
const submitToSession = vi.fn(async () => ({
runtimeSessionId: 'runtime-session-1',
storedSessionId: 'other-session'
}))
+
vi.mocked(sessionTileDelegate).mockReturnValue({
resumeTile,
submitToSession
@@ -357,10 +370,12 @@ describe('useQuickEntryBridge', () => {
} as unknown as typeof window.hermesDesktop
const resumeTile = vi.fn(async () => 'runtime-session-1')
+
const submitToSession = vi.fn(async () => ({
runtimeSessionId: 'runtime-session-1',
storedSessionId: null
}))
+
vi.mocked(sessionTileDelegate).mockReturnValue({
resumeTile,
submitToSession
@@ -394,9 +409,11 @@ describe('useQuickEntryBridge', () => {
} as unknown as typeof window.hermesDesktop
const resumeTile = vi.fn(async () => 'runtime-session-1')
+
const submitToSession = vi.fn(async () => {
throw new Error('gateway down')
})
+
vi.mocked(sessionTileDelegate).mockReturnValue({
resumeTile,
submitToSession
@@ -432,10 +449,12 @@ describe('useQuickEntryBridge', () => {
const resumeTile = vi.fn(async () => {
throw new Error('resume failed')
})
+
const submitToSession = vi.fn(async () => ({
runtimeSessionId: 'runtime-session-1',
storedSessionId: 'stored-session-1'
}))
+
vi.mocked(sessionTileDelegate).mockReturnValue({
resumeTile,
submitToSession
diff --git a/apps/desktop/src/app/quick-entry/quick-entry-app.test.tsx b/apps/desktop/src/app/quick-entry/quick-entry-app.test.tsx
index fe08c2857e5..62470ab29bc 100644
--- a/apps/desktop/src/app/quick-entry/quick-entry-app.test.tsx
+++ b/apps/desktop/src/app/quick-entry/quick-entry-app.test.tsx
@@ -23,6 +23,7 @@ describe('QuickEntryApp', () => {
return vi.fn()
}),
+ onLateResult: vi.fn(() => vi.fn()),
submit: vi.fn()
}
} as never
diff --git a/apps/desktop/src/app/session/hooks/session-context-drift.test.ts b/apps/desktop/src/app/session/hooks/session-context-drift.test.ts
index fdcf6a73207..9d9bda85797 100644
--- a/apps/desktop/src/app/session/hooks/session-context-drift.test.ts
+++ b/apps/desktop/src/app/session/hooks/session-context-drift.test.ts
@@ -3,9 +3,9 @@ import { afterEach, describe, expect, it } from 'vitest'
import { NEW_CHAT_ROUTE, sessionRoute, SETTINGS_ROUTE } from '../../routes'
import {
- pinStoredSessionForOwner,
pinnedOwnerCount,
pinnedStoredSessionIdsForOwner,
+ pinStoredSessionForOwner,
releaseStoredSessionPins,
routeTargetFromToken,
sessionContextDrift
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx b/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx
index 9d1fd27f90b..ec2cfbffa9a 100644
--- a/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-session-actions.test.tsx
@@ -1084,6 +1084,7 @@ describe('submitTextToNewSession pin release', () => {
return {} as never
})
+
let handle: HarnessHandle | null = null
render(
@@ -1105,12 +1106,15 @@ describe('submitTextToNewSession pin release', () => {
it('concurrent new-session submissions keep distinct owner pins', async () => {
const observations: Array<{ promptOwner: 'owner-a' | 'owner-b'; ownerA: string[]; ownerB: string[] }> = []
const runtimeOwner = new Map<string, 'owner-a' | 'owner-b'>()
+
const storedByOwner = {
'owner-a': 'stored-owner-a',
'owner-b': 'stored-owner-b'
} as const
+
let createCount = 0
const releaseCreates = deferred<void>()
+
const requestGateway = vi.fn(async (method: string, params?: Record<string, unknown>) => {
if (method === 'session.create') {
createCount += 1
@@ -1140,6 +1144,7 @@ describe('submitTextToNewSession pin release', () => {
return {} as never
})
+
let handle: HarnessHandle | null = null
render(
@@ -1173,6 +1178,7 @@ describe('submitTextToNewSession pin release', () => {
expect(observations).toHaveLength(2)
expect(observations.map(({ promptOwner }) => promptOwner).sort()).toEqual(['owner-a', 'owner-b'])
+
for (const observation of observations) {
const ownPins = observation.promptOwner === 'owner-a' ? observation.ownerA : observation.ownerB
const otherPins = observation[observation.promptOwner === 'owner-a' ? 'ownerB' : 'ownerA']
@@ -1183,6 +1189,7 @@ describe('submitTextToNewSession pin release', () => {
)
expect(otherPins).not.toContain(storedByOwner[observation.promptOwner])
}
+
expect(pinnedOwnerCount()).toBe(0)
})
@@ -1198,6 +1205,7 @@ describe('submitTextToNewSession pin release', () => {
return {} as never
})
+
let handle: HarnessHandle | null = null
render(
@@ -1223,6 +1231,7 @@ describe('submitTextToNewSession pin release', () => {
// settle is drift: the minted session must not receive the prompt and the
// caller gets a retryable failure, not a silent misroute.
const createPending = deferred<Record<string, string>>()
+
const requestGateway = vi.fn(async (method: string) => {
if (method === 'session.create') {
return (await createPending.promise) as never
@@ -1230,14 +1239,15 @@ describe('submitTextToNewSession pin release', () => {
return {} as never
})
+
const selectedRef = { current: 'stored-original' as string | null }
let routeToken = 'route:a'
let handle: HarnessHandle | null = null
render(
<Harness
- getRouteToken={() => routeToken}
getRoutedStoredSessionId={() => 'stored-original'}
+ getRouteToken={() => routeToken}
onReady={value => (handle = value)}
requestGateway={requestGateway}
selectedStoredSessionIdRef={selectedRef}
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
index d8772409f84..c4f3c03d9c6 100644
--- a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
+++ b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
@@ -982,9 +982,11 @@ export function useSessionActions({
const params = await desktopSessionCreateParams(resolveNewSessionCwd())
const created = await requestGateway<SessionCreateResponse>('session.create', params)
const stored = created.stored_session_id
+
if (!stored) {
throw new Error('The new session did not return a stored id.')
}
+
// Only a genuine user move to a DIFFERENT chat mid-create orphans the
// minted session; our own re-home below names it, so it is not drift.
const drift = sessionContextDrift({
@@ -1004,6 +1006,7 @@ export function useSessionActions({
// it (quick entry); otherwise this call owns its own generation.
const pinOwner = owner ?? `new-session-${created.session_id}`
pinStoredSessionForOwner(pinOwner, stored)
+
try {
markSessionCreatedThisRun(stored)
runtimeIdByStoredSessionIdRef.current.set(stored, created.session_id)
@@ -1013,9 +1016,8 @@ export function useSessionActions({
// atomic path cannot fall back to a route token (#85590).
await requestGateway('prompt.submit', { session_id: created.session_id, text })
navigate(sessionRoute(stored), { replace: true })
+
return { runtimeSessionId: created.session_id, sessionId: stored }
- } catch (error) {
- throw error
} finally {
// Terminal transition for this owner: accepted, failed, or cancelled.
// Owner-scoped pins cannot strand another request, so no tick budget is
diff --git a/apps/desktop/src/store/quick-entry.test.ts b/apps/desktop/src/store/quick-entry.test.ts
index 32615ade9c0..536d439640a 100644
--- a/apps/desktop/src/store/quick-entry.test.ts
+++ b/apps/desktop/src/store/quick-entry.test.ts
@@ -7,8 +7,8 @@ import {
type QuickComposerEvent,
quickComposerReducer,
type QuickComposerState,
- type QuickEntrySubmitPayload,
quickEntryResultEvent,
+ type QuickEntrySubmitPayload,
type QuickEntrySubmitResult
} from './quick-entry'
@@ -72,6 +72,7 @@ describe('quickComposerReducer', () => {
it('submit-error keeps the draft visible, records the error, and refocuses on retry', () => {
const { state } = run([connect, { draft: ' keep me ', type: 'edit' }, { submitId: 7, type: 'submit' }])
+
const failed = quickComposerReducer(state, {
message: 'Delivery failed',
submitId: 7,
@@ -110,6 +111,7 @@ describe('quickComposerReducer', () => {
{ draft: 'resume here', type: 'edit' },
{ submitId: 1, type: 'submit' }
])
+
const current = run([connect, { draft: 'current here', type: 'edit' }, { submitId: 2, type: 'submit' }])
expect(resumed.sent).toEqual([{ target: 's2', text: 'resume here' }])
@@ -271,6 +273,7 @@ describe('quickComposerReducer', () => {
{ submitId: 7, type: 'submit' },
{ type: 'dismiss' }
]).state
+
const state = quickComposerReducer(dismissed, { type: 'shown' }).state
expect(state.draft).toBe('pending prompt')
@@ -287,6 +290,7 @@ describe('quickComposerReducer', () => {
{ submitId: 7, type: 'submit' },
{ type: 'dismiss' }
]).state
+
const shown = quickComposerReducer(dismissed, { type: 'shown' }).state
const state = quickComposerReducer(shown, { submitId: 7, type: 'submit-ok' }).state
@@ -317,6 +321,7 @@ describe('quickComposerReducer', () => {
{ submitId: 7, type: 'submit' },
{ message: 'may still be delivered', submitId: 7, type: 'submit-unknown' }
])
+
const retried = run(
[
{ draft: 'try again', type: 'edit' },
@@ -384,6 +389,7 @@ describe('quickComposerReducer', () => {
{ submitId: 7, type: 'submit' },
{ message: 'may still be delivered', submitId: 7, type: 'submit-unknown' }
]).state
+
const state = quickComposerReducer(unknown, { submitId: 7, type: 'submit-ok' }).state
expect(state.draft).toBe('')
@@ -398,6 +404,7 @@ describe('quickComposerReducer', () => {
{ submitId: 7, type: 'submit' },
{ message: 'may still be delivered', submitId: 7, type: 'submit-unknown' }
]).state
+
const state = quickComposerReducer(unknown, { message: 'rejected', submitId: 7, type: 'submit-error' }).state
expect(state.draft).toBe('pending prompt')