diff --git a/packages/gui-extensions/src/wsl/runtime.test.ts b/packages/gui-extensions/src/wsl/runtime.test.ts index 709de89f1206..c190d57f1557 100644 --- a/packages/gui-extensions/src/wsl/runtime.test.ts +++ b/packages/gui-extensions/src/wsl/runtime.test.ts @@ -66,6 +66,11 @@ test("parseDiscoveredCli returns the discovered path, not a login-shell banner l expect(parseDiscoveredCli("")).toBeNull() expect(parseDiscoveredCli("Welcome to Ubuntu 24.04 LTS\n")).toBeNull() expect(parseDiscoveredCli("opencode\n")).toBeNull() + // A banner line can itself be an absolute path to an `opencode` binary; the script's own + // line comes after any banner, so the last path-shaped line is the discovered one. + expect(parseDiscoveredCli("/opt/old-opencode/bin/opencode\n/home/user/.opencode/bin/opencode\n")).toBe( + "/home/user/.opencode/bin/opencode", + ) }) // Runs the real discoverScript through `sh` against a fake installed CLI, diff --git a/packages/gui-extensions/src/wsl/runtime.ts b/packages/gui-extensions/src/wsl/runtime.ts index bdb8678233cd..d09cd3ce1d91 100644 --- a/packages/gui-extensions/src/wsl/runtime.ts +++ b/packages/gui-extensions/src/wsl/runtime.ts @@ -87,13 +87,15 @@ export function parseProbeAnswer(output: string) { export function parseDiscoveredCli(output: string) { // Discovery runs in a login shell (`sh -lc`), so a banner, MOTD or profile echo can precede - // the discovered path on stdout. The script prints only the CLI's absolute path, so take the - // line that is an absolute path to an `opencode` binary instead of the first line. + // the discovered path on stdout, and a banner line can itself be an absolute path to an + // `opencode` binary. The script prints only the CLI's absolute path, after any banner, so + // take the last line that is an absolute path to an `opencode` binary instead of the first + // matching line — the same last-candidate rule parseVersion and parseProbeAnswer follow. return ( output .split(/\r?\n/g) .map((line) => line.trim()) - .find((line) => line.startsWith("/") && line.endsWith("/opencode")) ?? null + .findLast((line) => line.startsWith("/") && line.endsWith("/opencode")) ?? null ) }