Files
hyperframes/packages/cli/src/utils/processTestUtils.ts
T
heygengenesis[bot]andmiguel.sierra 08d48ab753 fix(cli): guard process snapshot capture (#3974)
Co-authored-by: heygengenesis[bot] <262951085+heygengenesis[bot]@users.noreply.github.com>
Co-authored-by: miguel.sierra <229591595+miguel-heygen@users.noreply.github.com>
2026-09-16 06:33:29 +00:00

28 lines
775 B
TypeScript

import { readFileSync } from "node:fs";
export function testProcessIsAlive(pid: number): boolean {
if (process.platform === "linux") {
try {
const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
const state = stat.slice(stat.lastIndexOf(") ") + 2)[0];
return state !== "Z" && state !== "X";
} catch {
return false;
}
}
try {
process.kill(pid, 0);
return true;
} catch {
return false;
}
}
export async function waitForTestCondition(check: () => boolean, timeoutMs: number): Promise<void> {
const deadline = Date.now() + timeoutMs;
while (!check()) {
if (Date.now() >= deadline) throw new Error(`Condition not met within ${timeoutMs} ms`);
await new Promise((resolve) => setTimeout(resolve, 20));
}
}