fix(desktop): clarify primary SSH reuse failures

This commit is contained in:
Jaime Marques
2026-08-24 16:54:16 +01:00
committed by Teknium
parent 3263ca2af6
commit 14d16c2578
4 changed files with 58 additions and 4 deletions
@@ -60,6 +60,42 @@ test('labelSlug kebab-cases and never returns empty for non-empty input', () =>
assert.equal(labelSlug('!!!'), 'connection')
})
test('registry SSH fingerprint failures name the connection and ssh -G step', async () => {
const registry = migrateV1ToRegistry({
mode: 'ssh',
remote: { mode: 'ssh', host: 'build-host', user: 'alice' },
profiles: {}
})
const source = registry.connections.find(connection => connection.id === registry.primary)!
const cause = new Error('spawn ssh ENOENT')
source.label = 'Build box'
await assert.rejects(
reuseMatchingPrimarySshBackend({
connectionId: registry.primary,
effectiveFingerprint: async () => {
throw cause
},
ensurePrimary: async () => ({ mode: 'remote', remoteKind: 'ssh' }),
profile: 'default',
registry,
source
}),
error => {
assert.equal(
(error as Error).message,
`Could not resolve effective SSH config for connection "Build box" (${source.id}) via ssh -G: spawn ssh ENOENT`
)
assert.equal((error as Error).cause, cause)
return true
}
)
})
test('matching primary/default SSH route reuses the existing descriptor once', async () => {
const registry = migrateV1ToRegistry({
mode: 'ssh',
+20 -4
View File
@@ -344,9 +344,13 @@ export interface ReuseMatchingPrimarySshBackendOptions {
}
/**
* Reuse the already-booted v1 window SSH backend only when its actual dialing
* identity matches the registry primary. Guards run before either async
* dependency so secondary profiles and sources never bootstrap the primary.
* Reuse the v1 window SSH backend only when its actual dialing identity matches
* the registry primary. Resolving that descriptor may boot the primary; a
* mismatch returns null without reusing it so the caller continues with its
* separately scoped registry backend. A matching descriptor is returned
* unchanged and the caller may re-stamp routing fields such as profile and
* connectionId. Guards run before either async dependency so secondary
* profiles and sources never bootstrap the primary.
*/
export async function reuseMatchingPrimarySshBackend({
connectionId,
@@ -363,7 +367,19 @@ export async function reuseMatchingPrimarySshBackend({
return null
}
const sourceFingerprint = String(await effectiveFingerprint(source)).trim()
let sourceFingerprint
try {
sourceFingerprint = String(await effectiveFingerprint(source)).trim()
} catch (cause) {
const detail = cause instanceof Error ? cause.message : String(cause)
throw new Error(
`Could not resolve effective SSH config for connection "${source.label}" (${source.id}) via ssh -G: ${detail}`,
{ cause }
)
}
const descriptor = await ensurePrimary()
const activeSsh = descriptor.mode === 'remote' && descriptor.remoteKind === 'ssh' ? descriptor.ssh : null
const rootProfile = (value: unknown) => String(value || '').trim() || 'default'
@@ -70,6 +70,7 @@ test('primary remote descriptor preserves the effective SSH dialing identity', (
)
assert.equal(connection.ssh, ssh)
assert.equal(connection.ssh?.effectiveConfigFingerprint, 'effective-config')
})
test('primary remote descriptor keeps legacy unregistered routes unqualified', () => {
@@ -0,0 +1 @@
MrTheSoulz