From 9b80c221ce10b87d8c6e230a9d6c399490fbb01f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Facu=5FVi=C3=B1as?= Date: Wed, 11 Mar 2026 15:46:44 -0300 Subject: [PATCH] fix: isolate remote-questions config test for Windows compatibility resolveRemoteConfig test used process.env.HOME which is undefined on Windows (Node uses USERPROFILE). Use a temp directory with both HOME and USERPROFILE set, and clean up in a finally block. Co-Authored-By: Claude Opus 4.6 --- .../gsd/tests/remote-questions.test.ts | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/resources/extensions/gsd/tests/remote-questions.test.ts b/src/resources/extensions/gsd/tests/remote-questions.test.ts index f409224ce..5480b15e0 100644 --- a/src/resources/extensions/gsd/tests/remote-questions.test.ts +++ b/src/resources/extensions/gsd/tests/remote-questions.test.ts @@ -3,8 +3,6 @@ import assert from "node:assert/strict"; import { parseSlackReply, parseDiscordResponse } from "../../remote-questions/format.ts"; import { resolveRemoteConfig } from "../../remote-questions/config.ts"; -const originalEnv = { ...process.env }; - test("parseSlackReply handles single-number single-question answers", () => { const result = parseSlackReply("2", [{ id: "choice", @@ -90,18 +88,30 @@ test("parseDiscordResponse rejects multi-question reaction parsing", () => { }); test("resolveRemoteConfig clamps invalid timeout and poll interval values", async () => { - process.env.SLACK_BOT_TOKEN = "token"; - const home = process.env.HOME!; + const os = await import("node:os"); const fs = await import("node:fs"); const path = await import("node:path"); - const prefsPath = path.join(home, ".gsd", "preferences.md"); - fs.mkdirSync(path.dirname(prefsPath), { recursive: true }); - fs.writeFileSync(prefsPath, `---\nremote_questions:\n channel: slack\n channel_id: \"C123\"\n timeout_minutes: 999\n poll_interval_seconds: 0\n---\n`, "utf-8"); - const config = resolveRemoteConfig(); - assert.ok(config); - assert.equal(config?.timeoutMs, 30 * 60 * 1000); - assert.equal(config?.pollIntervalMs, 2 * 1000); + const savedHome = process.env.HOME; + const savedUserProfile = process.env.USERPROFILE; + const tempHome = path.join(os.tmpdir(), `gsd-remote-config-${Date.now()}-${Math.random().toString(36).slice(2)}`); + fs.mkdirSync(path.join(tempHome, ".gsd"), { recursive: true }); + process.env.HOME = tempHome; + process.env.USERPROFILE = tempHome; + process.env.SLACK_BOT_TOKEN = "token"; - process.env = { ...originalEnv }; + try { + const prefsPath = path.join(tempHome, ".gsd", "preferences.md"); + fs.writeFileSync(prefsPath, `---\nremote_questions:\n channel: slack\n channel_id: \"C123\"\n timeout_minutes: 999\n poll_interval_seconds: 0\n---\n`, "utf-8"); + + const config = resolveRemoteConfig(); + assert.ok(config); + assert.equal(config?.timeoutMs, 30 * 60 * 1000); + assert.equal(config?.pollIntervalMs, 2 * 1000); + } finally { + process.env.HOME = savedHome; + process.env.USERPROFILE = savedUserProfile; + delete process.env.SLACK_BOT_TOKEN; + fs.rmSync(tempHome, { recursive: true, force: true }); + } });