Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(minikube): record the real group state behind each injected EPERM

Alfredo Lopez21a92f8549ea
diff --git a/scripts/tests/fixtures/run-with-deadline/deny-group-sigkill.mjs b/scripts/tests/fixtures/run-with-deadline/deny-group-sigkill.mjs
index aad95ce43..8ab7924ec 100644
--- a/scripts/tests/fixtures/run-with-deadline/deny-group-sigkill.mjs
+++ b/scripts/tests/fixtures/run-with-deadline/deny-group-sigkill.mjs
@@ -3,19 +3,51 @@
// On macOS, kill(-pgid, SIGKILL) returns EPERM when the only processes left in
// the group are already exiting, so the runner's final reap can be refused
// after the wrapped command has exited. That race is not reproducible on
-// demand, so this preload makes every SIGKILL addressed to a process group fail
-// the same way. Signal 0 still reaches the real kill(), so the runner's
-// liveness probe reports whether the group is actually gone.
+// demand, so this preload makes every signal in DENY_GROUP_SIGNALS (default
+// SIGKILL) addressed to a process group fail the same way. Signal 0 still
+// reaches the real kill(), so the runner's liveness probe reports whether the
+// group is actually gone.
+//
+// Each denial is logged with the group's real state just before it
+// (before=alive|ESRCH|EPERM from a real kill(pid, 0)), so a test can tell
+// whether the injected refusal hit a live group or an empty one.
import { appendFileSync } from "node:fs";
+import { constants as osConstants } from "node:os";
import process from "node:process";
const log = process.env.DENY_GROUP_SIGKILL_LOG;
if (!log) throw new Error("DENY_GROUP_SIGKILL_LOG is required");
+const denied = new Set((process.env.DENY_GROUP_SIGNALS ?? "SIGKILL").split(","));
+for (const name of denied) {
+ if (!Number.isInteger(osConstants.signals[name])) {
+ throw new Error(`DENY_GROUP_SIGNALS has an unknown signal: ${name}`);
+ }
+}
+
+// process.kill accepts a signal name or number; compare by name.
+function signalName(signal) {
+ if (typeof signal === "string") return signal;
+ return Object.keys(osConstants.signals).find(
+ (name) => osConstants.signals[name] === signal,
+ );
+}
+
const realKill = process.kill.bind(process);
-process.kill = (pid, signal) => {
- if (pid < 0 && signal === "SIGKILL") {
- appendFileSync(log, `denied pgid=${-pid}\n`);
+
+function groupState(pid) {
+ try {
+ realKill(pid, 0);
+ return "alive";
+ } catch (error) {
+ return error.code;
+ }
+}
+
+process.kill = (pid, signal = "SIGTERM") => {
+ const name = signalName(signal);
+ if (pid < 0 && denied.has(name)) {
+ appendFileSync(log, `denied pgid=${-pid} signal=${name} before=${groupState(pid)}\n`);
throw Object.assign(new Error("kill EPERM"), {
code: "EPERM",
errno: -1,
diff --git a/scripts/tests/test-run-with-deadline-reap.sh b/scripts/tests/test-run-with-deadline-reap.sh
index 332295a7a..a4a5809e5 100755
--- a/scripts/tests/test-run-with-deadline-reap.sh
+++ b/scripts/tests/test-run-with-deadline-reap.sh
@@ -3,7 +3,8 @@
# status when the kernel refuses the SIGKILL with EPERM because the group is
# already exiting (macOS), and must still fail loud when the refused group is
# alive. The EPERM is injected by a preload, because the kernel race cannot be
-# produced on demand.
+# produced on demand; the preload logs the group's real state before each
+# injected refusal, so each case asserts which state it actually exercised.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
@@ -54,7 +55,9 @@ assert_denied_reap_after_timeout_keeps_the_timeout_status() {
run_denied denied-timeout "$deny_log" "$output" \
--timeout-seconds 1 --kill-grace-seconds 1 -- sleep 30 || status=$?
- if [[ "$status" -eq 124 ]] && grep -Fq 'denied pgid=' "$deny_log" \
+ # before=ESRCH records that the SIGTERM had already emptied the group when the
+ # injected SIGKILL refusal landed.
+ if [[ "$status" -eq 124 ]] && grep -Fq 'signal=SIGKILL before=ESRCH' "$deny_log" \
&& grep -Fq 'event=timeout' "$output" \
&& grep -Fq 'event=reap-permission-denied' "$output" \
&& grep -Fq 'groupGone=true' "$output" \
@@ -86,7 +89,7 @@ assert_denied_reap_of_a_live_group_fails_loud() {
# the group really was alive, so the non-zero status is the refused reap and
# not the wrapped command.
if [[ "$status" -ne 0 && "$alive_after" == true ]] \
- && grep -Fq 'denied pgid=' "$deny_log" \
+ && grep -Fq 'signal=SIGKILL before=alive' "$deny_log" \
&& grep -Fq 'event=exit' "$output" && grep -Fq 'exitCode=0' "$output" \
&& grep -Fq 'event=reap-failed' "$output" && grep -Fq 'reason=EPERM' "$output" \
&& ! grep -Fq 'event=reap-permission-denied' "$output"; then