Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(e2e): bind storm wake evidence to generation
Alfredo Lopezec6158f2f463
diff --git a/scripts/e2e/e2e-host-storm-gate.sh b/scripts/e2e/e2e-host-storm-gate.shindex 06aee419b..b98dbd5da 100755--- a/scripts/e2e/e2e-host-storm-gate.sh+++ b/scripts/e2e/e2e-host-storm-gate.sh@@ -563,6 +563,23 @@ wake_lifecycle_state() {kctl -n "$MCP_HOST_NS" get host "$WAKE_HOST_REF" -o jsonpath='{.status.lifecycle.state}' 2>/dev/null || true}+# shellcheck disable=SC2329 # invoked from the wait_until callback below+wake_handled_generation() {+ kctl -n "$MCP_HOST_NS" get host "$WAKE_HOST_REF" \+ -o jsonpath='{.status.lifecycle.wakeHandledGeneration}' 2>/dev/null || true+}++# Correlate the public wake request with HCC's durable lifecycle status. This+# predicate is deliberately pure so the static gate test can exercise the+# same ordering contract used by the cluster E2E.+# shellcheck disable=SC2329 # invoked from the wait_until callback below+wake_generation_is_handled() {+ local requested="$1" handled="$2"+ [[ "$requested" =~ ^[1-9][0-9]*$ ]] || return 1+ [[ "$handled" =~ ^[0-9]+$ ]] || return 1+ (( handled >= requested ))+}+# shellcheck disable=SC2329 # invoked from _wake_converged_probe (runs via wait_until)wake_ready_pod_exists() {kctl -n "$MCP_HOST_NS" get pods -l "app=${WAKE_HOST_REF}" \@@ -601,19 +618,31 @@ mint_rpc_token() {# The wake route is the user-facing rpc-proxy endpoint Desktop uses;# rpc-proxy owns the control-api hop. Never kubectl scale.-WAKE_STATUS=''; WAKE_BODY=''+WAKE_STATUS=''; WAKE_BODY=''; WAKE_GENERATION=''post_wake() {- local resp+ local resp response_status response_generation+ WAKE_STATUS=''; WAKE_BODY=''; WAKE_GENERATION=''mint_rpc_token || return 1resp=$(curl -sS -m 30 -w '\n%{http_code}' -X POST \"${RPC_BASE}/api/v1/rpc/hosts/${WAKE_HOST_REF}/wake" \-H "Authorization: Bearer ${RPC_TOKEN}" -H 'Content-Type: application/json') || {echo "wake POST failed at ${RPC_BASE}" >&2; return 1; }WAKE_STATUS="$(echo "$resp" | tail -n1)"; WAKE_BODY="$(echo "$resp" | sed '$d')"- case "$WAKE_STATUS" in- 200|202|204) return 0 ;;- *) echo "wake POST returned HTTP ${WAKE_STATUS}: ${WAKE_BODY}" >&2; return 1 ;;- esac+ [[ "$WAKE_STATUS" == '202' ]] || {+ echo "wake POST returned HTTP ${WAKE_STATUS}, expected 202: ${WAKE_BODY}" >&2+ return 1+ }+ response_status="$(jq -r '.status // empty' <<<"$WAKE_BODY" 2>/dev/null || true)"+ response_generation="$(jq -r '.wakeGeneration // empty' <<<"$WAKE_BODY" 2>/dev/null || true)"+ [[ "$response_status" == 'wake-requested' ]] || {+ echo "wake POST returned unexpected status '${response_status:-<missing>}': ${WAKE_BODY}" >&2+ return 1+ }+ [[ "$response_generation" =~ ^[1-9][0-9]*$ ]] || {+ echo "wake POST returned invalid wakeGeneration '${response_generation:-<missing>}': ${WAKE_BODY}" >&2+ return 1+ }+ WAKE_GENERATION="$response_generation"}# ─── HCC cadence shortening (only when the wake target must suspend) ──@@ -812,22 +841,37 @@ fiT_WAKE_MS="$(now_ms)"if post_wake; then- log "storm: wake POST accepted for ${WAKE_HOST_REF} (HTTP ${WAKE_STATUS})"+ log "storm: wake POST accepted for ${WAKE_HOST_REF} (HTTP ${WAKE_STATUS}, generation ${WAKE_GENERATION})"elsefail "storm: mid-storm wake POST failed for ${WAKE_HOST_REF}"; print_results; exit 1fi-# Prove that the supported wake reached HCC, completed its urgent reconcile,-# published at least one new queue sample, and left no urgent reconcile in-# flight. This closes the old process-death measurement gap for the wake: the-# pre-kill scrape is accepted only after its queue observation is durable.+# Prove that this specific supported wake reached HCC: its response generation+# must be durably reflected in lifecycle status. Then require a new urgent+# queue sample and an idle urgent lane on the same pod. Prometheus collectors+# are read independently, so this deliberately uses a two-scrape fence instead+# of assuming cross-metric atomicity: once the first scrape observes the urgent+# lane idle, HCC's observe-before-in-flight-decrement ordering guarantees the+# wake observation is durable and therefore visible to the second scrape.# shellcheck disable=SC2329 # invoked by name via wait_until_wake_urgent_evidence_recorded() {- local current_pod lifecycle_state pre_count post_count in_flight+ local current_pod lifecycle_state handled_generation+ local fence_in_flight pre_count post_count in_flightcurrent_pod="$(hcc_pod_name)"[[ -n "$current_pod" && "$current_pod" == "$HCC_POD_WAKE" ]] || return 1lifecycle_state="$(wake_lifecycle_state)"[[ -n "$lifecycle_state" && "$lifecycle_state" != 'suspended' ]] || return 1+ handled_generation="$(wake_handled_generation)"+ wake_generation_is_handled "$WAKE_GENERATION" "$handled_generation" || return 1+ scrape_hcc_metrics "$SCRAPE_WAKE_POST" "$HCC_POD_WAKE" || return 1+ fence_in_flight="$(awk -v metric="${IN_FLIGHT_METRIC}" '+ index($0, metric "{") == 1 && $0 ~ /lane="urgent"/ { total += $NF }+ END { print total + 0 }+ ' "$SCRAPE_WAKE_POST")"+ awk -v active="$fence_in_flight" 'BEGIN { exit !(active == 0) }' || return 1++ # The wake histogram observation precedes the decrement seen by the fence.+ # Re-scrape so the adjudicated histogram cannot predate that observation.scrape_hcc_metrics "$SCRAPE_WAKE_POST" "$HCC_POD_WAKE" || return 1pre_count="$(awk -v metric="${QUEUE_WAIT_METRIC}_bucket" 'index($0, metric "{") == 1 && $0 ~ /lane="urgent"/ && $0 ~ /le="\+Inf"/ { total += $NF }@@ -853,14 +897,18 @@ elseprint_results; exit 1fi-# Scrape B is the already-validated final wake-window scrape on the pre-kill-# pod. Reuse it rather than opening a second race between evidence and kill.+# Capture A7's fleet-failure baseline immediately before the kill. The wake+# scrape remains the A2 wake-window oracle; a separate fresh scrape prevents+# fleet failures after wake adjudication from falling outside A7's delta.HCC_POD_B="$(hcc_pod_name)"if [[ "$HCC_POD_B" != "$HCC_POD_A" ]]; thenfail "storm: HCC pod changed unexpectedly before the kill (${HCC_POD_A} -> ${HCC_POD_B:-<none>}) — counter deltas would be invalid"storm_diagnostics; print_results; exit 1fi-cp "$SCRAPE_WAKE_POST" "$SCRAPE_B"+if ! scrape_hcc_metrics "$SCRAPE_B" "$HCC_POD_B"; then+ fail "storm: could not capture the fresh pre-kill metric baseline"+ print_results; exit 1+filog "storm: pre-kill scrape B captured (pod ${HCC_POD_B})"T_KILL_MS="$(now_ms)"diff --git a/scripts/tests/test-host-storm-metric-gate.sh b/scripts/tests/test-host-storm-metric-gate.shindex baf188982..b0c86764c 100755--- a/scripts/tests/test-host-storm-metric-gate.sh+++ b/scripts/tests/test-host-storm-metric-gate.sh@@ -1,4 +1,5 @@#!/usr/bin/env bash+# shellcheck disable=SC2016 # literal source-contract assertions belowset -euo pipefailROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"@@ -99,13 +100,87 @@ grep -Fq 'VERDICT|A2-wake-urgent-hard-gate|PASS|' <<<"$HEALTHY_OUTPUT" ||WAKE_EVIDENCE_FUNCTION="$(sed -n '/^_wake_urgent_evidence_recorded() {$/,/^}$/p' "$GATE")"+WAKE_GENERATION_FUNCTION="$(+ sed -n '/^wake_generation_is_handled() {$/,/^}$/p' "$GATE"+)"+POST_WAKE_FUNCTION="$(+ sed -n '/^post_wake() {$/,/^}$/p' "$GATE"+)"++[[ -n "$WAKE_GENERATION_FUNCTION" ]] ||+ fail "runtime wake evidence has no generation-correlation predicate"++# Exercise the exact pure predicate embedded in the E2E gate. The requested+# generation is the business identifier returned by the public wake route;+# an older handled generation must never satisfy that request.+eval "$WAKE_GENERATION_FUNCTION"+if wake_generation_is_handled 7 6; then+ fail "wake generation predicate accepted an older handled generation"+fi+wake_generation_is_handled 7 7 ||+ fail "wake generation predicate rejected the exact handled generation"+wake_generation_is_handled 7 8 ||+ fail "wake generation predicate rejected a newer handled generation"+if wake_generation_is_handled 0 8 || wake_generation_is_handled invalid 8 ||+ wake_generation_is_handled 7 invalid; then+ fail "wake generation predicate accepted malformed generation evidence"+fi+# Literal source assertions intentionally match unexpanded shell variables.# shellcheck disable=SC2016if ! grep -Fq '"$current_pod" == "$HCC_POD_WAKE"' <<<"$WAKE_EVIDENCE_FUNCTION" ||! grep -Fq '"$lifecycle_state" != '\''suspended'\''' <<<"$WAKE_EVIDENCE_FUNCTION" ||+ ! grep -Fq 'handled_generation="$(wake_handled_generation)"' <<<"$WAKE_EVIDENCE_FUNCTION" ||+ ! grep -Fq 'wake_generation_is_handled "$WAKE_GENERATION" "$handled_generation"' <<<"$WAKE_EVIDENCE_FUNCTION" ||! grep -Fq 'metric="${IN_FLIGHT_METRIC}"' <<<"$WAKE_EVIDENCE_FUNCTION" ||! grep -Fq '(after - before) >= 1 && active == 0' <<<"$WAKE_EVIDENCE_FUNCTION"; then- fail "runtime wake evidence is not fenced to the same pod, completed lifecycle, metric delta, and idle urgent lane"+ fail "runtime wake evidence is not fenced to the same pod, requested generation, metric delta, and idle urgent lane"+fi+generation_check_line="$(+ grep -nF 'wake_generation_is_handled "$WAKE_GENERATION" "$handled_generation"' \+ <<<"$WAKE_EVIDENCE_FUNCTION" | cut -d: -f1+)"+metrics_scrape_line="$(+ grep -nF 'scrape_hcc_metrics "$SCRAPE_WAKE_POST" "$HCC_POD_WAKE"' \+ <<<"$WAKE_EVIDENCE_FUNCTION" | head -n1 | cut -d: -f1+)"+if [[ -z "$generation_check_line" || -z "$metrics_scrape_line" ]] ||+ (( generation_check_line >= metrics_scrape_line )); then+ fail "wake generation is not correlated before accepting shared urgent metrics"+fi+wake_scrape_count="$(+ grep -Fc 'scrape_hcc_metrics "$SCRAPE_WAKE_POST" "$HCC_POD_WAKE"' \+ <<<"$WAKE_EVIDENCE_FUNCTION"+)"+if (( wake_scrape_count < 2 )) ||+ ! grep -Fq 'fence_in_flight=' <<<"$WAKE_EVIDENCE_FUNCTION" ||+ ! grep -Fq 'active == 0' <<<"$WAKE_EVIDENCE_FUNCTION"; then+ fail "wake evidence lacks a completed-lane fence followed by a fresh metric scrape"+fi++# shellcheck disable=SC2016+if ! grep -Fq 'WAKE_GENERATION=' <<<"$POST_WAKE_FUNCTION" ||+ ! grep -Fq '"$WAKE_STATUS" == '\''202'\''' <<<"$POST_WAKE_FUNCTION" ||+ ! grep -Fq '.status // empty' <<<"$POST_WAKE_FUNCTION" ||+ ! grep -Fq '.wakeGeneration // empty' <<<"$POST_WAKE_FUNCTION"; then+ fail "public wake response is not validated as an accepted wake-generation contract"+fi++# A7 must start from a fresh scrape immediately before the kill. Reusing the+# earlier wake-evidence scrape creates an unobserved interval in which a fleet+# failure could occur and escape the pre/post recovery counter delta.+# shellcheck disable=SC2016+if ! grep -Fq 'scrape_hcc_metrics "$SCRAPE_B" "$HCC_POD_B"' "$GATE" ||+ grep -Fq 'cp "$SCRAPE_WAKE_POST" "$SCRAPE_B"' "$GATE"; then+ fail "pre-kill scrape B is not freshly captured after wake adjudication"+fi+fresh_scrape_line="$(+ grep -nF 'scrape_hcc_metrics "$SCRAPE_B" "$HCC_POD_B"' "$GATE" | cut -d: -f1+)"+kill_line="$(grep -nF 'T_KILL_MS="$(now_ms)"' "$GATE" | cut -d: -f1)"+if [[ -z "$fresh_scrape_line" || -z "$kill_line" ]] ||+ (( fresh_scrape_line >= kill_line )); then+ fail "fresh scrape B does not precede the HCC kill"fi-echo "PASS: host-storm metric oracle rejects a slow wake hidden by later fast probes"+echo "PASS: host-storm oracle binds wake generation, fences metrics, and refreshes the pre-kill baseline"