




















@@ -0,0 +1,47 @@
1+import path from "node:path";
2+import { afterEach, describe, expect, it, vi } from "vitest";
3+import { resolveBrowserOpenCommand } from "./browser-open.js";
4+import { _resetWindowsInstallRootsForTests } from "./windows-install-roots.js";
5+6+afterEach(() => {
7+vi.restoreAllMocks();
8+vi.unstubAllEnvs();
9+_resetWindowsInstallRootsForTests();
10+});
11+12+describe("resolveBrowserOpenCommand", () => {
13+it("does not resolve Windows browser launching through a relative SystemRoot", async () => {
14+vi.spyOn(process, "platform", "get").mockReturnValue("win32");
15+vi.stubEnv("SystemRoot", ".\\fake-root");
16+vi.stubEnv("windir", ".\\fake-windir");
17+_resetWindowsInstallRootsForTests({ queryRegistryValue: () => null });
18+19+const resolved = await resolveBrowserOpenCommand();
20+21+const rundll32 = path.win32.join("C:\\Windows", "System32", "rundll32.exe");
22+expect(resolved.argv).toEqual([rundll32, "url.dll,FileProtocolHandler"]);
23+expect(resolved.command).toBe(rundll32);
24+});
25+26+it("prefers the registry-backed Windows system root over process env", async () => {
27+vi.spyOn(process, "platform", "get").mockReturnValue("win32");
28+vi.stubEnv("SystemRoot", "C:\\PoisonedWindows");
29+_resetWindowsInstallRootsForTests({
30+queryRegistryValue: (key, valueName) => {
31+if (
32+key === "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" &&
33+valueName === "SystemRoot"
34+) {
35+return "D:\\Windows";
36+}
37+return null;
38+},
39+});
40+41+const resolved = await resolveBrowserOpenCommand();
42+43+const rundll32 = path.win32.join("D:\\Windows", "System32", "rundll32.exe");
44+expect(resolved.argv).toEqual([rundll32, "url.dll,FileProtocolHandler"]);
45+expect(resolved.command).toBe(rundll32);
46+});
47+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。