fix(desktop): route ambient SSH profile deletion to remote

This commit is contained in:
Kavyrocom
2026-08-24 06:20:54 +00:00
committed by Teknium
parent 2664599644
commit 76af834ddd
2 changed files with 34 additions and 2 deletions
+20 -2
View File
@@ -617,6 +617,17 @@ export const host = {
}
const targetProfile = route?.targetProfile || name
// A name-only call is ambient, not local: Bot Mode's active SSH roster
// rows deliberately use the ambient gateway door and therefore carry no
// explicit owner route. Preserve the active registry connection so the
// profile teardown and DELETE both land on the VPS instead of retiring the
// unrelated local pool and leaving the warmed remote backend to recreate
// the deleted profile.
const ambientConnectionId = route ? null : String(activeGatewayConnectionId() || '').trim()
const ambientRemoteConnectionId = ambientConnectionId && ambientConnectionId !== 'local'
? ambientConnectionId
: null
if (!name) {
throw new Error('deleteProfile: profile name required')
@@ -637,11 +648,18 @@ export const host = {
// A hover-warmed Bot Mode row owns a retained renderer socket. Retire it
// before Electron stops the profile backend so the socket closure cannot
// schedule a reconnect that resurrects the deleted profile.
if (!route || route.mode === 'local') {
if (route?.mode === 'local' || (!route && !ambientRemoteConnectionId)) {
retireLocalProfileGateways(targetProfile)
}
await deleteProfile(targetProfile, route ? { connectionId: route.connectionId, profile: route.profile } : undefined)
await deleteProfile(
targetProfile,
route
? { connectionId: route.connectionId, profile: route.profile }
: ambientRemoteConnectionId
? { connectionId: ambientRemoteConnectionId, profile: name }
: undefined
)
// The profile rail paints from the shared $profiles cache; without a
// refresh the deleted profile's badge survives and clicking it starts a
@@ -108,6 +108,7 @@ const { openSession: openSessionCore } = await import('@/app/open-session')
const { deleteProfile } = await import('@/hermes')
const {
activeGatewayConnectionId,
openGatewayForAgent,
openGatewayForProfile,
requestGatewayForAgent,
@@ -152,6 +153,7 @@ const profile = (name: string): ProfileInfo => ({
afterEach(() => {
vi.clearAllMocks()
vi.mocked(activeGatewayConnectionId).mockReturnValue('local')
$activeGatewayProfile.set('remote-worker')
$gatewaySwapTarget.set(null)
setMockAtom($focusedRuntimeId, null)
@@ -189,6 +191,18 @@ describe('connection-aware plugin host APIs', () => {
expect(refreshProfiles).toHaveBeenCalled()
})
it('pins an ambient SSH profile delete to the active connection and target profile', async () => {
vi.mocked(activeGatewayConnectionId).mockReturnValue('ssh-vps')
await host.deleteProfile('worker')
expect(retireLocalProfileGateways).not.toHaveBeenCalled()
expect(deleteProfile).toHaveBeenCalledWith('worker', {
connectionId: 'ssh-vps',
profile: 'worker'
})
})
it('refreshes the profile inventory before asking Electron for routes', async () => {
const getProfileRoutes = vi.fn(async () => [
{ connectionId: 'connection-local', mode: 'local', profile: 'desktop-primary', targetProfile: 'desktop-primary' },