diff --git a/src/infra/wsl.test.ts b/src/infra/wsl.test.ts index 63b7b9544b0..d026cf4bbb1 100644 --- a/src/infra/wsl.test.ts +++ b/src/infra/wsl.test.ts @@ -59,6 +59,13 @@ describe("wsl detection", () => { expect(readFileSyncMock).toHaveBeenCalledWith("/proc/version", "utf8"); }); + it("returns false when sync detection cannot read /proc/version", () => { + readFileSyncMock.mockImplementationOnce(() => { + throw new Error("ENOENT"); + }); + expect(isWSLSync()).toBe(false); + }); + it.each(["Linux version 6.6.0-1-microsoft-standard-WSL2", "Linux version 6.6.0-1-wsl2"])( "detects WSL2 sync from kernel version: %s", (kernelVersion) => { @@ -68,6 +75,12 @@ describe("wsl detection", () => { }, ); + it("returns false for WSL2 sync when WSL is detected but no WSL2 markers exist", () => { + readFileSyncMock.mockReturnValueOnce("Linux version 4.4.0-19041-Microsoft"); + readFileSyncMock.mockReturnValueOnce("Linux version 4.4.0-19041-Microsoft"); + expect(isWSL2Sync()).toBe(false); + }); + it("returns false for sync detection on non-linux platforms", () => { setPlatform("darwin"); expect(isWSLSync()).toBe(false); @@ -88,6 +101,13 @@ describe("wsl detection", () => { expect(readFileMock).toHaveBeenCalledTimes(2); }); + it("short-circuits async detection from WSL env vars without reading osrelease", async () => { + process.env.WSL_DISTRO_NAME = "Ubuntu"; + + await expect(isWSL()).resolves.toBe(true); + expect(readFileMock).not.toHaveBeenCalled(); + }); + it("returns false when async WSL detection cannot read osrelease", async () => { readFileMock.mockRejectedValueOnce(new Error("ENOENT")); await expect(isWSL()).resolves.toBe(false);