Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/main/ipc/wsl-host-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ import { WslHostService } from '../wsl/wsl-host-service'
import { WslHostVisibleWorkByWindow } from './wsl-host-visible-work-windows'
import type { WslHostAutomationWake } from '../wsl/wsl-host-automation-wake'
import { createWslHostAutomationWake } from './wsl-host-automation-wake-wiring'
import {
WSL_HOSTS_NEW_WORK_PAUSED_MESSAGE,
wslHostsGateOpen,
wslHostsServing
} from '../wsl/wsl-host-gate'
import { wslHostsGateOpen, wslHostsServing } from '../wsl/wsl-host-gate'
import { wslHostAddRefusal } from '../wsl/wsl-host-add-admission'
import {
getWslHostService,
setWslHostPhoneGate,
Expand Down Expand Up @@ -256,7 +253,7 @@ export function registerWslHostHandlers(args: WslHostHandlerArgs): void {
): Promise<WslHostAddResult> => {
// Serve-only keeps saved hosts working but admits none.
if (!wslHostsGateOpen()) {
return { ok: false, kind: 'disabled', message: WSL_HOSTS_NEW_WORK_PAUSED_MESSAGE }
return wslHostAddRefusal('disabled', 'newWorkPaused')
}
const result = await wsl.add(request)
if (result.ok) {
Expand Down
24 changes: 5 additions & 19 deletions src/main/wsl/wsl-distro-unsupported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,18 @@
import { OrcadHostUnsupportedError } from '../orcad/orcad-host-unavailable'
import { OrcadHostGlibcUnsupportedError } from '../managed-server/lifecycle/orcad-runtime-target'
import { RemoteNodeRuntimeSelfTestError } from '../ssh/orcad-remote-node-runtime-report'

export function wsl1DistroMessage(distro: string): string {
return (
`${distro} runs WSL 1, which Orca no longer supports. ` +
`Convert it to WSL 2 in a Windows terminal with: wsl --set-version ${distro} 2`
)
}

export function wslDistroNotRegisteredMessage(distro: string): string {
return (
`${distro} is not an installed WSL distro. ` +
'Run wsl --list --verbose in a Windows terminal to see the installed ones, ' +
'or reinstall it and try again.'
)
}
import { wslHostAddRefusalText } from '../../shared/wsl-host-failure-copy'

/** Keeps OrcadHostUnsupportedError's name, so callers that classify by name still see it. */
export class WslDistroVersion1Error extends OrcadHostUnsupportedError {
constructor(distro: string) {
super(wsl1DistroMessage(distro))
constructor(readonly distro: string) {
super(wslHostAddRefusalText('wsl1', { distro }).text)
}
}

export class WslDistroNotRegisteredError extends OrcadHostUnsupportedError {
constructor(distro: string) {
super(wslDistroNotRegisteredMessage(distro))
constructor(readonly distro: string) {
super(wslHostAddRefusalText('notRegistered', { distro }).text)
}
}

Expand Down
48 changes: 25 additions & 23 deletions src/main/wsl/wsl-host-add-admission.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
/** Why a distro cannot be added as a WSL host, decided before anything runs in it. */
import type { WslHostAddResult } from '../../shared/wsl-host-types'
import type { WslHostAddFailureKind, WslHostAddResult } from '../../shared/wsl-host-types'
import {
WSL_HOST_ADD_REFUSAL_COPY,
wslHostAddRefusalText,
type WslHostAddRefusalCode,
type WslHostCopyParams
} from '../../shared/wsl-host-failure-copy'
import type { WslHostDistroCandidate } from './wsl-host-distro-list'
import { wslDistroHolderKey } from './wsl-distro-holder-record'
import { wsl1DistroMessage, wslDistroNotRegisteredMessage } from './wsl-distro-unsupported'

export const WSL_HOSTS_DISABLED_MESSAGE = 'WSL hosts are turned off in Settings → Experimental.'
export const WSL_HOST_SERVER_FILES_MISSING_MESSAGE =
'This build of Orca can’t run WSL hosts (server files missing).'
export const WSL_HOSTS_DISABLED_MESSAGE = WSL_HOST_ADD_REFUSAL_COPY.turnedOff
export const WSL_HOST_SERVER_FILES_MISSING_MESSAGE = WSL_HOST_ADD_REFUSAL_COPY.serverFilesMissing

type WslHostAddRefusal = Extract<WslHostAddResult, { ok: false }>

/** A refusal whose English `message` and translation code come from one table. */
export function wslHostAddRefusal(
kind: WslHostAddFailureKind,
code: WslHostAddRefusalCode,
params?: WslHostCopyParams
): WslHostAddRefusal {
const { text, code: errorCode, params: errorParams } = wslHostAddRefusalText(code, params)
return { ok: false, kind, message: text, errorCode, ...(errorParams ? { errorParams } : {}) }
}

export const WSL_HOST_REMOVING_MESSAGE = 'This WSL host is being removed.'

export function wslHostNotConnectedMessage(distro: string): string {
Expand Down Expand Up @@ -45,12 +59,12 @@ export function wslHostRunRefusal(gate: {
hasServerFiles: () => boolean
}): WslHostAddRefusal | null {
if (!gate.isEnabled()) {
return { ok: false, kind: 'disabled', message: WSL_HOSTS_DISABLED_MESSAGE }
return wslHostAddRefusal('disabled', 'turnedOff')
}
// Reject missing packaged templates before C4 deploy emits an opaque deep failure.
return gate.hasServerFiles()
? null
: { ok: false, kind: 'server-files-missing', message: WSL_HOST_SERVER_FILES_MISSING_MESSAGE }
: wslHostAddRefusal('server-files-missing', 'serverFilesMissing')
}

export function sameWslDistro(left: string, right: string): boolean {
Expand All @@ -66,28 +80,16 @@ export function admitWslHostDistro(args: {
}): { distro: WslHostDistroCandidate } | WslHostAddRefusal {
const distro = args.candidates.find((candidate) => sameWslDistro(candidate.name, args.requested))
if (!distro) {
return {
ok: false,
kind: 'failed',
message: wslDistroNotRegisteredMessage(args.requested)
}
return wslHostAddRefusal('failed', 'notRegistered', { distro: args.requested })
}
if (distro.version === 1) {
return {
ok: false,
kind: 'unsupported-wsl1',
message: wsl1DistroMessage(distro.name)
}
return wslHostAddRefusal('unsupported-wsl1', 'wsl1', { distro: distro.name })
}
if (args.alreadyAdded(distro.name)) {
return { ok: false, kind: 'already-added', message: `${distro.name} is already a host.` }
return wslHostAddRefusal('already-added', 'alreadyAdded', { distro: distro.name })
}
if (distro.state === 'stopped' && !args.startIfStopped) {
return {
ok: false,
kind: 'distro-stopped',
message: `${distro.name} stopped since the list was read. Choose Start and add to start it.`
}
return wslHostAddRefusal('distro-stopped', 'distroStopped', { distro: distro.name })
}
return { distro }
}
31 changes: 31 additions & 0 deletions src/main/wsl/wsl-host-connection-record.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,35 @@ describe('toWslHostStatus', () => {
).toBeNull()
expect(toWslHostStatus(record, { state: 'connecting' }).deferredUpdate).toBeNull()
})

it('codes an unverifiable reason as a sentence, and keeps verbatim connect errors uncoded', () => {
expect(
toWslHostStatus(record, {
state: 'unverifiable',
reason: 'guest-unanswered',
terminals: 'unverifiable'
})
).toMatchObject({
detail: 'The distro is running but didn’t answer Orca’s check.',
detailCode: 'guestUnanswered'
})
const failed = toWslHostStatus(record, {
state: 'failed',
reason: 'bridge refused',
terminals: 'unverifiable'
})
expect(failed.detail).toBe('bridge refused')
expect(failed).not.toHaveProperty('detailCode')
const pendingStop = {
since: 1,
reason: 'The WSL service did not confirm whether the distro runs.',
reasonCode: 'serviceUnconfirmed',
verdict: 'unverifiable' as const
}
expect(toWslHostStatus({ ...record, pendingStop }, { state: 'closed' })).toMatchObject({
detail: pendingStop.reason,
detailCode: 'serviceUnconfirmed',
removalPending: true
})
})
})
46 changes: 42 additions & 4 deletions src/main/wsl/wsl-host-connection-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ import {
readWslHostDeployments,
type WslHostDeploymentRecord
} from '../../shared/wsl-host-deployment-store'
import {
wslHostStatusDetailText,
type WslHostCopyParams,
type WslHostStatusDetailCode
} from '../../shared/wsl-host-failure-copy'
import type { WslHostStatus } from '../../shared/wsl-host-types'
import type { WslOrcadConnection } from './wsl-orcad-connection'
import type { WslOrcadConnectionStatus } from './wsl-orcad-connection-status'
import type { WslLivenessUnverifiableReason } from './wsl-orcad-liveness-verdict'

/** Saves an explicit re-pair or a moved bridge; true when the pairing changed. */
export function persistWslHostConnection(
Expand Down Expand Up @@ -46,10 +52,7 @@ export function toWslHostStatus(
environmentId: record.environmentId,
distro: record.distro,
state: status.state,
detail:
status.state === 'failed' || status.state === 'unverifiable'
? status.reason
: (record.pendingStop?.reason ?? null),
...wslHostStatusDetail(record, status),
// Ready serves the incumbent; deferred serves nothing, so retain its Update/Force explanation.
deferredUpdate:
status.state === 'ready'
Expand All @@ -61,6 +64,41 @@ export function toWslHostStatus(
}
}

const UNVERIFIABLE_DETAIL_CODES: Record<WslLivenessUnverifiableReason, WslHostStatusDetailCode> = {
'running-list-unavailable': 'runningListUnavailable',
'guest-unanswered': 'guestUnanswered',
'orcad-unanswered': 'orcadUnanswered'
}

type WslHostStatusDetail = Pick<WslHostStatus, 'detail' | 'detailCode' | 'detailParams'>

function codedDetail(
detail: string,
code: string | undefined,
params: WslHostCopyParams | undefined
): WslHostStatusDetail {
return {
detail,
...(code ? { detailCode: code } : {}),
...(code && params ? { detailParams: params } : {})
}
}

function wslHostStatusDetail(
record: WslHostDeploymentRecord,
status: WslOrcadConnectionStatus
): WslHostStatusDetail {
if (status.state === 'unverifiable') {
const { text, code } = wslHostStatusDetailText(UNVERIFIABLE_DETAIL_CODES[status.reason])
return { detail: text, detailCode: code }
}
if (status.state === 'failed') {
return codedDetail(status.reason, status.reasonCode, status.reasonParams)
}
const stop = record.pendingStop
return stop ? codedDetail(stop.reason, stop.reasonCode, stop.reasonParams) : { detail: null }
}

/** The registered WSL hosts; an unreadable store reads as none rather than failing the caller. */
export function readWslHostRecordsQuietly(userDataPath: string): WslHostDeploymentRecord[] {
try {
Expand Down
3 changes: 2 additions & 1 deletion src/main/wsl/wsl-host-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { createWslOrcadLivenessSupervisor } from './wsl-orcad-liveness-wiring'
import type { WslOrcadLivenessSupervisor } from './wsl-orcad-liveness-supervisor'
import { confirmsRunning } from './wsl-orcad-liveness-evidence'
import { wslDistroHolderKey } from './wsl-distro-holder-record'
import { wslHostServerStopReason } from '../../shared/wsl-host-failure-copy'

function targetFor(distro: string): WslOrcadHostTarget {
return { kind: 'wsl', id: defaultWslOrcadEnvironmentId(distro), distro, label: distro }
Expand Down Expand Up @@ -206,7 +207,7 @@ export function createWslHostConnector(options: {
if (reachability === 'unavailable') {
return {
stopped: false,
reason: 'The WSL service did not confirm whether the distro runs.',
...wslHostServerStopReason('serviceUnconfirmed'),
verdict: 'unverifiable'
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/main/wsl/wsl-host-first-connect.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, it, vi } from 'vitest'
import { WslDistroVersion1Error } from './wsl-distro-unsupported'
import { connectForWslHostAdd } from './wsl-host-first-connect'

describe('connectForWslHostAdd', () => {
it('refuses a WSL 1 distro with the English message and its translation code', async () => {
const connector = {
connect: vi.fn().mockRejectedValue(new WslDistroVersion1Error('Ubuntu')),
disconnect: vi.fn().mockResolvedValue(undefined),
releaseHolder: vi.fn().mockResolvedValue(undefined)
}
await expect(connectForWslHostAdd(connector, 'Ubuntu', () => null)).resolves.toEqual({
ok: false,
kind: 'unsupported-wsl1',
message:
'Ubuntu runs WSL 1, which Orca no longer supports. Convert it to WSL 2 in a Windows terminal with: wsl --set-version Ubuntu 2',
errorCode: 'wsl1',
errorParams: { distro: 'Ubuntu' }
})
expect(connector.releaseHolder).toHaveBeenCalledWith('Ubuntu')
})
})
16 changes: 12 additions & 4 deletions src/main/wsl/wsl-host-first-connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import type { WslHostAddResult } from '../../shared/wsl-host-types'
import { OrcadHostUnsupportedError } from '../orcad/orcad-host-unavailable'
import type { WslHostConnector } from './wsl-host-service'
import { WslOrcadLaunchDeferredError } from './wsl-orcad-connection-errors'
import { WslDistroVersion1Error, wslUnsupportedDistroFixMessage } from './wsl-distro-unsupported'
import {
WslDistroNotRegisteredError,
WslDistroVersion1Error,
wslUnsupportedDistroFixMessage
} from './wsl-distro-unsupported'
import { wslHostAddRefusal } from './wsl-host-add-admission'
import { RemoteNodeRuntimeSelfTestError } from '../ssh/orcad-remote-node-runtime-report'
import type { WslOrcadConnection } from './wsl-orcad-connection'

Expand All @@ -30,6 +35,12 @@ export async function connectForWslHostAdd(
if (error instanceof WslOrcadLaunchDeferredError) {
return { ok: false, kind: 'deferred', message: error.launch.reason }
}
if (error instanceof WslDistroVersion1Error) {
return wslHostAddRefusal('unsupported-wsl1', 'wsl1', { distro: error.distro })
}
if (error instanceof WslDistroNotRegisteredError) {
return wslHostAddRefusal('unsupported-distro', 'notRegistered', { distro: error.distro })
}
return {
ok: false,
kind: connectFailureKind(error),
Expand All @@ -46,9 +57,6 @@ export async function connectForWslHostAdd(

/** A distro Orca can't run in reads apart from a connect that may work on retry. */
function connectFailureKind(error: unknown): WslHostAddRefusal['kind'] {
if (error instanceof WslDistroVersion1Error) {
return 'unsupported-wsl1'
}
return error instanceof OrcadHostUnsupportedError ||
error instanceof RemoteNodeRuntimeSelfTestError
? 'unsupported-distro'
Expand Down
2 changes: 0 additions & 2 deletions src/main/wsl/wsl-host-gate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import type { OrcadDeploymentLink } from '../../shared/runtime-environments'
import type { WslHostsPolicyState } from '../../shared/wsl-hosts-policy'

export const WSL_HOSTS_GATED_OFF_MESSAGE = 'WSL hosts are not available in this build.'
export const WSL_HOSTS_NEW_WORK_PAUSED_MESSAGE =
'Adding WSL hosts and moving projects onto them is paused in this build. Your saved WSL hosts keep working.'

// Fixed for the run once main reads the disk; nothing can create a host or a move while not open.
let promoted: { hasSavedWslHost: boolean; hasWslMoveCutover: boolean } | null = null
Expand Down
8 changes: 2 additions & 6 deletions src/main/wsl/wsl-host-registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { errorMessage } from '../../shared/error-message'
import { addWslHostEnvironment } from '../../shared/runtime-environment-wsl-host-store'
import type { WslHostDeploymentRecord } from '../../shared/wsl-host-deployment-store'
import { wslHostEnvironmentLabel, type WslHostAddResult } from '../../shared/wsl-host-types'
import {
admitWslHostDistro,
WSL_HOSTS_DISABLED_MESSAGE,
wslHostRunRefusal
} from './wsl-host-add-admission'
import { admitWslHostDistro, wslHostAddRefusal, wslHostRunRefusal } from './wsl-host-add-admission'
import { abandonWslHostAdd, connectForWslHostAdd } from './wsl-host-first-connect'
import type { WslHostConnector, WslHostServiceDependencies } from './wsl-host-service'
import { wslHostSshManagedRefusal } from './wsl-host-ssh-orcad-conflict'
Expand Down Expand Up @@ -56,7 +52,7 @@ export async function registerWslHost(
const connected = await connectForWslHostAdd(context.wsl(), distro.name, () =>
generation === context.disableGeneration()
? wslHostRunRefusal(context.deps)
: { ok: false, kind: 'disabled', message: WSL_HOSTS_DISABLED_MESSAGE }
: wslHostAddRefusal('disabled', 'turnedOff')
)
if (!('connection' in connected)) {
return connected
Expand Down
8 changes: 6 additions & 2 deletions src/main/wsl/wsl-host-removal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Dropping it would strand a still-running server that blocks the next add's activation.
*/
import { errorMessage } from '../../shared/error-message'
import { wslHostServerStopReason } from '../../shared/wsl-host-failure-copy'
import {
removeWslHostEnvironment,
setWslHostPendingStop
Expand Down Expand Up @@ -52,9 +53,12 @@ export async function removeWslHostServer(
noteWslHostUserAction({ kind: 'removed', distro: record.distro })
return { serverStop, removed: true }
}
const { reason, reasonCode, reasonParams } = serverStop
setWslHostPendingStop(userDataPath, record.environmentId, {
since: Date.now(),
reason: serverStop.reason,
reason,
...(reasonCode ? { reasonCode } : {}),
...(reasonCode && reasonParams ? { reasonParams } : {}),
verdict: serverStop.verdict ?? 'unverifiable'
})
return { serverStop: { ...serverStop, kept: true }, removed: false }
Expand All @@ -81,7 +85,7 @@ function noteServerKeptForPeers(
return {
stopped: false,
verdict: serverStop.keptForOtherDesktops ? 'live' : 'unverifiable',
reason: `Orca couldn’t record what this Remove left running: ${errorMessage(error)}`
...wslHostServerStopReason('removalUnrecorded', { detail: errorMessage(error) })
}
}
}
Expand Down
Loading
Loading