Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
tests/ui: add a seeded console stack you can click around
Antonio Ojea6437aa1d2aca
diff --git a/Makefile b/Makefileindex 96d33d9d..58fc5b4c 100644--- a/Makefile+++ b/Makefile@@ -149,6 +149,12 @@ ui-test: buildchmod +x ./tests/ui/run.sh./tests/ui/run.sh $(if $(WHAT),--grep "$(WHAT)")+# Same stack as ui-test, seeded and left running so you can click around.+.PHONY: ui-dev+ui-dev: build+ chmod +x ./tests/ui/dev.sh+ ./tests/ui/dev.sh+test-e2e: build docker-build@command -v bats >/dev/null 2>&1 || { \echo "bats not found; attempting install"; \diff --git a/site/content/docs/development/testing.md b/site/content/docs/development/testing.mdindex 27169df8..9331f4e1 100644--- a/site/content/docs/development/testing.md+++ b/site/content/docs/development/testing.md@@ -9,6 +9,7 @@ Current testing is intentionally minimal and aligned with the current binaries.1. Go tests: `make test`2. BATS CLI tests: `make test-e2e`3. Containerized BATS mesh tests: `make test-e2e-container`+4. Console UI tests: `make ui-test`## Commands@@ -17,6 +18,7 @@ make buildmake testmake test-e2emake test-e2e-container+make ui-test```## Go Tests@@ -72,6 +74,31 @@ Optional image override:MESH_RUNTIME_IMAGE=sam-e2e-runtime:dev make test-e2e-container```+## Console UI++Playwright drives the console in `tests/ui/console.spec.js`. The stack is built+in `tests/ui/lib/stack.sh` and runs entirely as local processes against a+throwaway sqlite database, so no docker, kind or postgres is involved.++```bash+make ui-test+make ui-test WHAT="policy editor" # --grep a subset+```++To click around that same stack instead of asserting against it:++```bash+make ui-dev+```++That seeds a mesh policy, enrolls a router and a node with bootstrap tokens, then+leaves the console running with its URL and admin token printed. Only the OIDC+issuer is a stand-in: it serves a discovery document but cannot sign tokens,+which is why enrollment uses bootstrap tokens rather than a JWT.++The console serves its static assets from `cmd/sam-console/public`, so edits to+the HTML, CSS or JS need only a browser refresh; only Go changes need a rebuild.+## Troubleshooting- Ensure Docker daemon is running before container tests.diff --git a/tests/ui/dev.sh b/tests/ui/dev.shnew file mode 100755index 00000000..9633c339--- /dev/null+++ b/tests/ui/dev.sh@@ -0,0 +1,116 @@+#!/bin/bash+# Copyright 2026 Google LLC+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+#+# Runs the console against a real control plane, seeded with a router and a node+# so the dashboard has something in it, and leaves it up until Ctrl-C. Everything+# is a local process against a throwaway sqlite DB: no docker, no kind, no+# postgres. Static assets are served from the working tree, so editing the HTML,+# CSS or JS only needs a browser refresh.+#+# Usage: make ui-dev (or tests/ui/dev.sh)++set -o errexit+set -o nounset+set -o pipefail++source "$(dirname "${BASH_SOURCE[0]}")/lib/stack.sh"+cd "${REPO_ROOT}"++trap stack_cleanup EXIT INT TERM++for binary in sam-control-plane sam-console sam-router sam-node; do+ if [[ ! -x "${REPO_ROOT}/bin/${binary}" ]]; then+ echo "missing ${REPO_ROOT}/bin/${binary}; run 'make build' first" >&2+ exit 1+ fi+done++stack_start++api() {+ local method="$1" path="$2"+ shift 2+ curl -fsS -X "${method}" \+ -H "Authorization: Bearer ${STACK_ADMIN_TOKEN}" \+ "$@" "${STACK_CP_URL}${path}"+}++echo "Seeding mesh policy..."+api POST /policies -H "Content-Type: application/json" -d '{+ "roles": [+ {"name": "sam-admin", "allowed_services": ["*"], "allowed_targets": ["*"]},+ {"name": "sam:role:router", "allowed_services": ["*"], "allowed_targets": ["*"]},+ {"name": "sam:role:node", "allowed_services": ["mcp://*", "system://sam.catalog"], "allowed_targets": ["*"]}+ ],+ "bindings": [+ {"role": "sam:role:router", "members": ["group:routers"]},+ {"role": "sam:role:node", "members": ["group:users"]},+ {"role": "sam-admin", "members": ["user:root-admin"]}+ ]+}' >/dev/null++# Enrolment is what puts routers and nodes on the dashboard, and a bootstrap+# token is the only way in without an issuer that can actually sign a JWT.+mint_token() {+ local role="$1" description="$2"+ api POST /user/bootstrap-tokens -H "Content-Type: application/json" \+ -d "{\"role\": \"${role}\", \"max_usages\": 1, \"ttl_hours\": 24, \"description\": \"${description}\"}" |+ sed -n 's/.*"token"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p'+}++echo "Enrolling a router..."+ROUTER_TOKEN=$(mint_token "sam:role:router" "ui-dev router")+"${REPO_ROOT}/bin/sam-router" \+ --control-plane "${STACK_CP_URL}" \+ --listen "/ip4/127.0.0.1/tcp/5101" \+ --keys-path "${WORK_DIR}/router.key" \+ --allow-loopback \+ --bootstrap-token "${ROUTER_TOKEN}" \+ >"${WORK_DIR}/router.log" 2>&1 &+PIDS+=($!)++echo "Enrolling a node..."+NODE_TOKEN=$(mint_token "sam:role:node" "ui-dev node")+NODE_DIR="${WORK_DIR}/node"+mkdir -p "${NODE_DIR}"+cat >"${NODE_DIR}/sam-node.yaml" <<'EOF'+version: "v1alpha1"+services: []+EOF+"${REPO_ROOT}/bin/sam-node" join "${STACK_CP_URL}" \+ --bootstrap-token "${NODE_TOKEN}" \+ --data-dir "${NODE_DIR}" \+ --config "${NODE_DIR}/sam-node.yaml" \+ --allow-loopback \+ >"${WORK_DIR}/node-join.log" 2>&1 || echo " node join failed, see ${WORK_DIR}/node-join.log" >&2++# A couple left over so the Bootstrap Tokens table is not empty.+mint_token "sam:role:node" "spare node token" >/dev/null+mint_token "sam:role:sambox" "spare box token" >/dev/null++cat <<EOF++ Console ${STACK_CONSOLE_URL}+ Log in with the admin token: ${STACK_ADMIN_TOKEN}++ Control plane ${STACK_CP_URL}+ Logs ${WORK_DIR}++ Static assets are served from cmd/sam-console/public, so edits to the HTML,+ CSS or JS just need a browser refresh. Ctrl-C tears everything down.++EOF++waitdiff --git a/tests/ui/lib/stack.sh b/tests/ui/lib/stack.shnew file mode 100644index 00000000..08266143--- /dev/null+++ b/tests/ui/lib/stack.sh@@ -0,0 +1,118 @@+# Copyright 2026 Google LLC+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+#+# Boots a control plane and console against a throwaway sqlite DB. Sourced by+# run.sh, which drives Playwright against it, and by dev.sh, which leaves it up+# for a human. No docker or kind required.+#+# Callers set STACK_* before sourcing; everything has a default.++STACK_ADMIN_TOKEN="${STACK_ADMIN_TOKEN:-ui-test-admin-token}"+STACK_CP_ADDR="${STACK_CP_ADDR:-127.0.0.1:8090}"+STACK_CONSOLE_ADDR="${STACK_CONSOLE_ADDR:-127.0.0.1:8091}"+STACK_OIDC_PORT="${STACK_OIDC_PORT:-18090}"++STACK_CP_URL="http://${STACK_CP_ADDR}"+STACK_CONSOLE_URL="http://${STACK_CONSOLE_ADDR}"+STACK_OIDC_ISSUER="http://127.0.0.1:${STACK_OIDC_PORT}"++# Both the control plane and the console read this from the environment.+export SAM_ADMIN_TOKEN="${STACK_ADMIN_TOKEN}"++REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)+WORK_DIR=$(mktemp -d)+PIDS=()++# $! can name a wrapper rather than the server itself (python3 is a shim on some+# systems), so walk the descendants instead of trusting the recorded pid alone.+kill_tree() {+ local pid="$1" child+ for child in $(pgrep -P "${pid}" 2>/dev/null || true); do+ kill_tree "${child}"+ done+ kill "${pid}" 2>/dev/null || true+}++stack_cleanup() {+ for pid in "${PIDS[@]:-}"; do+ kill_tree "${pid}"+ wait "${pid}" 2>/dev/null || true+ done+ rm -rf "${WORK_DIR}"+}++wait_for() {+ local url="$1" name="$2"+ for _ in $(seq 1 50); do+ if curl -fsS -o /dev/null "${url}" 2>/dev/null; then+ return 0+ fi+ sleep 0.2+ done+ echo "timed out waiting for ${name} at ${url}" >&2+ cat "${WORK_DIR}/${name}.log" >&2 || true+ return 1+}++stack_start_oidc() {+ echo "Starting mock OIDC discovery endpoint..."+ # Nothing here signs tokens: callers authenticate with the admin token or a+ # bootstrap token, so the issuer only has to satisfy the control plane's+ # startup discovery. A static document is enough.+ mkdir -p "${WORK_DIR}/oidc/.well-known"+ cat >"${WORK_DIR}/oidc/.well-known/openid-configuration" <<EOF+{+ "issuer": "${STACK_OIDC_ISSUER}",+ "authorization_endpoint": "${STACK_OIDC_ISSUER}/auth",+ "token_endpoint": "${STACK_OIDC_ISSUER}/token",+ "jwks_uri": "${STACK_OIDC_ISSUER}/keys"+}+EOF+ echo '{"keys":[]}' >"${WORK_DIR}/oidc/keys"+ python3 -m http.server "${STACK_OIDC_PORT}" --bind 127.0.0.1 --directory "${WORK_DIR}/oidc" \+ >"${WORK_DIR}/oidc.log" 2>&1 &+ PIDS+=($!)+ wait_for "${STACK_OIDC_ISSUER}/.well-known/openid-configuration" "oidc"+}++stack_start_control_plane() {+ echo "Starting control plane..."+ "${REPO_ROOT}/bin/sam-control-plane" \+ --bind-address "${STACK_CP_ADDR}" \+ --db-dsn "${WORK_DIR}/console-ui.db" \+ --issuer "${STACK_OIDC_ISSUER}" \+ --auto-approve-enrollment \+ >"${WORK_DIR}/control-plane.log" 2>&1 &+ PIDS+=($!)+ wait_for "${STACK_CP_URL}/info" "control-plane"+}++stack_start_console() {+ echo "Starting console..."+ # Served straight from the working tree, so a browser refresh picks up edits to+ # the HTML, CSS and JS without a rebuild.+ "${REPO_ROOT}/bin/sam-console" \+ --control-plane "${STACK_CP_URL}" \+ --bind-addr "${STACK_CONSOLE_ADDR}" \+ --static-dir "${REPO_ROOT}/cmd/sam-console/public" \+ >"${WORK_DIR}/console.log" 2>&1 &+ PIDS+=($!)+ wait_for "${STACK_CONSOLE_URL}/" "console"+}++stack_start() {+ stack_start_oidc+ stack_start_control_plane+ stack_start_console+}diff --git a/tests/ui/run.sh b/tests/ui/run.shindex 203b7ff3..a5461e09 100755--- a/tests/ui/run.sh+++ b/tests/ui/run.sh@@ -15,89 +15,22 @@## Boots a control plane and console against a throwaway sqlite DB, then runs the# Playwright console smoke test against them. No docker or kind required.+#+# To click around that same stack by hand instead, use dev.sh.set -o errexitset -o nounsetset -o pipefail-REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)+source "$(dirname "${BASH_SOURCE[0]}")/lib/stack.sh"cd "${REPO_ROOT}"-export SAM_ADMIN_TOKEN="ui-test-admin-token"-export SAM_CONSOLE_URL="http://127.0.0.1:8091"-OIDC_ISSUER="http://127.0.0.1:18090"--WORK_DIR=$(mktemp -d)-PIDS=()--cleanup() {- for pid in "${PIDS[@]:-}"; do- kill_tree "${pid}"- wait "${pid}" 2>/dev/null || true- done- rm -rf "${WORK_DIR}"-}--# $! can name a wrapper rather than the server itself (python3 is a shim on some-# systems), so walk the descendants instead of trusting the recorded pid alone.-kill_tree() {- local pid="$1" child- for child in $(pgrep -P "${pid}" 2>/dev/null || true); do- kill_tree "${child}"- done- kill "${pid}" 2>/dev/null || true-}-trap cleanup EXIT INT TERM--wait_for() {- local url="$1" name="$2"- for _ in $(seq 1 50); do- if curl -fsS -o /dev/null "${url}" 2>/dev/null; then- return 0- fi- sleep 0.2- done- echo "timed out waiting for ${name} at ${url}" >&2- cat "${WORK_DIR}/${name}.log" >&2 || true- return 1-}--echo "Starting mock OIDC discovery endpoint..."-# The console smoke test authenticates with the admin token, so the issuer only-# has to satisfy the control plane's startup discovery. A static document is enough.-mkdir -p "${WORK_DIR}/oidc/.well-known"-cat >"${WORK_DIR}/oidc/.well-known/openid-configuration" <<EOF-{- "issuer": "${OIDC_ISSUER}",- "authorization_endpoint": "${OIDC_ISSUER}/auth",- "token_endpoint": "${OIDC_ISSUER}/token",- "jwks_uri": "${OIDC_ISSUER}/keys"-}-EOF-echo '{"keys":[]}' >"${WORK_DIR}/oidc/keys"-python3 -m http.server 18090 --bind 127.0.0.1 --directory "${WORK_DIR}/oidc" \- >"${WORK_DIR}/oidc.log" 2>&1 &-PIDS+=($!)-wait_for "${OIDC_ISSUER}/.well-known/openid-configuration" "oidc"+trap stack_cleanup EXIT INT TERM-echo "Starting control plane..."-"${REPO_ROOT}/bin/sam-control-plane" \- --bind-address "127.0.0.1:8090" \- --db-dsn "${WORK_DIR}/console-ui-test.db" \- --issuer "${OIDC_ISSUER}" \- --auto-approve-enrollment \- >"${WORK_DIR}/control-plane.log" 2>&1 &-PIDS+=($!)-wait_for "http://127.0.0.1:8090/info" "control-plane"+export SAM_ADMIN_TOKEN="${STACK_ADMIN_TOKEN}"+export SAM_CONSOLE_URL="${STACK_CONSOLE_URL}"-echo "Starting console..."-"${REPO_ROOT}/bin/sam-console" \- --control-plane "http://127.0.0.1:8090" \- --bind-addr "127.0.0.1:8091" \- --static-dir "${REPO_ROOT}/cmd/sam-console/public" \- >"${WORK_DIR}/console.log" 2>&1 &-PIDS+=($!)-wait_for "${SAM_CONSOLE_URL}/" "console"+stack_startcd "${REPO_ROOT}/tests/ui"npm ci --no-audit --no-fund