mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
fix(telemetry): omit distros_running when the WSL running state wasn't probed
A skipped probe was reported as a confirmed empty list, so the daily snapshot sent distros_running=0 even with distros running. The field is now optional and left out when no probe ran. Refs #28167
This commit is contained in:
@@ -1,12 +1,32 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { listRunningDistrosForSnapshot } from './wsl-usage-reporter'
|
||||
import { buildWslUsageSnapshot } from './wsl-usage-snapshot'
|
||||
import { wslUsageSnapshotSchema } from '../../shared/telemetry/schemas/telemetry-wsl-usage-event-schemas'
|
||||
|
||||
describe('listRunningDistrosForSnapshot', () => {
|
||||
it('probes no running list when no Orca project uses WSL', async () => {
|
||||
it('probes no running list when no Orca project uses WSL, and says it did not', async () => {
|
||||
const probe = vi.fn(async () => ['Ubuntu'])
|
||||
await expect(
|
||||
listRunningDistrosForSnapshot([{ distro: 'Ubuntu' }], false, () => null, probe)
|
||||
).resolves.toEqual([])
|
||||
).resolves.toBeNull()
|
||||
expect(probe).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildWslUsageSnapshot running count', () => {
|
||||
const input = {
|
||||
registeredDistroCount: 1,
|
||||
userDistros: [{ version: 2 as const, state: 'stopped' as const }],
|
||||
wslPackageVersion: null,
|
||||
wslAvailableCached: null,
|
||||
projects: [],
|
||||
windowsDriveReposWithWslWorktrees: 0,
|
||||
wslHostsGateOpen: false
|
||||
}
|
||||
|
||||
it('omits distros_running when running state was not probed, rather than reporting 0', () => {
|
||||
const props = buildWslUsageSnapshot({ ...input, distrosRunningKnown: false })
|
||||
expect(props).not.toHaveProperty('distros_running')
|
||||
expect(wslUsageSnapshotSchema.safeParse(props).success).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -135,20 +135,23 @@ 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 Orca project uses WSL: telemetry alone shouldn't run `wsl.exe` (#28167).
|
||||
* or no Orca project uses WSL: telemetry alone shouldn't run `wsl.exe` (#28167). Null: not probed.
|
||||
*/
|
||||
export async function listRunningDistrosForSnapshot(
|
||||
registrations: readonly { distro: string }[] | null,
|
||||
hasWslProjects: boolean,
|
||||
peek: () => readonly string[] | null = peekConfirmedRunningWslDistros,
|
||||
probe: () => Promise<string[]> = listConfirmedRunningWslDistros
|
||||
): Promise<string[]> {
|
||||
): Promise<string[] | null> {
|
||||
const cached = peek()
|
||||
if (cached) {
|
||||
return [...cached]
|
||||
}
|
||||
const userNames = filterUserWslDistros((registrations ?? []).map(({ distro }) => distro))
|
||||
return userNames.length > 0 && hasWslProjects ? probe() : []
|
||||
if (userNames.length === 0) {
|
||||
return []
|
||||
}
|
||||
return hasWslProjects ? probe() : null
|
||||
}
|
||||
|
||||
export async function gatherWslUsageSnapshotInput(
|
||||
@@ -164,15 +167,18 @@ export async function gatherWslUsageSnapshotInput(
|
||||
() => hostDistros,
|
||||
getCachedWslDistros()?.[0] ?? null
|
||||
)
|
||||
let distrosRunningKnown = true
|
||||
const userDistros = await listWslHostDistros({
|
||||
readRegistrations: async () => registrations,
|
||||
readRunning: async () => ({
|
||||
status: 'confirmed',
|
||||
distros: await listRunningDistrosForSnapshot(registrations, projects.length > 0)
|
||||
})
|
||||
readRunning: async () => {
|
||||
const running = await listRunningDistrosForSnapshot(registrations, projects.length > 0)
|
||||
distrosRunningKnown = running !== null
|
||||
return { status: 'confirmed', distros: running ?? [] }
|
||||
}
|
||||
})
|
||||
return {
|
||||
registeredDistroCount: registrations?.length ?? null,
|
||||
distrosRunningKnown,
|
||||
// A confirmed read never yields 'unverifiable'; the snapshot's schema keeps its two states.
|
||||
userDistros: userDistros.map(({ version, state }) => ({
|
||||
version,
|
||||
|
||||
@@ -31,6 +31,8 @@ export type WslUsageSnapshotInput = {
|
||||
registeredDistroCount: number | null
|
||||
/** User distros (Docker Desktop's excluded) with WSL version and running state. */
|
||||
userDistros: readonly WslUsageDistro[]
|
||||
/** False when running state wasn't probed; `distros_running` is then omitted, not reported as 0. */
|
||||
distrosRunningKnown?: boolean
|
||||
wslPackageVersion: string | null
|
||||
wslAvailableCached: boolean | null
|
||||
projects: readonly WslUsageProject[]
|
||||
@@ -109,7 +111,11 @@ export function buildWslUsageSnapshot(input: WslUsageSnapshotInput): WslUsageSna
|
||||
...(version ? { wsl_version: version } : {}),
|
||||
distro_registry_readable: input.registeredDistroCount !== null,
|
||||
distros_installed: bucketWslUsageCount(userDistros.length),
|
||||
distros_running: bucketWslUsageCount(count(userDistros, (d) => d.state === 'running')),
|
||||
...(input.distrosRunningKnown === false
|
||||
? {}
|
||||
: {
|
||||
distros_running: bucketWslUsageCount(count(userDistros, (d) => d.state === 'running'))
|
||||
}),
|
||||
distros_wsl1: bucketWslUsageCount(count(userDistros, (d) => d.version === 1)),
|
||||
distros_wsl2: bucketWslUsageCount(count(userDistros, (d) => d.version === 2)),
|
||||
projects_wsl_total: bucketWslUsageCount(projects.length),
|
||||
|
||||
@@ -31,7 +31,8 @@ export const wslUsageSnapshotSchema = z
|
||||
/** False when the distro registry could not be read, so the distro buckets mean "unknown", not 0. */
|
||||
distro_registry_readable: z.boolean(),
|
||||
distros_installed: countBucketSchema,
|
||||
distros_running: countBucketSchema,
|
||||
/** Omitted when running state wasn't probed (no WSL project). Optional, so older payloads validate. */
|
||||
distros_running: countBucketSchema.optional(),
|
||||
distros_wsl1: countBucketSchema,
|
||||
distros_wsl2: countBucketSchema,
|
||||
projects_wsl_total: countBucketSchema,
|
||||
|
||||
Reference in New Issue
Block a user