diff --git a/src/renderer/src/components/status-bar/SshStatusSegment.tsx b/src/renderer/src/components/status-bar/SshStatusSegment.tsx index 0cf0efc382b..ab2be64160e 100644 --- a/src/renderer/src/components/status-bar/SshStatusSegment.tsx +++ b/src/renderer/src/components/status-bar/SshStatusSegment.tsx @@ -9,6 +9,10 @@ import { DropdownMenuTrigger } from '@/components/ui/dropdown-menu' import { useAppStore } from '../../store/index' +import { + selectOrcaCloudHiddenHostIds, + withoutHiddenHostEnvironments +} from '@/lib/orca-cloud/use-sidebar-hidden-checkouts' import { translate } from '@/i18n/i18n' import { useTranslate } from '@/i18n/use-translate' import { getHostDisplayLabelOverrides } from '../../../../shared/host-setting-overrides' @@ -58,6 +62,8 @@ export function SshStatusSegment({ const settings = useAppStore((s) => s.settings) const runtimeEnvironments = useAppStore((s) => s.runtimeEnvironments) const runtimeStatusByEnvironmentId = useAppStore((s) => s.runtimeStatusByEnvironmentId) + // Another team's cloud sandboxes are not this team's hosts (same scope as the sidebar, #722). + const hiddenCloudHostIds = useAppStore(selectOrcaCloudHiddenHostIds) const readRuntimeHostStatusSnapshots = useAppStore((s) => s.readRuntimeHostStatusSnapshots) const hydrateRuntimeEnvironmentStatuses = useAppStore((s) => s.hydrateRuntimeEnvironmentStatuses) const setActiveView = useAppStore((s) => s.setActiveView) @@ -73,7 +79,10 @@ export function SshStatusSegment({ [repos] ) const hostLabelOverrides = useMemo(() => getHostDisplayLabelOverrides(settings), [settings]) - const userManagedEnvironments = runtimeEnvironments.filter(isListedRemoteServer) + const userManagedEnvironments = withoutHiddenHostEnvironments( + runtimeEnvironments.filter(isListedRemoteServer), + hiddenCloudHostIds + ) // Why the registry: a managed server and its SSH host are one machine, shown on its active route. const visibleHosts = new Map( pickerExecutionHosts( diff --git a/src/renderer/src/lib/orca-cloud/leave-out-of-team-cloud-workspace.test.ts b/src/renderer/src/lib/orca-cloud/leave-out-of-team-cloud-workspace.test.ts index e0e8c415ec1..1193b74afe9 100644 --- a/src/renderer/src/lib/orca-cloud/leave-out-of-team-cloud-workspace.test.ts +++ b/src/renderer/src/lib/orca-cloud/leave-out-of-team-cloud-workspace.test.ts @@ -1,6 +1,9 @@ import { describe, expect, it, vi } from 'vitest' import type { AppState } from '@/store/types' -import { installLeaveOutOfTeamCloudWorkspace } from './leave-out-of-team-cloud-workspace' +import { + activeCloudWorkspaceLeftTeam, + installLeaveOutOfTeamCloudWorkspace +} from './leave-out-of-team-cloud-workspace' const environments = [ { id: 'cusk', name: 'push-test sandbox 1a2b3c4d', source: 'ephemeral-vm' }, @@ -88,3 +91,20 @@ describe('leaving an out-of-team cloud workspace', () => { expect(h.active()).toBe('repo::/w/cusk') }) }) + +describe('a paired cloud workspace of the team switched away (TEAM-SWITCH-STALE-PANE)', () => { + it('leaves it: the paired host went from the team (~) to hidden (-)', () => { + expect(activeCloudWorkspaceLeftTeam('~runtime:eval', '-runtime:eval', 'runtime:eval')).toBe( + true + ) + }) + + it('stays when the paired host is still the team scope, or the host is another one', () => { + expect( + activeCloudWorkspaceLeftTeam('~runtime:eval', '~runtime:eval\n-runtime:x', 'runtime:eval') + ).toBe(false) + expect(activeCloudWorkspaceLeftTeam('~runtime:eval', '-runtime:eval', 'runtime:other')).toBe( + false + ) + }) +}) diff --git a/src/renderer/src/lib/orca-cloud/leave-out-of-team-cloud-workspace.ts b/src/renderer/src/lib/orca-cloud/leave-out-of-team-cloud-workspace.ts index c0498a4933c..4898f2e4972 100644 --- a/src/renderer/src/lib/orca-cloud/leave-out-of-team-cloud-workspace.ts +++ b/src/renderer/src/lib/orca-cloud/leave-out-of-team-cloud-workspace.ts @@ -38,8 +38,11 @@ export function activeCloudWorkspaceLeftTeam( if (!hostId || previousScopeKey === nextScopeKey) { return false } + const previous = parseOrcaCloudHostScopeKey(previousScopeKey) + // TEAM-SWITCH-STALE-PANE: a paired cloud workspace of the team (`~host`, since #690) leaves too, + // or another team's workspace stayed open in the main pane after the switch (n57). return ( - parseOrcaCloudHostScopeKey(previousScopeKey).primaryHostIds.has(hostId) && + (previous.primaryHostIds.has(hostId) || previous.pairedHostIds.has(hostId)) && parseOrcaCloudHostScopeKey(nextScopeKey).hiddenHostIds.has(hostId) ) } 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 95219ea3230..25d041a6420 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 @@ -6,6 +6,7 @@ import { parseOrcaCloudHostScopeKey, selectOrcaCloudHiddenHostIds, selectOrcaCloudHostScopeKey, + withoutHiddenHostEnvironments, withoutHiddenHostRepos } from './use-sidebar-hidden-checkouts' @@ -184,3 +185,14 @@ describe('hidden cloud hosts for Run on and the reconnect banner (STALE-RUN-TARG ) }) }) + +describe('the status bar host list after a team switch (TEAM-SWITCH-STALE-PANE)', () => { + it("drops another team's cloud servers and keeps the rest", () => { + const envs = [{ id: 'eval' }, { id: 'acme' }, { id: 'ssh-box' }] + expect(withoutHiddenHostEnvironments(envs, new Set(['runtime:eval']))).toEqual([ + { id: 'acme' }, + { id: 'ssh-box' } + ]) + expect(withoutHiddenHostEnvironments(envs, new Set())).toBe(envs) + }) +}) 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 f94ae5f58ff..fbf8cba02f6 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 @@ -101,6 +101,23 @@ export function useSidebarHiddenCheckouts(): HiddenVmCheckouts { ) } +/** + * TEAM-SWITCH-STALE-PANE: runtime servers without another team's cloud sandboxes, so the status bar's + * host list and count follow the same team scope as the sidebar (n57: "3 hosts" after the switch). + */ +export function withoutHiddenHostEnvironments( + environments: readonly E[], + hiddenHostIds: ReadonlySet +): readonly E[] { + if (hiddenHostIds.size === 0) { + return environments + } + const kept = environments.filter( + (environment) => !hiddenHostIds.has(toRuntimeExecutionHostId(environment.id)) + ) + return kept.length === environments.length ? environments : kept +} + /** Repos without another team's sandbox projects, so none surfaces as its own project header. */ export function withoutHiddenHostRepos>( repos: readonly R[],