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 <noreply@anthropic.com>
This commit is contained in:
Priyanshu Choudhary 2026-04-08 22:50:00 +05:30
parent ae1a6e4fc5
commit 2c12b1eef6
2 changed files with 18 additions and 1 deletions

View File

@ -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");

View File

@ -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;
}