From 7b9e20f2fa23f1415649fe6c5a5d9f705398770f Mon Sep 17 00:00:00 2001 From: MotorwaySouth9 Date: Fri, 16 Jan 2026 09:02:02 +0800 Subject: [PATCH] test: harden windows lsp test cleanup --- src/cli/doctor/checks/lsp.test.ts | 18 ++++++++++-------- src/tools/lsp/config.test.ts | 22 ++++++++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/cli/doctor/checks/lsp.test.ts b/src/cli/doctor/checks/lsp.test.ts index e21ebc418..259456faa 100644 --- a/src/cli/doctor/checks/lsp.test.ts +++ b/src/cli/doctor/checks/lsp.test.ts @@ -22,15 +22,17 @@ describe("lsp check", () => { // #given const spawnSpy = spyOn(Bun, "spawn") - // #when getting servers info - await lsp.getLspServersInfo() + try { + // #when getting servers info + await lsp.getLspServersInfo() - // #then should not spawn which - const calls = spawnSpy.mock.calls - const whichCalls = calls.filter((c) => Array.isArray(c) && Array.isArray(c[0]) && c[0][0] === "which") - expect(whichCalls.length).toBe(0) - - spawnSpy.mockRestore() + // #then should not spawn which + const calls = spawnSpy.mock.calls + const whichCalls = calls.filter((c) => Array.isArray(c) && Array.isArray(c[0]) && c[0][0] === "which") + expect(whichCalls.length).toBe(0) + } finally { + spawnSpy.mockRestore() + } }) }) diff --git a/src/tools/lsp/config.test.ts b/src/tools/lsp/config.test.ts index 977b6af00..66c4a6f30 100644 --- a/src/tools/lsp/config.test.ts +++ b/src/tools/lsp/config.test.ts @@ -24,14 +24,20 @@ describe("isServerInstalled", () => { console.error(`Failed to clean up temp dir: ${e}`) } - const keys = ["PATH", "Path", "PATHEXT"] - for (const key of keys) { - const val = savedEnv[key] - if (val === undefined) { - delete process.env[key] - } else { - process.env[key] = val - } + const pathVal = savedEnv.PATH ?? savedEnv.Path + if (pathVal === undefined) { + delete process.env.PATH + delete process.env.Path + } else { + process.env.PATH = pathVal + process.env.Path = pathVal + } + + const pathextVal = savedEnv.PATHEXT + if (pathextVal === undefined) { + delete process.env.PATHEXT + } else { + process.env.PATHEXT = pathextVal } })