feat(workspaces): gate SSH create-from until connected (#2135)
* feat(workspaces): gate ssh create-from until connected * chore: remove ssh workspace design doc
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
CornerDownLeft,
|
||||
FolderPlus,
|
||||
LoaderCircle,
|
||||
PlugZap,
|
||||
Settings2
|
||||
} from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
@@ -29,6 +30,7 @@ import SmartWorkspaceNameField, {
|
||||
type SmartWorkspaceNameSelection
|
||||
} from '@/components/new-workspace/SmartWorkspaceNameField'
|
||||
import type { WorkspaceCreateErrorDisplay } from '@/lib/workspace-create-error-format'
|
||||
import type { SshConnectionStatus } from '../../../shared/ssh-types'
|
||||
|
||||
const isMac = typeof navigator !== 'undefined' && navigator.userAgent.includes('Mac')
|
||||
|
||||
@@ -67,12 +69,28 @@ type NewWorkspaceComposerCardProps = {
|
||||
shouldWaitForSetupCheck: boolean
|
||||
resolvedSetupDecision: 'run' | 'skip' | null
|
||||
createError: WorkspaceCreateErrorDisplay | null
|
||||
selectedRepoConnectionId: string | null
|
||||
selectedRepoSshStatus: SshConnectionStatus | null
|
||||
selectedRepoRequiresConnection: boolean
|
||||
selectedRepoConnectInProgress: boolean
|
||||
onConnectSelectedRepo: () => Promise<void>
|
||||
canUseSparseCheckout: boolean
|
||||
sparsePresets: SparsePreset[]
|
||||
sparseSelectedPresetId: string | null
|
||||
onSparseSelectPreset: (preset: SparsePreset | null) => void
|
||||
}
|
||||
|
||||
const SSH_STATUS_LABELS: Record<SshConnectionStatus, string> = {
|
||||
disconnected: 'SSH not connected',
|
||||
connecting: 'Connecting SSH...',
|
||||
'auth-failed': 'SSH authentication failed',
|
||||
'deploying-relay': 'Preparing SSH connection...',
|
||||
connected: 'Connected',
|
||||
reconnecting: 'Reconnecting SSH...',
|
||||
'reconnection-failed': 'SSH reconnection failed',
|
||||
error: 'SSH connection error'
|
||||
}
|
||||
|
||||
function SetupCommandPreview({
|
||||
setupConfig,
|
||||
headerAction
|
||||
@@ -213,6 +231,11 @@ export default function NewWorkspaceComposerCard({
|
||||
shouldWaitForSetupCheck,
|
||||
resolvedSetupDecision,
|
||||
createError,
|
||||
selectedRepoConnectionId,
|
||||
selectedRepoSshStatus,
|
||||
selectedRepoRequiresConnection,
|
||||
selectedRepoConnectInProgress,
|
||||
onConnectSelectedRepo,
|
||||
canUseSparseCheckout,
|
||||
sparsePresets,
|
||||
sparseSelectedPresetId,
|
||||
@@ -222,6 +245,17 @@ export default function NewWorkspaceComposerCard({
|
||||
const openModal = useAppStore((s) => s.openModal)
|
||||
const defaultTuiAgent = useAppStore((s) => s.settings?.defaultTuiAgent ?? null)
|
||||
const updateSettings = useAppStore((s) => s.updateSettings)
|
||||
const selectedRepoName = React.useMemo(() => {
|
||||
const repo = eligibleRepos.find((candidate) => candidate.id === repoId)
|
||||
return repo?.displayName ?? repo?.path ?? 'This repository'
|
||||
}, [eligibleRepos, repoId])
|
||||
const sshStatusLabel = selectedRepoSshStatus
|
||||
? SSH_STATUS_LABELS[selectedRepoSshStatus]
|
||||
: 'Not connected'
|
||||
const connectButtonLabel =
|
||||
selectedRepoSshStatus === 'disconnected' || selectedRepoSshStatus === null
|
||||
? 'Connect'
|
||||
: 'Reconnect'
|
||||
|
||||
const handleSetDefaultAgent = React.useCallback(
|
||||
(next: TuiAgent | 'blank' | null) => {
|
||||
@@ -303,6 +337,35 @@ export default function NewWorkspaceComposerCard({
|
||||
triggerClassName="h-9 w-full border-input text-sm focus:border-ring focus:ring-[3px] focus:ring-ring/50"
|
||||
showStandaloneAddButton={false}
|
||||
/>
|
||||
{selectedRepoRequiresConnection && selectedRepoConnectionId ? (
|
||||
<div
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
className="flex items-center justify-between gap-3 rounded-md border border-border/70 bg-muted/35 px-3 py-2"
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<div className="truncate text-xs font-medium text-foreground">
|
||||
Connect {selectedRepoName}
|
||||
</div>
|
||||
<div className="mt-0.5 text-[11px] text-muted-foreground">{sshStatusLabel}</div>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="xs"
|
||||
onClick={() => void onConnectSelectedRepo()}
|
||||
disabled={selectedRepoConnectInProgress}
|
||||
className="shrink-0"
|
||||
>
|
||||
{selectedRepoConnectInProgress ? (
|
||||
<LoaderCircle className="size-3.5 animate-spin" />
|
||||
) : (
|
||||
<PlugZap className="size-3.5" />
|
||||
)}
|
||||
{selectedRepoConnectInProgress ? 'Connecting' : connectButtonLabel}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="min-w-0 space-y-1">
|
||||
@@ -323,6 +386,8 @@ export default function NewWorkspaceComposerCard({
|
||||
onLinearIssueSelect={onSmartLinearIssueSelect}
|
||||
selectedSource={smartNameSelection}
|
||||
onClearSelectedSource={onClearSmartNameSelection}
|
||||
disabled={selectedRepoRequiresConnection}
|
||||
disabledPlaceholder="Connect this repo first"
|
||||
onPlainEnter={() => {
|
||||
// Why: Enter on the workspace name advances focus to the next
|
||||
// field (Agent combobox) rather than submitting, letting the user
|
||||
|
||||
@@ -74,6 +74,8 @@ type SmartWorkspaceNameFieldProps = {
|
||||
onClearSelectedSource: () => void
|
||||
inputRef?: React.RefObject<HTMLInputElement | null>
|
||||
onPlainEnter?: () => void
|
||||
disabled?: boolean
|
||||
disabledPlaceholder?: string
|
||||
}
|
||||
|
||||
export type SmartWorkspaceNameSelection = {
|
||||
@@ -136,7 +138,9 @@ export default function SmartWorkspaceNameField({
|
||||
selectedSource,
|
||||
onClearSelectedSource,
|
||||
inputRef,
|
||||
onPlainEnter
|
||||
onPlainEnter,
|
||||
disabled = false,
|
||||
disabledPlaceholder
|
||||
}: SmartWorkspaceNameFieldProps): React.JSX.Element {
|
||||
const {
|
||||
addRepo,
|
||||
@@ -196,6 +200,9 @@ export default function SmartWorkspaceNameField({
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (disabled) {
|
||||
return
|
||||
}
|
||||
// Why: the composer can be opened before any other Linear-aware surface
|
||||
// (TaskPage, IntegrationsPane) has had a chance to refresh status, leaving
|
||||
// `linearStatus.connected=false` even when the user is actually connected.
|
||||
@@ -203,7 +210,24 @@ export default function SmartWorkspaceNameField({
|
||||
if (!linearStatusChecked) {
|
||||
void checkLinearConnection()
|
||||
}
|
||||
}, [checkLinearConnection, linearStatusChecked])
|
||||
}, [checkLinearConnection, disabled, linearStatusChecked])
|
||||
|
||||
useEffect(() => {
|
||||
if (!disabled) {
|
||||
return
|
||||
}
|
||||
setOpen(false)
|
||||
setGithubItems([])
|
||||
setGitlabItems([])
|
||||
setBranches([])
|
||||
setLinearIssues([])
|
||||
setGithubLoading(false)
|
||||
setGitlabLoading(false)
|
||||
setBranchesLoading(false)
|
||||
setLinearLoading(false)
|
||||
setCommandValue('')
|
||||
setCrossRepoPrompt(null)
|
||||
}, [disabled])
|
||||
|
||||
useEffect(() => {
|
||||
const timer = window.setTimeout(() => setDebouncedQuery(value), SEARCH_DEBOUNCE_MS)
|
||||
@@ -226,7 +250,7 @@ export default function SmartWorkspaceNameField({
|
||||
const shouldQueryLinear = mode === 'smart' || mode === 'linear'
|
||||
|
||||
useEffect(() => {
|
||||
if (!shouldQueryGithub || !selectedRepo?.path) {
|
||||
if (disabled || !shouldQueryGithub || !selectedRepo?.path) {
|
||||
setGithubItems([])
|
||||
setGithubLoading(false)
|
||||
return
|
||||
@@ -344,6 +368,7 @@ export default function SmartWorkspaceNameField({
|
||||
}
|
||||
}, [
|
||||
debouncedQuery,
|
||||
disabled,
|
||||
fetchWorkItems,
|
||||
getCachedWorkItems,
|
||||
normalizedGhQuery,
|
||||
@@ -354,7 +379,7 @@ export default function SmartWorkspaceNameField({
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
if (!shouldQueryBranches || !selectedRepo) {
|
||||
if (disabled || !shouldQueryBranches || !selectedRepo) {
|
||||
setBranches([])
|
||||
setBranchesLoading(false)
|
||||
return
|
||||
@@ -385,10 +410,10 @@ export default function SmartWorkspaceNameField({
|
||||
return () => {
|
||||
stale = true
|
||||
}
|
||||
}, [debouncedQuery, selectedRepo, shouldQueryBranches])
|
||||
}, [debouncedQuery, disabled, selectedRepo, shouldQueryBranches])
|
||||
|
||||
useEffect(() => {
|
||||
if (!shouldQueryLinear || !linearStatus.connected) {
|
||||
if (disabled || !shouldQueryLinear || !linearStatus.connected) {
|
||||
setLinearIssues([])
|
||||
setLinearLoading(false)
|
||||
return
|
||||
@@ -421,7 +446,7 @@ export default function SmartWorkspaceNameField({
|
||||
// Why: list/search actions are stable store methods; depending on them
|
||||
// would refetch on unrelated store writes.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [debouncedQuery, linearStatus.connected, shouldQueryLinear])
|
||||
}, [debouncedQuery, disabled, linearStatus.connected, shouldQueryLinear])
|
||||
|
||||
// Why: GitLab paste-URL flow. Watches the debounced query for a GitLab
|
||||
// issue/MR URL (parseGitLabIssueOrMRLink already filters non-GitLab URLs
|
||||
@@ -433,6 +458,7 @@ export default function SmartWorkspaceNameField({
|
||||
useEffect(() => {
|
||||
if (
|
||||
!shouldQueryGitlab ||
|
||||
disabled ||
|
||||
!onGitLabItemSelect ||
|
||||
!selectedRepo?.path ||
|
||||
selectedRepo.connectionId
|
||||
@@ -487,7 +513,7 @@ export default function SmartWorkspaceNameField({
|
||||
return () => {
|
||||
stale = true
|
||||
}
|
||||
}, [mode, onGitLabItemSelect, parsedGlLink, selectedRepo, shouldQueryGitlab])
|
||||
}, [disabled, mode, onGitLabItemSelect, parsedGlLink, selectedRepo, shouldQueryGitlab])
|
||||
|
||||
// Why: when the user is on the GitLab tab (or in 'smart' mix) and
|
||||
// hasn't pasted a URL, surface the project's MRs filtered by the
|
||||
@@ -495,7 +521,7 @@ export default function SmartWorkspaceNameField({
|
||||
// MR list view. Smart mode includes GitLab MRs alongside GitHub
|
||||
// items so the unified picker actually surfaces both providers.
|
||||
useEffect(() => {
|
||||
if ((mode !== 'gitlab' && mode !== 'smart') || !onGitLabItemSelect) {
|
||||
if (disabled || (mode !== 'gitlab' && mode !== 'smart') || !onGitLabItemSelect) {
|
||||
return
|
||||
}
|
||||
if (!selectedRepo?.path || selectedRepo.connectionId) {
|
||||
@@ -542,7 +568,7 @@ export default function SmartWorkspaceNameField({
|
||||
return () => {
|
||||
stale = true
|
||||
}
|
||||
}, [mode, mrStateFilter, onGitLabItemSelect, parsedGlLink, selectedRepo])
|
||||
}, [disabled, mode, mrStateFilter, onGitLabItemSelect, parsedGlLink, selectedRepo])
|
||||
|
||||
const rows = useMemo<RowEntry[]>(() => {
|
||||
const trimmed = value.trim()
|
||||
@@ -760,8 +786,9 @@ export default function SmartWorkspaceNameField({
|
||||
setCrossRepoPrompt(null)
|
||||
}, [debouncedQuery])
|
||||
|
||||
const placeholder =
|
||||
mode === 'smart'
|
||||
const placeholder = disabled
|
||||
? (disabledPlaceholder ?? 'Unavailable')
|
||||
: mode === 'smart'
|
||||
? 'Type a name, #1234, branch, GitHub or Linear URL'
|
||||
: mode === 'github'
|
||||
? 'Search GitHub PRs and issues'
|
||||
@@ -777,7 +804,7 @@ export default function SmartWorkspaceNameField({
|
||||
value={mode}
|
||||
onValueChange={(next) => {
|
||||
setMode(next as SmartNameMode)
|
||||
setOpen(next !== 'text')
|
||||
setOpen(!disabled && next !== 'text')
|
||||
requestAnimationFrame(() => localInputRef.current?.focus({ preventScroll: true }))
|
||||
}}
|
||||
className="gap-0"
|
||||
@@ -827,7 +854,10 @@ export default function SmartWorkspaceNameField({
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
|
||||
<Popover open={open && mode !== 'text'} onOpenChange={setOpen}>
|
||||
<Popover
|
||||
open={!disabled && open && mode !== 'text'}
|
||||
onOpenChange={(next) => setOpen(disabled ? false : next)}
|
||||
>
|
||||
<Command
|
||||
value={commandValue}
|
||||
onValueChange={setCommandValue}
|
||||
@@ -896,12 +926,12 @@ export default function SmartWorkspaceNameField({
|
||||
value={value}
|
||||
onChange={(event) => {
|
||||
onValueChange(event.target.value)
|
||||
if (mode !== 'text') {
|
||||
if (!disabled && mode !== 'text') {
|
||||
setOpen(true)
|
||||
}
|
||||
}}
|
||||
onFocus={() => {
|
||||
if (mode !== 'text') {
|
||||
if (!disabled && mode !== 'text') {
|
||||
setOpen(true)
|
||||
}
|
||||
}}
|
||||
@@ -943,6 +973,7 @@ export default function SmartWorkspaceNameField({
|
||||
}
|
||||
}}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
className="h-9 pl-8 text-sm"
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -52,6 +52,11 @@ import {
|
||||
getFullComposerCreateDisabled,
|
||||
getQuickComposerCreateDisabled
|
||||
} from '@/lib/new-workspace-create-gates'
|
||||
import {
|
||||
canUseRepoBackedComposerSources,
|
||||
getSelectedRepoSshGate,
|
||||
isSshConnectInProgress
|
||||
} from '@/lib/new-workspace-ssh-gate'
|
||||
import { getSuggestedCreatureName } from '@/components/sidebar/worktree-name-suggestions'
|
||||
import type { SmartWorkspaceNameSelection } from '@/components/new-workspace/SmartWorkspaceNameField'
|
||||
import { ensureHooksConfirmed } from '@/lib/ensure-hooks-confirmed'
|
||||
@@ -68,6 +73,7 @@ import {
|
||||
getWorkspaceCreateErrorToastMessage,
|
||||
type WorkspaceCreateErrorDisplay
|
||||
} from '@/lib/workspace-create-error-format'
|
||||
import type { SshConnectionStatus } from '../../../shared/ssh-types'
|
||||
|
||||
export type UseComposerStateOptions = {
|
||||
initialRepoId?: string
|
||||
@@ -166,6 +172,11 @@ export type ComposerCardProps = {
|
||||
selectedRepoPath: string | null
|
||||
/** True when the selected repo is a remote SSH repo. */
|
||||
selectedRepoIsRemote: boolean
|
||||
selectedRepoConnectionId: string | null
|
||||
selectedRepoSshStatus: SshConnectionStatus | null
|
||||
selectedRepoRequiresConnection: boolean
|
||||
selectedRepoConnectInProgress: boolean
|
||||
onConnectSelectedRepo: () => Promise<void>
|
||||
/** Transient inline hint shown next to the Start-from trigger after a repo
|
||||
* switch resets a prior selection (e.g. "was PR #8778"). Null when none. */
|
||||
startFromResetHint: string | null
|
||||
@@ -267,6 +278,8 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
|
||||
const worktreesByRepo = useAppStore((s) => s.worktreesByRepo)
|
||||
const sparsePresetsByRepo = useAppStore((s) => s.sparsePresetsByRepo)
|
||||
const workspaceStatuses = useAppStore((s) => s.workspaceStatuses)
|
||||
const sshConnectionStates = useAppStore((s) => s.sshConnectionStates)
|
||||
const sshConnectedGeneration = useAppStore((s) => s.sshConnectedGeneration)
|
||||
const eligibleRepos = useMemo(() => repos.filter((repo) => isGitRepoKind(repo)), [repos])
|
||||
const draftRepoId = persistDraft ? (newWorkspaceDraft?.repoId ?? null) : null
|
||||
const resolvedInitialWorkspaceStatus = useMemo(
|
||||
@@ -288,6 +301,16 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
|
||||
|
||||
const [internalRepoId, setInternalRepoId] = useState<string>(resolvedInitialRepoId)
|
||||
const repoId = repoIdOverride ?? internalRepoId
|
||||
const selectedRepo = eligibleRepos.find((repo) => repo.id === repoId)
|
||||
const selectedRepoConnectionId = selectedRepo?.connectionId ?? null
|
||||
const selectedRepoSshState = selectedRepoConnectionId
|
||||
? (sshConnectionStates.get(selectedRepoConnectionId) ?? null)
|
||||
: null
|
||||
const { selectedRepoSshStatus, selectedRepoRequiresConnection, selectedRepoConnectInProgress } =
|
||||
getSelectedRepoSshGate({
|
||||
connectionId: selectedRepoConnectionId,
|
||||
status: selectedRepoSshState?.status ?? null
|
||||
})
|
||||
const repoIdRef = useRef(repoId)
|
||||
repoIdRef.current = repoId
|
||||
const setRepoId = useCallback(
|
||||
@@ -369,9 +392,8 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
|
||||
// Why: when the selected repo is remote (has a connectionId), read the
|
||||
// per-connection agent list instead of the local one. This ensures the
|
||||
// Create Workspace dialog shows agents installed on the SSH host, not the
|
||||
// local machine. Derived from eligibleRepos directly because selectedRepo
|
||||
// is declared later in this function.
|
||||
const connectionId = eligibleRepos.find((r) => r.id === repoId)?.connectionId ?? null
|
||||
// local machine.
|
||||
const connectionId = selectedRepoConnectionId
|
||||
const isRemote = typeof connectionId === 'string'
|
||||
const detectedAgentList = useAppStore((s) => {
|
||||
if (isRemote) {
|
||||
@@ -432,8 +454,8 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
|
||||
agentPromptRef.current = agentPrompt
|
||||
const connectionIdRef = useRef(connectionId)
|
||||
connectionIdRef.current = connectionId
|
||||
|
||||
const selectedRepo = eligibleRepos.find((repo) => repo.id === repoId)
|
||||
const selectedRepoConnectionIdRef = useRef(selectedRepoConnectionId)
|
||||
selectedRepoConnectionIdRef.current = selectedRepoConnectionId
|
||||
|
||||
// Why: resolves the selected repo's owner/repo slug so a PR URL pasted
|
||||
// into the workspace name field can be matched against the current repo.
|
||||
@@ -740,6 +762,9 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
|
||||
// on mount (deduped by the store). For remote repos it re-runs when the
|
||||
// selected repo changes so the agent list matches the SSH host.
|
||||
useEffect(() => {
|
||||
if (isRemote && selectedRepoSshStatus !== 'connected') {
|
||||
return
|
||||
}
|
||||
let cancelled = false
|
||||
const detect = isRemote ? ensureRemoteDetectedAgents(connectionId) : ensureDetectedAgents()
|
||||
void detect.then((ids) => {
|
||||
@@ -760,7 +785,7 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
|
||||
// detection targets the correct host. Draft/settings deps are intentionally
|
||||
// excluded — detection is a best-effort PATH snapshot.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [connectionId, isRemote])
|
||||
}, [connectionId, isRemote, selectedRepoSshStatus])
|
||||
|
||||
// Per-repo: load yaml hooks + issue command template.
|
||||
useEffect(() => {
|
||||
@@ -812,15 +837,49 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
|
||||
}
|
||||
}, [commitHookCheckIfCurrent, enableIssueAutomation, loadHookCheckForRepo, repoId, settings])
|
||||
|
||||
const onConnectSelectedRepo = useCallback(async (): Promise<void> => {
|
||||
const targetId = selectedRepoConnectionIdRef.current
|
||||
if (!targetId) {
|
||||
return
|
||||
}
|
||||
const liveState = useAppStore.getState()
|
||||
const liveRepo = liveState.repos.find((repo) => repo.id === repoIdRef.current)
|
||||
if (liveRepo?.connectionId !== targetId) {
|
||||
return
|
||||
}
|
||||
const liveStatus = liveState.sshConnectionStates.get(targetId)?.status ?? null
|
||||
if (liveStatus === 'connected' || isSshConnectInProgress(liveStatus)) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await window.api.ssh.connect({ targetId })
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : 'Failed to connect to repository.')
|
||||
}
|
||||
}, [])
|
||||
|
||||
// Why: warm the Start-from picker's PR cache on composer mount and whenever
|
||||
// the selected repo changes so opening the picker paints instantly from
|
||||
// cache.
|
||||
const canPrefetchSelectedRepoWorkItems = canUseRepoBackedComposerSources({
|
||||
connectionId: selectedRepoConnectionId,
|
||||
status: selectedRepoSshStatus
|
||||
})
|
||||
const prefetchSshConnectedGeneration =
|
||||
selectedRepoConnectionId && selectedRepoSshStatus === 'connected' ? sshConnectedGeneration : 0
|
||||
useEffect(() => {
|
||||
if (!selectedRepo?.path) {
|
||||
if (!selectedRepo?.path || !canPrefetchSelectedRepoWorkItems) {
|
||||
return
|
||||
}
|
||||
prefetchWorkItems(selectedRepo.id, selectedRepo.path, PER_REPO_FETCH_LIMIT, 'is:pr is:open')
|
||||
}, [prefetchWorkItems, selectedRepo?.id, selectedRepo?.path])
|
||||
}, [
|
||||
canPrefetchSelectedRepoWorkItems,
|
||||
prefetchSshConnectedGeneration,
|
||||
prefetchWorkItems,
|
||||
selectedRepo?.id,
|
||||
selectedRepo?.path
|
||||
])
|
||||
|
||||
// Reset setup decision when config / policy changes.
|
||||
useEffect(() => {
|
||||
@@ -1568,6 +1627,7 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
|
||||
!repoId ||
|
||||
!workspaceName ||
|
||||
!selectedRepo ||
|
||||
selectedRepoRequiresConnection ||
|
||||
shouldWaitForSetupCheck ||
|
||||
shouldWaitForIssueAutomationCheck ||
|
||||
(requiresExplicitSetupChoice && !setupDecision) ||
|
||||
@@ -1711,6 +1771,7 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
|
||||
resolvedSetupDecision,
|
||||
resolvedInitialWorkspaceStatus,
|
||||
selectedRepo,
|
||||
selectedRepoRequiresConnection,
|
||||
settings?.agentCmdOverrides,
|
||||
settings?.rightSidebarOpenByDefault,
|
||||
setRightSidebarOpen,
|
||||
@@ -1742,6 +1803,7 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
|
||||
!repoId ||
|
||||
!workspaceName ||
|
||||
!selectedRepo ||
|
||||
selectedRepoRequiresConnection ||
|
||||
(requiresExplicitSetupChoice && !setupDecision) ||
|
||||
sparseError !== null
|
||||
) {
|
||||
@@ -1944,6 +2006,7 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
|
||||
resolvedSetupDecision,
|
||||
resolvedInitialWorkspaceStatus,
|
||||
selectedRepo,
|
||||
selectedRepoRequiresConnection,
|
||||
settings?.agentCmdOverrides,
|
||||
settings?.rightSidebarOpenByDefault,
|
||||
setRightSidebarOpen,
|
||||
@@ -1970,6 +2033,7 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
|
||||
shouldWaitForIssueAutomationCheck,
|
||||
requiresExplicitSetupChoice,
|
||||
hasSetupDecision: Boolean(setupDecision),
|
||||
selectedRepoRequiresConnection,
|
||||
sparseError
|
||||
}
|
||||
const createDisabled =
|
||||
@@ -2027,6 +2091,11 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
|
||||
linkedWorkItem?.type === 'pr' && baseBranch ? linkedWorkItem.number : null,
|
||||
selectedRepoPath: selectedRepo?.path ?? null,
|
||||
selectedRepoIsRemote: Boolean(selectedRepo?.connectionId),
|
||||
selectedRepoConnectionId,
|
||||
selectedRepoSshStatus,
|
||||
selectedRepoRequiresConnection,
|
||||
selectedRepoConnectInProgress,
|
||||
onConnectSelectedRepo,
|
||||
startFromResetHint,
|
||||
note,
|
||||
onNoteChange: setNote,
|
||||
|
||||
@@ -13,6 +13,7 @@ const readyInput: ComposerCreateGateInput = {
|
||||
shouldWaitForIssueAutomationCheck: false,
|
||||
requiresExplicitSetupChoice: false,
|
||||
hasSetupDecision: false,
|
||||
selectedRepoRequiresConnection: false,
|
||||
sparseError: null
|
||||
}
|
||||
|
||||
@@ -47,6 +48,9 @@ describe('new workspace create gates', () => {
|
||||
expect(getQuickComposerCreateDisabled({ ...readyInput, repoId: '' })).toBe(true)
|
||||
expect(getQuickComposerCreateDisabled({ ...readyInput, workspaceSeedName: '' })).toBe(true)
|
||||
expect(getQuickComposerCreateDisabled({ ...readyInput, creating: true })).toBe(true)
|
||||
expect(
|
||||
getQuickComposerCreateDisabled({ ...readyInput, selectedRepoRequiresConnection: true })
|
||||
).toBe(true)
|
||||
expect(
|
||||
getQuickComposerCreateDisabled({
|
||||
...readyInput,
|
||||
|
||||
@@ -6,6 +6,7 @@ export type ComposerCreateGateInput = {
|
||||
shouldWaitForIssueAutomationCheck: boolean
|
||||
requiresExplicitSetupChoice: boolean
|
||||
hasSetupDecision: boolean
|
||||
selectedRepoRequiresConnection: boolean
|
||||
sparseError: string | null
|
||||
}
|
||||
|
||||
@@ -14,6 +15,7 @@ function hasBlockingCreateState(input: ComposerCreateGateInput): boolean {
|
||||
!input.repoId ||
|
||||
!input.workspaceSeedName ||
|
||||
input.creating ||
|
||||
input.selectedRepoRequiresConnection ||
|
||||
(input.requiresExplicitSetupChoice && !input.hasSetupDecision) ||
|
||||
input.sparseError !== null
|
||||
)
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
canUseRepoBackedComposerSources,
|
||||
getSelectedRepoSshGate,
|
||||
isSshConnectInProgress
|
||||
} from './new-workspace-ssh-gate'
|
||||
import type { SshConnectionStatus } from '../../../shared/ssh-types'
|
||||
|
||||
describe('new workspace SSH gate', () => {
|
||||
it('does not gate local repos', () => {
|
||||
expect(getSelectedRepoSshGate({ connectionId: null, status: 'disconnected' })).toEqual({
|
||||
selectedRepoConnectionId: null,
|
||||
selectedRepoSshStatus: null,
|
||||
selectedRepoRequiresConnection: false,
|
||||
selectedRepoConnectInProgress: false
|
||||
})
|
||||
expect(canUseRepoBackedComposerSources({ connectionId: null, status: null })).toBe(true)
|
||||
})
|
||||
|
||||
it('treats connected SSH repos as ready', () => {
|
||||
expect(getSelectedRepoSshGate({ connectionId: 'ssh-1', status: 'connected' })).toEqual({
|
||||
selectedRepoConnectionId: 'ssh-1',
|
||||
selectedRepoSshStatus: 'connected',
|
||||
selectedRepoRequiresConnection: false,
|
||||
selectedRepoConnectInProgress: false
|
||||
})
|
||||
expect(canUseRepoBackedComposerSources({ connectionId: 'ssh-1', status: 'connected' })).toBe(
|
||||
true
|
||||
)
|
||||
})
|
||||
|
||||
it('blocks missing and failed SSH states as connectable', () => {
|
||||
const blockedStatuses: (SshConnectionStatus | null)[] = [
|
||||
null,
|
||||
'disconnected',
|
||||
'auth-failed',
|
||||
'reconnection-failed',
|
||||
'error'
|
||||
]
|
||||
|
||||
for (const status of blockedStatuses) {
|
||||
expect(getSelectedRepoSshGate({ connectionId: 'ssh-1', status })).toMatchObject({
|
||||
selectedRepoConnectionId: 'ssh-1',
|
||||
selectedRepoSshStatus: status,
|
||||
selectedRepoRequiresConnection: true,
|
||||
selectedRepoConnectInProgress: false
|
||||
})
|
||||
expect(canUseRepoBackedComposerSources({ connectionId: 'ssh-1', status })).toBe(false)
|
||||
}
|
||||
})
|
||||
|
||||
it('marks active SSH transitions as blocked and in progress', () => {
|
||||
const inProgressStatuses: SshConnectionStatus[] = [
|
||||
'connecting',
|
||||
'deploying-relay',
|
||||
'reconnecting'
|
||||
]
|
||||
|
||||
for (const status of inProgressStatuses) {
|
||||
expect(isSshConnectInProgress(status)).toBe(true)
|
||||
expect(getSelectedRepoSshGate({ connectionId: 'ssh-1', status })).toMatchObject({
|
||||
selectedRepoRequiresConnection: true,
|
||||
selectedRepoConnectInProgress: true
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,34 @@
|
||||
import type { SshConnectionStatus } from '../../../shared/ssh-types'
|
||||
|
||||
export type SelectedRepoSshGate = {
|
||||
selectedRepoConnectionId: string | null
|
||||
selectedRepoSshStatus: SshConnectionStatus | null
|
||||
selectedRepoRequiresConnection: boolean
|
||||
selectedRepoConnectInProgress: boolean
|
||||
}
|
||||
|
||||
export function isSshConnectInProgress(status: SshConnectionStatus | null): boolean {
|
||||
return status === 'connecting' || status === 'deploying-relay' || status === 'reconnecting'
|
||||
}
|
||||
|
||||
export function getSelectedRepoSshGate(input: {
|
||||
connectionId: string | null | undefined
|
||||
status: SshConnectionStatus | null | undefined
|
||||
}): SelectedRepoSshGate {
|
||||
const selectedRepoConnectionId = input.connectionId ?? null
|
||||
const selectedRepoSshStatus = selectedRepoConnectionId ? (input.status ?? null) : null
|
||||
return {
|
||||
selectedRepoConnectionId,
|
||||
selectedRepoSshStatus,
|
||||
selectedRepoRequiresConnection:
|
||||
selectedRepoConnectionId !== null && selectedRepoSshStatus !== 'connected',
|
||||
selectedRepoConnectInProgress: isSshConnectInProgress(selectedRepoSshStatus)
|
||||
}
|
||||
}
|
||||
|
||||
export function canUseRepoBackedComposerSources(input: {
|
||||
connectionId: string | null | undefined
|
||||
status: SshConnectionStatus | null | undefined
|
||||
}): boolean {
|
||||
return !input.connectionId || input.status === 'connected'
|
||||
}
|
||||
Reference in New Issue
Block a user