From 92696558c3b7d906e62e6fa2a2efd1e1180bd7b7 Mon Sep 17 00:00:00 2001 From: s546126 Date: Thu, 23 Jul 2026 23:38:43 -0700 Subject: [PATCH] fix(settings): gate project path setup on host connection (#9410) Co-authored-by: linshengtao Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> --- .../settings/RepositoryHostSetupActions.tsx | 27 +++++----- .../RepositoryHostSetupsSection.test.tsx | 50 +++++++++++++++++++ .../repository-host-add-project-steps.tsx | 12 +++-- .../repository-host-setup-options.test.ts | 39 +++++++++++++++ .../settings/repository-host-setup-options.ts | 15 +++++- src/renderer/src/i18n/locales/en.json | 1 + src/renderer/src/i18n/locales/es.json | 1 + src/renderer/src/i18n/locales/ja.json | 1 + src/renderer/src/i18n/locales/ko.json | 1 + src/renderer/src/i18n/locales/zh.json | 1 + 10 files changed, 128 insertions(+), 20 deletions(-) diff --git a/src/renderer/src/components/settings/RepositoryHostSetupActions.tsx b/src/renderer/src/components/settings/RepositoryHostSetupActions.tsx index 43be0d1f6..e6edcbe68 100644 --- a/src/renderer/src/components/settings/RepositoryHostSetupActions.tsx +++ b/src/renderer/src/components/settings/RepositoryHostSetupActions.tsx @@ -68,11 +68,16 @@ export function RepositoryHostSetupActions({ const [isCloning, setIsCloning] = useState(false) const [isCreatingPendingSetup, setIsCreatingPendingSetup] = useState(false) const defaultSetupHostOption = - setupHostOptions.find((option) => option.isAvailable) ?? setupHostOptions[0] ?? null + setupHostOptions.find((option) => option.isAvailable && option.canUsePathActions) ?? + setupHostOptions.find((option) => option.isAvailable) ?? + setupHostOptions[0] ?? + null const setupTargetHostId = selectedSetupHostId ?? defaultSetupHostOption?.id ?? null const setupTargetHostOption = setupHostOptions.find((option) => option.id === setupTargetHostId) ?? null const canUseSetupTargetHost = setupTargetHostOption?.isAvailable ?? false + const canUsePathActions = + canUseSetupTargetHost && (setupTargetHostOption?.canUsePathActions ?? false) if (setupHostOptions.length === 0) { return null @@ -88,7 +93,7 @@ export function RepositoryHostSetupActions({ } const handleExistingFolder = async (): Promise => { - if (!setupTargetHostId || !canUseSetupTargetHost || !setupPath.trim()) { + if (!setupTargetHostId || !canUsePathActions || !setupPath.trim()) { return } setIsSettingUp(true) @@ -110,12 +115,7 @@ export function RepositoryHostSetupActions({ } const handleClone = async (): Promise => { - if ( - !setupTargetHostId || - !canUseSetupTargetHost || - !cloneUrl.trim() || - !cloneDestination.trim() - ) { + if (!setupTargetHostId || !canUsePathActions || !cloneUrl.trim() || !cloneDestination.trim()) { return } setIsCloning(true) @@ -229,7 +229,7 @@ export function RepositoryHostSetupActions({ {option.label} - {!option.isAvailable ? ( + {!option.isAvailable || !option.canUsePathActions ? ( {option.detail} @@ -239,14 +239,15 @@ export function RepositoryHostSetupActions({ ))} - {!canUseSetupTargetHost && setupTargetHostOption ? ( + {(!canUseSetupTargetHost || !canUsePathActions) && setupTargetHostOption ? (

{setupTargetHostOption.detail}

) : null} {step === 'choose' ? ( setStep('existing')} onClone={() => setStep('clone')} onPlan={() => setStep('planned')} @@ -256,7 +257,7 @@ export function RepositoryHostSetupActions({ setStep('choose')} onPathChange={setSetupPath} @@ -268,7 +269,7 @@ export function RepositoryHostSetupActions({ setStep('choose')} onCloneUrlChange={setCloneUrl} diff --git a/src/renderer/src/components/settings/RepositoryHostSetupsSection.test.tsx b/src/renderer/src/components/settings/RepositoryHostSetupsSection.test.tsx index 073f68a65..c448002aa 100644 --- a/src/renderer/src/components/settings/RepositoryHostSetupsSection.test.tsx +++ b/src/renderer/src/components/settings/RepositoryHostSetupsSection.test.tsx @@ -54,6 +54,15 @@ function makeSetup( } } +function connectedSshState(targetId: string) { + return { + targetId, + status: 'connected' as const, + error: null, + reconnectAttempt: 0 + } +} + beforeEach(() => { useAppStore.setState(useAppStore.getInitialState(), true) container = document.createElement('div') @@ -437,6 +446,7 @@ describe('RepositoryHostSetupsSection', () => { }) ], sshTargetLabels: new Map([['openclaw 2', 'openclaw 2']]), + sshConnectionStates: new Map([['openclaw 2', connectedSshState('openclaw 2')]]), openSettingsPage, openSettingsTarget, setSettingsProjectHostSelection, @@ -513,6 +523,7 @@ describe('RepositoryHostSetupsSection', () => { }) ], sshTargetLabels: new Map([['openclaw 2', 'openclaw 2']]), + sshConnectionStates: new Map([['openclaw 2', connectedSshState('openclaw 2')]]), openSettingsPage, openSettingsTarget, setSettingsProjectHostSelection, @@ -556,6 +567,45 @@ describe('RepositoryHostSetupsSection', () => { expect(openSettingsTarget).not.toHaveBeenCalled() }) + it('blocks path setup until an SSH host connects but keeps placeholders available', () => { + const localRepo = makeRepo({ + id: 'local-repo', + displayName: 'Orca', + path: '/Users/alice/orca' + }) + useAppStore.setState({ + repos: [localRepo], + projects: [makeProject({ id: 'github:stablyai/orca' })], + projectHostSetups: [ + makeSetup({ + id: 'local-repo', + projectId: 'github:stablyai/orca', + repoId: 'local-repo', + hostId: 'local', + path: '/Users/alice/orca' + }) + ], + sshTargetLabels: new Map([['openclaw 2', 'openclaw 2']]) + }) + + renderSection(localRepo) + clickButton('Add to another host') + + expect(container.textContent).toContain( + 'Connect this host before importing or cloning the project' + ) + expect(findButton('Browse folder')?.disabled).toBe(true) + expect(findButton('Clone from URL')?.disabled).toBe(true) + expect(findButton('Add host placeholder')?.disabled).toBe(false) + + act(() => { + useAppStore.getState().setSshConnectionState('openclaw 2', connectedSshState('openclaw 2')) + }) + + expect(findButton('Browse folder')?.disabled).toBe(false) + expect(findButton('Clone from URL')?.disabled).toBe(false) + }) + it('creates pending setup metadata for a known host without requiring a path', async () => { const createProjectHostSetup = vi.fn().mockResolvedValue({ project: makeProject({ id: 'github:stablyai/orca' }), diff --git a/src/renderer/src/components/settings/repository-host-add-project-steps.tsx b/src/renderer/src/components/settings/repository-host-add-project-steps.tsx index 87640ed44..7a26255fc 100644 --- a/src/renderer/src/components/settings/repository-host-add-project-steps.tsx +++ b/src/renderer/src/components/settings/repository-host-add-project-steps.tsx @@ -7,12 +7,14 @@ import { Input } from '../ui/input' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select' export function HostSetupStartActions({ - disabled, + pathActionsDisabled, + planDisabled, onBrowse, onClone, onPlan }: { - disabled: boolean + pathActionsDisabled: boolean + planDisabled: boolean onBrowse: () => void onClone: () => void onPlan: () => void @@ -26,7 +28,7 @@ export function HostSetupStartActions({ 'auto.components.settings.RepositoryPane.browseFolderHelp', 'Use an existing checkout or folder on this host.' )} - disabled={disabled} + disabled={pathActionsDisabled} selected onClick={onBrowse} /> @@ -45,7 +47,7 @@ export function HostSetupStartActions({ 'auto.components.settings.RepositoryPane.cloneFromUrlHelp', 'Clone this repository onto the selected host.' )} - disabled={disabled} + disabled={pathActionsDisabled} onClick={onClone} className="rounded-t-md" /> @@ -59,7 +61,7 @@ export function HostSetupStartActions({ 'auto.components.settings.RepositoryPane.addPlannedHostHelp', 'Remember this host and finish adding the project later.' )} - disabled={disabled} + disabled={planDisabled} onClick={onPlan} className="rounded-b-md border-t border-border/70" /> diff --git a/src/renderer/src/components/settings/repository-host-setup-options.test.ts b/src/renderer/src/components/settings/repository-host-setup-options.test.ts index 9a48b60b5..6ec07deca 100644 --- a/src/renderer/src/components/settings/repository-host-setup-options.test.ts +++ b/src/renderer/src/components/settings/repository-host-setup-options.test.ts @@ -28,7 +28,46 @@ function runtimeHost( } as ExecutionHostRegistryEntry } +function sshHost(health: ExecutionHostRegistryEntry['health']): ExecutionHostRegistryEntry { + return { + id: 'ssh:ssh-1', + kind: 'ssh', + label: 'SSH Host', + detail: 'SSH', + health + } +} + describe('buildSetupHostOptions', () => { + it('enables connected SSH hosts', () => { + expect( + buildSetupHostOptions({ + projectHostSetups: [], + hostOptions: [sshHost('available')] + })[0] + ).toMatchObject({ + isAvailable: true, + canUsePathActions: true, + detail: 'SSH' + }) + }) + + it.each(['disconnected', 'connecting', 'error'] as const)( + 'disables path actions for %s SSH hosts', + (health) => { + expect( + buildSetupHostOptions({ + projectHostSetups: [], + hostOptions: [sshHost(health)] + })[0] + ).toMatchObject({ + isAvailable: true, + canUsePathActions: false, + detail: 'Connect this host before importing or cloning the project' + }) + } + ) + it('disables runtime hosts while capabilities are unknown', () => { expect( buildSetupHostOptions({ diff --git a/src/renderer/src/components/settings/repository-host-setup-options.ts b/src/renderer/src/components/settings/repository-host-setup-options.ts index b1e571a19..c66d8fd14 100644 --- a/src/renderer/src/components/settings/repository-host-setup-options.ts +++ b/src/renderer/src/components/settings/repository-host-setup-options.ts @@ -12,6 +12,7 @@ export type SetupHostOption = { label: string detail: string isAvailable: boolean + canUsePathActions: boolean } export function getSetupStateLabel(setupState: ProjectHostSetupState): string { @@ -50,11 +51,21 @@ export function buildSetupHostOptions({ .filter((host) => !setupHostIds.has(host.id)) .map((host) => { const availability = getHostSetupAvailability(host) + // Why: import and clone require live remote providers, while an offline + // host can still be recorded as a placeholder for later setup. + const canUsePathActions = host.health === 'local' || host.health === 'available' return { id: host.id, label: host.label || getExecutionHostLabel(host.id), - detail: availability.detail, - isAvailable: availability.isAvailable + detail: + availability.isAvailable && !canUsePathActions + ? translate( + 'auto.components.settings.RepositoryPane.hostSetupConnectionRequired', + 'Connect this host before importing or cloning the project' + ) + : availability.detail, + isAvailable: availability.isAvailable, + canUsePathActions } }) } diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json index 58ce12d68..8d623b7bb 100644 --- a/src/renderer/src/i18n/locales/en.json +++ b/src/renderer/src/i18n/locales/en.json @@ -6359,6 +6359,7 @@ "removeSetup": "Remove", "hostSetupBlockedVersion": "Orca server version is incompatible", "hostSetupMissingCapability": "Update Orca on this host to set up projects", + "hostSetupConnectionRequired": "Connect this host before importing or cloning the project", "setupProjectOnHost": "Set up on another host", "setupProjectOnHostHelp": "Choose a host, then import an existing checkout, clone the repository there, or track a setup that will be provisioned later.", "setupExistingFolder": "Import existing folder", diff --git a/src/renderer/src/i18n/locales/es.json b/src/renderer/src/i18n/locales/es.json index 918675b4c..2ddddbc99 100644 --- a/src/renderer/src/i18n/locales/es.json +++ b/src/renderer/src/i18n/locales/es.json @@ -6300,6 +6300,7 @@ "removeSetup": "Eliminar", "hostSetupBlockedVersion": "La versión del servidor Orca no es compatible", "hostSetupMissingCapability": "Actualiza Orca en este host para configurar proyectos", + "hostSetupConnectionRequired": "Conecta este host antes de importar o clonar el proyecto", "setupProjectOnHost": "Configurar en otro host", "setupProjectOnHostHelp": "Elige un host y luego importa un checkout existente, clona el repositorio allí o registra una configuración que se aprovisionará más tarde.", "setupExistingFolder": "Importar carpeta existente", diff --git a/src/renderer/src/i18n/locales/ja.json b/src/renderer/src/i18n/locales/ja.json index 51c6f1df7..29c477118 100644 --- a/src/renderer/src/i18n/locales/ja.json +++ b/src/renderer/src/i18n/locales/ja.json @@ -6322,6 +6322,7 @@ "removeSetup": "削除", "hostSetupBlockedVersion": "Orca server version is incompatible", "hostSetupMissingCapability": "Update Orca on this host to set up projects", + "hostSetupConnectionRequired": "プロジェクトをインポートまたはクローンする前に、このホストに接続してください", "setupProjectOnHost": "別のホストで設定", "setupProjectOnHostHelp": "Choose a host, then import an existing checkout, clone the repository there, or track a setup that will be provisioned later.", "setupExistingFolder": "既存フォルダをインポート", diff --git a/src/renderer/src/i18n/locales/ko.json b/src/renderer/src/i18n/locales/ko.json index f51816662..f03e1a7c4 100644 --- a/src/renderer/src/i18n/locales/ko.json +++ b/src/renderer/src/i18n/locales/ko.json @@ -6285,6 +6285,7 @@ "removeSetup": "제거", "hostSetupBlockedVersion": "Orca 서버 버전이 호환되지 않습니다.", "hostSetupMissingCapability": "프로젝트를 설정하려면 이 호스트의 Orca를 업데이트하세요.", + "hostSetupConnectionRequired": "프로젝트를 가져오거나 클론하기 전에 이 호스트에 연결하세요.", "setupProjectOnHost": "다른 호스트에 설정", "setupProjectOnHostHelp": "호스트를 선택한 뒤 기존 체크아웃을 가져오거나, repos를 클론하거나, 나중에 준비될 설정을 추적합니다.", "setupExistingFolder": "기존 폴더 가져오기", diff --git a/src/renderer/src/i18n/locales/zh.json b/src/renderer/src/i18n/locales/zh.json index bc3c14b7d..c3bf99eef 100644 --- a/src/renderer/src/i18n/locales/zh.json +++ b/src/renderer/src/i18n/locales/zh.json @@ -6285,6 +6285,7 @@ "removeSetup": "移除", "hostSetupBlockedVersion": "Orca 服务器版本不兼容", "hostSetupMissingCapability": "在此主机上更新 Orca 以设置项目", + "hostSetupConnectionRequired": "请先连接此主机,再导入或克隆项目", "setupProjectOnHost": "在其他主机上设置", "setupProjectOnHostHelp": "选择一台主机,然后导入已有检出、在那里克隆仓库,或跟踪稍后才配置的设置。", "setupExistingFolder": "导入现有文件夹",