mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
refactor(mobile): export the New Workspace SSH target key
Names an SSH target by its holding host and id, so other server-aware screens can key their SSH state the same way. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
} from '../tasks/mobile-workspace-source-operations'
|
} from '../tasks/mobile-workspace-source-operations'
|
||||||
import {
|
import {
|
||||||
deriveWorkspaceSshGate,
|
deriveWorkspaceSshGate,
|
||||||
|
workspaceSshTargetKey,
|
||||||
type WorkspaceSshGate,
|
type WorkspaceSshGate,
|
||||||
type WorkspaceSshRecord
|
type WorkspaceSshRecord
|
||||||
} from '../tasks/workspace-ssh-gate'
|
} from '../tasks/workspace-ssh-gate'
|
||||||
@@ -43,8 +44,7 @@ export function useNewWorkspaceExecutionTarget(args: {
|
|||||||
connect: () => Promise<void>
|
connect: () => Promise<void>
|
||||||
} {
|
} {
|
||||||
const { client, connectionId, server, visible } = args
|
const { client, connectionId, server, visible } = args
|
||||||
// Why the host too: the desktop and a server can each hold a target with the same id.
|
const target = workspaceSshTargetKey(server, connectionId)
|
||||||
const target = JSON.stringify([server ?? null, connectionId])
|
|
||||||
const [sshState, setSshEntry] = useState<SshStateEntry | null>(null)
|
const [sshState, setSshEntry] = useState<SshStateEntry | null>(null)
|
||||||
const setSshState = (record: WorkspaceSshRecord) => setSshEntry({ target, record })
|
const setSshState = (record: WorkspaceSshRecord) => setSshEntry({ target, record })
|
||||||
// A connect reply lands only while its target is still the one shown, so it never overwrites another's.
|
// A connect reply lands only while its target is still the one shown, so it never overwrites another's.
|
||||||
|
|||||||
@@ -1,7 +1,23 @@
|
|||||||
import { describe, expect, it } from 'vitest'
|
import { describe, expect, it } from 'vitest'
|
||||||
import { deriveWorkspaceSshGate, workspaceSshStatusLabel } from './workspace-ssh-gate'
|
import {
|
||||||
|
deriveWorkspaceSshGate,
|
||||||
|
workspaceSshStatusLabel,
|
||||||
|
workspaceSshTargetKey
|
||||||
|
} from './workspace-ssh-gate'
|
||||||
|
|
||||||
describe('workspace SSH gate', () => {
|
describe('workspace SSH gate', () => {
|
||||||
|
it('keys a target by the host holding it, so same-named targets on two hosts differ', () => {
|
||||||
|
expect(workspaceSshTargetKey(undefined, 'devbox')).not.toBe(
|
||||||
|
workspaceSshTargetKey('runtime:env-1', 'devbox')
|
||||||
|
)
|
||||||
|
expect(workspaceSshTargetKey('runtime:env-1', 'devbox')).not.toBe(
|
||||||
|
workspaceSshTargetKey('runtime:env-2', 'devbox')
|
||||||
|
)
|
||||||
|
expect(workspaceSshTargetKey('runtime:env-1', 'devbox')).toBe(
|
||||||
|
workspaceSshTargetKey('runtime:env-1', 'devbox')
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it('does not gate local repositories', () => {
|
it('does not gate local repositories', () => {
|
||||||
expect(
|
expect(
|
||||||
deriveWorkspaceSshGate({
|
deriveWorkspaceSshGate({
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { ExecutionHostId } from '../../../src/shared/execution-host'
|
||||||
import type { SshConnectionState, SshConnectionStatus } from '../../../src/shared/ssh-types'
|
import type { SshConnectionState, SshConnectionStatus } from '../../../src/shared/ssh-types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,6 +15,17 @@ export type WorkspaceSshRecord = Omit<SshConnectionState, 'error' | 'reconnectAt
|
|||||||
reconnectAttempt?: number
|
reconnectAttempt?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Names an SSH target by the host holding it as well as its id: the desktop and a server can each
|
||||||
|
* hold a target with the same id. `server` is undefined for the desktop's own targets.
|
||||||
|
*/
|
||||||
|
export function workspaceSshTargetKey(
|
||||||
|
server: ExecutionHostId | undefined,
|
||||||
|
connectionId: string | null
|
||||||
|
): string {
|
||||||
|
return JSON.stringify([server ?? null, connectionId])
|
||||||
|
}
|
||||||
|
|
||||||
export type WorkspaceSshGate = {
|
export type WorkspaceSshGate = {
|
||||||
status: SshConnectionStatus | null
|
status: SshConnectionStatus | null
|
||||||
requiresConnection: boolean
|
requiresConnection: boolean
|
||||||
|
|||||||
Reference in New Issue
Block a user