Skip to content

Commit 80f8711

Browse files
committed
Reuse the toolchain-report parser and wording for the engine-range check
Drop parseNodeVersion in favor of parseToolchainReport().nodeVersion, and source the out-of-range message from formatMissingToolsReason so the two paths can't give conflicting nvm advice (the resolved node path is still appended to pin down which install needs switching). A version mismatch is deterministic between back-to-back preflights, so return retryLimit: 1 and surface the dialog on the first attempt instead of burning the default five rounds; the fail-closed missing-version case keeps the default allowance for one-off probe hiccups. The probe also no longer pays a second Node cold start per preflight: the existing heredoc invocation now reports nodeVersion over fd 3.
1 parent e7652e9 commit 80f8711

2 files changed

Lines changed: 40 additions & 61 deletions

File tree

‎apps/desktop/src/wsl/DesktopWslEnvironment.test.ts‎

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
formatNodePtyProbeFailureReason,
1919
formatWslShellTransportFailureReason,
2020
parseNodePath,
21-
parseNodeVersion,
2221
parseResolvedPath,
2322
parseToolchainReport,
2423
probeWslDistros,
@@ -196,25 +195,6 @@ describe("parseResolvedPath", () => {
196195
});
197196
});
198197

199-
describe("parseNodeVersion", () => {
200-
it("extracts the version from a nodeVersion: line", () => {
201-
const stdout = "nodePath:/usr/bin/node\nresolvedPath:/usr/bin\nnodeVersion:18.20.8\n";
202-
expect(parseNodeVersion(stdout)).toBe("18.20.8");
203-
});
204-
205-
it("returns null when there is no nodeVersion line at all", () => {
206-
expect(parseNodeVersion("nodePath:/usr/bin/node\nresolvedPath:/usr/bin\n")).toBeNull();
207-
});
208-
209-
it("returns null when the value after the prefix is empty", () => {
210-
expect(parseNodeVersion("nodeVersion:\n")).toBeNull();
211-
});
212-
213-
it("trims surrounding whitespace and a trailing carriage return", () => {
214-
expect(parseNodeVersion(" nodeVersion:22.22.1\r\n")).toBe("22.22.1");
215-
});
216-
});
217-
218198
describe("formatMissingToolsReason", () => {
219199
it("returns null when everything is present and node is in range", () => {
220200
expect(
@@ -284,18 +264,18 @@ describe("ensureNodePtyImpl: WSL Node engine-range preflight (#3611)", () => {
284264

285265
it("rejects a resolved Node that does not satisfy nodeEngineRange (the reporter's exact case)", () =>
286266
Effect.gen(function* () {
287-
const result = yield* ensureNodePtyImpl(
288-
"Ubuntu",
289-
"C:\\repo",
290-
windowsToWslPath,
291-
{ nodeEngineRange: "^22.16 || ^23.11 || >=24.10" },
292-
);
267+
const result = yield* ensureNodePtyImpl("Ubuntu", "C:\\repo", windowsToWslPath, {
268+
nodeEngineRange: "^22.16 || ^23.11 || >=24.10",
269+
});
293270
expect(result.ok).toBe(false);
294271
if (!result.ok) {
295272
expect(result.fatal).toBe(true);
296273
expect(result.reason).toContain("18.20.8");
297274
expect(result.reason).toContain("^22.16 || ^23.11 || >=24.10");
298275
expect(result.reason).toContain("/home/josh/.nvm/versions/node/v18.20.8/bin/node");
276+
// Deterministic mismatch: surfaced on the first attempt instead of
277+
// burning the default preflight retry allowance.
278+
expect(result.retryLimit).toBe(1);
299279
}
300280
}).pipe(
301281
Effect.provideService(
@@ -312,16 +292,16 @@ describe("ensureNodePtyImpl: WSL Node engine-range preflight (#3611)", () => {
312292

313293
it("rejects (fail closed) when a range is required but the probe didn't report a version (bot-flagged fix)", () =>
314294
Effect.gen(function* () {
315-
const result = yield* ensureNodePtyImpl(
316-
"Ubuntu",
317-
"C:\\repo",
318-
windowsToWslPath,
319-
{ nodeEngineRange: "^22.16 || ^23.11 || >=24.10" },
320-
);
295+
const result = yield* ensureNodePtyImpl("Ubuntu", "C:\\repo", windowsToWslPath, {
296+
nodeEngineRange: "^22.16 || ^23.11 || >=24.10",
297+
});
321298
expect(result.ok).toBe(false);
322299
if (!result.ok) {
323300
expect(result.fatal).toBe(true);
324301
expect(result.reason).toContain("^22.16 || ^23.11 || >=24.10");
302+
// Possibly a one-off probe hiccup: keeps the default retry allowance,
303+
// unlike the deterministic version-mismatch case.
304+
expect(result.retryLimit).toBeUndefined();
325305
}
326306
}).pipe(
327307
Effect.provideService(
@@ -339,12 +319,9 @@ describe("ensureNodePtyImpl: WSL Node engine-range preflight (#3611)", () => {
339319

340320
it("does not false-positive when the resolved Node satisfies nodeEngineRange (happy path unchanged)", () =>
341321
Effect.gen(function* () {
342-
const result = yield* ensureNodePtyImpl(
343-
"Ubuntu",
344-
"C:\\repo",
345-
windowsToWslPath,
346-
{ nodeEngineRange: "^22.16 || ^23.11 || >=24.10" },
347-
);
322+
const result = yield* ensureNodePtyImpl("Ubuntu", "C:\\repo", windowsToWslPath, {
323+
nodeEngineRange: "^22.16 || ^23.11 || >=24.10",
324+
});
348325
expect(result).toEqual({
349326
ok: true,
350327
nodePath: "/home/josh/.nvm/versions/node/v22.22.1/bin/node",

‎apps/desktop/src/wsl/DesktopWslEnvironment.ts‎

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,13 @@ const NODE_PTY_PROBE_SCRIPT = (
223223
linuxServerDir: string,
224224
) => `printf 'nodePath:%s\\n' "$(command -v node 2>/dev/null)"
225225
printf 'resolvedPath:%s\\n' "$PATH"
226-
printf 'nodeVersion:%s\\n' "$(node -p 'process.versions.node' 2>/dev/null)"
227-
cd ${shellQuote(linuxServerDir)} && node <<'NODE' >/dev/null 2>&1
226+
cd ${shellQuote(linuxServerDir)} && node <<'NODE' 3>&1 >/dev/null 2>&1
227+
// Emit the version over fd 3 -- duplicated onto the probe's real stdout by
228+
// the 3>&1 above, before stdout/stderr are silenced -- so the engine-range
229+
// check reuses this node invocation instead of paying a second Node cold
230+
// start on every preflight. First statement on purpose: the version must be
231+
// reported even when the dependency checks below exit early.
232+
require("node:fs").writeSync(3, "nodeVersion:" + process.versions.node + "\\n");
228233
// The server bundle externalizes its deps to node_modules, and the WSL Node
229234
// can't read inside app.asar, so confirm those deps are unpacked on the real
230235
// filesystem before reporting the backend healthy. "effect" is the framework
@@ -330,23 +335,6 @@ export const parseResolvedPath = (stdout: string): string | null => {
330335
return resolvedPath.length > 0 ? resolvedPath : null;
331336
};
332337

333-
// Captures the resolved node's own reported version (`process.versions.node`)
334-
// from NODE_PTY_PROBE_SCRIPT, so a node that resolves but doesn't satisfy
335-
// `engines.node` can be caught at preflight instead of silently no-op'ing
336-
// (Node < the version where `import.meta.main` exists makes the server's
337-
// `if (import.meta.main)` launch gate never run, producing a clean exit
338-
// code=0 with no stdout/stderr and nothing ever listening on the port).
339-
export const parseNodeVersion = (stdout: string): string | null => {
340-
const prefix = "nodeVersion:";
341-
const line = stdout
342-
.split("\n")
343-
.map((candidate) => candidate.trim())
344-
.find((candidate) => candidate.startsWith(prefix));
345-
if (line === undefined) return null;
346-
const version = line.slice(prefix.length).trim();
347-
return version.length > 0 ? version : null;
348-
};
349-
350338
export const formatMissingToolsReason = (
351339
report: ToolchainReport,
352340
requiredRange: string | null,
@@ -491,26 +479,40 @@ export const ensureNodePtyImpl = (
491479
// unconditionally as soon as nodePath resolves) so this doesn't mask a
492480
// more specific, unrelated probe failure (e.g. the exitCode === 3 case
493481
// above) behind a Node-version error in the rare case both are true.
494-
const nodeVersion = parseNodeVersion(probe.stdout);
482+
const nodeVersion = parseToolchainReport(probe.stdout).nodeVersion;
495483
const requiredRange = options.nodeEngineRange?.trim() || null;
496484
if (requiredRange !== null) {
497485
if (nodeVersion === null) {
498486
// A range is required but the probe didn't report a version --
499487
// fail closed rather than silently letting an unchecked Node
500488
// through (the exact failure class this check exists to catch).
501-
// Fatal/bounded like the mismatch case below, so a one-off probe
502-
// hiccup still gets a few retries before falling back.
489+
// Fatal/bounded with the default retry allowance, so a one-off
490+
// probe hiccup still gets a few retries before falling back.
503491
return {
504492
ok: false,
505493
reason: `Could not determine the WSL Node.js version, which is required to satisfy ${requiredRange}. The version probe did not report a version; please report this if it persists.`,
506494
fatal: true,
507495
} as const;
508496
}
509497
if (!satisfiesSemverRange(nodeVersion, requiredRange)) {
498+
// Single source for the out-of-range wording and remediation --
499+
// formatMissingToolsReason's nodeOutOfRange branch -- so this
500+
// message can't drift from the toolchain-report path's. The
501+
// resolved path is appended because it pins down WHICH node needs
502+
// switching (e.g. an nvm default alias).
503+
const mismatch =
504+
formatMissingToolsReason({ missingTools: [], nodeVersion }, requiredRange) ??
505+
`WSL Node.js v${nodeVersion} does not satisfy the required range ${requiredRange}.`;
510506
return {
511507
ok: false,
512-
reason: `Found Node.js v${nodeVersion} at ${nodePath}, which does not satisfy the required range ${requiredRange}. Activate a supported version (e.g. nvm alias default 22 && nvm use 22) and restart T3 Code.`,
508+
reason: `${mismatch} (Resolved node: ${nodePath}.)`,
513509
fatal: true,
510+
// Unlike the missing-version case above, the resolved version
511+
// cannot change between the manager's back-to-back preflight
512+
// retries, so surface the actionable error immediately instead
513+
// of burning the default retry allowance on a deterministic
514+
// failure.
515+
retryLimit: 1,
514516
} as const;
515517
}
516518
}

0 commit comments

Comments
 (0)