Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/lib/onboard/windows-host-ollama.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { afterEach, describe, expect, it, vi } from "vitest";

const runCapture = vi.fn<(command: string | string[]) => string>(() => "");

vi.mock("../runner", () => ({
runCapture: (command: string | string[]) => runCapture(command),
}));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix mock signature to match the real runCapture signature.

The mock signature doesn't match the actual runCapture function. Looking at src/lib/runner.ts:216-261, the real signature is:

function runCapture(cmd: readonly string[], opts: CaptureOptions = {}): string

But the mock only declares one parameter. This may cause TypeScript compilation errors when the code under test calls runCapture([...], { ignoreError: true }).

🔧 Proposed fix to match the real signature
-const runCapture = vi.fn<(command: string | string[]) => string>(() => "");
+const runCapture = vi.fn<(cmd: readonly string[], opts?: { ignoreError?: boolean }) => string>(() => "");

 vi.mock("../runner", () => ({
-  runCapture: (command: string | string[]) => runCapture(command),
+  runCapture: (cmd: readonly string[], opts?: { ignoreError?: boolean }) => runCapture(cmd, opts),
 }));

Then update the mock implementation to use the correct parameter name:

-    runCapture.mockImplementation((command) => {
-      const cmd = Array.isArray(command) ? command.join(" ") : command;
+    runCapture.mockImplementation((cmd) => {
+      const cmdStr = cmd.join(" ");
-      if (cmd.includes("Get-Command ollama.exe")) return "";
+      if (cmdStr.includes("Get-Command ollama.exe")) return "";
       // ... update other checks similarly
     });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/onboard/windows-host-ollama.test.ts` around lines 6 - 10, The mock
for runCapture has the wrong signature; update the mock declaration and
implementation to match the real function signature runCapture(cmd: readonly
string[], opts: CaptureOptions = {}): string by changing the vi.fn to accept two
parameters (cmd: readonly string[], opts?: CaptureOptions) and updating the
vi.mock implementation to forward both arguments (command and opts) to the
runCapture mock; import or reference the CaptureOptions type if needed so
TypeScript types line up with the real runCapture used by the tests.


vi.mock("../platform", () => ({
isWsl: vi.fn(() => true),
}));

import { isWsl } from "../platform";
import { detectWindowsHostOllama } from "./windows-host-ollama";

describe("detectWindowsHostOllama", () => {
afterEach(() => {
vi.clearAllMocks();
vi.mocked(isWsl).mockReturnValue(true);
});

it("detects installed-but-not-running Ollama via known install path (#4066)", () => {
const knownPath = "C:\\Users\\tester\\AppData\\Local\\Programs\\Ollama\\ollama.exe";
runCapture.mockImplementation((command) => {
const cmd = Array.isArray(command) ? command.join(" ") : command;
if (cmd.includes("Get-Command ollama.exe")) return "";
if (cmd.includes("Get-Process ollama") && cmd.includes("Path")) return "";
if (cmd.includes("Get-Process ollama") && cmd.includes("Id")) return "";
if (cmd.includes("Test-Path -LiteralPath")) return knownPath;
if (cmd.includes("Get-NetTCPConnection")) return "";
return "";
});

expect(detectWindowsHostOllama()).toEqual({
installed: true,
installedPath: knownPath,
loopbackOnly: false,
});
});
});
9 changes: 3 additions & 6 deletions src/lib/onboard/windows-host-ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,9 @@ function probeInstalledPath(): string {
// lookup (#3949).
const processPath = powershell(GET_PROCESS_OLLAMA_PATH);
if (processPath.length > 0) return processPath;
// Some WSL-launched PowerShell sessions can see the Windows ollama PID
// but cannot read the Path property. Only after observing the live
// daemon, fall back to fixed installer locations so the restart path
// still has an explicit executable to launch.
const pid = powershell(GET_PROCESS_OLLAMA_ID);
if (!pid) return "";
// Silent installs often land in fixed locations without updating PATH or
// leaving a running daemon to probe. Check those paths even when no PID is
// visible so WSL onboarding offers Start instead of Install (#4066).
return powershell(GET_KNOWN_OLLAMA_INSTALL_PATH);
}

Expand Down
Loading