Files
orca/src/main/ssh/managed-server-serving-gate.ts
T
Neil 506aa03195 refactor(managed-server): move the managed server's lifecycle into src/main/managed-server/lifecycle/ (#30343)
orcad-managed-*, orcad-runtime-*, orcad-stdio-bridge-*, orcad-decommission-* and orcad-rollback-*
leave src/main/ssh. git mv plus import and path-literal rewrites; two e2e route regexes learn the
new folder. orcad-runtime-maintenance stays for now because open #29834 edits it.
2026-10-18 06:01:46 -07:00

47 lines
1.7 KiB
TypeScript

/** Whether a connect's serving check ends it, or lets the update check run (and redeploy). */
import type { HostServerUpdateOnConnect } from './managed-server-update-check'
import {
MANAGED_ORCAD_FENCED_DETAIL,
MANAGED_ORCAD_NOT_ACTIVATED_DETAIL,
type OrcadManagedServing
} from '../managed-server/lifecycle/orcad-managed-serving'
import type { HostServerOnConnectResult } from './ssh-host-server-on-connect'
type ManagedRoute = Extract<HostServerOnConnectResult, { route: 'managed' }>
/**
* The managed result for a server that is not serving, or null when the update check runs next.
* A host with no active version (another desktop stopped it) goes on to the update, which
* redeploys this desktop's still-linked server instead of leaving it stranded.
*/
export function unservedManagedResult(
environmentId: string,
serving: OrcadManagedServing
): ManagedRoute | null {
if (serving.state !== 'unverifiable' || serving.detail === MANAGED_ORCAD_NOT_ACTIVATED_DETAIL) {
return null
}
// Still the managed route: a stopped server says nothing about the host's terminals.
return {
route: 'managed',
environmentId,
serving,
...(serving.detail === MANAGED_ORCAD_FENCED_DETAIL ? { fenceHeld: true as const } : {})
}
}
/** Keeps the "not activated" note when the update did not bring a server back. */
export function managedResultAfterUpdate(
environmentId: string,
serving: OrcadManagedServing,
{ note, reason, fenceBusy }: HostServerUpdateOnConnect
): ManagedRoute {
return {
route: 'managed',
environmentId,
...(note ? { update: note } : {}),
...(serving.state === 'unverifiable' && reason !== 'updated' ? { serving } : {}),
...(fenceBusy ? { fenceHeld: true as const } : {})
}
}