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 { 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)); } }