Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import type { AcpClientInfo } from '@/infrastructure/api/service-api/ACPClientAP
import { loadWorkspaceAcpMenuClients } from './workspaceAcpMenuClients';
import WorkspaceAcpSessionSubmenu from './WorkspaceAcpSessionSubmenu';
import SessionsSection from '../sessions/SessionsSection';
import { remoteWorkspaceBadge, type RemoteWorkspaceBadge } from './remoteWorkspaceBadge';
import { useWorkspaceSessionViewStore } from '../../workspaceSessionView';
import {
WorkspaceKind,
Expand Down Expand Up @@ -93,6 +94,8 @@ function containsWorkspaceNameControlCharacter(value: string): boolean {

interface WorkspaceItemProps {
workspace: WorkspaceInfo;
/** Compact remote badge computed across opened workspaces; derived locally when absent. */
remoteBadge?: RemoteWorkspaceBadge;
isActive: boolean;
isSelected: boolean;
isSingle?: boolean;
Expand All @@ -106,6 +109,7 @@ interface WorkspaceItemProps {

const WorkspaceItem: React.FC<WorkspaceItemProps> = ({
workspace,
remoteBadge,
isActive,
isSelected,
isSingle = false,
Expand Down Expand Up @@ -271,17 +275,14 @@ const WorkspaceItem: React.FC<WorkspaceItemProps> = ({
const statusLabel = t(`nav.workspaces.remote.status.${status}`, {
defaultValue: t('nav.workspaces.remote.status.unknown'),
});
const connectionLabel =
workspace.connectionName?.trim()
|| workspace.sshHost?.trim()
|| workspace.connectionId?.trim()
|| '';
const hostLabel = workspace.sshHost?.trim() || connectionLabel;
const badge = remoteBadge ?? remoteWorkspaceBadge(workspace);
const connectionLabel = badge?.connection ?? '';
const hostLabel = badge?.host || connectionLabel;

return {
status,
statusLabel,
connectionLabel,
badgeLabel: badge?.label ?? connectionLabel,
/** A green dot already reads as "fine"; spell out only the states that need attention. */
showStatusText: status !== 'connected',
tooltip: t('nav.workspaces.remote.tooltip', {
Expand All @@ -295,11 +296,10 @@ const WorkspaceItem: React.FC<WorkspaceItemProps> = ({
}),
};
}, [
remoteBadge,
remoteConnStatus,
t,
workspace.connectionId,
workspace.connectionName,
workspace.sshHost,
workspace,
workspaceIsRemote,
]);

Expand Down Expand Up @@ -1318,7 +1318,7 @@ const WorkspaceItem: React.FC<WorkspaceItemProps> = ({
aria-hidden="true"
/>
<span className="openbitfun-nav-panel__workspace-item-remote-host">
{remoteMeta.connectionLabel}
{remoteMeta.badgeLabel}
</span>
{remoteMeta.showStatusText ? (
<span className="openbitfun-nav-panel__workspace-item-remote-status">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,18 @@
text-overflow: clip;
}

/**
* The folder name owns the row; the remote chip is secondary metadata. It may
* shrink to an ellipsis (full details stay in its tooltip) and never takes
* more than a bounded share of the row.
*/
&__workspace-item-remote {
display: inline-flex;
align-items: center;
gap: var(--openbitfun-space-2);
flex: 0 0 auto;
flex: 0 1 auto;
min-width: 0;
max-width: 45%;
margin-left: auto;
min-height: 24px;
padding: 0 var(--openbitfun-space-2);
Expand All @@ -477,11 +484,6 @@
background var(--openbitfun-motion-duration-fast) var(--openbitfun-motion-easing-standard),
color var(--openbitfun-motion-duration-fast) var(--openbitfun-motion-easing-standard);

&.is-connected {
background: var(--openbitfun-color-status-success-surface);
color: var(--openbitfun-color-status-success-content);
}

&.is-error,
&.is-disconnected {
background: var(--openbitfun-color-status-danger-surface);
Expand All @@ -495,8 +497,11 @@
}

&__workspace-item-remote-host {
flex: 0 0 auto;
flex: 0 1 auto;
min-width: 0;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}

&__workspace-item-remote-status {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useContentResourceStore } from '@/app/workbench/contentResourceStore';
import { getActiveSurfaceId, onSurfaceActivated } from '@/infrastructure/peer-device/deviceSurface';
import { notificationService } from '@/shared/notification-system';
import WorkspaceItem from './WorkspaceItem';
import { remoteWorkspaceBadges } from './remoteWorkspaceBadge';
import SessionViewTransition from './SessionViewTransition';
import SessionsSection, { type WorkspaceSessionScope } from '../sessions/SessionsSection';
import { useWorkspaceSessionViewStore } from '../../workspaceSessionView';
Expand Down Expand Up @@ -51,6 +52,8 @@ const WorkspaceListSection: React.FC<WorkspaceListSectionProps> = ({ variant, sc
activeWorkspaceId,
reorderOpenedWorkspacesInSection,
} = useWorkspaceContext();
// Remote badges are compared across every opened workspace so equal compact labels expand.
const remoteBadges = useMemo(() => remoteWorkspaceBadges(openedWorkspacesList), [openedWorkspacesList]);
const [draggedWorkspaceId, setDraggedWorkspaceId] = useState<string | null>(null);
const [dropTarget, setDropTarget] = useState<{
workspaceId: string;
Expand Down Expand Up @@ -320,6 +323,7 @@ const WorkspaceListSection: React.FC<WorkspaceListSectionProps> = ({ variant, sc
>
<WorkspaceItem
workspace={workspace}
remoteBadge={remoteBadges.get(workspace.id)}
isActive={isActive}
isSelected={isSelected}
isSingle={!draggable}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,18 @@ describe('WorkspaceListSection layout styles', () => {
expect(remoteNameButton).toContain('flex: 1 1 0;');
expect(remoteNameButton).toContain('max-width: none;');
expect(remoteChip).toContain('gap: var(--openbitfun-space-2);');
expect(remoteChip).toContain('flex: 0 0 auto;');
// The folder name owns the row; the chip shrinks and stays bounded (#3517).
expect(remoteChip).toContain('flex: 0 1 auto;');
expect(remoteChip).toContain('min-width: 0;');
expect(remoteChip).toContain('max-width: 45%;');
expect(remoteChip).toContain('margin-left: auto;');
expect(remoteChip).toContain('padding: 0 var(--openbitfun-space-2);');
expect(remoteChip).toContain('border-radius: var(--openbitfun-radius-base);');
expect(stylesheet).toContain(
'&.is-connected {\n' +
' background: var(--openbitfun-color-status-success-surface);\n' +
' color: var(--openbitfun-color-status-success-content);',
);
expect(remoteHost).toContain('flex: 0 0 auto;');
// A connected chip stays neutral; the green status dot already reports it.
expect(remoteChip).not.toContain('status-success-surface');
expect(remoteHost).toContain('flex: 0 1 auto;');
expect(remoteHost).toContain('white-space: nowrap;');
expect(remoteHost).not.toContain('text-overflow: ellipsis;');
expect(remoteHost).toContain('text-overflow: ellipsis;');

const source = readWorkspaceItemSource();
const remoteNameStart = source.indexOf('behavior="marquee"');
Expand All @@ -236,12 +236,12 @@ describe('WorkspaceListSection layout styles', () => {

expect(remoteMetaStart).toBeGreaterThanOrEqual(0);
expect(remoteMetaEnd).toBeGreaterThan(remoteMetaStart);
expect(source).toContain('const hostLabel = workspace.sshHost?.trim() || connectionLabel;');
expect(source).toContain('const badge = remoteBadge ?? remoteWorkspaceBadge(workspace);');
expect(source).toContain('<OverflowText');
expect(source).toContain('behavior="marquee"');
expect(searchIndicatorStart).toBeGreaterThan(remoteNameStart);
expect(remoteMetaStart).toBeGreaterThan(searchIndicatorStart);
expect(remoteMetaMarkup).toContain('remoteMeta.connectionLabel');
expect(remoteMetaMarkup).toContain('remoteMeta.badgeLabel');
expect(remoteMetaMarkup.indexOf('workspace-item-status-dot'))
.toBeLessThan(remoteMetaMarkup.indexOf('workspace-item-remote-host'));
expect(source).not.toContain('workspace-item-subtitle');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { describe, expect, it } from 'vitest';
import { WorkspaceKind } from '@/shared/types';
import { remoteWorkspaceBadge, remoteWorkspaceBadges } from './remoteWorkspaceBadge';

const remote = (
id: string,
connectionId: string,
connectionName: string,
sshHost: string,
) => ({ id, workspaceKind: WorkspaceKind.Remote, connectionId, connectionName, sshHost });

describe('remoteWorkspaceBadges (#3517)', () => {
it('drops the login user from generated names and keeps the full endpoint for the tooltip', () => {
const badge = remoteWorkspaceBadge(remote(
'w1', 'ssh-root@gpu-node-17.cluster.podtc.example.com', 'root@gpu-node-17.cluster.podtc.example.com',
'gpu-node-17.cluster.podtc.example.com',
));
expect(badge).toEqual({
label: 'gpu-node-17.cluster.podtc.example.com',
connection: 'root@gpu-node-17.cluster.podtc.example.com',
host: 'root@gpu-node-17.cluster.podtc.example.com',
});
});

it('shows a saved connection name or SSH config alias as is', () => {
const badge = remoteWorkspaceBadge(remote('w1', 'ssh-root@10.0.0.8', 'gpu-box', '10.0.0.8'));
expect(badge?.label).toBe('gpu-box');
expect(badge?.connection).toBe('gpu-box');
expect(badge?.host).toBe('root@10.0.0.8');
});

it('shows a custom name containing @ as is', () => {
expect(remoteWorkspaceBadge(remote('w1', 'ssh-root@10.0.0.8', 'team@gpu', '10.0.0.8'))?.label)
.toBe('team@gpu');
// Another user on the same host is not this connection's default shape.
expect(remoteWorkspaceBadge(remote('w2', 'ssh-root@10.0.0.8', 'alice@10.0.0.8', '10.0.0.8'))?.label)
.toBe('alice@10.0.0.8');
// Neither is a different port.
expect(remoteWorkspaceBadge(remote('w3', 'ssh-root@10.0.0.8#2202', 'root@10.0.0.8:2203', '10.0.0.8#2202'))?.label)
.toBe('root@10.0.0.8:2203');
expect(remoteWorkspaceBadge(remote('w4', 'ssh-root@10.0.0.8#2202', 'root@10.0.0.8:2202', '10.0.0.8#2202'))?.label)
.toBe('10.0.0.8:2202');
});

it('keeps port-scoped connections on one address distinct', () => {
const badges = remoteWorkspaceBadges([
remote('a', 'ssh-root@node.example.com', 'root@node.example.com', 'node.example.com'),
remote('b', 'ssh-root@node.example.com#2202', 'root@node.example.com', 'node.example.com#2202'),
]);
expect(badges.get('a')?.label).toBe('node.example.com');
expect(badges.get('b')?.label).toBe('node.example.com:2202');
expect(badges.get('b')?.host).toBe('root@node.example.com:2202');
});

it('expands to user@host when two different connections would read the same', () => {
const badges = remoteWorkspaceBadges([
remote('a', 'ssh-root@host.example.com', 'root@host.example.com', 'host.example.com'),
remote('b', 'ssh-alice@host.example.com', 'alice@host.example.com', 'host.example.com'),
remote('c', 'ssh-alice@host.example.com', 'alice@host.example.com', 'host.example.com'),
]);
expect(badges.get('a')?.label).toBe('root@host.example.com');
expect(badges.get('b')?.label).toBe('alice@host.example.com');
expect(badges.get('c')?.label).toBe('alice@host.example.com');
});

it('keeps folders on the same connection compact', () => {
const badges = remoteWorkspaceBadges([
remote('a', 'ssh-root@host.example.com', 'root@host.example.com', 'host.example.com'),
remote('b', 'ssh-root@host.example.com', 'root@host.example.com', 'host.example.com'),
]);
expect(badges.get('a')?.label).toBe('host.example.com');
expect(badges.get('b')?.label).toBe('host.example.com');
});

it('disambiguates equal aliases with the endpoint and ignores local workspaces', () => {
const badges = remoteWorkspaceBadges([
remote('a', 'ssh-root@a.example.com', 'dev', 'a.example.com'),
remote('b', 'ssh-root@b.example.com', 'dev', 'b.example.com'),
{ id: 'local', workspaceKind: WorkspaceKind.Normal, sshHost: 'localhost' },
]);
expect(badges.get('a')?.label).toBe('dev · root@a.example.com');
expect(badges.get('b')?.label).toBe('dev · root@b.example.com');
expect(badges.has('local')).toBe(false);
});

it('falls back to the connection id when older records omit name and host', () => {
const badge = remoteWorkspaceBadge({ id: 'w', workspaceKind: WorkspaceKind.Remote, connectionId: 'ssh-root@legacy.example.com' });
expect(badge?.label).toBe('legacy.example.com');
expect(badge?.host).toBe('root@legacy.example.com');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { WorkspaceKind, type WorkspaceInfo } from '@/shared/types';
import { sshConnectionIdPortScope } from '@/shared/utils/sshConnectionIdentity';

type RemoteWorkspaceFacts = Pick<WorkspaceInfo, 'id' | 'workspaceKind' | 'connectionId' | 'connectionName' | 'sshHost'>;

export interface RemoteWorkspaceBadge {
/** Compact label shown next to the folder name. */
label: string;
/** Full connection name for the tooltip and accessible name. */
connection: string;
/** Full `user@host:port` style endpoint for the tooltip. */
host: string;
}

interface RemoteEndpointParts {
connectionKey: string;
alias?: string;
user?: string;
host: string;
portScope?: string;
}

const SSH_ID = /^ssh-([^@]*)@([^#:]+)/;

/**
* Whether a saved name is the dialog default for this connection: exactly
* `user@host` (optionally `:port`) with the connection's own user, host and
* port, or the bare host. Any other name was chosen by the user, `@` included.
*/
function isGeneratedName(
name: string,
user: string | undefined,
hosts: readonly (string | undefined)[],
portScope: string | undefined,
): boolean {
if (!name) return true;
const port = portScope?.split('~')[0];
return hosts.some(host => {
if (!host) return false;
if (name === host) return true;
if (!user) return false;
const base = `${user}@${host}`;
return name === base || (port !== undefined && name === `${base}:${port}`);
});
}

function endpointParts(workspace: RemoteWorkspaceFacts): RemoteEndpointParts {
const connectionId = workspace.connectionId?.trim() ?? '';
const name = workspace.connectionName?.trim() ?? '';
const rawHost = workspace.sshHost?.trim() ?? '';
// Port-scoped workspace identities spell the host as `host#port` (#3670).
const hashIndex = rawHost.indexOf('#');
const hostScope = hashIndex >= 0 ? rawHost.slice(hashIndex + 1) : undefined;
const sshHost = hashIndex >= 0 ? rawHost.slice(0, hashIndex) : rawHost;
const idMatch = SSH_ID.exec(connectionId);
const user = idMatch?.[1] || undefined;
const idHost = idMatch?.[2];
const host = sshHost || idHost || name || connectionId;
const portScope = sshConnectionIdPortScope(connectionId) ?? (hostScope || undefined);
return {
connectionKey: connectionId || `${user ?? ''}@${host}`,
alias: isGeneratedName(name, user, [host, idHost], portScope) ? undefined : name,
user,
host,
portScope,
};
}

function withPort(host: string, portScope?: string): string {
return portScope ? `${host}:${portScope}` : host;
}

function fullEndpoint(parts: RemoteEndpointParts): string {
return withPort(parts.user ? `${parts.user}@${parts.host}` : parts.host, parts.portScope);
}

function compactLabel(parts: RemoteEndpointParts): string {
return parts.alias ?? withPort(parts.host, parts.portScope);
}

/**
* Compact remote badges for the opened workspaces. The badge shows the saved
* connection alias, or the host without the login user; a non-default port
* stays visible so port-mapped nodes on one address remain distinct. When two
* different connections would still read the same, both fall back to the full
* `user@host:port` endpoint. Full details always stay in the tooltip.
*/
export function remoteWorkspaceBadges(
workspaces: readonly RemoteWorkspaceFacts[],
): Map<string, RemoteWorkspaceBadge> {
const parts = workspaces
.filter(workspace => workspace.workspaceKind === WorkspaceKind.Remote)
.map(workspace => ({ workspace, parts: endpointParts(workspace) }));
const connectionsByLabel = new Map<string, Set<string>>();
for (const entry of parts) {
const label = compactLabel(entry.parts);
const keys = connectionsByLabel.get(label) ?? new Set<string>();
keys.add(entry.parts.connectionKey);
connectionsByLabel.set(label, keys);
}
const badges = new Map<string, RemoteWorkspaceBadge>();
for (const { workspace, parts: entry } of parts) {
const compact = compactLabel(entry);
const ambiguous = (connectionsByLabel.get(compact)?.size ?? 0) > 1;
const endpoint = fullEndpoint(entry);
badges.set(workspace.id, {
label: ambiguous ? (entry.alias ? `${entry.alias} · ${endpoint}` : endpoint) : compact,
connection: workspace.connectionName?.trim() || endpoint,
host: endpoint,
});
}
return badges;
}

export function remoteWorkspaceBadge(workspace: RemoteWorkspaceFacts): RemoteWorkspaceBadge | undefined {
return remoteWorkspaceBadges([workspace]).get(workspace.id);
}
Loading