Skip to content

The agent that grows with you

fix(desktop): fold the confirm gate into the existing selecting guard; trim tests to two invariants

teknium1014f395b7411
diff --git a/apps/desktop/src/app/settings/terminal-backend-panel.test.tsx b/apps/desktop/src/app/settings/terminal-backend-panel.test.tsx
index 6fecc3caa39..60c8df10b54 100644
--- a/apps/desktop/src/app/settings/terminal-backend-panel.test.tsx
+++ b/apps/desktop/src/app/settings/terminal-backend-panel.test.tsx
@@ -136,28 +136,6 @@ describe('TerminalBackendPanel', () => {
expect(screen.getByText(/Docker daemon not reachable/)).toBeTruthy()
})
- it('does not stack a second confirm dialog on a double click while one is pending', async () => {
- const confirmGate = deferred<boolean>()
- confirmMock.mockReturnValue(confirmGate.promise)
- const { TerminalBackendPanel } = await import('./terminal-backend-panel')
- render(<TerminalBackendPanel onConfiguredChange={vi.fn()} />)
-
- const dockerButton = await screen.findByRole('button', { name: /Docker/ })
- fireEvent.click(dockerButton)
- fireEvent.click(dockerButton)
- fireEvent.click(dockerButton)
-
- await waitFor(() => expect(confirmMock).toHaveBeenCalledTimes(1))
-
- await act(async () => {
- confirmGate.resolve(true)
- await confirmGate.promise
- })
-
- // Only one selection is ever issued, matching the single confirm call.
- await waitFor(() => expect(selectTerminalBackend).toHaveBeenCalledTimes(1))
- })
-
it('does not select a needs_setup backend when the confirm dialog is declined', async () => {
const confirmGate = deferred<boolean>()
confirmMock.mockReturnValue(confirmGate.promise)
@@ -185,10 +163,7 @@ describe('TerminalBackendPanel', () => {
fireEvent.click(await screen.findByRole('button', { name: /Local/ }))
- // Local is already active: handleSelect's guard clause returns before
- // calling confirm() or selectTerminalBackend() at all, so there is no
- // async boundary to wait on — assert immediately instead of sleeping.
- expect(confirmMock).not.toHaveBeenCalled()
+ await new Promise(resolve => setTimeout(resolve, 50))
expect(selectTerminalBackend).not.toHaveBeenCalled()
})
})
diff --git a/apps/desktop/src/app/settings/terminal-backend-panel.tsx b/apps/desktop/src/app/settings/terminal-backend-panel.tsx
index 345d86076b0..db3a19ae268 100644
--- a/apps/desktop/src/app/settings/terminal-backend-panel.tsx
+++ b/apps/desktop/src/app/settings/terminal-backend-panel.tsx
@@ -43,11 +43,10 @@ function StatusPill({ backend }: { backend: TerminalBackendInfo }) {
* `terminal.backend` config enum. Each backend row carries a live health probe
* (Docker daemon reachable, SSH host configured, Modal/Daytona credentials
* present) so users see Ready / Needs-setup guidance instead of a bare
- * dropdown. Selecting a needs-setup backend is allowed — the row shows what's
- * missing rather than blocking, matching the CLI configurator — but it is
- * persisted immediately and every session that re-reads the config afterward
- * inherits a backend that can't run anything, so we gate it behind an
- * explicit confirm() first.
+ * dropdown. Selecting a needs-setup backend is still allowed (matching the CLI
+ * configurator) but goes through a confirm step first: the write persists
+ * immediately and every later session inherits a backend with no terminal or
+ * file tools, so one ambient click must not do that silently.
*/
export function TerminalBackendPanel({ onConfiguredChange }: TerminalBackendPanelProps) {
const { t } = useI18n()
@@ -55,7 +54,6 @@ export function TerminalBackendPanel({ onConfiguredChange }: TerminalBackendPane
const [data, setData] = useState<TerminalBackendsResponse | null>(null)
const [loading, setLoading] = useState(true)
const [selecting, setSelecting] = useState<string | null>(null)
- const [confirming, setConfirming] = useState<string | null>(null)
const refresh = useCallback(async () => {
setLoading(true)
@@ -74,33 +72,27 @@ export function TerminalBackendPanel({ onConfiguredChange }: TerminalBackendPane
}, [refresh])
async function handleSelect(backend: TerminalBackendInfo) {
- if (backend.active || selecting || confirming) {
+ if (backend.active || selecting) {
return
}
- if (backend.status === 'needs_setup') {
- setConfirming(backend.name)
- let proceed: boolean
- try {
- proceed = await confirm({
+ setSelecting(backend.name)
+
+ try {
+ if (backend.status === 'needs_setup') {
+ const proceed = await confirm({
title: copy.needsSetupConfirmTitle(backend.label),
description: backend.detail
? copy.needsSetupConfirmDescription(backend.detail)
: copy.needsSetupConfirmDescriptionGeneric,
confirmLabel: copy.needsSetupConfirmAction
})
- } finally {
- setConfirming(null)
- }
- if (!proceed) {
- return
+ if (!proceed) {
+ return
+ }
}
- }
-
- setSelecting(backend.name)
- try {
await selectTerminalBackend(backend.name)
// Mirror the backend write locally so the active highlight tracks the
// new selection without a refetch (probes are unchanged by a select).
@@ -153,7 +145,7 @@ export function TerminalBackendPanel({ onConfiguredChange }: TerminalBackendPane
? 'border-(--ui-stroke-secondary) bg-(--ui-bg-tertiary)'
: 'border-transparent bg-background/55 hover:bg-accent/40'
)}
- disabled={selecting !== null || confirming !== null}
+ disabled={selecting !== null}
key={backend.name}
onClick={() => void handleSelect(backend)}
type="button"