Files
orca/src/shared/path-existence-batch.ts
T
Neil 3a68805eee fix(wsl): Settings CLI status, CLI repair, interop health and link checks never boot a stopped distro (E9) (#35412)
* fix(wsl): Settings CLI status, startup CLI repair, interop health and link checks never boot a stopped distro (E9)

- cli:getWslInstallStatus: opening Settings takes a settled running read and shows a refreshable
  "not running" status instead of starting the distro; the refresh button passes wakeWslDistro.
- Startup CLI repair re-reads each listed distro (settled) right before its repair spawns and
  defers it otherwise, so a distro stopping mid fan-out is not restarted.
- Interop health: stop-triggered checks no longer trust the stop event's list; every check takes a
  settled read, and again before the root repair.
- shell:pathsExist (chat link and terminal hover existence) refuses a stopped distro's UNC path
  instead of statting it; callers already retry an unverifiable answer.

* docs(wsl): note the missing-kernel availability probe as the known E9 exception

* fix(wsl): shell:pathsExist refuses only the stopped distro's path, not the whole batch

One UNC path in a stopped distro no longer fails the host paths checked with it; the renderer
treats that path alone as unverifiable and retries it.
2026-10-28 18:24:26 -07:00

43 lines
1.5 KiB
TypeScript

export const PATH_EXISTENCE_BATCH_MAX = 128
export const PATH_EXISTENCE_BATCH_CAPABILITY = 'files.pathsExist'
export type PathExistenceResult = { exists: boolean } | { error: string }
/** The desktop shell batch: a boolean per answered path, an error for one it refused. */
export type ShellPathExistence = boolean | { error: string }
export function validatePathExistenceBatch(paths: unknown): asserts paths is string[] {
if (
!Array.isArray(paths) ||
paths.length > PATH_EXISTENCE_BATCH_MAX ||
paths.some((path) => typeof path !== 'string')
) {
throw new Error('Invalid path existence batch')
}
}
export async function capturePathExistence(
check: () => Promise<boolean>
): Promise<PathExistenceResult> {
try {
return { exists: await check() }
} catch (error) {
return { error: error instanceof Error ? error.message : String(error) }
}
}
export function requirePathExistenceResults(value: unknown, count: number): PathExistenceResult[] {
if (!Array.isArray(value) || value.length !== count) {
throw new Error('Invalid path existence response')
}
return value.map((row: unknown): PathExistenceResult => {
if (row && typeof row === 'object') {
if ('exists' in row && typeof row.exists === 'boolean' && !('error' in row)) {
return { exists: row.exists }
}
if ('error' in row && typeof row.error === 'string' && !('exists' in row)) {
return { error: row.error }
}
}
throw new Error('Invalid path existence response')
})
}