Skip to content

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

TypeScript

test(hcc): cover readiness fleet scale

Alfredo Lopezd1b216353877
diff --git a/host-context-controller/src/networkPolicyReconciler.test.ts b/host-context-controller/src/networkPolicyReconciler.test.ts
index cdae110ea..261a80d09 100644
--- a/host-context-controller/src/networkPolicyReconciler.test.ts
+++ b/host-context-controller/src/networkPolicyReconciler.test.ts
@@ -2923,5 +2923,24 @@ describe('NetworkPolicyReconciler', () => {
reconciler.cleanupExternalEgress('openai-mcp', 'mcp-server')
).resolves.toBeUndefined()
})
+
+ it('does not report a revocation when the policy was already absent', async () => {
+ const error = Object.assign(new Error('not found'), { code: 404 })
+ const onDeleted = vi.fn()
+ mockApi.listNamespacedNetworkPolicy.mockResolvedValue({
+ items: [{ metadata: { name: 'ext-egress-openai-mcp-old-api-443' } }],
+ })
+ mockApi.deleteNamespacedNetworkPolicy.mockRejectedValueOnce(error)
+
+ await reconciler.cleanupExternalEgress(
+ 'openai-mcp',
+ 'mcp-server',
+ undefined,
+ undefined,
+ onDeleted
+ )
+
+ expect(onDeleted).not.toHaveBeenCalled()
+ })
})
})
diff --git a/host-context-controller/src/networkPolicyReconciler.ts b/host-context-controller/src/networkPolicyReconciler.ts
index 6999a4b95..e3cf6065a 100644
--- a/host-context-controller/src/networkPolicyReconciler.ts
+++ b/host-context-controller/src/networkPolicyReconciler.ts
@@ -1530,7 +1530,9 @@ export class NetworkPolicyReconciler {
console.error(`[NetPol] Failed to delete external egress policy "${name}":`, error)
throw error
}
- onDeleted?.()
+ // A concurrent actor may already have removed the policy. The safety
+ // invariant still holds, but this pass did not revoke it and must not
+ // inflate the authoritative safety-pass `revoked` counter.
}
}
}
diff --git a/scripts/e2e/e2e-hcc-mcp-context-readiness.sh b/scripts/e2e/e2e-hcc-mcp-context-readiness.sh
index 9f63a04d0..dd12926c5 100755
--- a/scripts/e2e/e2e-hcc-mcp-context-readiness.sh
+++ b/scripts/e2e/e2e-hcc-mcp-context-readiness.sh
@@ -10,7 +10,9 @@
# before it reports Ready. While the query is held, the gate also applies a
# real Context watch update and requires that Context's three NetworkPolicies
# converge independently. It then releases DNS and proves eventual McpServer
-# runtime convergence.
+# runtime convergence. It also creates a fleet wider than the controller's
+# bounded worker width, so the branch-owned runtime proof covers the original
+# large-fleet symptom rather than a single delayed object only.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -53,6 +55,7 @@ RUN_LABEL="$(truncate_rfc1123 "$RUN_ID")"
MCP_NAME="$(truncate_rfc1123 "e2e-hcc-mcp-${RUN_ID}")"
CONTEXT_NAME="$(truncate_rfc1123 "e2e-hcc-context-${RUN_ID}")"
CONTEXT_ID="$CONTEXT_NAME"
+MCP_FLEET_SIZE="${E2E_HCC_MCP_FLEET_SIZE:-11}"
TARGET_DNS="$(truncate_rfc1123 "hcc-readiness-${RUN_ID}").example.com"
DNS_BLOCKER_NAME="$(truncate_rfc1123 "e2e-hcc-dns-${RUN_ID}")"
DNS_BLOCKER_POLICY="$(truncate_rfc1123 "${DNS_BLOCKER_NAME}-policy")"
@@ -83,6 +86,9 @@ HCC_MUTATED=0
DNS_BLOCKER_CREATED=0
MCP_CREATED=0
CONTEXT_CREATED=0
+PEER_FLEET_CREATED=0
+MCP_FLEET_NAMES=("$MCP_NAME")
+CONTEXT_FLEET_NAMES=("$CONTEXT_NAME")
# Read and mutated by the sourced compare-and-swap lock helper.
# shellcheck disable=SC2034
HCC_GATE_LOCK_ACQUIRED=0
@@ -93,6 +99,16 @@ HCC_GATE_LOCK_UID=""
# shellcheck disable=SC2034
HCC_GATE_FINALIZATION_FAILURE=""
+[[ "$MCP_FLEET_SIZE" =~ ^[0-9]+$ ]] && [ "$MCP_FLEET_SIZE" -gt 10 ] &&
+ [ "$MCP_FLEET_SIZE" -le 24 ] || {
+ echo "E2E_HCC_MCP_FLEET_SIZE must be an integer from 11 through 24; got ${MCP_FLEET_SIZE}." >&2
+ exit 1
+}
+for ((index = 2; index <= MCP_FLEET_SIZE; index++)); do
+ MCP_FLEET_NAMES+=("$(truncate_rfc1123 "e2e-hcc-mcp-${RUN_ID}-${index}")")
+ CONTEXT_FLEET_NAMES+=("$(truncate_rfc1123 "e2e-hcc-context-${RUN_ID}-${index}")")
+done
+
die() {
if [ -n "$NEW_HCC_POD" ]; then
echo "Recent HCC logs from ${NEW_HCC_POD}:" >&2
@@ -369,12 +385,58 @@ external_egress_policy_converged() {
}
fixture_resources_absent() {
- fixture_mcp_runtime_absent && context_policies_absent
+ fixture_mcp_runtime_absent && context_policies_absent && peer_fleet_runtime_absent
}
fixture_inputs_absent() {
resource_absent context "$CONTEXT_NAME" "$MCP_NS" &&
- resource_absent mcpserver "$MCP_NAME" "$MCP_NS"
+ resource_absent mcpserver "$MCP_NAME" "$MCP_NS" && peer_fleet_inputs_absent
+}
+
+peer_fleet_inputs_absent() {
+ local index
+ for ((index = 1; index < ${#MCP_FLEET_NAMES[@]}; index++)); do
+ resource_absent context "${CONTEXT_FLEET_NAMES[index]}" "$MCP_NS" || return 1
+ resource_absent mcpserver "${MCP_FLEET_NAMES[index]}" "$MCP_NS" || return 1
+ done
+}
+
+peer_fleet_runtime_absent() {
+ local index server
+ for ((index = 1; index < ${#MCP_FLEET_NAMES[@]}; index++)); do
+ server="${MCP_FLEET_NAMES[index]}"
+ resource_absent deployment "$server" "$MCP_NS" || return 1
+ resource_absent service "$server" "$MCP_NS" || return 1
+ done
+}
+
+peer_fleet_converged() {
+ local index server context desired available namespace policy_type policy_count
+ for ((index = 1; index < ${#MCP_FLEET_NAMES[@]}; index++)); do
+ server="${MCP_FLEET_NAMES[index]}"
+ context="${CONTEXT_FLEET_NAMES[index]}"
+ desired="$(kctl get deployment "$server" -n "$MCP_NS" -o jsonpath='{.spec.replicas}' 2>/dev/null)" || return 1
+ available="$(kctl get deployment "$server" -n "$MCP_NS" -o jsonpath='{.status.availableReplicas}' 2>/dev/null)" || return 1
+ [ "${desired:-0}" -ge 1 ] && [ "${available:-0}" -ge 1 ] || return 1
+ kctl get service "$server" -n "$MCP_NS" >/dev/null 2>&1 || return 1
+ kctl get mcpserver "$server" -n "$MCP_NS" -o json | jq -e '
+ any(.status.conditions[]?; .type == "Ready" and .status == "True")
+ ' >/dev/null || return 1
+ kctl get context "$context" -n "$MCP_NS" -o json | jq -e --arg server "$server" '
+ .spec.mcpServers == [$server]
+ ' >/dev/null || return 1
+ for namespace_policy in \
+ "${MCP_NS}:context-allow" \
+ "${HOST_NS}:context-allow" \
+ "${RPC_PROXY_NS}:rpc-proxy-egress"; do
+ namespace="${namespace_policy%%:*}"
+ policy_type="${namespace_policy#*:}"
+ policy_count="$(kctl get networkpolicy -n "$namespace" \
+ -l "${CONTEXT_LABEL}=${context},${MCP_SERVER_LABEL}=${server},${POLICY_TYPE_LABEL}=${policy_type}" \
+ -o json 2>/dev/null | jq '.items | length')" || return 1
+ [ "$policy_count" = 1 ] || return 1
+ done
+ done
}
baseline_policies_exist() {
@@ -399,6 +461,47 @@ mcp_egress_binding_is_udp() {
' >/dev/null
}
+create_peer_fleet() {
+ local index server context
+ for ((index = 1; index < ${#MCP_FLEET_NAMES[@]}; index++)); do
+ server="${MCP_FLEET_NAMES[index]}"
+ context="${CONTEXT_FLEET_NAMES[index]}"
+ kctl apply -f - >/dev/null <<EOF
+apiVersion: clerum.io/v1alpha1
+kind: Context
+metadata:
+ name: ${context}
+ namespace: ${MCP_NS}
+ labels:
+ e2e.clerum.io/suite: ${SUITE_NAME}
+ e2e.clerum.io/run: "${RUN_LABEL}"
+spec:
+ contextId: ${context}
+ description: Gate-owned peer Context for HCC readiness fleet coverage.
+ mcpServers: [${server}]
+---
+apiVersion: clerum.io/v1alpha1
+kind: McpServer
+metadata:
+ name: ${server}
+ namespace: ${MCP_NS}
+ labels:
+ e2e.clerum.io/suite: ${SUITE_NAME}
+ e2e.clerum.io/run: "${RUN_LABEL}"
+spec:
+ contextRef: ${context}
+ description: Gate-owned peer McpServer for bounded HCC fleet coverage.
+ image: clerum/mock-mcp-server:test
+ imagePullPolicy: IfNotPresent
+ transport:
+ type: streamableHttp
+ url: http://${server}.${MCP_NS}.svc.cluster.local:3000/mcp
+ port: 3000
+EOF
+ done
+ PEER_FLEET_CREATED=1
+}
+
fixture_converged() {
local desired available
desired="$(kctl get deployment "$MCP_NAME" -n "$MCP_NS" \
@@ -626,6 +729,34 @@ delete_residual_fixture_runtime() {
--ignore-not-found --wait=true --timeout=60s >/dev/null 2>&1 || failed=1
kctl delete networkpolicy -n "$MCP_NS" -l "${MCP_SERVER_LABEL}=${MCP_NAME}" \
--ignore-not-found --wait=true --timeout=60s >/dev/null 2>&1 || failed=1
+ delete_peer_fleet_runtime || failed=1
+ [ "$failed" = 0 ]
+}
+
+delete_peer_fleet_runtime() {
+ local index server failed=0
+ for ((index = 1; index < ${#MCP_FLEET_NAMES[@]}; index++)); do
+ server="${MCP_FLEET_NAMES[index]}"
+ kctl delete deployment "$server" -n "$MCP_NS" --ignore-not-found --wait=true --timeout=60s \
+ >/dev/null 2>&1 || failed=1
+ kctl delete service "$server" -n "$MCP_NS" --ignore-not-found --wait=true --timeout=60s \
+ >/dev/null 2>&1 || failed=1
+ kctl delete configmap "${server}-nginx-conf" -n "$MCP_NS" --ignore-not-found --wait=true --timeout=60s \
+ >/dev/null 2>&1 || failed=1
+ kctl delete networkpolicy -n "$MCP_NS" -l "${MCP_SERVER_LABEL}=${server}" \
+ --ignore-not-found --wait=true --timeout=60s >/dev/null 2>&1 || failed=1
+ done
+ [ "$failed" = 0 ]
+}
+
+delete_peer_fleet_inputs() {
+ local index failed=0
+ for ((index = 1; index < ${#MCP_FLEET_NAMES[@]}; index++)); do
+ kctl delete context "${CONTEXT_FLEET_NAMES[index]}" -n "$MCP_NS" \
+ --ignore-not-found --wait=true --timeout=60s >/dev/null 2>&1 || failed=1
+ kctl delete mcpserver "${MCP_FLEET_NAMES[index]}" -n "$MCP_NS" \
+ --ignore-not-found --wait=true --timeout=60s >/dev/null 2>&1 || failed=1
+ done
[ "$failed" = 0 ]
}
@@ -687,6 +818,12 @@ cleanup() {
fixture_inputs_removed=0
}
fi
+ if [ "$PEER_FLEET_CREATED" = 1 ]; then
+ delete_peer_fleet_inputs || {
+ cleanup_failed=1
+ fixture_inputs_removed=0
+ }
+ fi
if ! wait_until 60 "gate-owned Context and McpServer inputs to disappear" \
fixture_inputs_absent >/dev/null 2>&1; then
cleanup_failed=1
@@ -1074,6 +1211,9 @@ wait_until 60 "McpServer API to expose the revised UDP external-egress binding"
mcp_egress_binding_is_udp ||
die "McpServer external-egress revision did not persist"
+create_peer_fleet || die "could not create the gate-owned MCP/Context peer fleet"
+ok "created ${#MCP_FLEET_NAMES[@]} gate-owned MCP/Context fixtures for bounded-worker coverage"
+
kctl scale deployment "$HCC_DEPLOY" -n "$HCC_NS" --replicas=1 >/dev/null
capture_hcc() {
@@ -1121,7 +1261,11 @@ baseline_policies_exist ||
die "baseline safety NetworkPolicies are absent while HCC reports Ready"
hcc_identity_is_stable ||
die "HCC restarted while the MCP external-egress query was held"
+wait_until 300 "unblocked peer MCP/Context fleet to converge during held primary egress" \
+ peer_fleet_converged ||
+ die "peer MCP/Context fleet did not converge while the primary egress remained held"
ok "/ready is 200 and discovery contains the exact McpServer while its real initial convergence is blocked"
+ok "all unblocked peer MCP/Context fixtures converged while the primary egress remained held"
ok "baseline NetworkPolicies exist and the stale same-name external-egress policy was revoked before Ready"
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.sh
index 848ee93ac..1a460168f 100755
--- a/scripts/tests/test-hcc-watch-recovery-gate.sh
+++ b/scripts/tests/test-hcc-watch-recovery-gate.sh
@@ -521,6 +521,25 @@ else
fail "MCP readiness gate duplicates ownership or retains a deadline, pod-absence, or port edge"
fi
+# A single held McpServer proves the minimal failure, but this gate must also
+# cross the controller's bounded worker width with independent, gate-owned
+# McpServer/Context pairs. Keep this as a static contract so future edits do
+# not silently reduce the fleet scenario back to one fixture. The fixture
+# must exist while HCC is stopped, otherwise it would not exercise startup.
+mcp_peer_create_line="$(grep -nF 'create_peer_fleet || die' "$MCP_READINESS_GATE" | cut -d: -f1)"
+mcp_restart_line="$(grep -nF 'kctl scale deployment "$HCC_DEPLOY" -n "$HCC_NS" --replicas=1' "$MCP_READINESS_GATE" | tail -1 | cut -d: -f1)"
+if grep -Fq 'MCP_FLEET_SIZE="${E2E_HCC_MCP_FLEET_SIZE:-11}"' "$MCP_READINESS_GATE" &&
+ grep -Fq '[ "$MCP_FLEET_SIZE" -gt 10 ]' "$MCP_READINESS_GATE" &&
+ grep -Fq 'create_peer_fleet' "$MCP_READINESS_GATE" &&
+ grep -Fq 'peer_fleet_converged' "$MCP_READINESS_GATE" &&
+ grep -Fq 'unblocked peer MCP/Context fleet to converge during held primary egress' "$MCP_READINESS_GATE" &&
+ [ -n "$mcp_peer_create_line" ] && [ -n "$mcp_restart_line" ] &&
+ [ "$mcp_peer_create_line" -lt "$mcp_restart_line" ]; then
+ pass "MCP readiness gate crosses the bounded worker width with gate-owned MCP and Context peers"
+else
+ fail "MCP readiness gate does not prove a fleet larger than the worker width"
+fi
+
for gate in "${GATES[@]}"; do
acquire_line="$(grep -nF 'acquire_hcc_watch_gate_lock' "$gate" | tail -1 | cut -d: -f1)"
case "$gate" in