mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
fix(wsl): drop project-demand scoping; keep only harmless WSL probe skips
Review found the legacy-demand reader had false negatives (per-tab WSL shells, worktrees outside the repo, non-persistent net use, early return) that silently dropped running distros' sessions, and a false positive for moved repos. wsl --list does not start a distro, and the session scan and CLI repair already touch only confirmed-running distros, so revert that scoping. Keep the Claude publish and telemetry skips, which only omit a running-list read when there is nothing to do with it. Refs #28000 #28167 #13190 #13278
This commit is contained in:
@@ -1,62 +1,38 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type * as LegacyWslDemandModule from '../../wsl/discovery/legacy-wsl-demand'
|
||||
import type { LegacyWslDemand } from '../../wsl/discovery/legacy-wsl-demand'
|
||||
|
||||
const wsl = vi.hoisted(() => {
|
||||
const unknownDemand = (): LegacyWslDemand | null => null
|
||||
return {
|
||||
demand: unknownDemand(),
|
||||
readRunningHomes: vi.fn(async (scope?: (running: string[]) => string[]) => ({
|
||||
homes: (scope ? scope(['Ubuntu', 'Debian']) : ['Ubuntu', 'Debian']).map(
|
||||
(distro) => `\\\\wsl.localhost\\${distro}\\home\\u`
|
||||
),
|
||||
confirmed: true
|
||||
}))
|
||||
}
|
||||
})
|
||||
const wsl = vi.hoisted(() => ({
|
||||
readRunningHomes: vi.fn(async () => ({
|
||||
homes: ['\\\\wsl.localhost\\Ubuntu\\home\\u', '\\\\wsl.localhost\\Debian\\home\\u'],
|
||||
confirmed: true
|
||||
}))
|
||||
}))
|
||||
|
||||
vi.mock('../../wsl/discovery/distro-catalog', () => ({
|
||||
hasCachedWslDistros: () => false,
|
||||
getCachedWslDistros: () => null
|
||||
hasCachedWslDistros: () => true,
|
||||
getCachedWslDistros: () => ['Ubuntu', 'Debian']
|
||||
}))
|
||||
vi.mock('../../wsl/discovery/wsl-home-unless-stopped', () => ({
|
||||
readRunningWslHomeDirsUnlessStopped: wsl.readRunningHomes,
|
||||
listLastKnownRunningWslHomeDirs: async () => []
|
||||
}))
|
||||
vi.mock('../../wsl/discovery/legacy-wsl-demand', async (original) => ({
|
||||
...(await original<typeof LegacyWslDemandModule>()),
|
||||
currentLegacyWslDemand: () => wsl.demand
|
||||
}))
|
||||
vi.mock('../../wsl/discovery/wsl-default-distro', () => ({
|
||||
resolveWslDefaultDistro: async () => 'Debian'
|
||||
}))
|
||||
|
||||
import { getAiVaultWslScanHomeDirs } from './ai-vault-scan-roots'
|
||||
|
||||
const realPlatform = process.platform
|
||||
|
||||
// Review repro for #43496: sessions in a running distro must never vanish because no saved
|
||||
// project, tab or mapped drive names it (per-tab WSL shells, worktrees elsewhere, `net use`).
|
||||
describe('AI vault WSL scan homes', () => {
|
||||
beforeEach(() => {
|
||||
Object.defineProperty(process, 'platform', { value: 'win32' })
|
||||
wsl.readRunningHomes.mockClear()
|
||||
})
|
||||
afterEach(() => {
|
||||
Object.defineProperty(process, 'platform', { value: realPlatform })
|
||||
})
|
||||
|
||||
it('reads no running distros when no legacy project uses WSL', async () => {
|
||||
wsl.demand = { distros: [], defaultDistro: false }
|
||||
await expect(getAiVaultWslScanHomeDirs()).resolves.toEqual([])
|
||||
expect(wsl.readRunningHomes).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('scans only the distros legacy projects or the default WSL terminal use', async () => {
|
||||
wsl.demand = { distros: ['ubuntu'], defaultDistro: false }
|
||||
await expect(getAiVaultWslScanHomeDirs()).resolves.toEqual([
|
||||
'\\\\wsl.localhost\\Ubuntu\\home\\u'
|
||||
])
|
||||
wsl.demand = { distros: [], defaultDistro: true }
|
||||
it('scans every running distro, whatever the saved projects use', async () => {
|
||||
await expect(getAiVaultWslScanHomeDirs()).resolves.toEqual([
|
||||
'\\\\wsl.localhost\\Ubuntu\\home\\u',
|
||||
'\\\\wsl.localhost\\Debian\\home\\u'
|
||||
])
|
||||
})
|
||||
|
||||
@@ -7,12 +7,6 @@ import {
|
||||
listLastKnownRunningWslHomeDirs,
|
||||
readRunningWslHomeDirsUnlessStopped
|
||||
} from '../../wsl/discovery/wsl-home-unless-stopped'
|
||||
import {
|
||||
currentLegacyWslDemand,
|
||||
filterToLegacyWslDemand,
|
||||
hasLegacyWslDemand
|
||||
} from '../../wsl/discovery/legacy-wsl-demand'
|
||||
import { resolveWslDefaultDistro } from '../../wsl/discovery/wsl-default-distro'
|
||||
import { filterPathsToRunningWslDistrosAsync } from '../../wsl/filesystem/wsl-running-path-filter'
|
||||
import type { AiVaultScanOptions } from '../session-scanner-types'
|
||||
import { managedOpenCodeAccountDataDirs } from '../../opencode/accounts/opencode-managed-account-data-dirs'
|
||||
@@ -88,30 +82,15 @@ export function configuredAdditionalCodexHomePaths(): readonly string[] {
|
||||
return sources.getAdditionalCodexHomePaths?.() ?? []
|
||||
}
|
||||
|
||||
/**
|
||||
* Trust cached absence of any distro; otherwise a confirmed running list (E9). Only distros with
|
||||
* legacy projects are scanned from Windows: a WSL host's orcad scans its own (#28000).
|
||||
*/
|
||||
/** Trust cached absence of any distro; otherwise a confirmed running list (E9). */
|
||||
async function scanWslHomeDirs(): Promise<{ homes: string[]; confirmed: boolean }> {
|
||||
const demand = currentLegacyWslDemand()
|
||||
if (
|
||||
process.platform !== 'win32' ||
|
||||
(hasCachedWslDistros() && getCachedWslDistros()?.length === 0) ||
|
||||
(demand && !hasLegacyWslDemand(demand))
|
||||
(hasCachedWslDistros() && getCachedWslDistros()?.length === 0)
|
||||
) {
|
||||
return { homes: [], confirmed: true }
|
||||
}
|
||||
if (!demand) {
|
||||
return readRunningWslHomeDirsUnlessStopped()
|
||||
}
|
||||
const defaultDistro = demand.defaultDistro ? await resolveWslDefaultDistro() : null
|
||||
return readRunningWslHomeDirsUnlessStopped((running) =>
|
||||
filterToLegacyWslDemand(
|
||||
running,
|
||||
demand,
|
||||
typeof defaultDistro === 'symbol' ? undefined : defaultDistro
|
||||
)
|
||||
)
|
||||
return readRunningWslHomeDirsUnlessStopped()
|
||||
}
|
||||
|
||||
/** WSL homes for work that reads inside them: a stopped distro's home is absent, not refused. */
|
||||
|
||||
@@ -1,70 +1,54 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { reconcileManagedWslCliRegistrations } from './wsl-cli-registration-reconciliation'
|
||||
import type { LegacyWslDemand } from '../../wsl/discovery/legacy-wsl-demand'
|
||||
|
||||
function rig(args: { recorded: string[]; hostDistros: string[]; demand: LegacyWslDemand | null }) {
|
||||
const listDistros = vi.fn(async () => ['Ubuntu', 'Debian'])
|
||||
const listRunningDistros = vi.fn(async () => ['Ubuntu', 'Debian'])
|
||||
const repair = vi.fn(async () => ({
|
||||
changed: false,
|
||||
managed: true,
|
||||
status: { state: 'installed' as const }
|
||||
}))
|
||||
const options = {
|
||||
platform: 'win32' as const,
|
||||
isPackaged: true,
|
||||
userDataPath: '/unused',
|
||||
createInstaller: () => ({ repairManagedRegistration: repair }),
|
||||
getHostLauncherTarget: async () => 'C:\\Orca\\orca.cmd',
|
||||
registry: {
|
||||
getCandidates: (available: string[], context?: { inspectableDistros?: readonly string[] }) =>
|
||||
// Registered distros pass; host distros pass only when inspectable.
|
||||
Promise.resolve(
|
||||
available.filter(
|
||||
(distro) =>
|
||||
args.recorded.includes(distro) || context?.inspectableDistros?.includes(distro)
|
||||
)
|
||||
),
|
||||
recordObservations: async () => {},
|
||||
listRecorded: async () => args.recorded
|
||||
},
|
||||
listOrcaHostDistros: () => args.hostDistros,
|
||||
listRunningDistros,
|
||||
isDistroRunning: async () => true,
|
||||
deferUntilRunning: () => {},
|
||||
readLegacyDemand: () => args.demand
|
||||
// Review repro for #43496: a WSL host distro must stay inspectable at startup without any
|
||||
// local project naming it, since nothing re-runs discovery when such a project appears later.
|
||||
describe('reconcileManagedWslCliRegistrations', () => {
|
||||
function rig(running: string[]) {
|
||||
const repair = vi.fn(async () => ({
|
||||
changed: true,
|
||||
managed: true,
|
||||
status: { state: 'installed' as const }
|
||||
}))
|
||||
const deferred: string[] = []
|
||||
const options = {
|
||||
platform: 'win32' as const,
|
||||
isPackaged: true,
|
||||
userDataPath: '/unused',
|
||||
listDistros: async () => ['Ubuntu', 'Debian'],
|
||||
createInstaller: () => ({ repairManagedRegistration: repair }),
|
||||
getHostLauncherTarget: async () => 'C:\\Orca\\orca.cmd',
|
||||
registry: {
|
||||
getCandidates: async (
|
||||
available: string[],
|
||||
context?: { inspectableDistros?: readonly string[] }
|
||||
) => available.filter((distro) => context?.inspectableDistros?.includes(distro)),
|
||||
recordObservations: async () => {}
|
||||
},
|
||||
listOrcaHostDistros: () => ['Ubuntu'],
|
||||
listRunningDistros: async () => running,
|
||||
isDistroRunning: async (distro: string) => running.includes(distro),
|
||||
deferUntilRunning: (distro: string) => {
|
||||
deferred.push(distro)
|
||||
}
|
||||
}
|
||||
return { options, repair, deferred }
|
||||
}
|
||||
return { options, listDistros, listRunningDistros, repair }
|
||||
}
|
||||
|
||||
describe('reconcileManagedWslCliRegistrations scoping', () => {
|
||||
it('runs no wsl.exe for a WSL-host-only user', async () => {
|
||||
const { options, listRunningDistros, repair } = rig({
|
||||
recorded: [],
|
||||
hostDistros: ['Ubuntu'],
|
||||
demand: { distros: [], defaultDistro: false }
|
||||
})
|
||||
const getCandidates = vi.fn(options.registry.getCandidates)
|
||||
await expect(
|
||||
reconcileManagedWslCliRegistrations({
|
||||
...options,
|
||||
registry: { ...options.registry, getCandidates }
|
||||
})
|
||||
).resolves.toEqual([])
|
||||
// Returned before the distro list, which is the first `wsl.exe` call.
|
||||
expect(getCandidates).not.toHaveBeenCalled()
|
||||
expect(listRunningDistros).not.toHaveBeenCalled()
|
||||
expect(repair).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('skips a WSL host distro with no legacy project but still repairs a user-installed CLI', async () => {
|
||||
const { options, listDistros, repair } = rig({
|
||||
recorded: ['Debian'],
|
||||
hostDistros: ['Ubuntu'],
|
||||
demand: { distros: [], defaultDistro: false }
|
||||
})
|
||||
const results = await reconcileManagedWslCliRegistrations({ ...options, listDistros })
|
||||
expect(results.map((result) => result.distro)).toEqual(['Debian'])
|
||||
it('inspects a running WSL host distro that no local project uses', async () => {
|
||||
const { options, repair } = rig(['Ubuntu'])
|
||||
const results = await reconcileManagedWslCliRegistrations(options)
|
||||
expect(results).toEqual([
|
||||
{ distro: 'Ubuntu', outcome: 'repaired', state: 'installed', managed: true }
|
||||
])
|
||||
expect(repair).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('defers a stopped WSL host distro instead of starting it', async () => {
|
||||
const { options, repair, deferred } = rig([])
|
||||
const results = await reconcileManagedWslCliRegistrations(options)
|
||||
expect(results).toEqual([{ distro: 'Ubuntu', outcome: 'deferred' }])
|
||||
expect(deferred).toEqual(['Ubuntu'])
|
||||
expect(repair).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,25 +1,19 @@
|
||||
import type { CliInstallState, CliInstallStatus } from '../../../shared/cli/cli-install-types'
|
||||
import { listWslDistrosAsync } from '../../wsl/discovery/distro-catalog'
|
||||
import {
|
||||
deferUntilWslDistroRunning,
|
||||
isWslDistroRunning,
|
||||
listConfirmedRunningWslDistros
|
||||
} from '../../wsl/discovery/wsl-background-distro-gate'
|
||||
import { listWslDistrosAsync } from '../../wsl/discovery/distro-catalog'
|
||||
import { CliInstaller } from '../cli-installer'
|
||||
import {
|
||||
getWslCliRegistrationCandidates,
|
||||
listRecordedWslCliDistros,
|
||||
recordWslCliRegistrationObservations,
|
||||
type WslCliRegistrationObservation
|
||||
} from './wsl-cli-registration-registry'
|
||||
import { WslCliInstaller } from './wsl-cli-installer'
|
||||
import { runSerializedWslCliRegistrationOperation } from './wsl-cli-registration-operation'
|
||||
import { readWslHostDeployments } from '../../../shared/remote-runtime/host-store/runtime-environment-registry'
|
||||
import {
|
||||
currentLegacyWslDemand,
|
||||
filterToLegacyWslDemand,
|
||||
type LegacyWslDemand
|
||||
} from '../../wsl/discovery/legacy-wsl-demand'
|
||||
|
||||
// Why: each repair spawns a guest shell; a small cap bounds the startup fan-out.
|
||||
const MAX_CONCURRENT_DISTRO_REPAIRS = 2
|
||||
@@ -45,8 +39,6 @@ type WslCliRegistrationRegistry = {
|
||||
context?: WslCliRegistrationCandidateContext
|
||||
) => Promise<string[]>
|
||||
recordObservations: (observations: WslCliRegistrationObservation[]) => Promise<void>
|
||||
/** Distros with Orca's registration record, read without `wsl.exe`. */
|
||||
listRecorded?: () => Promise<string[]>
|
||||
}
|
||||
|
||||
type WslCliRegistrationReconciliationOptions = {
|
||||
@@ -64,8 +56,6 @@ type WslCliRegistrationReconciliationOptions = {
|
||||
/** Settled read taken right before each repair spawns. */
|
||||
isDistroRunning?: (distro: string) => Promise<boolean>
|
||||
deferUntilRunning?: (distro: string, key: string, task: () => unknown) => void
|
||||
/** Null (unknown) keeps every host distro inspectable. */
|
||||
readLegacyDemand?: () => LegacyWslDemand | null
|
||||
}
|
||||
|
||||
export type WslCliRegistrationReconciliationResult =
|
||||
@@ -99,8 +89,7 @@ export async function reconcileManagedWslCliRegistrations(
|
||||
getCandidates: (availableDistros, context) =>
|
||||
getWslCliRegistrationCandidates(options.userDataPath, availableDistros, context ?? {}),
|
||||
recordObservations: (observations) =>
|
||||
recordWslCliRegistrationObservations(options.userDataPath, observations),
|
||||
listRecorded: () => listRecordedWslCliDistros(options.userDataPath)
|
||||
recordWslCliRegistrationObservations(options.userDataPath, observations)
|
||||
} satisfies WslCliRegistrationRegistry)
|
||||
|
||||
let createInstaller = options.createInstaller
|
||||
@@ -122,23 +111,14 @@ export async function reconcileManagedWslCliRegistrations(
|
||||
getHostLauncherTarget ??= () => getHostStatus().then((status) => status.launcherPath)
|
||||
}
|
||||
|
||||
const hostDistros = await (
|
||||
options.listOrcaHostDistros ?? (async () => await orcaHostDistros(options.userDataPath))
|
||||
)()
|
||||
// A WSL host's own orcad serves its distro; only legacy projects there need the bridge CLI (#28000).
|
||||
const demand = (options.readLegacyDemand ?? currentLegacyWslDemand)()
|
||||
const inspectableDistros = demand
|
||||
? filterToLegacyWslDemand(hostDistros, demand, undefined)
|
||||
: hostDistros
|
||||
// Orca's own records name every possible candidate: with none, `wsl.exe` has nothing to list.
|
||||
if (!options.listDistros && !(await hasRecordedOrInspectable(registry, inspectableDistros))) {
|
||||
return []
|
||||
}
|
||||
const availableDistros = await (options.listDistros ?? listWslDistrosAsync)()
|
||||
const currentTarget = getHostLauncherTarget
|
||||
? await getHostLauncherTarget().catch(() => null)
|
||||
: null
|
||||
const appVersion = options.appVersion ?? ''
|
||||
const inspectableDistros = await (
|
||||
options.listOrcaHostDistros ?? (async () => await orcaHostDistros(options.userDataPath))
|
||||
)()
|
||||
const candidates = await registry.getCandidates(availableDistros, {
|
||||
currentTarget,
|
||||
appVersion,
|
||||
@@ -237,16 +217,6 @@ export async function reconcileManagedWslCliRegistrations(
|
||||
return [...results, ...deferred]
|
||||
}
|
||||
|
||||
async function hasRecordedOrInspectable(
|
||||
registry: WslCliRegistrationRegistry,
|
||||
inspectable: readonly string[]
|
||||
): Promise<boolean> {
|
||||
// A registry that can't list its records keeps the unscoped listing.
|
||||
return (
|
||||
inspectable.length > 0 || !registry.listRecorded || (await registry.listRecorded()).length > 0
|
||||
)
|
||||
}
|
||||
|
||||
async function orcaHostDistros(userDataPath: string): Promise<string[]> {
|
||||
try {
|
||||
return (await readWslHostDeployments(userDataPath)).deployments.map((record) => record.distro)
|
||||
|
||||
@@ -223,12 +223,6 @@ export async function getWslCliRegistrationCandidates(
|
||||
})
|
||||
}
|
||||
|
||||
/** Distros carrying Orca's own registration record; read from disk, so no `wsl.exe`. */
|
||||
export async function listRecordedWslCliDistros(userDataPath: string): Promise<string[]> {
|
||||
await getKeyedSerializedQueueTail(writeQueues, getRegistryPath(userDataPath))
|
||||
return (await readState(userDataPath)).registeredDistros
|
||||
}
|
||||
|
||||
export function recordWslCliRegistrationObservations(
|
||||
userDataPath: string,
|
||||
observations: WslCliRegistrationObservation[],
|
||||
|
||||
@@ -59,7 +59,6 @@ import {
|
||||
logWslCliReconciliationResults,
|
||||
reconcileManagedWslCliRegistrations
|
||||
} from '../cli/wsl/wsl-cli-registration-reconciliation'
|
||||
import { setLegacyWslDemandStore } from '../wsl/discovery/legacy-wsl-demand'
|
||||
import { createWslCliReconciliationStartupBarrier } from './wsl-startup/wsl-cli-reconciliation-startup-barrier'
|
||||
import { agentHookServer } from '../agent-hooks/server/agent-hook-server'
|
||||
import { isAgentStatusHooksEnabled } from '../../shared/agent-hook-listener/configuration/agent-status-hooks-setting'
|
||||
@@ -121,6 +120,27 @@ export async function initializeReadyFoundation(): Promise<void> {
|
||||
usesMockKeychain: app.commandLine.hasSwitch('use-mock-keychain')
|
||||
})
|
||||
}
|
||||
// Managed WSL launchers live outside the bundle; reconcile launcher/bridge compatibility after app updates.
|
||||
state.managedWslCliReconciliationStatus = 'pending'
|
||||
state.managedWslCliReconciliationReady = reconcileManagedWslCliRegistrations({
|
||||
isPackaged: app.isPackaged,
|
||||
userDataPath: canonicalUserDataPath,
|
||||
appVersion: app.getVersion()
|
||||
})
|
||||
.then((results) => {
|
||||
logWslCliReconciliationResults(results)
|
||||
state.managedWslCliReconciliationStatus = 'settled'
|
||||
})
|
||||
.catch((error) => {
|
||||
state.managedWslCliReconciliationStatus = 'failed'
|
||||
console.warn(
|
||||
'[wsl-cli] Managed registration reconciliation discovery failed:',
|
||||
error instanceof Error ? error.message : String(error)
|
||||
)
|
||||
})
|
||||
state.managedWslCliStartupBarrierReady = createWslCliReconciliationStartupBarrier(
|
||||
state.managedWslCliReconciliationReady
|
||||
)
|
||||
const profile = ensureActiveOrcaProfile()
|
||||
state.activeOrcaProfile = profile
|
||||
// Read durable browser hosting ID before window argv stamps it or renderer and lease ownership diverge.
|
||||
@@ -154,29 +174,6 @@ export async function initializeReadyFoundation(): Promise<void> {
|
||||
}
|
||||
const store = profileState.store
|
||||
state.store = store
|
||||
// Scopes legacy-bridge WSL background work to distros the user's projects are on.
|
||||
setLegacyWslDemandStore(store)
|
||||
// Managed WSL launchers live outside the bundle; reconcile after app updates. After the store: it scopes the distros.
|
||||
state.managedWslCliReconciliationStatus = 'pending'
|
||||
state.managedWslCliReconciliationReady = reconcileManagedWslCliRegistrations({
|
||||
isPackaged: app.isPackaged,
|
||||
userDataPath: canonicalUserDataPath,
|
||||
appVersion: app.getVersion()
|
||||
})
|
||||
.then((results) => {
|
||||
logWslCliReconciliationResults(results)
|
||||
state.managedWslCliReconciliationStatus = 'settled'
|
||||
})
|
||||
.catch((error) => {
|
||||
state.managedWslCliReconciliationStatus = 'failed'
|
||||
console.warn(
|
||||
'[wsl-cli] Managed registration reconciliation discovery failed:',
|
||||
error instanceof Error ? error.message : String(error)
|
||||
)
|
||||
})
|
||||
state.managedWslCliStartupBarrierReady = createWslCliReconciliationStartupBarrier(
|
||||
state.managedWslCliReconciliationReady
|
||||
)
|
||||
hangWatchdog?.setMenuBarIconSetting(store.getSettings().showMenuBarIcon !== false)
|
||||
// SSH users keep ssh2 loaded before interactive use, as before #35731; others load it on first connect.
|
||||
if (store.getSshTargets().length > 0) {
|
||||
|
||||
@@ -2,17 +2,10 @@ import { describe, expect, it, vi } from 'vitest'
|
||||
import { listRunningDistrosForSnapshot } from './wsl-usage-reporter'
|
||||
|
||||
describe('listRunningDistrosForSnapshot', () => {
|
||||
const registrations = [{ distro: 'Ubuntu' }]
|
||||
|
||||
it('probes no running list when no legacy project uses a distro', async () => {
|
||||
it('probes no running list when no Orca project uses WSL', async () => {
|
||||
const probe = vi.fn(async () => ['Ubuntu'])
|
||||
await expect(
|
||||
listRunningDistrosForSnapshot(
|
||||
registrations,
|
||||
() => null,
|
||||
probe,
|
||||
() => ({ distros: [], defaultDistro: false })
|
||||
)
|
||||
listRunningDistrosForSnapshot([{ distro: 'Ubuntu' }], false, () => null, probe)
|
||||
).resolves.toEqual([])
|
||||
expect(probe).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@@ -14,11 +14,6 @@ import { getCachedWslAvailability } from '../wsl/discovery/wsl-availability'
|
||||
import { getCachedWslDistros } from '../wsl/discovery/distro-catalog'
|
||||
import { listConfirmedRunningWslDistros } from '../wsl/discovery/wsl-background-distro-gate'
|
||||
import { filterUserWslDistros } from '../wsl/discovery/wsl-distro-list-output'
|
||||
import {
|
||||
currentLegacyWslDemand,
|
||||
hasLegacyWslDemand,
|
||||
type LegacyWslDemand
|
||||
} from '../wsl/discovery/legacy-wsl-demand'
|
||||
import { peekConfirmedRunningWslDistros } from '../wsl/discovery/wsl-running-distro-cache'
|
||||
import { loadWindowsNativeRegistry, WINDOWS_REG_SZ } from '../windows/windows-native-registry'
|
||||
import { readWslDistroRegistrations } from '../wsl/discovery/wsl-distro-registry-id'
|
||||
@@ -140,21 +135,20 @@ async function readWslHostDistros(userDataPath: string): Promise<Map<string, str
|
||||
|
||||
/**
|
||||
* Reuse a confirmed running list; otherwise one shared probe, and none when no user distro exists
|
||||
* or no legacy project uses one (telemetry alone must not run `wsl.exe`, #28167).
|
||||
* or no Orca project uses WSL: telemetry alone shouldn't run `wsl.exe` (#28167).
|
||||
*/
|
||||
export async function listRunningDistrosForSnapshot(
|
||||
registrations: readonly { distro: string }[] | null,
|
||||
hasWslProjects: boolean,
|
||||
peek: () => readonly string[] | null = peekConfirmedRunningWslDistros,
|
||||
probe: () => Promise<string[]> = listConfirmedRunningWslDistros,
|
||||
readDemand: () => LegacyWslDemand | null = currentLegacyWslDemand
|
||||
probe: () => Promise<string[]> = listConfirmedRunningWslDistros
|
||||
): Promise<string[]> {
|
||||
const cached = peek()
|
||||
if (cached) {
|
||||
return [...cached]
|
||||
}
|
||||
const userNames = filterUserWslDistros((registrations ?? []).map(({ distro }) => distro))
|
||||
const demand = readDemand()
|
||||
return userNames.length > 0 && (!demand || hasLegacyWslDemand(demand)) ? probe() : []
|
||||
return userNames.length > 0 && hasWslProjects ? probe() : []
|
||||
}
|
||||
|
||||
export async function gatherWslUsageSnapshotInput(
|
||||
@@ -163,14 +157,20 @@ export async function gatherWslUsageSnapshotInput(
|
||||
): Promise<WslUsageSnapshotInput> {
|
||||
const gateOpen = wslHostsGateOpen()
|
||||
const registrations = await readWslDistroRegistrations()
|
||||
const hostDistros = gateOpen ? await readWslHostDistros(userDataPath) : new Map<string, string>()
|
||||
const projects = collectWslProjects(
|
||||
store,
|
||||
gateOpen,
|
||||
() => hostDistros,
|
||||
getCachedWslDistros()?.[0] ?? null
|
||||
)
|
||||
const userDistros = await listWslHostDistros({
|
||||
readRegistrations: async () => registrations,
|
||||
readRunning: async () => ({
|
||||
status: 'confirmed',
|
||||
distros: await listRunningDistrosForSnapshot(registrations)
|
||||
distros: await listRunningDistrosForSnapshot(registrations, projects.length > 0)
|
||||
})
|
||||
})
|
||||
const hostDistros = gateOpen ? await readWslHostDistros(userDataPath) : new Map<string, string>()
|
||||
return {
|
||||
registeredDistroCount: registrations?.length ?? null,
|
||||
// A confirmed read never yields 'unverifiable'; the snapshot's schema keeps its two states.
|
||||
@@ -180,12 +180,7 @@ export async function gatherWslUsageSnapshotInput(
|
||||
})),
|
||||
wslPackageVersion: readWslPackageVersion(),
|
||||
wslAvailableCached: getCachedWslAvailability(),
|
||||
projects: collectWslProjects(
|
||||
store,
|
||||
gateOpen,
|
||||
() => hostDistros,
|
||||
getCachedWslDistros()?.[0] ?? null
|
||||
),
|
||||
projects,
|
||||
windowsDriveReposWithWslWorktrees: await countWindowsDriveReposWithWslWorktrees(store),
|
||||
wslHostsGateOpen: gateOpen,
|
||||
wslHostsGateState: wslHostsGateState(),
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { Repo } from '../../../shared/repository/repo-types'
|
||||
import type { Project } from '../../../shared/project/project-types'
|
||||
import type { FolderWorkspace } from '../../../shared/folder-workspaces/folder-workspace-types'
|
||||
import {
|
||||
filterToLegacyWslDemand,
|
||||
hasLegacyWslDemand,
|
||||
readLegacyWslDemand,
|
||||
type LegacyWslDemandStore
|
||||
} from './legacy-wsl-demand'
|
||||
|
||||
function repo(id: string, path: string, extra: Partial<Repo> = {}): Repo {
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the demand reader only touches id, path, kind and host fields.
|
||||
return { id, path, displayName: id, badgeColor: '', addedAt: 0, ...extra } as Repo
|
||||
}
|
||||
|
||||
function store(args: {
|
||||
repos?: Repo[]
|
||||
projects?: Project[]
|
||||
folders?: Partial<FolderWorkspace>[]
|
||||
settings?: ReturnType<LegacyWslDemandStore['getSettings']>
|
||||
}): LegacyWslDemandStore {
|
||||
return {
|
||||
getRepos: () => args.repos ?? [],
|
||||
getProjects: () => args.projects ?? [],
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the reader only touches folderPath and host fields.
|
||||
getFolderWorkspaces: () => (args.folders ?? []) as FolderWorkspace[],
|
||||
getSettings: () => args.settings ?? {}
|
||||
}
|
||||
}
|
||||
|
||||
const noMappedDrives = (): null => null
|
||||
|
||||
describe('readLegacyWslDemand', () => {
|
||||
it('names no distro for Windows projects and WSL-host projects', () => {
|
||||
const demand = readLegacyWslDemand(
|
||||
store({
|
||||
repos: [
|
||||
repo('win', 'C:\\src\\app'),
|
||||
repo('host', '/home/u/app', { executionHostId: 'runtime:wsl-env' }),
|
||||
repo('ssh', '/srv/app', { connectionId: 'ssh-1' })
|
||||
]
|
||||
}),
|
||||
noMappedDrives
|
||||
)
|
||||
expect(demand).toEqual({ distros: [], defaultDistro: false })
|
||||
expect(hasLegacyWslDemand(demand)).toBe(false)
|
||||
})
|
||||
|
||||
it('names the distro of a WSL-share project, worktree folder or folder workspace', () => {
|
||||
const demand = readLegacyWslDemand(
|
||||
store({
|
||||
repos: [
|
||||
repo('a', '\\\\wsl.localhost\\Ubuntu\\home\\u\\a'),
|
||||
repo('b', 'C:\\src\\b', { worktreeBasePath: '\\\\wsl$\\Debian\\home\\u\\wt' })
|
||||
],
|
||||
folders: [{ folderPath: '\\\\wsl.localhost\\Alpine\\home\\u\\notes' }]
|
||||
}),
|
||||
noMappedDrives
|
||||
)
|
||||
expect(demand.distros.sort()).toEqual(['Alpine', 'Debian', 'Ubuntu'])
|
||||
expect(demand.defaultDistro).toBe(false)
|
||||
})
|
||||
|
||||
it('names the distro behind a drive letter mapped to its share', () => {
|
||||
const demand = readLegacyWslDemand(store({ repos: [repo('a', 'W:\\home\\u\\a')] }), (letter) =>
|
||||
letter === 'W' ? '\\\\wsl.localhost\\Ubuntu' : null
|
||||
)
|
||||
expect(demand.distros).toEqual(['Ubuntu'])
|
||||
})
|
||||
|
||||
it('counts the default distro for WSL terminals with no distro chosen', () => {
|
||||
const demand = readLegacyWslDemand(
|
||||
store({ settings: { terminalWindowsShell: 'wsl.exe' } }),
|
||||
noMappedDrives
|
||||
)
|
||||
expect(demand).toEqual({ distros: [], defaultDistro: true })
|
||||
})
|
||||
})
|
||||
|
||||
describe('filterToLegacyWslDemand', () => {
|
||||
it('keeps named distros case-insensitively and drops the rest', () => {
|
||||
expect(
|
||||
filterToLegacyWslDemand(
|
||||
['ubuntu', 'Debian'],
|
||||
{ distros: ['Ubuntu'], defaultDistro: false },
|
||||
null
|
||||
)
|
||||
).toEqual(['ubuntu'])
|
||||
})
|
||||
|
||||
it('keeps the default distro, or every candidate while the default is unknown', () => {
|
||||
const demand = { distros: [], defaultDistro: true }
|
||||
expect(filterToLegacyWslDemand(['Ubuntu', 'Debian'], demand, 'Debian')).toEqual(['Debian'])
|
||||
expect(filterToLegacyWslDemand(['Ubuntu', 'Debian'], demand, undefined)).toEqual([
|
||||
'Ubuntu',
|
||||
'Debian'
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -1,175 +0,0 @@
|
||||
/**
|
||||
* Which distros the user has legacy-bridge work on: work Windows-side Orca does through `wsl.exe`
|
||||
* or a `\\wsl.localhost` share. A WSL host's distro is not here; its orcad does that work inside.
|
||||
* Background probes (#28000, #13190) are scoped to these distros, and skipped when there are none.
|
||||
*/
|
||||
import type { GlobalSettings } from '../../../shared/settings/global-settings-types'
|
||||
import type { Repo } from '../../../shared/repository/repo-types'
|
||||
import type { FolderWorkspace } from '../../../shared/folder-workspaces/folder-workspace-types'
|
||||
import {
|
||||
getRepoExecutionHostId,
|
||||
LOCAL_EXECUTION_HOST_ID
|
||||
} from '../../../shared/execution-host/execution-host'
|
||||
import { parseWslUncPath } from '../../../shared/file-access/wsl-paths'
|
||||
import { isWslShellName } from '../../../shared/shell/launch/local-windows-terminal-runtime'
|
||||
import {
|
||||
resolveLocalWorkspaceRuntime,
|
||||
type ProjectRuntimeResolutionStore
|
||||
} from '../../workspaces/execution-host/local-project-runtime-resolution'
|
||||
import { classifyLocalWslProject } from '../../telemetry/wsl-usage-snapshot'
|
||||
import { loadWindowsNativeRegistry, WINDOWS_REG_SZ } from '../../windows/windows-native-registry'
|
||||
|
||||
export type LegacyWslDemandStore = Omit<ProjectRuntimeResolutionStore, 'getSettings'> & {
|
||||
getRepos: () => Repo[]
|
||||
getFolderWorkspaces?: () => FolderWorkspace[]
|
||||
getSettings: () => Partial<
|
||||
Pick<
|
||||
GlobalSettings,
|
||||
| 'localWindowsRuntimeDefault'
|
||||
| 'experimentalWslHosts'
|
||||
| 'agentCmdOverrides'
|
||||
| 'terminalWindowsShell'
|
||||
| 'terminalWindowsWslDistro'
|
||||
>
|
||||
>
|
||||
}
|
||||
|
||||
export type LegacyWslDemand = {
|
||||
/** Named distros, as the user's paths and settings spell them. */
|
||||
distros: string[]
|
||||
/** Some work runs in whichever distro `wsl.exe` defaults to. */
|
||||
defaultDistro: boolean
|
||||
}
|
||||
|
||||
/** A drive letter's `net use` target, read from the registry; no spawn and no share access. */
|
||||
export type ReadMappedDriveShare = (letter: string) => string | null
|
||||
|
||||
const DRIVE_PATH = /^([A-Za-z]):(?:[\\/]|$)/
|
||||
|
||||
function readMappedDriveShareFromRegistry(letter: string): string | null {
|
||||
try {
|
||||
const registry = loadWindowsNativeRegistry()
|
||||
const values = registry.getRegistryKey(registry.HK.CU, `Network\\${letter.toUpperCase()}`)
|
||||
const remote = Object.entries(values ?? {}).find(
|
||||
([name]) => name.toLowerCase() === 'remotepath'
|
||||
)?.[1]
|
||||
return remote?.type === WINDOWS_REG_SZ && typeof remote.value === 'string' ? remote.value : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/** The distro a path names: a WSL share, or a drive letter mapped to one. */
|
||||
function distroForPath(path: string, readMappedDrive: ReadMappedDriveShare): string | null {
|
||||
const unc = parseWslUncPath(path)
|
||||
if (unc) {
|
||||
return unc.distro
|
||||
}
|
||||
const letter = DRIVE_PATH.exec(path)?.[1]
|
||||
const share = letter ? readMappedDrive(letter) : null
|
||||
return share ? (parseWslUncPath(share)?.distro ?? null) : null
|
||||
}
|
||||
|
||||
export function readLegacyWslDemand(
|
||||
store: LegacyWslDemandStore,
|
||||
readMappedDrive: ReadMappedDriveShare = readMappedDriveShareFromRegistry
|
||||
): LegacyWslDemand {
|
||||
const distros = new Map<string, string>()
|
||||
let defaultDistro = false
|
||||
const add = (distro: string | null): void => {
|
||||
const name = distro?.trim()
|
||||
if (name) {
|
||||
distros.set(name.toLowerCase(), name)
|
||||
} else {
|
||||
defaultDistro = true
|
||||
}
|
||||
}
|
||||
// Drive lookups repeat across a project's worktree folders.
|
||||
const mappedDrives = new Map<string, string | null>()
|
||||
const readMappedDriveOnce: ReadMappedDriveShare = (letter) => {
|
||||
const key = letter.toUpperCase()
|
||||
if (!mappedDrives.has(key)) {
|
||||
mappedDrives.set(key, readMappedDrive(key))
|
||||
}
|
||||
return mappedDrives.get(key) ?? null
|
||||
}
|
||||
for (const repo of store.getRepos()) {
|
||||
if (getRepoExecutionHostId(repo) !== LOCAL_EXECUTION_HOST_ID) {
|
||||
continue
|
||||
}
|
||||
const pathDistro =
|
||||
distroForPath(repo.path, readMappedDriveOnce) ??
|
||||
(repo.worktreeBasePath ? distroForPath(repo.worktreeBasePath, readMappedDriveOnce) : null)
|
||||
if (pathDistro) {
|
||||
add(pathDistro)
|
||||
continue
|
||||
}
|
||||
const project = classifyLocalWslProject(
|
||||
repo,
|
||||
resolveLocalWorkspaceRuntime(store, repo, repo.path)
|
||||
)
|
||||
if (project) {
|
||||
add(project.distro)
|
||||
}
|
||||
}
|
||||
for (const workspace of store.getFolderWorkspaces?.() ?? []) {
|
||||
const host = workspace.executionHostId ?? LOCAL_EXECUTION_HOST_ID
|
||||
if (workspace.connectionId || host !== LOCAL_EXECUTION_HOST_ID) {
|
||||
continue
|
||||
}
|
||||
const distro = distroForPath(workspace.folderPath, readMappedDriveOnce)
|
||||
if (distro) {
|
||||
add(distro)
|
||||
}
|
||||
}
|
||||
const settings = store.getSettings()
|
||||
if (isWslShellName(settings.terminalWindowsShell)) {
|
||||
add(settings.terminalWindowsWslDistro ?? null)
|
||||
}
|
||||
return { distros: [...distros.values()], defaultDistro }
|
||||
}
|
||||
|
||||
export function hasLegacyWslDemand(demand: LegacyWslDemand): boolean {
|
||||
return demand.defaultDistro || demand.distros.length > 0
|
||||
}
|
||||
|
||||
/**
|
||||
* `candidates` the demand covers. `defaultDistro` names the distro `wsl.exe` defaults to, when
|
||||
* known; unknown keeps every candidate, since any of them may be the default.
|
||||
*/
|
||||
export function filterToLegacyWslDemand(
|
||||
candidates: readonly string[],
|
||||
demand: LegacyWslDemand,
|
||||
defaultDistro: string | null | undefined
|
||||
): string[] {
|
||||
const wanted = new Set(demand.distros.map((distro) => distro.toLowerCase()))
|
||||
return candidates.filter((candidate) => {
|
||||
const key = candidate.toLowerCase()
|
||||
if (wanted.has(key)) {
|
||||
return true
|
||||
}
|
||||
if (!demand.defaultDistro) {
|
||||
return false
|
||||
}
|
||||
return defaultDistro === undefined || defaultDistro?.toLowerCase() === key
|
||||
})
|
||||
}
|
||||
|
||||
let demandStore: LegacyWslDemandStore | null = null
|
||||
|
||||
/** Main installs the loaded store; until then (and in utility processes) demand is unknown. */
|
||||
export function setLegacyWslDemandStore(store: LegacyWslDemandStore | null): void {
|
||||
demandStore = store
|
||||
}
|
||||
|
||||
/** Null before the store loads or outside main: callers keep their unscoped behavior. */
|
||||
export function currentLegacyWslDemand(): LegacyWslDemand | null {
|
||||
if (process.platform !== 'win32' || !demandStore) {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
return readLegacyWslDemand(demandStore)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -21,15 +21,13 @@ async function homesOf(distros: readonly string[]): Promise<string[]> {
|
||||
* lists none and says so (`confirmed: false`): a stale "running" answer plus a cached home would
|
||||
* hand a stopped distro's root to the scanner.
|
||||
*/
|
||||
export async function readRunningWslHomeDirsUnlessStopped(
|
||||
scopeDistros: (running: string[]) => string[] = (running) => running
|
||||
): Promise<{
|
||||
export async function readRunningWslHomeDirsUnlessStopped(): Promise<{
|
||||
homes: string[]
|
||||
confirmed: boolean
|
||||
}> {
|
||||
const read = await readConfirmedRunningWslDistros()
|
||||
return read.status === 'confirmed'
|
||||
? { homes: await homesOf(scopeDistros(read.distros)), confirmed: true }
|
||||
? { homes: await homesOf(read.distros), confirmed: true }
|
||||
: { homes: [], confirmed: false }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user