Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(minikube): require the reap window to survive a wall-clock step
Alfredo Lopez2f8613a4b275
diff --git a/scripts/tests/fixtures/run-with-deadline/deny-group-sigkill.mjs b/scripts/tests/fixtures/run-with-deadline/deny-group-sigkill.mjsindex 8ab7924ec..b8386d0a7 100644--- a/scripts/tests/fixtures/run-with-deadline/deny-group-sigkill.mjs+++ b/scripts/tests/fixtures/run-with-deadline/deny-group-sigkill.mjs@@ -11,6 +11,11 @@// 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.+//+// DENY_GROUP_CLOCK_STEP_MS, when set, steps the wall clock (Date.now) forward+// by that amount at the first liveness probe after a denial, i.e. inside the+// runner's reap wait, the way an NTP step would. The step is logged as+// `clock-step ms=<n>` so a test can prove it happened.import { appendFileSync } from "node:fs";import { constants as osConstants } from "node:os";import process from "node:process";@@ -33,6 +38,15 @@ function signalName(signal) {);}+const clockStep = Number(process.env.DENY_GROUP_CLOCK_STEP_MS ?? 0);+if (!Number.isInteger(clockStep) || clockStep < 0) {+ throw new Error("DENY_GROUP_CLOCK_STEP_MS must be a non-negative integer");+}+const realNow = Date.now.bind(Date);+let clockOffset = 0;+let clockStepPending = false;+if (clockStep > 0) Date.now = () => realNow() + clockOffset;+const realKill = process.kill.bind(process);function groupState(pid) {@@ -45,9 +59,15 @@ function groupState(pid) {}process.kill = (pid, signal = "SIGTERM") => {+ if (pid < 0 && signal === 0 && clockStepPending) {+ clockStepPending = false;+ clockOffset = clockStep;+ appendFileSync(log, `clock-step ms=${clockStep}\n`);+ }const name = signalName(signal);if (pid < 0 && denied.has(name)) {appendFileSync(log, `denied pgid=${-pid} signal=${name} before=${groupState(pid)}\n`);+ if (clockStep > 0 && clockOffset === 0) clockStepPending = true;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.shindex a4a5809e5..8f8ea90b9 100755--- a/scripts/tests/test-run-with-deadline-reap.sh+++ b/scripts/tests/test-run-with-deadline-reap.sh@@ -49,6 +49,46 @@ assert_denied_reap_after_exit_keeps_the_child_status() {fi}+assert_denied_reap_waits_for_a_group_that_dies_after_the_first_poll() {+ local output="$TMP_DIR/transient.out" deny_log="$TMP_DIR/transient.deny" status=0+ : >"$deny_log"+ run_denied denied-transient "$deny_log" "$output" \+ --timeout-seconds 10 --kill-grace-seconds 1 -- bash -c 'sleep 0.3 & exit 7' || status=$?++ # before=alive proves the refusal hit a live group: the 0.3 s helper dies+ # well after the first 25 ms poll, so only a wait that spans the window+ # keeps the child's status.+ if [[ "$status" -eq 7 ]] && grep -Fq 'signal=SIGKILL before=alive' "$deny_log" \+ && grep -Fq 'event=exit' "$output" && grep -Fq 'exitCode=7' "$output" \+ && grep -Fq 'event=reap-permission-denied' "$output" \+ && grep -Fq 'groupGone=true' "$output" \+ && ! grep -Fq 'event=reap-failed' "$output"; then+ pass "an EPERM reap of a group that dies after the first poll keeps status 7"+ else+ fail "denied reap of a dying group (status=$status): $(cat "$deny_log") $(cat "$output")"+ fi+}++assert_denied_reap_survives_a_wall_clock_step() {+ local output="$TMP_DIR/clock.out" deny_log="$TMP_DIR/clock.deny" status=0+ : >"$deny_log"+ DENY_GROUP_CLOCK_STEP_MS=2000 run_denied denied-clock "$deny_log" "$output" \+ --timeout-seconds 10 --kill-grace-seconds 1 -- bash -c 'sleep 0.3 & exit 7' || status=$?++ # clock-step proves the wall clock moved 2 s forward inside the 1 s reap+ # window; the window must still be measured in elapsed time.+ if [[ "$status" -eq 7 ]] && grep -Fq 'signal=SIGKILL before=alive' "$deny_log" \+ && grep -Fq 'clock-step ms=2000' "$deny_log" \+ && grep -Fq 'event=exit' "$output" && grep -Fq 'exitCode=7' "$output" \+ && grep -Fq 'event=reap-permission-denied' "$output" \+ && grep -Fq 'groupGone=true' "$output" \+ && ! grep -Fq 'event=reap-failed' "$output"; then+ pass "an EPERM reap keeps status 7 when the wall clock steps forward during the wait"+ else+ fail "denied reap across a clock step (status=$status): $(cat "$deny_log") $(cat "$output")"+ fi+}+assert_denied_reap_after_timeout_keeps_the_timeout_status() {local output="$TMP_DIR/timeout.out" deny_log="$TMP_DIR/timeout.deny" status=0: >"$deny_log"@@ -127,6 +167,8 @@ assert_every_defined_case_is_invoked() {}assert_denied_reap_after_exit_keeps_the_child_status+assert_denied_reap_waits_for_a_group_that_dies_after_the_first_poll+assert_denied_reap_survives_a_wall_clock_stepassert_denied_reap_after_timeout_keeps_the_timeout_statusassert_denied_reap_of_a_live_group_fails_loudassert_an_undenied_reap_reports_no_permission_event