From e2c6f2ebc4468e7e7839d611c2b0393e08a2cd3c Mon Sep 17 00:00:00 2001 From: Cad from Arca Date: Sat, 1 Aug 2026 11:49:16 +0000 Subject: [PATCH] test(desktop): cover mapped non-default SSH profile --- .../desktop/electron/remote-lifecycle.test.ts | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/apps/desktop/electron/remote-lifecycle.test.ts b/apps/desktop/electron/remote-lifecycle.test.ts index c6f411475fd33..136eb555807c5 100644 --- a/apps/desktop/electron/remote-lifecycle.test.ts +++ b/apps/desktop/electron/remote-lifecycle.test.ts @@ -2,6 +2,7 @@ import assert from 'node:assert/strict' import { test } from 'vitest' +import { profileSshOverride } from './connection-config' import { buildSpawnCommand, cleanupStale, @@ -420,6 +421,50 @@ test('connect() spawns fresh when there is no lockfile, adopts the served token' assert.equal(result.tokenFingerprint, fingerprintToken('the-served-token')) }) +test('managed SSH maps a local scope to a different non-default remote profile', async () => { + const localScope = 'work' + const sshConfig = profileSshOverride( + { + profiles: { + [localScope]: { + mode: 'ssh', + host: 'remote-box', + remoteProfile: 'writer_2' + } + } + }, + localScope + ) + + assert.equal(sshConfig?.remoteProfile, 'writer_2') + + const ssh = fakeSsh([ + [/uname/, 'Linux\nx86_64'], + [/\[ -x/, 'OK'], + [/cat .*lock\.json/, ''], + [/grep -q ssh-session-token-file/, 'YES\n'], + [/python3 -c/, ''], + [/printf '%s\\n'/, ''], + [/setsid/, '778\n'], + [/kill -0 778/, 'ALIVE'], + [/cat .*\.log/, 'HERMES_BACKEND_READY port=52000\n'] + ]) + + await connect( + connectDeps(ssh, { + profile: sshConfig?.remoteProfile, + adoptServedToken: async () => 'mapped-profile-token' + }) + ) + + const spawn = ssh.calls.find(command => /setsid|nohup/.test(command)) || '' + assert.match(spawn, /--profile\b/) + assert.ok(spawn.includes('writer_2')) + assert.match(spawn, /serve\s+--isolated/) + assert.match(spawn, /\.hermes\/desktop-ssh\/[0-9a-f]{32}\/[0-9a-f]{16}\.token/) + assert.ok(!spawn.includes(' work'), 'the local Desktop scope must not become the remote profile') +}) + test('connect() reuses a healthy dashboard when fingerprint + probe pass', async () => { const reuseToken = 'stored-token' const lock = ownedLock({ tokenFingerprint: fingerprintToken(reuseToken) })