mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
* fix(cli): Windows process reads and Chrome cleanup no longer pass PowerShell command text * fix(cli): a forced Chrome close on Windows ends what Chrome started * test(cli): the forced-close test's child holds no pipe to the browser * test(cli): the forced-close test's child outlives a dead parent, as Chrome's do * test(cli): forced-close test waits for the kill; PowerShell starts only via processReadArgs * fix(cli): Windows cleanup ends only a process the CLI started, never a pid it was handed
75 lines
2.7 KiB
TypeScript
75 lines
2.7 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const { execFileSyncMock } = vi.hoisted(() => ({ execFileSyncMock: vi.fn() }));
|
|
|
|
vi.mock("node:child_process", () => ({
|
|
execFileSync: execFileSyncMock,
|
|
execSync: vi.fn(),
|
|
}));
|
|
|
|
import { isProcessDescendant, processAncestorSnapshot, processIdentity } from "./orphanCleanup.js";
|
|
|
|
describe("Windows orphan-cleanup child-process options", () => {
|
|
const originalPlatform = process.platform;
|
|
|
|
beforeEach(() => {
|
|
Object.defineProperty(process, "platform", { value: "win32", configurable: true });
|
|
execFileSyncMock.mockImplementation((command: string, args: string[]) => {
|
|
if (command === "taskkill") return Buffer.alloc(0);
|
|
const [read, pid] = args.slice(-2);
|
|
if (read === "identity") return "123456\n";
|
|
if (read === "parent" && pid === "400") return "300\n";
|
|
if (read === "parent" && pid === "300") return "200\n";
|
|
return "1\n";
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
Object.defineProperty(process, "platform", { value: originalPlatform, configurable: true });
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("hides PowerShell process-identity windows", () => {
|
|
expect(processIdentity(4321)).toBe("windows:123456");
|
|
expect(isProcessDescendant(400, 200)).toBe(true);
|
|
|
|
expect(execFileSyncMock).toHaveBeenCalledTimes(3);
|
|
for (const call of execFileSyncMock.mock.calls) {
|
|
expect(call[2]).toEqual(expect.objectContaining({ windowsHide: true }));
|
|
}
|
|
});
|
|
|
|
it("captures the complete Windows ancestor chain with one hidden PowerShell lookup", () => {
|
|
execFileSyncMock.mockImplementation((_command: string, args: string[]) => {
|
|
if (args.includes("table")) {
|
|
return "400 300 444\n300 200 333\n200 1 222\n";
|
|
}
|
|
return "";
|
|
});
|
|
|
|
expect(processAncestorSnapshot(400)).toEqual([
|
|
{ pid: 300, identity: "windows:333" },
|
|
{ pid: 200, identity: "windows:222" },
|
|
]);
|
|
expect(execFileSyncMock).toHaveBeenCalledOnce();
|
|
expect(execFileSyncMock.mock.calls[0]?.[2]).toEqual(
|
|
expect.objectContaining({ windowsHide: true }),
|
|
);
|
|
});
|
|
|
|
it("keeps a Windows parent created in the same tick as its child", () => {
|
|
execFileSyncMock.mockImplementation(() => "400 300 333\n300 200 333\n200 1 222\n");
|
|
|
|
expect(processAncestorSnapshot(400).map((ancestor) => ancestor.pid)).toEqual([300, 200]);
|
|
});
|
|
|
|
it("stops the Windows ancestor chain at a parent pid reused by a later process", () => {
|
|
execFileSyncMock.mockImplementation(() => "400 300 444\n300 200 333\n200 999 222\n999 5 555\n");
|
|
|
|
expect(processAncestorSnapshot(400)).toEqual([
|
|
{ pid: 300, identity: "windows:333" },
|
|
{ pid: 200, identity: "windows:222" },
|
|
]);
|
|
});
|
|
});
|