diff --git a/src/renderer/src/components/NewWorkspaceComposerCard.test.tsx b/src/renderer/src/components/NewWorkspaceComposerCard.test.tsx index 2883fdc5c..e3af7f426 100644 --- a/src/renderer/src/components/NewWorkspaceComposerCard.test.tsx +++ b/src/renderer/src/components/NewWorkspaceComposerCard.test.tsx @@ -3,18 +3,43 @@ import React from 'react' import { act } from 'react' import { createRoot, type Root } from 'react-dom/client' -import { afterEach, describe, expect, it, vi } from 'vitest' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import NewWorkspaceComposerCard from './NewWorkspaceComposerCard' import type { NewWorkspaceProjectOption } from '@/lib/new-workspace-project-options' +import type { ProjectHostSetupOption } from '@/lib/project-host-setup-options' + +const storeMocks = vi.hoisted(() => ({ + closeModal: vi.fn(), + openModal: vi.fn(), + openSettingsPage: vi.fn(), + openSettingsTarget: vi.fn(), + setRuntimeEnvironmentStatus: vi.fn() +})) + +const apiMocks = vi.hoisted(() => ({ + runtimeGetStatus: vi.fn(), + sshConnect: vi.fn() +})) vi.mock('@/store', () => ({ - useAppStore: (selector: (state: unknown) => unknown) => - selector({ - openModal: vi.fn(), - activeModal: null, - settings: { defaultTuiAgent: null, disabledTuiAgents: [] }, - updateSettings: vi.fn() - }) + useAppStore: Object.assign( + (selector: (state: unknown) => unknown) => + selector({ + closeModal: storeMocks.closeModal, + openModal: storeMocks.openModal, + openSettingsPage: storeMocks.openSettingsPage, + openSettingsTarget: storeMocks.openSettingsTarget, + setRuntimeEnvironmentStatus: storeMocks.setRuntimeEnvironmentStatus, + activeModal: 'none', + settings: { defaultTuiAgent: null, disabledTuiAgents: [] }, + updateSettings: vi.fn() + }), + { + getState: () => ({ + setRuntimeEnvironmentStatus: storeMocks.setRuntimeEnvironmentStatus + }) + } + ) })) vi.mock('@/components/contextual-tours/use-contextual-tour', () => ({ @@ -31,6 +56,13 @@ vi.mock('@/components/agent/AgentCombobox', () => ({ default: () => })) +// Stub the host-add dialog to its `mode` — the composer's job is to open it with the right +// mode; the dialog's own SSH/runtime IPC has separate coverage. +vi.mock('@/components/sidebar/AddRemoteHostDialog', () => ({ + AddRemoteHostDialog: ({ mode }: { mode: 'ssh' | 'server' | null }) => + mode ?
: null +})) + vi.mock('@/components/sparse/SparseCheckoutPresetSelect', () => ({ default: () => })) @@ -105,6 +137,59 @@ const sourceRepos = [ } ] +const localReadyHostOption: ProjectHostSetupOption = { + kind: 'ready', + id: 'setup-local', + projectId: 'project-group:platform', + hostId: 'local', + repoId: 'repo-a', + label: 'Local Mac', + detail: 'Orca', + path: '/Users/alice/orca' +} + +const devboxNeedsSetupHostOption: ProjectHostSetupOption = { + kind: 'needs-setup', + id: 'needs-setup:ssh:devbox', + projectId: 'project-group:platform', + hostId: 'ssh:devbox', + label: 'Devbox', + detail: 'Project not set up on this host', + isAvailable: true, + attention: false +} + +const disconnectedDevboxNeedsSetupHostOption: ProjectHostSetupOption = { + kind: 'needs-setup', + id: 'needs-setup:ssh:devbox', + projectId: 'project-group:platform', + hostId: 'ssh:devbox', + label: 'Devbox', + detail: 'Connect this host to set up projects', + isAvailable: false, + attention: false, + connectAction: { kind: 'ssh', targetId: 'devbox' } +} + +const disconnectedBastionNeedsSetupHostOption: ProjectHostSetupOption = { + kind: 'needs-setup', + id: 'needs-setup:ssh:bastion', + projectId: 'project-group:platform', + hostId: 'ssh:bastion', + label: 'Bastion', + detail: 'Connect this host to set up projects', + isAvailable: false, + attention: false, + connectAction: { kind: 'ssh', targetId: 'bastion' } +} + +function findConnectButton(label: string): HTMLButtonElement | undefined { + const item = findRunTargetItem(label) + return [...(item?.querySelectorAll('button') ?? [])].find((button) => + button.textContent?.includes('Connect') + ) +} + function renderCard( overrides: Partial
- {setupConfig.command}
-
- ++@@ -801,6 +1055,61 @@ export default function NewWorkspaceComposerCard({ } openModal('add-repo') }, [onAddProjectOverride, openModal]) + // Why: open the host-add form inline over the composer (not via Settings) so the user's + // in-progress workspace form survives; the new host lands in the store and flows straight + // back into the run-target picker without a navigation round-trip. + const [addRemoteHostMode, setAddRemoteHostMode] = React.useState{setupConfig.command}(null) + const handleAddSshHost = React.useCallback((): void => { + setAddRemoteHostMode('ssh') + }, []) + const handleAddRemoteServer = React.useCallback((): void => { + setAddRemoteHostMode('server') + }, []) + const handleConnectRunTargetHost = React.useCallback( + async (option: NeedsSetupProjectHostOption): Promise => { + const action = option.connectAction + if (!action) { + return + } + try { + if (action.kind === 'ssh') { + // Why: ssh.connect has no built-in timeout; a stalled connect would otherwise leave the + // row's spinner/disabled state stuck forever. Bound the UI wait — the backend keeps + // connecting and the picker updates from store SSH state if it later succeeds. + await withUiConnectTimeout(window.api.ssh.connect({ targetId: action.targetId })) + return + } + + const response = await window.api.runtimeEnvironments.getStatus({ + selector: action.environmentId, + timeoutMs: 15_000 + }) + const runtimeStatus = unwrapRuntimeRpcResult (response) + // Why: the composer button is only a reachability retry; the separate + // project setup flow remains a follow-up once the host is online. + useAppStore.getState().setRuntimeEnvironmentStatus(action.environmentId, { + status: runtimeStatus, + checkedAt: Date.now() + }) + } catch (error) { + if (action.kind === 'runtime') { + useAppStore.getState().setRuntimeEnvironmentStatus(action.environmentId, { + status: null, + checkedAt: Date.now() + }) + } + toast.error( + error instanceof Error + ? error.message + : translate( + 'auto.components.NewWorkspaceComposerCard.hostConnectionFailed', + 'Connection failed' + ) + ) + } + }, + [] + ) const handleNotePaste = React.useCallback((event: React.ClipboardEvent ) => { const text = event.clipboardData.getData('text/plain') const byteLengthMeasurement = measureTextControlPasteByteLength(text, { @@ -838,6 +1147,16 @@ export default function NewWorkspaceComposerCard({ () => projectHostSetupOptions.filter((option) => option.kind === 'ready'), [projectHostSetupOptions] ) + const needsSetupProjectHostSetupOptions = React.useMemo( + () => projectHostSetupOptions.filter((option) => option.kind === 'needs-setup'), + [projectHostSetupOptions] + ) + // Why: the picker now also hosts the Add host handoff; even a single ready + // host needs this affordance for users who have not registered the target yet. + const shouldShowRunTargetPicker = + readyProjectHostSetupOptions.length > 0 || + ephemeralVmRecipes.length > 0 || + needsSetupProjectHostSetupOptions.length > 0 const handleProjectHostSetupChange = React.useCallback( (setupId: string): void => { onProjectHostSetupChange?.(setupId) @@ -925,18 +1244,21 @@ export default function NewWorkspaceComposerCard({ )} ) : null} - {readyProjectHostSetupOptions.length > 1 || ephemeralVmRecipes.length > 0 ? ( + {shouldShowRunTargetPicker ? ( ) : null} @@ -1465,6 +1792,10 @@ export default function NewWorkspaceComposerCard({{ephemeralVmRecipeError ? ( @@ -1136,6 +1458,9 @@ export default function NewWorkspaceComposerCard({ {/* Why: keep the Advanced disclosure header grouped with the content below while preserving spacing from the Agent field above. */}
+ {/* Why: -ml-2 pulls the button so its label aligns flush-left with the field labels above + while the padded hover highlight extends past the label on the left. The scroll + container's px-2 inset gives that overhang room so it isn't clipped. */}- {/* Why: `orca.yaml` is the committed source of truth, so the preview reconstructs the real YAML shape rather than a raw shell blob. */} -+ {/* Why: `orca.yaml` is the committed source of truth for shared setup, + so the preview reconstructs the real YAML shape instead of showing a raw + shell blob that hides where the command came from. */} + + + {/* Why: group the run-setup and wait-for-setup toggles in one bordered box so + they read as a single settings cluster, aligned hard-right. */} + {!requiresExplicitSetupChoice || showSetupAgentStartupPolicy ? ( + + {requiresExplicitSetupChoice ? null : ( ++ ) : null} {requiresExplicitSetupChoice ? (+ + {setupRunLabel} + ++ )} + {showSetupAgentStartupPolicy ? ( + // Why: nothing to wait for when setup won't run — disable the toggle and + // dim the label so it reads as inactive (the switch dims itself). ++ onSetupDecisionChange( + resolvedSetupDecision === 'run' ? 'skip' : 'run' + ) + } + ariaLabel={setupRunLabel} + /> + -+ ) : null} ++ {translate( + 'auto.components.NewWorkspaceComposerCard.waitForSetupBeforeAgent', + 'Wait for setup to complete before starting agent' )} - /> + + + {translate( + 'auto.components.NewWorkspaceComposerCard.waitForSetupBeforeAgentHelp', + 'Turn this on when setup installs dependencies, MCP servers, or config files the agent needs during startup.' + )} + - - onSetupDecisionChange(event.target.checked ? 'run' : 'skip') ++ onSetupAgentStartupPolicyChange( + setupAgentStartupPolicy === 'wait-for-setup' + ? 'start-immediately' + : 'wait-for-setup' + ) } - className="sr-only" + ariaLabel={translate( + 'auto.components.NewWorkspaceComposerCard.waitForSetupBeforeAgent', + 'Wait for setup to complete before starting agent' + )} /> - {setupRunLabel} - - ) - } - /> + @@ -1335,39 +1695,6 @@ export default function NewWorkspaceComposerCard({ ) : null}) : null} - - {showSetupAgentStartupPolicy ? ( -- - - {translate( - 'auto.components.NewWorkspaceComposerCard.waitForSetupBeforeAgent', - 'Wait for setup to complete before starting agent' - )} - - - {translate( - 'auto.components.NewWorkspaceComposerCard.waitForSetupBeforeAgentHelp', - 'Turn this on when setup installs dependencies, MCP servers, or config files the agent needs during startup.' - )} - - -- ) : null}- onSetupAgentStartupPolicyChange( - setupAgentStartupPolicy === 'wait-for-setup' - ? 'start-immediately' - : 'wait-for-setup' - ) - } - ariaLabel={translate( - 'auto.components.NewWorkspaceComposerCard.waitForSetupBeforeAgent', - 'Wait for setup to complete before starting agent' - )} - /> -
+ {translate( + 'auto.components.settings.SshTargetForm.3b01ca44a0', + 'Optional. Used for tunneling (e.g. Cloudflare Access, ProxyCommand).' + )} +
++ {translate( + 'auto.components.settings.SshTargetForm.feae1d1e69', + 'Optional. Equivalent to ProxyJump / ssh -J.' + )} +
++ {translate( + 'auto.components.settings.SshTargetForm.53e9aabfc0', + 'Uses OpenSSH multiplexing when available. Turn off for hosts with custom SSH restrictions.' + )} +
++ {translate( + 'auto.components.settings.SshTargetForm.b574994adc', + 'Use End Remote Terminals or Reset Relay when you want to stop them.' + )} +
++ {translate( + 'auto.components.settings.SshTargetForm.1b19b00e93', + 'Bounded timeouts must be between 60 seconds and 7 days.' + )} +
+