fix(settings): gate project path setup on host connection (#9410)

Co-authored-by: linshengtao <linshengtao@bytedance.com>
Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com>
This commit is contained in:
s546126
2026-07-23 23:38:43 -07:00
committed by GitHub
co-authored by linshengtao Brennan Benson
parent 817197fc31
commit 92696558c3
10 changed files with 128 additions and 20 deletions
@@ -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<void> => {
if (!setupTargetHostId || !canUseSetupTargetHost || !setupPath.trim()) {
if (!setupTargetHostId || !canUsePathActions || !setupPath.trim()) {
return
}
setIsSettingUp(true)
@@ -110,12 +115,7 @@ export function RepositoryHostSetupActions({
}
const handleClone = async (): Promise<void> => {
if (
!setupTargetHostId ||
!canUseSetupTargetHost ||
!cloneUrl.trim() ||
!cloneDestination.trim()
) {
if (!setupTargetHostId || !canUsePathActions || !cloneUrl.trim() || !cloneDestination.trim()) {
return
}
setIsCloning(true)
@@ -229,7 +229,7 @@ export function RepositoryHostSetupActions({
<SelectItem key={option.id} value={option.id} disabled={!option.isAvailable}>
<span className="min-w-0">
<span className="block truncate">{option.label}</span>
{!option.isAvailable ? (
{!option.isAvailable || !option.canUsePathActions ? (
<span className="block truncate text-[11px] text-muted-foreground">
{option.detail}
</span>
@@ -239,14 +239,15 @@ export function RepositoryHostSetupActions({
))}
</SelectContent>
</Select>
{!canUseSetupTargetHost && setupTargetHostOption ? (
{(!canUseSetupTargetHost || !canUsePathActions) && setupTargetHostOption ? (
<p className="text-xs text-muted-foreground">{setupTargetHostOption.detail}</p>
) : null}
</div>
{step === 'choose' ? (
<HostSetupStartActions
disabled={!canUseSetupTargetHost}
pathActionsDisabled={!canUsePathActions}
planDisabled={!canUseSetupTargetHost}
onBrowse={() => setStep('existing')}
onClone={() => setStep('clone')}
onPlan={() => setStep('planned')}
@@ -256,7 +257,7 @@ export function RepositoryHostSetupActions({
<HostSetupExistingFolderStep
setupPath={setupPath}
setupKind={setupKind}
disabled={!canUseSetupTargetHost}
disabled={!canUsePathActions}
isSettingUp={isSettingUp}
onBack={() => setStep('choose')}
onPathChange={setSetupPath}
@@ -268,7 +269,7 @@ export function RepositoryHostSetupActions({
<HostSetupCloneStep
cloneUrl={cloneUrl}
cloneDestination={cloneDestination}
disabled={!canUseSetupTargetHost}
disabled={!canUsePathActions}
isCloning={isCloning}
onBack={() => setStep('choose')}
onCloneUrlChange={setCloneUrl}
@@ -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' }),
@@ -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"
/>
@@ -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({
@@ -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
}
})
}
+1
View File
@@ -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",
+1
View File
@@ -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",
+1
View File
@@ -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": "既存フォルダをインポート",
+1
View File
@@ -6285,6 +6285,7 @@
"removeSetup": "제거",
"hostSetupBlockedVersion": "Orca 서버 버전이 호환되지 않습니다.",
"hostSetupMissingCapability": "프로젝트를 설정하려면 이 호스트의 Orca를 업데이트하세요.",
"hostSetupConnectionRequired": "프로젝트를 가져오거나 클론하기 전에 이 호스트에 연결하세요.",
"setupProjectOnHost": "다른 호스트에 설정",
"setupProjectOnHostHelp": "호스트를 선택한 뒤 기존 체크아웃을 가져오거나, repos를 클론하거나, 나중에 준비될 설정을 추적합니다.",
"setupExistingFolder": "기존 폴더 가져오기",
+1
View File
@@ -6285,6 +6285,7 @@
"removeSetup": "移除",
"hostSetupBlockedVersion": "Orca 服务器版本不兼容",
"hostSetupMissingCapability": "在此主机上更新 Orca 以设置项目",
"hostSetupConnectionRequired": "请先连接此主机,再导入或克隆项目",
"setupProjectOnHost": "在其他主机上设置",
"setupProjectOnHostHelp": "选择一台主机,然后导入已有检出、在那里克隆仓库,或跟踪稍后才配置的设置。",
"setupExistingFolder": "导入现有文件夹",