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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type * as DistroGate from '../wsl-background-distro-gate'
import type { DaemonServer } from './daemon-server'
import type { DaemonPtyAdapter } from './daemon-pty-adapter'
import { createMockSubprocess, startDaemonAdapterHarness } from './daemon-pty-adapter-test-harness'
import { parseWslDistroStoppedHold } from '../../shared/wsl-distro-stopped-hold'
import { parseWslDistroHold } from '../../shared/wsl-distro-stopped-hold'

const readState = vi.hoisted(() =>
vi.fn(
Expand Down Expand Up @@ -54,7 +54,10 @@ describe('a passive restore of a WSL bridge pane (E9)', () => {

it('is held, starting nothing, when a settled read finds the distro stopped', async () => {
const error = await restore({ wslPassiveRestore: true }).catch((caught: unknown) => caught)
expect(error instanceof Error ? parseWslDistroStoppedHold(error.message) : null).toBe('Ubuntu')
expect(error instanceof Error ? parseWslDistroHold(error.message) : null).toEqual({
distro: 'Ubuntu',
state: 'stopped'
})
expect(spawns).toBe(0)
expect(readState).toHaveBeenCalledWith('Ubuntu', { retryUnverifiable: true })
})
Expand All @@ -69,7 +72,11 @@ describe('a passive restore of a WSL bridge pane (E9)', () => {
it('holds when the read cannot tell, too', async () => {
readState.mockResolvedValue('unverifiable')
const error = await restore({ wslPassiveRestore: true }).catch((caught: unknown) => caught)
expect(error instanceof Error ? parseWslDistroStoppedHold(error.message) : null).toBe('Ubuntu')
// Named as such, so the card says Orca couldn't check rather than that the distro stopped.
expect(error instanceof Error ? parseWslDistroHold(error.message) : null).toEqual({
distro: 'Ubuntu',
state: 'unverifiable'
})
expect(spawns).toBe(0)
})

Expand Down
7 changes: 4 additions & 3 deletions src/main/daemon/daemon-wsl-passive-restore-hold.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readWslDistroRunningState } from '../wsl-background-distro-gate'
import { wslDistroStoppedHoldMessage } from '../../shared/wsl-distro-stopped-hold'
import { wslDistroHoldMessage } from '../../shared/wsl-distro-stopped-hold'
import type { PtySpawnOptions } from '../providers/pty-provider-contract'

/**
Expand All @@ -20,7 +20,8 @@ export async function holdPassiveRestoreOfStoppedWslDistro(
) {
return
}
if ((await readWslDistroRunningState(wslDistro, { retryUnverifiable: true })) !== 'running') {
throw new Error(wslDistroStoppedHoldMessage(wslDistro))
const state = await readWslDistroRunningState(wslDistro, { retryUnverifiable: true })
if (state !== 'running') {
throw new Error(wslDistroHoldMessage(wslDistro, state))
}
}
17 changes: 14 additions & 3 deletions src/renderer/src/components/terminal-pane/WslDistroStoppedCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,31 @@ import { RemoteRuntimeRecoveryCard } from './RemoteRuntimeRecoveryCard'
/** A pane whose WSL distro is stopped: nothing restarts it on its own (E9); Start is the user's act. */
export function WslDistroStoppedCard({
distro,
unverifiable = false,
onStart,
data
}: {
distro: string
/** The running read gave no answer: say so rather than claim the distro stopped. */
unverifiable?: boolean
onStart: () => void
data: Record<`data-${string}`, string>
}): React.JSX.Element {
return (
<RemoteRuntimeRecoveryCard
icon="stopped"
data={data}
title={translate('components.native-chat.hostOutage.stopped', '{{distro}} is stopped', {
distro
})}
title={
unverifiable
? translate(
'components.native-chat.hostOutage.unverifiable',
"Orca couldn't check whether {{distro}} is running",
{ distro }
Comment on lines +24 to +26

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 The distro name gets hidden

The longer title can hide the distro name in narrow split panes. RemoteRuntimeRecoveryCard puts the title on one line with truncate, so users may see only “Orca couldn't check whether…” beside Start. Let this message wrap, or put it in the card's wrapping body, so users can read which distro could not be checked.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

)
: translate('components.native-chat.hostOutage.stopped', '{{distro}} is stopped', {
distro
})
}
action={{
label: translate('components.native-chat.hostOutage.start', 'Start'),
onClick: onStart
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// @vitest-environment happy-dom

import '@testing-library/jest-dom/vitest'
import { cleanup, render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { makePaneKey } from '../../../../shared/stable-pane-id'
import { WslDistroStoppedHoldCard } from './WslDistroStoppedHoldCard'
import {
holdPaneForStoppedWslDistro,
wslDistroStoppedHoldStore
} from './wsl-distro-stopped-hold-state'

vi.mock('@/i18n/i18n', () => ({
translate: (_key: string, fallback: string, options?: Record<string, string>) =>
fallback.replace(/\{\{(\w+)\}\}/g, (_match, name: string) => options?.[name] ?? ''),
getIntlLocale: () => 'en-US'
}))

const TAB = '11111111-1111-4111-8111-111111111111'
const LEAF = '22222222-2222-4222-8222-222222222222'

afterEach(() => {
cleanup()
wslDistroStoppedHoldStore.setState({ panes: {} })
})

function holdPane(state: 'stopped' | 'unverifiable') {
const release = vi.fn(async () => {})
holdPaneForStoppedWslDistro(makePaneKey(TAB, LEAF), { distro: 'Ubuntu', state, release })
render(<WslDistroStoppedHoldCard tabId={TAB} leafId={LEAF} />)
return release
}

describe('a restored WSL bridge pane held for its distro (E9)', () => {
it('says the distro is stopped when the read found it stopped', () => {
holdPane('stopped')
expect(screen.getByText('Ubuntu is stopped')).toBeInTheDocument()
})

// The read gave no answer, so the card must not claim the distro stopped.
it("says Orca couldn't check when the read could not tell, and still offers Start", async () => {
const release = holdPane('unverifiable')
expect(screen.getByText("Orca couldn't check whether Ubuntu is running")).toBeInTheDocument()
expect(screen.queryByText('Ubuntu is stopped')).not.toBeInTheDocument()

await userEvent.setup().click(screen.getByRole('button', { name: 'Start' }))
expect(release).toHaveBeenCalledOnce()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ export function WslDistroStoppedHoldCard({
tabId: string
leafId: string
}): React.JSX.Element | null {
const distro = useWslDistroStoppedHold(makePaneKey(tabId, leafId))
if (!distro) {
const hold = useWslDistroStoppedHold(makePaneKey(tabId, leafId))
if (!hold) {
return null
}
return (
<WslDistroStoppedCard
distro={distro}
data={{ 'data-terminal-wsl-distro-stopped-hold': distro }}
onStart={() => startHeldPanesForWslDistro(distro)}
distro={hold.distro}
unverifiable={hold.state === 'unverifiable'}
data={{
'data-terminal-wsl-distro-stopped-hold': hold.distro,
'data-terminal-wsl-distro-hold-state': hold.state
}}
onStart={() => startHeldPanesForWslDistro(hold.distro)}
/>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { ConnectPanePtySession } from './connect-pane-pty-session'
import type { HeldPaneReopenOutcome } from '../newer-daemon-hold-state'
import { holdForNewerDaemon } from './newer-daemon-hold-pane'
import { holdForStoppedWslDistro, wslRestoreStartArgs } from './wsl-distro-stopped-hold-pane'
import { parseWslDistroStoppedHold } from '../../../../../shared/wsl-distro-stopped-hold'
import { parseWslDistroHold } from '../../../../../shared/wsl-distro-stopped-hold'
import { NEWER_DAEMON_HOLD_ERROR } from '../../../../../shared/newer-daemon-hold'
import { PANE_NOT_LIVE_ERROR } from '../../../../../shared/pane-attach-only-view'
import { ORCA_LAYOUT_OWNER_IS_MAIN } from '../../../../../shared/layout-owner-switch'
Expand Down Expand Up @@ -91,7 +91,7 @@ function connectDeferredSessionReattach(
let paneOwnerUnverified = false
let paneOwnerChanged = false
let heldByNewerDaemon = false
let heldForStoppedDistro: string | null = null
let heldForStoppedDistro: ReturnType<typeof parseWslDistroHold> = null
// Why: main started this pane's agent; the window's attach never resumes it a second time.
const attachOnlyView = mainStartsPane(session)
const resumeStartup = session.buildColdRestoreAgentResumeStartup()
Expand All @@ -112,9 +112,7 @@ function connectDeferredSessionReattach(
heldByNewerDaemon = true
return
}
heldForStoppedDistro ??= session.runtimeEnvironmentId
? null
: parseWslDistroStoppedHold(message)
heldForStoppedDistro ??= session.runtimeEnvironmentId ? null : parseWslDistroHold(message)
if (heldForStoppedDistro) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
noteUserWorkspaceSwitch,
resetWorkspaceSwitchUserActsForTests
} from '@/lib/workspace-switch-user-act'
import { wslDistroStoppedHoldMessage } from '../../../../../shared/wsl-distro-stopped-hold'
import { wslDistroHoldMessage } from '../../../../../shared/wsl-distro-stopped-hold'
import {
startHeldPanesForWslDistro,
wslDistroStoppedHoldStore
Expand All @@ -20,7 +20,7 @@ vi.mock('./pty-connect-limits', () => ({
isSshSessionGoneError: () => false
}))

const HOLD = `Error invoking remote method 'pty:spawn': Error: ${wslDistroStoppedHoldMessage('Ubuntu')}`
const HOLD = `Error invoking remote method 'pty:spawn': Error: ${wslDistroHoldMessage('Ubuntu', 'stopped')}`

function createSession(opts: { runtimeEnvironmentId?: string } = {}) {
let onError: (message: string) => void = () => {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { takeWorkspaceSwitchWake } from '@/lib/workspace-switch-user-act'
import { holdPaneForStoppedWslDistro } from '../wsl-distro-stopped-hold-state'
import { recordPtyConnectDiagnostic } from './pty-connect-limits'
import type { ConnectPanePtySession } from './connect-pane-pty-session'
import type { WslDistroHoldState } from '../../../../../shared/wsl-distro-stopped-hold'

// Clears the saved screen the hold painted so the restore below paints it once.
const CLEAR_HELD_SCREEN = '\x1b[0m\x1b[2J\x1b[3J\x1b[H'
Expand Down Expand Up @@ -34,10 +35,10 @@ export function wslRestoreStartArgs(
export function holdForStoppedWslDistro(
session: ConnectPanePtySession,
sessionId: string,
distro: string,
hold: { distro: string; state: WslDistroHoldState },
reconnect: () => Promise<unknown>
): void {
recordPtyConnectDiagnostic(`pane=${session.pane.id} -> HELD FOR STOPPED WSL ${distro}`)
recordPtyConnectDiagnostic(`pane=${session.pane.id} -> HELD FOR WSL ${hold.state} ${hold.distro}`)
const generation = session.transportStreamGeneration
const terminal = session.pane.terminal
const isCurrent = (): boolean =>
Expand All @@ -49,7 +50,7 @@ export function holdForStoppedWslDistro(
// Why: nothing backs this pane, so keystrokes have nowhere to go.
terminal.options.disableStdin = true
const forget = holdPaneForStoppedWslDistro(session.cacheKey, {
distro,
...hold,
release: async () => {
held = false
if (!isCurrent()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { useStore } from 'zustand'
import { createStore } from 'zustand/vanilla'
import type { WslDistroHoldState } from '../../../../shared/wsl-distro-stopped-hold'

type HeldPane = {
distro: string
/** What the running read said: a stop, or no answer. */
state: WslDistroHoldState
/** Reconnects as the user's act, which may start the distro. */
release: () => Promise<unknown>
}
Expand Down Expand Up @@ -39,7 +42,11 @@ export function startHeldPanesForWslDistro(distro: string): void {
}
}

/** The stopped distro this pane is held for, or null. */
export function useWslDistroStoppedHold(paneKey: string): string | null {
return useStore(wslDistroStoppedHoldStore, (state) => state.panes[paneKey]?.distro ?? null)
/** The distro this pane is held for and what its read said, or null. */
export function useWslDistroStoppedHold(
paneKey: string
): { distro: string; state: WslDistroHoldState } | null {
const distro = useStore(wslDistroStoppedHoldStore, (store) => store.panes[paneKey]?.distro)
const state = useStore(wslDistroStoppedHoldStore, (store) => store.panes[paneKey]?.state)
return distro && state ? { distro, state } : null
}
3 changes: 2 additions & 1 deletion src/renderer/src/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -19264,7 +19264,8 @@
"reconnecting": "{{hostName}} stellt die Verbindung wieder her…",
"reconnect": "Erneut verbinden",
"stopped": "{{distro}} ist gestoppt",
"start": "Starten"
"start": "Starten",
"unverifiable": "Orca konnte nicht prüfen, ob {{distro}} läuft"
},
"interruptedContinue": {
"continue": "Fortfahren",
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19681,7 +19681,8 @@
"reconnecting": "{{hostName}} is reconnecting…",
"reconnect": "Reconnect",
"stopped": "{{distro}} is stopped",
"start": "Start"
"start": "Start",
"unverifiable": "Orca couldn't check whether {{distro}} is running"
},
"interruptedContinue": {
"continue": "Continue",
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/src/i18n/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -19426,7 +19426,10 @@
"hostOutage": {
"offline": "{{hostName}} está sin conexión",
"reconnecting": "{{hostName}} se está reconectando…",
"reconnect": "Reconectar"
"reconnect": "Reconectar",
"stopped": "{{distro}} está detenido",
"start": "Iniciar",
"unverifiable": "Orca no pudo comprobar si {{distro}} se está ejecutando"
},
"interruptedContinue": {
"continue": "Continuar",
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -19608,7 +19608,10 @@
"hostOutage": {
"offline": "{{hostName}} est hors ligne",
"reconnecting": "{{hostName}} se reconnecte…",
"reconnect": "Reconnecter"
"reconnect": "Reconnecter",
"stopped": "{{distro}} est arrêté",
"start": "Démarrer",
"unverifiable": "Orca n'a pas pu vérifier si {{distro}} est en cours d'exécution"
},
"interruptedContinue": {
"continue": "Continuer",
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/src/i18n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -18907,7 +18907,10 @@
"hostOutage": {
"offline": "{{hostName}} はオフラインです",
"reconnecting": "{{hostName}} に再接続しています…",
"reconnect": "再接続"
"reconnect": "再接続",
"stopped": "{{distro}} は停止しています",
"start": "起動",
"unverifiable": "Orca は {{distro}} が実行中かどうかを確認できませんでした"
},
"interruptedContinue": {
"continue": "続行",
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/src/i18n/locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -18907,7 +18907,10 @@
"hostOutage": {
"offline": "{{hostName}}이(가) 오프라인입니다",
"reconnecting": "{{hostName}}에 다시 연결하는 중…",
"reconnect": "다시 연결"
"reconnect": "다시 연결",
"stopped": "{{distro}}이(가) 중지되었습니다",
"start": "시작",
"unverifiable": "Orca가 {{distro}}이(가) 실행 중인지 확인하지 못했습니다"
},
"interruptedContinue": {
"continue": "계속",
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/src/i18n/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -20140,7 +20140,10 @@
"hostOutage": {
"offline": "{{hostName}} está offline",
"reconnecting": "{{hostName}} está reconectando…",
"reconnect": "Reconectar"
"reconnect": "Reconectar",
"stopped": "{{distro}} está parado",
"start": "Iniciar",
"unverifiable": "O Orca não conseguiu verificar se {{distro}} está em execução"
},
"interruptedContinue": {
"continue": "Continuar",
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/src/i18n/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -19856,7 +19856,10 @@
"hostOutage": {
"offline": "{{hostName}} не в сети",
"reconnecting": "Повторное подключение к {{hostName}}…",
"reconnect": "Подключиться снова"
"reconnect": "Подключиться снова",
"stopped": "{{distro}} остановлен",
"start": "Запустить",
"unverifiable": "Orca не удалось проверить, запущен ли {{distro}}"
},
"interruptedContinue": {
"continue": "Продолжить",
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/src/i18n/locales/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -19246,7 +19246,10 @@
"hostOutage": {
"offline": "{{hostName}} çevrimdışı",
"reconnecting": "{{hostName}} yeniden bağlanıyor…",
"reconnect": "Yeniden bağlan"
"reconnect": "Yeniden bağlan",
"stopped": "{{distro}} durduruldu",
"start": "Başlat",
"unverifiable": "Orca, {{distro}} öğesinin çalışıp çalışmadığını denetleyemedi"
},
"interruptedContinue": {
"continue": "Devam et",
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/src/i18n/locales/zh-Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -18990,7 +18990,10 @@
"hostOutage": {
"offline": "{{hostName}} 已離線",
"reconnecting": "正在重新連線 {{hostName}}…",
"reconnect": "重新連線"
"reconnect": "重新連線",
"stopped": "{{distro}} 已停止",
"start": "啟動",
"unverifiable": "Orca 無法確認 {{distro}} 是否正在執行"
},
"interruptedContinue": {
"continue": "繼續",
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/src/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -18877,7 +18877,10 @@
"hostOutage": {
"offline": "{{hostName}} 已离线",
"reconnecting": "正在重新连接 {{hostName}}…",
"reconnect": "重新连接"
"reconnect": "重新连接",
"stopped": "{{distro}} 已停止",
"start": "启动",
"unverifiable": "Orca 无法确认 {{distro}} 是否正在运行"
},
"interruptedContinue": {
"continue": "继续",
Expand Down
Loading
Loading