Skip to content

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

TypeScript

test(e2e): honor cluster-unreachable skip gate in network-policies suite

Alfredo Lopez3cd311d38895
diff --git a/tests/e2e/integration/network-policies.test.ts b/tests/e2e/integration/network-policies.test.ts
index aba9302b2..d0be8d271 100644
--- a/tests/e2e/integration/network-policies.test.ts
+++ b/tests/e2e/integration/network-policies.test.ts
@@ -8,12 +8,50 @@
* the NetworkPolicy is blocking traffic as expected. A successful response or
* connection refused (port not listening) would indicate a policy gap.
*/
-import { describe, expect, it } from 'vitest'
+import { beforeAll, describe, expect, it } from 'vitest'
import { execFileSync } from 'child_process'
// Short timeout for negative tests — we expect these to time out
const NP_TIMEOUT = 3
+// ─── Cluster reachability gate ───────────────────────────────────────────────
+// This suite drives kubectl against a live minikube cluster (Calico CNI + all
+// services deployed). Mirrors the opt-in-skip convention already used by the
+// sibling integration suites — channel-reader-via-api.test.ts and
+// mcpCredentialRotation.helpers.ts (E2E_SKIP_IF_CLUSTER_UNREACHABLE) plus
+// registry-pull-secret-runtime.test.ts (E2E_REQUIRE_CLUSTER / CI):
+// - Default (no flag): fail-fast when the cluster is unreachable. A silent
+// pass would hide a broken E2E setup, so the suite must NOT be neutralized
+// unconditionally.
+// - E2E_SKIP_IF_CLUSTER_UNREACHABLE=1: opt in to a clean skip for the tier
+// that runs integration WITHOUT a cluster (T1).
+// - E2E_REQUIRE_CLUSTER=1 or CI=true: force a hard failure even if the skip
+// flag is also set — CI must never skip.
+const SKIP_IF_UNREACHABLE = process.env.E2E_SKIP_IF_CLUSTER_UNREACHABLE === '1'
+const REQUIRE_CLUSTER = process.env.E2E_REQUIRE_CLUSTER === '1' || process.env.CI === 'true'
+
+let clusterReachable = false
+
+/**
+ * One-shot reachability probe: succeeds only when kubectl can talk to the API
+ * server. This is a precondition probe (the established sibling idiom —
+ * registry-pull-secret-runtime.test.ts's `kubectlOrNull`), NOT an error
+ * swallow: its boolean result drives the fail-hard-or-skip decision in
+ * `beforeAll`, which stays loud in the default and CI paths.
+ */
+function probeClusterReachable(): boolean {
+ try {
+ execFileSync('kubectl', ['get', 'ns', 'default', '-o', 'name'], {
+ encoding: 'utf-8',
+ timeout: 15_000,
+ stdio: ['ignore', 'pipe', 'pipe'],
+ })
+ return true
+ } catch {
+ return false
+ }
+}
+
interface ConnectResult {
reachable: boolean
statusCode?: number
@@ -141,8 +179,32 @@ function testConnectivity(
}
describe('NetworkPolicy Enforcement (Calico)', () => {
+ beforeAll(() => {
+ clusterReachable = probeClusterReachable()
+ if (clusterReachable) return
+
+ const msg =
+ '[network-policies] kubernetes cluster not reachable (kubectl get ns default failed)'
+ if (REQUIRE_CLUSTER) {
+ throw new Error(
+ `${msg}. Refusing to skip: E2E_REQUIRE_CLUSTER/CI is set, and a silent skip here ` +
+ 'would report success while asserting nothing about NetworkPolicy enforcement. ' +
+ 'Bring up the cluster (e.g. `make minikube-setup`) or unset the flag.'
+ )
+ }
+ if (SKIP_IF_UNREACHABLE) {
+ console.log(`${msg} — tests will be skipped (E2E_SKIP_IF_CLUSTER_UNREACHABLE=1)`)
+ return
+ }
+ throw new Error(
+ `${msg}. This E2E suite requires a minikube cluster with Calico CNI and all services ` +
+ 'deployed. Run `make minikube-setup` first, or set E2E_SKIP_IF_CLUSTER_UNREACHABLE=1 to skip.'
+ )
+ })
+
// ─── Prerequisite Check ──────────────────────────────────────────────
it('Calico CNI is active', () => {
+ if (!clusterReachable) return
const pods = execFileSync(
'kubectl',
['get', 'pods', '-n', 'kube-system', '-l', 'k8s-app=calico-node', '--no-headers'],
@@ -152,6 +214,7 @@ describe('NetworkPolicy Enforcement (Calico)', () => {
})
it('deny-all policies exist in secured namespaces', () => {
+ if (!clusterReachable) return
const namespaces = ['mcp-host', 'mcp-server', 'rpc-proxy', 'sandbox-recipes']
for (const ns of namespaces) {
let nps: string
@@ -185,6 +248,7 @@ describe('NetworkPolicy Enforcement (Calico)', () => {
// ─── POSITIVE TESTS (Allowed Traffic) ────────────────────────────────
describe('Allowed traffic (positive)', () => {
it('control-api → registry-api:8085 (cross-namespace, registry access)', () => {
+ if (!clusterReachable) return
const result = testConnectivity(
'control-plane',
'control-api',
@@ -194,6 +258,7 @@ describe('NetworkPolicy Enforcement (Calico)', () => {
})
it('control-ui → control-api:8090 (UI backend path)', () => {
+ if (!clusterReachable) return
const result = testConnectivity(
'control-plane',
'control-ui',
@@ -203,6 +268,7 @@ describe('NetworkPolicy Enforcement (Calico)', () => {
})
it('external-rest-api → profile-control-funnel:8080 (internal control path)', () => {
+ if (!clusterReachable) return
const result = testConnectivity(
'profiles',
'external-rest-api',
@@ -212,11 +278,13 @@ describe('NetworkPolicy Enforcement (Calico)', () => {
})
it('rpc-proxy → mcp-host:8080 (message relay)', () => {
+ if (!clusterReachable) return
const result = testConnectivity('rpc-proxy', 'rpc-proxy', getMcpHostRuntimeUrl())
expect(result.reachable).toBe(true)
})
it('mcp-host can reach the HCC gateway readiness endpoint', () => {
+ if (!clusterReachable) return
const result = testConnectivity(
'mcp-host',
getMcpHostRuntimeName(),
@@ -231,6 +299,7 @@ describe('NetworkPolicy Enforcement (Calico)', () => {
// ─── NEGATIVE TESTS (Blocked by Design) ──────────────────────────────
describe('Blocked traffic (negative — deny-all enforced)', () => {
it('mcp-host → rpc-proxy:8094 (reverse direction blocked)', () => {
+ if (!clusterReachable) return
const result = testConnectivity(
'mcp-host',
getMcpHostRuntimeName(),
@@ -241,6 +310,7 @@ describe('NetworkPolicy Enforcement (Calico)', () => {
})
it('mcp-host → control-api:8090 (no direct access to control-plane)', () => {
+ if (!clusterReachable) return
const result = testConnectivity(
'mcp-host',
getMcpHostRuntimeName(),
@@ -251,6 +321,7 @@ describe('NetworkPolicy Enforcement (Calico)', () => {
})
it('channel-reader → workflow approval gateway:8092 (must go through mcp-host)', () => {
+ if (!clusterReachable) return
const podName = getChannelReaderPodName()
if (!podName) {
console.warn('SKIPPED: no running channel-reader pod in channels')
@@ -267,6 +338,7 @@ describe('NetworkPolicy Enforcement (Calico)', () => {
})
it('mcp-host → registry-api:8085 (no direct registry access)', () => {
+ if (!clusterReachable) return
const result = testConnectivity(
'mcp-host',
getMcpHostRuntimeName(),
@@ -277,6 +349,7 @@ describe('NetworkPolicy Enforcement (Calico)', () => {
})
it('control-api → rpc-proxy:8094 (no direct control-plane hop)', () => {
+ if (!clusterReachable) return
const result = testConnectivity(
'control-plane',
'control-api',
@@ -287,6 +360,7 @@ describe('NetworkPolicy Enforcement (Calico)', () => {
})
it('external-rest-api → rpc-proxy:8094 (desktop app reaches rpc-proxy directly, not via backend)', () => {
+ if (!clusterReachable) return
const result = testConnectivity(
'profiles',
'external-rest-api',
@@ -297,18 +371,21 @@ describe('NetworkPolicy Enforcement (Calico)', () => {
})
it('control-api → mcp-host:8080 directly (must go through rpc-proxy)', () => {
+ if (!clusterReachable) return
const result = testConnectivity('control-plane', 'control-api', getMcpHostRuntimeUrl())
expect(result.reachable).toBe(false)
expect(result.error).toContain('timeout')
})
it('external-rest-api → mcp-host:8080 directly (must go through rpc-proxy)', () => {
+ if (!clusterReachable) return
const result = testConnectivity('profiles', 'external-rest-api', getMcpHostRuntimeUrl())
expect(result.reachable).toBe(false)
expect(result.error).toContain('timeout')
})
it('mcp-proxy → external-rest-api:3000 (no reverse path)', () => {
+ if (!clusterReachable) return
const result = testConnectivity(
'mcp-server',
'mcp-proxy',
@@ -349,6 +426,7 @@ describe('NetworkPolicy Enforcement (Calico)', () => {
}
it('sandbox-recipes → control-api:8090 (isolated sandbox)', () => {
+ if (!clusterReachable) return
const podName = findExecPod('sandbox-recipes', 'app=db')
if (!podName) {
console.warn('SKIPPED: no running db pod in sandbox-recipes')
@@ -365,6 +443,7 @@ describe('NetworkPolicy Enforcement (Calico)', () => {
})
it('sandbox-recipes → rpc-proxy:8094 (isolated sandbox)', () => {
+ if (!clusterReachable) return
const podName = findExecPod('sandbox-recipes', 'app=db')
if (!podName) {
console.warn('SKIPPED: no running db pod in sandbox-recipes')
diff --git a/tests/e2e/package-lock.json b/tests/e2e/package-lock.json
index 6284891d7..62930fee6 100644
--- a/tests/e2e/package-lock.json
+++ b/tests/e2e/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-e2e-tests",
- "version": "0.1.61",
+ "version": "0.1.62",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-e2e-tests",
- "version": "0.1.61",
+ "version": "0.1.62",
"devDependencies": {
"@types/jsonwebtoken": "^9.0.10",
"@types/node": "^22.0.0",
diff --git a/tests/e2e/package.json b/tests/e2e/package.json
index 0131122ca..0357c0ddd 100644
--- a/tests/e2e/package.json
+++ b/tests/e2e/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-e2e-tests",
- "version": "0.1.61",
+ "version": "0.1.62",
"private": true,
"type": "module",
"scripts": {