diff --git a/src/renderer/src/components/terminal-pane/pty-transport/recovery/server-outage/remote-server-outage.test.ts b/src/renderer/src/components/terminal-pane/pty-transport/recovery/server-outage/remote-server-outage.test.ts new file mode 100644 index 00000000000..69d76f6bf6b --- /dev/null +++ b/src/renderer/src/components/terminal-pane/pty-transport/recovery/server-outage/remote-server-outage.test.ts @@ -0,0 +1,40 @@ +import { describe, expect, it, vi } from 'vitest' +import type { AppState } from '@/store/types' + +vi.mock('../../../../../lib/workspace/ownership/workspace-runtime-environment', () => ({ + selectWorkspaceRuntimeEnvironmentId: (_state: unknown, worktreeId: string | null) => + worktreeId === 'wt-pick' ? 'pick' : null +})) +vi.mock('@/runtime/hosts/connections/runtime-host-connection-state', () => ({ + runtimeHostConnectionStateForEntry: (entry: { reconnecting?: boolean } | undefined) => + entry?.reconnecting ? 'reconnecting' : 'connected' +})) + +import { selectRetryingOutageEnvironmentId } from './remote-server-outage' + +function state(activeOrgId: string): AppState { + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the selectors read only these fields. + return { + runtimeEnvironments: [ + { + id: 'pick', + name: 'endpass-pick (cloud)', + orcaCloudPaired: true, + orcaCloudPairedAccountId: 'org:eval' + } + ], + cloudAccountIdByEnvironmentId: {}, + orcaProfileAuthStatus: { cloud: { userId: 'u1', activeOrgId } }, + runtimeStatusByEnvironmentId: new Map([['pick', { reconnecting: true }]]) + } as unknown as AppState +} + +describe('reconnect banner scope (STALE-RUN-TARGET)', () => { + it("announces the active team's cloud workspace reconnecting", () => { + expect(selectRetryingOutageEnvironmentId(state('eval'), 'wt-pick')).toBe('pick') + }) + + it("stays quiet for another team's cloud workspace, which the sidebar hides too", () => { + expect(selectRetryingOutageEnvironmentId(state('noplan'), 'wt-pick')).toBeNull() + }) +}) diff --git a/src/renderer/src/components/terminal-pane/pty-transport/recovery/server-outage/remote-server-outage.ts b/src/renderer/src/components/terminal-pane/pty-transport/recovery/server-outage/remote-server-outage.ts index 0fa5797744d..be0071872b8 100644 --- a/src/renderer/src/components/terminal-pane/pty-transport/recovery/server-outage/remote-server-outage.ts +++ b/src/renderer/src/components/terminal-pane/pty-transport/recovery/server-outage/remote-server-outage.ts @@ -6,6 +6,7 @@ import { tailscaleHostOfEndpoint } from '../../../../../../../shared/remote-runt import { selectExecutionHostDisplayLabel } from '@/runtime/hosts/display/execution-host-display-label' import { runtimeHostConnectionStateForEntry } from '@/runtime/hosts/connections/runtime-host-connection-state' import type { RemoteRuntimeRecoveryCause } from '../../remote-runtime/recovery/remote-runtime-recovery-copy' +import { selectOrcaCloudHiddenHostIds } from '@/lib/orca-cloud/use-sidebar-hidden-checkouts' /** Read shared server reconnection once so individual panes do not announce the same outage. */ export function selectRetryingOutageEnvironmentId( @@ -13,7 +14,12 @@ export function selectRetryingOutageEnvironmentId( worktreeId: string | null | undefined ): string | null { const environmentId = selectWorkspaceRuntimeEnvironmentId(state, worktreeId) - if (!environmentId) { + // STALE-RUN-TARGET: another team's cloud workspace is out of scope here (same rule as the + // sidebar), so its dropped connection is not announced; it is checked again on its own team. + if ( + !environmentId || + selectOrcaCloudHiddenHostIds(state).has(toRuntimeExecutionHostId(environmentId)) + ) { return null } // Only reconnecting proves transport loss; checking or failed probes over a live socket do not. diff --git a/src/renderer/src/hooks/composer-state/composer-target-store.ts b/src/renderer/src/hooks/composer-state/composer-target-store.ts index 18e96c7eca6..45219a351b1 100644 --- a/src/renderer/src/hooks/composer-state/composer-target-store.ts +++ b/src/renderer/src/hooks/composer-state/composer-target-store.ts @@ -14,6 +14,7 @@ import type { ComposerDecisions } from './composer-decisions' import type { WorkspaceCreationTargetHint } from '@/lib/workspace/creation/project-host-workspace-target' import { selectWorktreesByRepo } from '@/store/workspaces/catalog/workspace-record-fields' import { selectAllKnownWorkspaceStatuses } from '@/store/workspaces/status/host-workspace-status-columns' +import { selectOrcaCloudHiddenHostIds } from '@/lib/orca-cloud/use-sidebar-hidden-checkouts' export type ComposerStateInput = { initialRepoId?: string @@ -129,6 +130,9 @@ export function useComposerTargetStore(options: ComposerStateInput, decisions: C const eligibleRepos = useMemo(() => getNewWorkspaceDialogEligibleRepos(repos), [repos]) + // STALE-RUN-TARGET: another team's cloud workspace isn't a place to run (same rule as the sidebar). + const hiddenCloudHostIds = useAppStore(selectOrcaCloudHiddenHostIds) + const hostOptions = useMemo( () => buildExecutionHostRegistry({ @@ -140,8 +144,9 @@ export function useComposerTargetStore(options: ComposerStateInput, decisions: C runtimeEnvironments, runtimeStatusByEnvironmentId, hostLabelOverrides: getHostDisplayLabelOverrides(settings) - }), + }).filter((host) => !hiddenCloudHostIds.has(host.id)), [ + hiddenCloudHostIds, repos, settings, sshConnectionStates, diff --git a/src/renderer/src/lib/orca-cloud/use-sidebar-hidden-checkouts.test.ts b/src/renderer/src/lib/orca-cloud/use-sidebar-hidden-checkouts.test.ts index a04dfb40e3c..95219ea3230 100644 --- a/src/renderer/src/lib/orca-cloud/use-sidebar-hidden-checkouts.test.ts +++ b/src/renderer/src/lib/orca-cloud/use-sidebar-hidden-checkouts.test.ts @@ -4,6 +4,7 @@ import { EMPTY_PENDING_VM_CHECKOUT_INDEX } from '../../../../shared/pending-vm-c import { withOrcaCloudHosts } from '@/runtime/ephemeral-vm/vm-create-hidden-checkouts' import { parseOrcaCloudHostScopeKey, + selectOrcaCloudHiddenHostIds, selectOrcaCloudHostScopeKey, withoutHiddenHostRepos } from './use-sidebar-hidden-checkouts' @@ -151,3 +152,35 @@ describe('GH-CREATE-NO-ROW hand-off', () => { expect(hidden(pairing('runtime:p'))).toEqual(['runtime:p']) }) }) + +describe('hidden cloud hosts for Run on and the reconnect banner (STALE-RUN-TARGET)', () => { + const state = (activeOrgId: string) => { + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the selector reads only these fields. + return { + runtimeEnvironments: [ + { + id: 'pick', + name: 'endpass-pick (cloud)', + orcaCloudPaired: true, + orcaCloudPairedAccountId: 'org:eval' + } + ], + cloudAccountIdByEnvironmentId: {}, + orcaProfileAuthStatus: { cloud: { userId: 'u1', activeOrgId } } + } as unknown as Pick + } + + it("names another team's paired workspace, the same host the sidebar hides", () => { + expect([...selectOrcaCloudHiddenHostIds(state('noplan'))]).toEqual(['runtime:pick']) + }) + + it("keeps the active team's paired workspace", () => { + expect(selectOrcaCloudHiddenHostIds(state('eval')).size).toBe(0) + }) + + it('answers the same set while nothing changed, so store subscribers do not re-render', () => { + expect(selectOrcaCloudHiddenHostIds(state('noplan'))).toBe( + selectOrcaCloudHiddenHostIds(state('noplan')) + ) + }) +}) diff --git a/src/renderer/src/lib/orca-cloud/use-sidebar-hidden-checkouts.ts b/src/renderer/src/lib/orca-cloud/use-sidebar-hidden-checkouts.ts index c953844e6d7..f94ae5f58ff 100644 --- a/src/renderer/src/lib/orca-cloud/use-sidebar-hidden-checkouts.ts +++ b/src/renderer/src/lib/orca-cloud/use-sidebar-hidden-checkouts.ts @@ -73,6 +73,21 @@ export function parseOrcaCloudHostScopeKey(key: string): { return { primaryHostIds, pairedHostIds, hiddenHostIds } } +let hiddenCache: { key: string; ids: ReadonlySet } | null = null + +/** + * STALE-RUN-TARGET: the Orca Cloud hosts the sidebar scopes out (another team's sandbox, owned or + * PAIRED). Run on and the reconnect banner use the same rule, so a team switch never leaves another + * team's workspace listed as a place to run, or announced as reconnecting, where it can't be used. + */ +export function selectOrcaCloudHiddenHostIds(state: CloudScopeState): ReadonlySet { + const key = selectOrcaCloudHostScopeKey(state) + if (hiddenCache?.key !== key) { + hiddenCache = { key, ids: parseOrcaCloudHostScopeKey(key).hiddenHostIds } + } + return hiddenCache.ids +} + /** * What sidebar lists hide: VM checkouts whose create is in progress, an Orca Cloud clone beside its * listed workspace, and every row of another team's sandbox.