fix(infra): resolve Windows binary lookup tool · openclaw/openclaw@d3b4444
vincentkoc
·
2026-06-21
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Covers host binary detection command selection. |
| 2 | +import path from "node:path"; |
| 3 | +import { afterEach, describe, expect, it, vi } from "vitest"; |
| 4 | +import { withMockedWindowsPlatform } from "../test-utils/vitest-spies.js"; |
| 5 | +import { resetWindowsInstallRootsForTests } from "./windows-install-roots.js"; |
| 6 | + |
| 7 | +const runCommandWithTimeoutMock = vi.hoisted(() => vi.fn()); |
| 8 | + |
| 9 | +vi.mock("../process/exec.js", () => ({ |
| 10 | +runCommandWithTimeout: runCommandWithTimeoutMock, |
| 11 | +})); |
| 12 | + |
| 13 | +import { detectBinary } from "./detect-binary.js"; |
| 14 | + |
| 15 | +afterEach(() => { |
| 16 | +vi.restoreAllMocks(); |
| 17 | +vi.unstubAllEnvs(); |
| 18 | +runCommandWithTimeoutMock.mockReset(); |
| 19 | +resetWindowsInstallRootsForTests(); |
| 20 | +}); |
| 21 | + |
| 22 | +describe("detectBinary", () => { |
| 23 | +it("uses the trusted Windows where.exe when probing PATH", async () => { |
| 24 | +vi.stubEnv("SystemRoot", "D:\\Windows"); |
| 25 | +resetWindowsInstallRootsForTests({ queryRegistryValue: () => null }); |
| 26 | +runCommandWithTimeoutMock.mockResolvedValue({ |
| 27 | +code: 0, |
| 28 | +stdout: "D:\\Tools\\openclaw.exe\n", |
| 29 | +}); |
| 30 | + |
| 31 | +await withMockedWindowsPlatform(async () => { |
| 32 | +await expect(detectBinary("openclaw")).resolves.toBe(true); |
| 33 | +}); |
| 34 | + |
| 35 | +expect(runCommandWithTimeoutMock).toHaveBeenCalledWith( |
| 36 | +[path.win32.join("D:\\Windows", "System32", "where.exe"), "openclaw"], |
| 37 | +{ timeoutMs: 2000 }, |
| 38 | +); |
| 39 | +}); |
| 40 | +}); |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。