Skip to content

Agent Mesh

optimize e2e tests

Antonio Ojea2642c0126ce0
diff --git a/tests/e2e/container_mesh.bats b/tests/e2e/container_mesh.bats
index 9838c4a0..07a2514e 100644
--- a/tests/e2e/container_mesh.bats
+++ b/tests/e2e/container_mesh.bats
@@ -3,14 +3,6 @@
load "lib/container_mesh.bash"
setup() {
- if ! mesh_require_docker; then
- skip "docker not available or daemon not running"
- fi
-
- if [[ ! -x "./bin/sam-node" || ! -x "./bin/sam-hub" ]]; then
- skip "missing binaries; run: make build"
- fi
-
mesh_setup_env
mkdir -p tests/e2e/logs
}
diff --git a/tests/e2e/datapath.bats b/tests/e2e/datapath.bats
index a9d6bcff..29effa60 100644
--- a/tests/e2e/datapath.bats
+++ b/tests/e2e/datapath.bats
@@ -3,14 +3,6 @@
load "lib/container_mesh.bash"
setup() {
- if ! mesh_require_docker; then
- skip "docker not available or daemon not running"
- fi
-
- if [[ ! -x "./bin/sam-node" || ! -x "./bin/sam-hub" || ! -x "./bin/mcp-client" ]]; then
- skip "missing binaries; run: make build"
- fi
-
mesh_setup_env
}
diff --git a/tests/e2e/docs_snippets.bats b/tests/e2e/docs_snippets.bats
index 9936857f..fdb3d233 100644
--- a/tests/e2e/docs_snippets.bats
+++ b/tests/e2e/docs_snippets.bats
@@ -3,14 +3,6 @@
load "lib/container_mesh.bash"
setup() {
- if ! mesh_require_docker; then
- skip "docker not available or daemon not running"
- fi
-
- if [[ ! -x "./bin/sam-node" || ! -x "./bin/sam-hub" ]]; then
- skip "missing binaries; run: make build"
- fi
-
mesh_setup_env
}
diff --git a/tests/e2e/find_remote_tools.bats b/tests/e2e/find_remote_tools.bats
index d53fa53d..01387d51 100644
--- a/tests/e2e/find_remote_tools.bats
+++ b/tests/e2e/find_remote_tools.bats
@@ -24,9 +24,6 @@ start_calc_mcp() {
}
setup() {
- if ! mesh_require_docker; then
- skip "docker not available or daemon not running"
- fi
mesh_setup_env
build_calc_mcp_image
}
diff --git a/tests/e2e/key_rotation_test.bats b/tests/e2e/key_rotation_test.bats
index 7586443c..8803717d 100644
--- a/tests/e2e/key_rotation_test.bats
+++ b/tests/e2e/key_rotation_test.bats
@@ -3,14 +3,6 @@
load "lib/container_mesh.bash"
setup() {
- if ! mesh_require_docker; then
- skip "docker not available or daemon not running"
- fi
-
- if [[ ! -x "./bin/sam-node" || ! -x "./bin/sam-hub" ]]; then
- skip "missing binaries; run: make build"
- fi
-
mesh_setup_env
}
diff --git a/tests/e2e/kind_wi.bats b/tests/e2e/kind_wi.bats
index 6337a4e3..b167c241 100644
--- a/tests/e2e/kind_wi.bats
+++ b/tests/e2e/kind_wi.bats
@@ -1,25 +1,12 @@
#!/usr/bin/env bats
setup() {
- if ! command -v kind >/dev/null 2>&1; then
- skip "kind not available"
- fi
- if ! command -v kubectl >/dev/null 2>&1; then
- skip "kubectl not available"
- fi
- if ! command -v jq >/dev/null 2>&1; then
- skip "jq not available"
- fi
-
# We use a unique cluster name to avoid conflicts
CLUSTER_NAME="sam-wi-test-$RANDOM"
# Create Kind cluster
kind create cluster --name "${CLUSTER_NAME}"
- # Build images
- make docker-build
-
# Load images into Kind
kind load docker-image sam-hub:local --name "${CLUSTER_NAME}"
kind load docker-image sam-node:local --name "${CLUSTER_NAME}"
diff --git a/tests/e2e/lib/container_mesh.bash b/tests/e2e/lib/container_mesh.bash
index b796a2c9..7fc84afe 100644
--- a/tests/e2e/lib/container_mesh.bash
+++ b/tests/e2e/lib/container_mesh.bash
@@ -47,6 +47,9 @@ if [[ -z "${MESH_HELPERS_LOADED:-}" ]]; then
}
mesh_setup_env() {
+ if [[ -n "${MESH_NETWORK:-}" ]]; then
+ return 0
+ fi
mesh_cleanup_stale_resources
mesh_build_runtime_image
@@ -72,19 +75,21 @@ if [[ -z "${MESH_HELPERS_LOADED:-}" ]]; then
fi
}
- mesh_cleanup_env() {
+ mesh_cleanup_test_resources() {
local c
for c in "${MESH_CONTAINERS[@]}"; do
docker rm -f "${c}" >/dev/null 2>&1 || true
done
- if [[ -n "${MESH_NETWORK}" ]]; then
- docker network rm "${MESH_NETWORK}" >/dev/null 2>&1 || true
- fi
- if [[ -n "${MESH_SOCKET_DIR}" ]]; then
- rm -rf "${MESH_SOCKET_DIR}"
- fi
MESH_CONTAINERS=()
- MESH_NETWORK=""
+ }
+
+ mesh_cleanup_env() {
+ mesh_cleanup_test_resources
+ # We leave the network and socket dir alive for the suite
+ }
+
+ mesh_cleanup_suite() {
+ mesh_cleanup_stale_resources
}
mesh_gen_hex32() {
@@ -187,6 +192,9 @@ if [[ -z "${MESH_HELPERS_LOADED:-}" ]]; then
mesh_start_mock_oidc() {
local name="${MESH_PREFIX}-oidc"
+ if docker inspect -f '{{.State.Running}}' "${name}" 2>/dev/null | grep -q "true"; then
+ return 0
+ fi
docker run -d \
--name "${name}" \
--network "${MESH_NETWORK}" \
@@ -199,6 +207,9 @@ if [[ -z "${MESH_HELPERS_LOADED:-}" ]]; then
mesh_start_hub() {
local name="${MESH_PREFIX}-hub"
+ if docker inspect -f '{{.State.Running}}' "${name}" 2>/dev/null | grep -q "true"; then
+ return 0
+ fi
local key
key="$(mesh_gen_hex32)"
diff --git a/tests/e2e/policy.bats b/tests/e2e/policy.bats
index e95bd339..af9ba09e 100644
--- a/tests/e2e/policy.bats
+++ b/tests/e2e/policy.bats
@@ -135,14 +135,6 @@ mesh_call_remote_tool() {
}
setup() {
- if ! mesh_require_docker; then
- skip "docker not available or daemon not running"
- fi
-
- if [[ ! -x "./bin/sam-node" || ! -x "./bin/sam-hub" ]]; then
- skip "missing binaries; run: make build"
- fi
-
mesh_setup_env
mkdir -p tests/e2e/logs
diff --git a/tests/e2e/python_sdk_test.bats b/tests/e2e/python_sdk_test.bats
index 1f3d4bf6..63637099 100644
--- a/tests/e2e/python_sdk_test.bats
+++ b/tests/e2e/python_sdk_test.bats
@@ -3,14 +3,6 @@
load "lib/container_mesh.bash"
setup() {
- if ! mesh_require_docker; then
- skip "docker not available or daemon not running"
- fi
-
- if [[ ! -x "./bin/sam-node" || ! -x "./bin/sam-hub" ]]; then
- skip "missing binaries; run: make build"
- fi
-
mesh_setup_env
}
diff --git a/tests/e2e/relay.bats b/tests/e2e/relay.bats
index e9b71502..228b082f 100644
--- a/tests/e2e/relay.bats
+++ b/tests/e2e/relay.bats
@@ -3,14 +3,6 @@
load "lib/container_mesh.bash"
setup() {
- if ! mesh_require_docker; then
- skip "docker not available or daemon not running"
- fi
-
- if [[ ! -x "./bin/sam-node" || ! -x "./bin/sam-hub" ]]; then
- skip "missing binaries; run: make build"
- fi
-
mesh_setup_env
mkdir -p tests/e2e/logs
}
diff --git a/tests/e2e/revocation_test.bats b/tests/e2e/revocation_test.bats
index 76bd1ee6..d32ac40b 100644
--- a/tests/e2e/revocation_test.bats
+++ b/tests/e2e/revocation_test.bats
@@ -3,14 +3,6 @@
load "lib/container_mesh.bash"
setup() {
- if ! mesh_require_docker; then
- skip "docker not available or daemon not running"
- fi
-
- if [[ ! -x "./bin/sam-node" || ! -x "./bin/sam-hub" ]]; then
- skip "missing binaries; run: make build"
- fi
-
mesh_setup_env
}
diff --git a/tests/e2e/sam.bats b/tests/e2e/sam.bats
index f519b49c..5b636d4e 100644
--- a/tests/e2e/sam.bats
+++ b/tests/e2e/sam.bats
@@ -4,14 +4,6 @@ setup() {
export SAM_NODE_BINARY="${SAM_NODE_BINARY:-./bin/sam-node}"
export SAM_HUB_BINARY="${SAM_HUB_BINARY:-./bin/sam-hub}"
- make
- if [[ ! -x "$SAM_NODE_BINARY" ]]; then
- skip "sam-node binary not found at $SAM_NODE_BINARY"
- fi
- if [[ ! -x "$SAM_HUB_BINARY" ]]; then
- skip "sam-hub binary not found at $SAM_HUB_BINARY"
- fi
-
export TEST_TMPDIR
TEST_TMPDIR="$(mktemp -d)"
export HOME="$TEST_TMPDIR/home"
diff --git a/tests/e2e/services.bats b/tests/e2e/services.bats
index 27a501f4..8a29102e 100644
--- a/tests/e2e/services.bats
+++ b/tests/e2e/services.bats
@@ -23,14 +23,6 @@ start_calc_mcp() {
}
setup() {
- if ! mesh_require_docker; then
- skip "docker not available or daemon not running"
- fi
-
- if [[ ! -x "./bin/sam-node" || ! -x "./bin/sam-hub" || ! -x "./bin/mcp-client" ]]; then
- skip "missing binaries; run: make build"
- fi
-
mesh_setup_env
build_calc_mcp_image
}
diff --git a/tests/e2e/setup_suite.bash b/tests/e2e/setup_suite.bash
index bebdfb73..58301f96 100644
--- a/tests/e2e/setup_suite.bash
+++ b/tests/e2e/setup_suite.bash
@@ -5,12 +5,47 @@ set -eu
function setup_suite {
export BATS_TEST_TIMEOUT=150
+ if ! command -v docker >/dev/null 2>&1 || ! docker info >/dev/null 2>&1; then
+ echo "docker not available or daemon not running" >&2
+ exit 1
+ fi
+ if ! command -v kind >/dev/null 2>&1; then
+ echo "kind not available" >&2
+ exit 1
+ fi
+ if ! command -v kubectl >/dev/null 2>&1; then
+ echo "kubectl not available" >&2
+ exit 1
+ fi
+ if ! command -v jq >/dev/null 2>&1; then
+ echo "jq not available" >&2
+ exit 1
+ fi
+
# tests/e2e
cd "$BATS_TEST_DIRNAME"/../..
make
make docker-build
+
+ if [[ ! -x "./bin/sam-node" || ! -x "./bin/sam-hub" || ! -x "./bin/mcp-client" ]]; then
+ echo "missing binaries; run: make build" >&2
+ exit 1
+ fi
+
+ export BATS_TEST_NUMBER=0
+ source tests/e2e/lib/container_mesh.bash
+ mesh_setup_env
+ export MESH_PREFIX
+ export MESH_NETWORK
+
+ # Ensure the mock oidc and hub are running for all tests
+ mesh_start_mock_oidc
+ mesh_start_hub
}
function teardown_suite {
+ cd "$BATS_TEST_DIRNAME"/../..
+ source tests/e2e/lib/container_mesh.bash
+ mesh_cleanup_suite
echo "teardown suite"
}
\ No newline at end of file