Skip to content

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

TypeScript

fix(e2e): await the verified PR A proxy route

Alfredo Lopezbdf23886aed1
diff --git a/scripts/e2e/_lib/hcc-watch-recovery-fixture.sh b/scripts/e2e/_lib/hcc-watch-recovery-fixture.sh
index 744f2d2a9..02390f5fc 100755
--- a/scripts/e2e/_lib/hcc-watch-recovery-fixture.sh
+++ b/scripts/e2e/_lib/hcc-watch-recovery-fixture.sh
@@ -176,6 +176,11 @@ hcc_proxy_safe_error_records() {
{event,code}'
}
+hcc_proxy_positive_probe() {
+ kctl exec deployment/"$HCC_DEPLOY" -n "$HCC_NS" -c host-context-controller -- \
+ node -e "$1" "$2" "$3" "$4" >/dev/null
+}
+
verify_hcc_proxy_network_policy() {
local proxy_dns="${PROXY_NAME}.${HCC_NS}.svc"
local proxy_ip positive_probe negative_probe probe_status
@@ -189,8 +194,10 @@ verify_hcc_proxy_network_policy() {
const fs=require('fs'),https=require('https');
const root='/var/run/secrets/kubernetes.io/serviceaccount/';
const safeCodes=['ECONNREFUSED','ECONNRESET','ETIMEDOUT','ENOTFOUND','EAI_AGAIN','EHOSTUNREACH','ENETUNREACH','EPROTO','CERT_HAS_EXPIRED','CERT_NOT_YET_VALID','DEPTH_ZERO_SELF_SIGNED_CERT','SELF_SIGNED_CERT_IN_CHAIN','UNABLE_TO_VERIFY_LEAF_SIGNATURE','UNABLE_TO_GET_ISSUER_CERT_LOCALLY','ERR_TLS_CERT_ALTNAME_INVALID','ERR_TLS_HANDSHAKE_TIMEOUT'];
-const request=https.request({host:process.argv[1],port:443,path:'/version',servername:process.argv[2]||'kubernetes.default.svc',ca:process.argv[3]?Buffer.from(process.argv[3],'base64'):fs.readFileSync(root+'ca.crt'),rejectUnauthorized:true,headers:{authorization:'Bearer '+fs.readFileSync(root+'token','utf8')}},response=>{response.resume();response.on('end',()=>process.exit(response.statusCode===200?0:2))});
-request.setTimeout(5000,()=>request.destroy(Object.assign(new Error(),{code:'ETIMEDOUT'})));request.on('error',error=>{const code=error?.code;console.error(JSON.stringify({event:'hcc-fixture-positive-probe-error',code:safeCodes.includes(code)?code:'UNKNOWN'}));process.exit(3)});request.end();
+let deadline;
+const fail=error=>{clearTimeout(deadline);const code=error?.code;console.error(JSON.stringify({event:'hcc-fixture-positive-probe-error',code:safeCodes.includes(code)?code:'UNKNOWN'}));process.exit(3)};
+const request=https.request({host:process.argv[1],port:443,path:'/version',servername:process.argv[2]||'kubernetes.default.svc',ca:process.argv[3]?Buffer.from(process.argv[3],'base64'):fs.readFileSync(root+'ca.crt'),rejectUnauthorized:true,headers:{authorization:'Bearer '+fs.readFileSync(root+'token','utf8')}},response=>{response.resume();response.on('end',()=>{clearTimeout(deadline);process.exit(response.statusCode===200?0:2)});response.on('error',fail)});
+deadline=setTimeout(()=>fail({code:'ETIMEDOUT'}),5000);request.on('error',fail);request.end();
NODE
)"
if [ "${E2E_HCC_PR_A:-0}" = 1 ]; then
@@ -201,8 +208,14 @@ NODE
die 'PR A proxy public trust configuration missing'
positive_servername=$proxy_dns
fi
- if ! kctl exec deployment/"$HCC_DEPLOY" -n "$HCC_NS" -c host-context-controller -- \
- node -e "$positive_probe" "$proxy_dns" "$positive_servername" "$proxy_public_ca" >/dev/null; then
+ local -a probe_command
+ probe_command=(hcc_proxy_positive_probe "$positive_probe" "$proxy_dns" "$positive_servername" "$proxy_public_ca")
+ # PR A replaces the relay with a TLS listener; its Service route can settle
+ # after Deployment readiness. Other callers need no new wait-helper contract.
+ if [ "${E2E_HCC_PR_A:-0}" = 1 ]; then
+ probe_command=(wait_until 20 'HCC verified API proxy route' "${probe_command[@]}")
+ fi
+ if ! "${probe_command[@]}"; then
hcc_proxy_safe_error_records || true
die "HCC cannot reach the Kubernetes API through the isolated proxy"
fi
diff --git a/scripts/tests/hcc-watch-api-proxy.test.mjs b/scripts/tests/hcc-watch-api-proxy.test.mjs
index 2690c99de..e4e6f4562 100644
--- a/scripts/tests/hcc-watch-api-proxy.test.mjs
+++ b/scripts/tests/hcc-watch-api-proxy.test.mjs
@@ -106,6 +106,8 @@ verify_hcc_proxy_network_policy
},
},
console: { error: value => records.push(JSON.parse(value)) },
+ setTimeout,
+ clearTimeout,
Buffer,
})
assert.equal(exitCode, 3)
@@ -117,6 +119,41 @@ verify_hcc_proxy_network_policy
])
assert.equal(JSON.stringify(records).includes(marker), false)
}
+ // A peer that never ends its response cannot extend the five-second wall
+ // deadline through activity; expiration is explicit ETIMEDOUT, never success.
+ let expire
+ let expiredExit
+ const expiredRecords = []
+ const pending = {
+ on() {
+ return pending
+ },
+ end() {},
+ }
+ runInNewContext(code, {
+ require: name =>
+ name === 'fs' ? { readFileSync: () => Buffer.from(marker) } : { request: () => pending },
+ process: {
+ argv: ['node', 'fixture', 'fixture', ''],
+ exit: value => {
+ expiredExit = value
+ },
+ },
+ console: { error: value => expiredRecords.push(JSON.parse(value)) },
+ Buffer,
+ setTimeout(callback, ms) {
+ assert.equal(ms, 5000)
+ expire = callback
+ return 1
+ },
+ clearTimeout() {},
+ })
+ assert.equal(expiredExit, undefined)
+ expire()
+ assert.equal(expiredExit, 3)
+ assert.deepEqual(expiredRecords, [
+ { event: 'hcc-fixture-positive-probe-error', code: 'ETIMEDOUT' },
+ ])
})
test('failed positive probe collects only bounded safe proxy event/code records before exit', () => {
diff --git a/scripts/tests/test-hcc-watch-pr-a.sh b/scripts/tests/test-hcc-watch-pr-a.sh
index 6b704eb1f..bfdb71335 100644
--- a/scripts/tests/test-hcc-watch-pr-a.sh
+++ b/scripts/tests/test-hcc-watch-pr-a.sh
@@ -1,4 +1,6 @@
#!/usr/bin/env bash
+# Fixture globals are consumed by sourced helpers and the evaluated production wait loop.
+# shellcheck disable=SC2034
set -euo pipefail
ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd -P)"
tmp="$(mktemp -d)"
@@ -85,6 +87,11 @@ for mode in 0 1; do
(
source "$ROOT/scripts/e2e/_lib/hcc-watch-recovery-fixture.sh"
E2E_HCC_PR_A=$mode PROXY_NAME=fixture-proxy HCC_NS=control-plane HCC_DEPLOY=host-context-controller
+ if [[ "$mode" = 1 ]]; then
+ wait_until() { shift 2; "$@"; }
+ else
+ unset -f wait_until
+ fi
kctl() {
case "$1/$2" in
get/service) printf '10.0.0.1';;
@@ -107,3 +114,63 @@ for mode in 0 1; do
fi
done
printf 'PASS: PR A verifies its public fixture CA/name; PR B preserves Kubernetes trust\n'
+
+# Exercise the production wait loop with a virtual clock and only the kubectl
+# boundary doubled. TLS failure and HTTP non-200 never count as readiness.
+for mode in 0 1; do
+ for outcome in success transient permanent; do
+ status=0
+ (
+ source "$ROOT/scripts/e2e/_lib/hcc-watch-recovery-fixture.sh"
+ if [[ "$mode" = 1 ]]; then
+ eval "$(sed -n '/^wait_until() {/,/^}/p' "$ROOT/scripts/e2e/e2e-hcc-watch-churn-readiness.sh")"
+ else
+ # CommunicationChannel recovery does not provide this helper at all.
+ unset -f wait_until
+ fi
+ E2E_HCC_PR_A=$mode HCC_PR_A_WORK_DEADLINE=600
+ PROXY_NAME=fixture-proxy HCC_NS=fixture HCC_DEPLOY=fixture HCC_IMAGE=fixture
+ PROBE_NAME=fixture-negative PROBE_EGRESS_NP=fixture-negative-policy
+ clock=0 attempts=0
+ date() { printf '%s' "$clock"; }
+ sleep() { clock=$((clock + 1)); }
+ kctl() {
+ case "$1/$2" in
+ get/service) printf '10.0.0.1';;
+ get/configmap)
+ jq -cn '{data:{"config.json":"{\"clusters\":[{\"cluster\":{\"certificate-authority-data\":\"cHVibGljLXRlc3QtY2E=\"}}]}"}}';;
+ exec/*)
+ attempts=$((attempts + 1))
+ [[ "${10}" == *rejectUnauthorized:true* ]] || exit 9
+ [[ "${10}" == *'response.statusCode===200?0:2'* ]] || exit 9
+ if [[ "$outcome" = success ]]; then return 0; fi
+ if [[ "$outcome" = transient && "$attempts" = 3 ]]; then return 0; fi
+ if [[ "$outcome" = transient && "$attempts" = 2 ]]; then return 2; fi
+ return 3;;
+ apply/*) cat >/dev/null; printf '%s' "$attempts" > "$tmp/attempts-$mode-$outcome"; exit 0;;
+ logs/*) :;;
+ *) exit 9;;
+ esac
+ }
+ die() { printf '%s' "$attempts" > "$tmp/attempts-$mode-$outcome"; exit 1; }
+ verify_hcc_proxy_network_policy
+ ) > "$tmp/readiness-$mode-$outcome" 2>&1 || status=$?
+ attempts="$(cat "$tmp/attempts-$mode-$outcome")"
+ if [[ "$outcome" = success ]]; then
+ [[ "$status" = 0 && "$attempts" = 1 ]]
+ elif [[ "$mode" = 0 ]]; then
+ [[ "$status" = 1 && "$attempts" = 1 ]] || {
+ echo "FAIL: legacy caller without wait_until exited $status after $attempts attempts" >&2; exit 1;
+ }
+ elif [[ "$outcome" = transient ]]; then
+ [[ "$status" = 0 && "$attempts" = 3 ]] || {
+ echo "FAIL: transient readiness exited $status after $attempts attempts (mode $mode)" >&2; exit 1;
+ }
+ else
+ [[ "$status" = 1 && "$attempts" -gt 1 && "$attempts" -le 21 ]] || {
+ echo "FAIL: permanent trust failure exited $status after $attempts attempts (mode $mode)" >&2; exit 1;
+ }
+ fi
+ done
+done
+printf 'PASS: PR A retries within budget; legacy callers without wait_until remain strict and one-shot\n'