Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(e2e): add safety_pass /metrics as the third readiness-contract signal [R3-M6]
Alfredo Lopezee8795d105d2
diff --git a/scripts/e2e/e2e-hcc-mcp-context-readiness.sh b/scripts/e2e/e2e-hcc-mcp-context-readiness.shindex c3720290b..e84616983 100755--- a/scripts/e2e/e2e-hcc-mcp-context-readiness.sh+++ b/scripts/e2e/e2e-hcc-mcp-context-readiness.sh@@ -791,6 +791,46 @@ probe_new_hcc_ready_endpoint() {return 1}+# Third, independent signal of the safety contract (M6): the authoritative pass+# must actually have MEASURED and REVOKED. The unit tests assert the readiness+# predicate over vi.fn() mocks, so a metric rename would leave them green; these+# family-name literals live in the gate, so a rename turns the REAL gate red.+# Pure adjudication over a /metrics scrape — unit-testable without a cluster.+safety_pass_metrics_are_certified() {+ local metrics=$1+ grep -Fq -- 'clerum_hcc_networkpolicy_safety_pass_duration_seconds' <<<"$metrics" || return 1+ # At least one policy revoked by an authoritative pass ($NF is the sample+ # value; tolerant of extra/reordered labels).+ awk '$0 ~ /^clerum_hcc_networkpolicy_safety_pass_policies_total\{/ && /operation="revoked"/ { if ($NF + 0 >= 1) found = 1 } END { exit(found ? 0 : 1) }' <<<"$metrics"+}++# Scrapes the running replacement pod's /metrics over the same in-pod node/http+# channel the /ready probes use, then adjudicates. The sub-0.5s window B4 leaves+# unobservable on /ready is covered here: the counter is monotonic.+safety_pass_metrics_certify() {+ local metrics+ metrics="$(kctl exec "pod/${NEW_HCC_POD}" -n "$HCC_NS" -c host-context-controller -- \+ env "HCC_E2E_PORT=${HCC_PORT}" \+ node -e '+ const http = require("node:http");+ const request = http.get(+ {host: "127.0.0.1", port: Number(process.env.HCC_E2E_PORT), path: "/metrics"},+ response => {+ let body = "";+ response.setEncoding("utf8");+ response.on("data", chunk => { body += chunk; });+ response.on("end", () => {+ process.stdout.write(body);+ process.exit(response.statusCode === 200 ? 0 : 1);+ });+ }+ );+ request.setTimeout(2000, () => { request.destroy(); process.exit(1); });+ request.on("error", () => process.exit(1));+ ')" || return 1+ safety_pass_metrics_are_certified "$metrics"+}+hcc_ready_after_stale_policy_revoked() {# A single poll that sees 200 WHILE the stale policy is still present is a# safety-contract violation and must be FATAL, never retried: retrying lets a@@ -1499,7 +1539,11 @@ baseline_policies_unchanged ||die "baseline safety NetworkPolicy ownership or specs changed during safety convergence"hcc_identity_is_stable ||die "HCC restarted while the MCP external-egress query was held"+wait_until_fast 30 "authoritative safety pass metrics to certify the revocation" \+ safety_pass_metrics_certify ||+ die "safety_pass_* metrics did not corroborate the stale-policy revocation (families renamed or pass never measured?)"ok "/ready is 200 while the divergent stale policy and affected runtime remain absent"+ok "safety_pass_* metrics corroborate an authoritative pass revoked the stale policy"ok "baseline NetworkPolicies remain present throughout fail-closed safety convergence"initial_empty_context_log="[NetPol] Reconciling context \"${CONTEXT_ID}\" — allowed servers: []"diff --git a/scripts/tests/test-hcc-watch-recovery-gate.sh b/scripts/tests/test-hcc-watch-recovery-gate.shindex d696ccc90..1226e7b73 100755--- a/scripts/tests/test-hcc-watch-recovery-gate.sh+++ b/scripts/tests/test-hcc-watch-recovery-gate.sh@@ -912,6 +912,47 @@ if (elsefail "wait_until_fast retried past a fatal ordering violation to a later clean poll"fi++# M6: the third contract signal adjudicates a real /metrics scrape. Extract the+# PURE predicate (the wrapper does kctl exec, untestable here) and feed it+# synthetic scrapes. The family-name literals are exactly what a metric rename+# would break — a rename leaves the vi.fn() unit tests green but must turn this+# and the real gate red.+safety_pass_metrics_predicate="$(+ sed -n '/^safety_pass_metrics_are_certified() {$/,/^}$/p' "$MCP_READINESS_GATE"+)"+[ -n "$safety_pass_metrics_predicate" ] ||+ fail "could not extract safety_pass_metrics_are_certified from the readiness gate"+metrics_with_revocation='clerum_hcc_networkpolicy_safety_pass_duration_seconds_count 1+clerum_hcc_networkpolicy_safety_pass_policies_total{operation="listed"} 5+clerum_hcc_networkpolicy_safety_pass_policies_total{operation="revoked"} 1'+metrics_without_family='clerum_hcc_some_other_family_total 3'+metrics_zero_revoked='clerum_hcc_networkpolicy_safety_pass_duration_seconds_count 1+clerum_hcc_networkpolicy_safety_pass_policies_total{operation="revoked"} 0'+if (+ eval "$safety_pass_metrics_predicate"+ safety_pass_metrics_are_certified "$metrics_with_revocation"+); then+ pass "safety_pass metrics predicate certifies a scrape with >=1 revoked policy"+else+ fail "safety_pass metrics predicate rejected a valid certifying scrape"+fi+if (+ eval "$safety_pass_metrics_predicate"+ ! safety_pass_metrics_are_certified "$metrics_without_family"+); then+ pass "safety_pass metrics predicate rejects a scrape missing the duration family (rename guard)"+else+ fail "safety_pass metrics predicate passed with the safety_pass family absent"+fi+if (+ eval "$safety_pass_metrics_predicate"+ ! safety_pass_metrics_are_certified "$metrics_zero_revoked"+); then+ pass "safety_pass metrics predicate rejects a scrape with zero revoked policies"+else+ fail "safety_pass metrics predicate passed with zero policies revoked"+fiif (probe_new_hcc_ready_endpoint() { return 1; }external_egress_policy_absent() { return 0; }@@ -1458,7 +1499,7 @@ if grep -Fq 'source "${SCRIPT_DIR}/_lib/hcc-watch-recovery-fixture.sh"' \grep -Fq 'hcc_pods_absent' "$MCP_READINESS_GATE" &&! grep -Fq -- '--for=delete' "$MCP_READINESS_GATE" &&! grep -Fq 'port: 8081' "$MCP_READINESS_GATE" &&- [ "$mcp_port_probe_count" = 3 ] &&+ [ "$mcp_port_probe_count" = 4 ] &&[ "$mcp_pod_absence_count" = 4 ]; thenpass "MCP readiness gate shares exact-head ownership and uses bounded portable runtime probes"else