From 2c12b1eef6ce7b5ce464f1a9aa7d2efab5c2bf5c Mon Sep 17 00:00:00 2001 From: Priyanshu Choudhary <57816400+Priyanchew@users.noreply.github.com> Date: Wed, 8 Apr 2026 22:50:00 +0530 Subject: [PATCH] test(core): add IPv6 netstat test for findPidByPort + mark _resetShellCache as @internal - Add test case for IPv6 LISTENING entries ([::]:3000) in Windows netstat output - Add @internal JSDoc to _resetShellCache to clarify it is test-only Co-Authored-By: Claude Sonnet 4.6 --- packages/core/src/__tests__/platform.mock.test.ts | 15 +++++++++++++++ packages/core/src/platform.ts | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/core/src/__tests__/platform.mock.test.ts b/packages/core/src/__tests__/platform.mock.test.ts index 667bcc68a..a5435b19c 100644 --- a/packages/core/src/__tests__/platform.mock.test.ts +++ b/packages/core/src/__tests__/platform.mock.test.ts @@ -272,6 +272,21 @@ describe("findPidByPort", () => { expect(pid).toBeNull(); }); + it("finds PID from IPv6 LISTENING line on Windows", async () => { + setPlatform("win32"); + // netstat -ano includes IPv6 entries like [::]:3000 when server binds to all interfaces + const netstatOutput = [ + " Proto Local Address Foreign Address State PID", + " TCP [::]:3000 [::]:0 LISTENING 55", + ].join("\n"); + resolveExecFile(netstatOutput); + + const mod = await import("../platform.js"); + const pid = await mod.findPidByPort(3000); + + expect(pid).toBe("55"); + }); + it("returns null when no LISTENING line matches on Windows", async () => { setPlatform("win32"); resolveExecFile(" TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 99\n"); diff --git a/packages/core/src/platform.ts b/packages/core/src/platform.ts index 6f3f65b19..987025ba6 100644 --- a/packages/core/src/platform.ts +++ b/packages/core/src/platform.ts @@ -63,7 +63,9 @@ export function getShell(): ShellInfo { return cachedShell; } -/** Reset cached shell (for testing) */ +/** Reset cached shell (for testing) + * @internal + */ export function _resetShellCache(): void { cachedShell = null; }