Skip to content

Agent Mesh

tests: add console UI smoke test

Antonio Ojea88ab43bf4665
diff --git a/.github/workflows/ui.yml b/.github/workflows/ui.yml
new file mode 100644
index 00000000..5b5aea8a
--- /dev/null
+++ b/.github/workflows/ui.yml
@@ -0,0 +1,62 @@
+# 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.
+
+name: console-ui
+
+on:
+ push:
+ branches:
+ - "main"
+ tags:
+ - "v*"
+ pull_request:
+ branches: [main]
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+env:
+ GO_VERSION: "1.26"
+
+jobs:
+ console_ui_smoke:
+ runs-on: ubuntu-latest
+ name: Console UI smoke test
+ steps:
+ - name: Checkout
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+
+ - uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
+ with:
+ go-version: ${{ env.GO_VERSION }}
+ cache: false
+
+ - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
+ with:
+ node-version: "22"
+ cache: npm
+ cache-dependency-path: tests/ui/package-lock.json
+
+ - name: Run console UI smoke test
+ run: make ui-test
+
+ - name: Upload Playwright report
+ if: failure()
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: playwright-report-${{ github.run_id }}
+ path: tests/ui/playwright-report
diff --git a/.gitignore b/.gitignore
index 32b8b626..97f52808 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,6 +38,11 @@ bin/
/sam-box
/sam-router
/sam-console
+
+# Playwright console UI tests
+node_modules/
+tests/ui/playwright-report/
+tests/ui/test-results/
/sam-control-plane
/mcp-client
/nano-init
diff --git a/Makefile b/Makefile
index 14c0272f..c6afecfd 100644
--- a/Makefile
+++ b/Makefile
@@ -142,6 +142,11 @@ test-python-e2e: build docker-build
e2e-test: build docker-build
bats -j 10 --verbose-run $(if $(WHAT),--filter "$(WHAT)") tests/e2e/
+.PHONY: ui-test
+ui-test: build
+ chmod +x ./tests/ui/run.sh
+ ./tests/ui/run.sh $(if $(WHAT),--grep "$(WHAT)")
+
test-e2e: build docker-build
@command -v bats >/dev/null 2>&1 || { \
echo "bats not found; attempting install"; \
diff --git a/tests/ui/console.spec.js b/tests/ui/console.spec.js
new file mode 100644
index 00000000..2664c58f
--- /dev/null
+++ b/tests/ui/console.spec.js
@@ -0,0 +1,107 @@
+// 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.
+
+const { test, expect } = require('@playwright/test');
+
+const ADMIN_TOKEN = process.env.SAM_ADMIN_TOKEN || 'ui-test-admin-token';
+
+// Tests run serially with a single worker, so one collector is enough.
+let jsFailures = [];
+
+// The landing page deliberately probes an authenticated endpoint before login,
+// so a 401 and its handler's console.error are expected, not defects.
+const EXPECTED_NOISE = [
+ 'Unauthorized. Please login again.',
+ 'Failed to load resource: the server responded with a status of 401',
+];
+
+// The console is hand-written vanilla JS with no build step, so a renamed element
+// id or a typo only surfaces at runtime. Fail the test on any uncaught error.
+test.beforeEach(async ({ page }) => {
+ jsFailures = [];
+ page.on('pageerror', (err) => jsFailures.push(`uncaught: ${err.message}`));
+ page.on('console', (msg) => {
+ if (msg.type() !== 'error') {
+ return;
+ }
+ const text = msg.text();
+ if (EXPECTED_NOISE.some((allowed) => text.includes(allowed))) {
+ return;
+ }
+ jsFailures.push(`console.error: ${text}`);
+ });
+});
+
+test.afterEach(async () => {
+ expect(jsFailures, 'console reported JavaScript errors').toEqual([]);
+});
+
+async function login(page) {
+ await page.goto('/');
+ await page.fill('#admin-token-input', ADMIN_TOKEN);
+ await page.click('button:has-text("Login as Admin")');
+ await expect(page.locator('#app-container')).toBeVisible();
+}
+
+test('admin can log in and reach the bootstrap token form', async ({ page }) => {
+ await login(page);
+
+ await page.click('.nav-item[data-target="bootstrap"]');
+ await expect(page.locator('#view-bootstrap')).toBeVisible();
+ await expect(page.locator('#form-generate-token')).toBeVisible();
+
+ // Owner ID is admin-only and optional.
+ await expect(page.locator('#token-owner')).toBeVisible();
+ const required = await page.locator('#token-owner').evaluate((el) => el.required);
+ expect(required).toBe(false);
+});
+
+test('generating a token shows a copyable value and lists it', async ({ page }) => {
+ await login(page);
+ await page.click('.nav-item[data-target="bootstrap"]');
+
+ await expect(page.locator('#token-result')).toBeHidden();
+
+ await page.selectOption('#token-role', 'sam:role:node');
+ await page.fill('#token-desc', 'playwright smoke');
+ await page.click('#form-generate-token button[type="submit"]');
+
+ const tokenField = page.locator('#token-result-value');
+ await expect(page.locator('#token-result')).toBeVisible();
+ await expect(tokenField).toHaveValue(/^sam-bt-[0-9a-f]{32}$/);
+
+ const token = await tokenField.inputValue();
+ await expect(page.locator('#token-result-owner')).toHaveText('root-admin');
+ await expect(page.locator('#token-result-cmd')).toContainText(token);
+
+ // The copy affordance is the whole point of the panel; prove it works.
+ await page.click('#token-copy-btn');
+ await expect(page.locator('#token-copy-btn')).toHaveText('Copied');
+ const clipboard = await page.evaluate(() => navigator.clipboard.readText());
+ expect(clipboard).toBe(token);
+
+ // The new token must appear in the active token list after the refresh.
+ await expect(page.locator('#table-bootstrap')).toContainText('root-admin');
+ await expect(page.locator('#table-bootstrap')).toContainText('sam:role:node');
+});
+
+test('omitting the owner attributes the token to the session user', async ({ page }) => {
+ await login(page);
+ await page.click('.nav-item[data-target="bootstrap"]');
+
+ await expect(page.locator('#token-owner')).toHaveValue('');
+ await page.click('#form-generate-token button[type="submit"]');
+
+ await expect(page.locator('#token-result-owner')).toHaveText('root-admin');
+});
diff --git a/tests/ui/package-lock.json b/tests/ui/package-lock.json
new file mode 100644
index 00000000..3f4d834a
--- /dev/null
+++ b/tests/ui/package-lock.json
@@ -0,0 +1,76 @@
+{
+ "name": "sam-console-ui-tests",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "sam-console-ui-tests",
+ "devDependencies": {
+ "@playwright/test": "1.58.0"
+ }
+ },
+ "node_modules/@playwright/test": {
+ "version": "1.58.0",
+ "resolved": "https://us-npm.pkg.dev/artifact-foundry-prod/ah-3p-staging-npm/@playwright/test/-/test-1.58.0.tgz",
+ "integrity": "sha512-fWza+Lpbj6SkQKCrU6si4iu+fD2dD3gxNHFhUPxsfXBPhnv3rRSQVd0NtBUT9Z/RhF/boCBcuUaMUSTRTopjZg==",
+ "dev": true,
+ "license": "Apache-2.0",
+ "dependencies": {
+ "playwright": "1.58.0"
+ },
+ "bin": {
+ "playwright": "cli.js"
+ },
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/fsevents": {
+ "version": "2.3.2",
+ "resolved": "https://us-npm.pkg.dev/artifact-foundry-prod/ah-3p-staging-npm/fsevents/-/fsevents-2.3.2.tgz",
+ "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
+ "dev": true,
+ "hasInstallScript": true,
+ "license": "MIT",
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
+ }
+ },
+ "node_modules/playwright": {
+ "version": "1.58.0",
+ "resolved": "https://us-npm.pkg.dev/artifact-foundry-prod/ah-3p-staging-npm/playwright/-/playwright-1.58.0.tgz",
+ "integrity": "sha512-2SVA0sbPktiIY/MCOPX8e86ehA/e+tDNq+e5Y8qjKYti2Z/JG7xnronT/TXTIkKbYGWlCbuucZ6dziEgkoEjQQ==",
+ "dev": true,
+ "license": "Apache-2.0",
+ "dependencies": {
+ "playwright-core": "1.58.0"
+ },
+ "bin": {
+ "playwright": "cli.js"
+ },
+ "engines": {
+ "node": ">=18"
+ },
+ "optionalDependencies": {
+ "fsevents": "2.3.2"
+ }
+ },
+ "node_modules/playwright-core": {
+ "version": "1.58.0",
+ "resolved": "https://us-npm.pkg.dev/artifact-foundry-prod/ah-3p-staging-npm/playwright-core/-/playwright-core-1.58.0.tgz",
+ "integrity": "sha512-aaoB1RWrdNi3//rOeKuMiS65UCcgOVljU46At6eFcOFPFHWtd2weHRRow6z/n+Lec0Lvu0k9ZPKJSjPugikirw==",
+ "dev": true,
+ "license": "Apache-2.0",
+ "bin": {
+ "playwright-core": "cli.js"
+ },
+ "engines": {
+ "node": ">=18"
+ }
+ }
+ }
+}
diff --git a/tests/ui/package.json b/tests/ui/package.json
new file mode 100644
index 00000000..0ee9238c
--- /dev/null
+++ b/tests/ui/package.json
@@ -0,0 +1,11 @@
+{
+ "name": "sam-console-ui-tests",
+ "private": true,
+ "description": "Playwright smoke test for the SAM console UI",
+ "scripts": {
+ "test": "playwright test"
+ },
+ "devDependencies": {
+ "@playwright/test": "1.58.0"
+ }
+}
diff --git a/tests/ui/playwright.config.js b/tests/ui/playwright.config.js
new file mode 100644
index 00000000..fa8adb05
--- /dev/null
+++ b/tests/ui/playwright.config.js
@@ -0,0 +1,38 @@
+// 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.
+
+const { defineConfig, devices } = require('@playwright/test');
+
+module.exports = defineConfig({
+ testDir: '.',
+ timeout: 30000,
+ expect: { timeout: 5000 },
+ fullyParallel: false,
+ forbidOnly: !!process.env.CI,
+ retries: 0,
+ workers: 1,
+ reporter: process.env.CI ? [['list'], ['html', { open: 'never' }]] : 'list',
+ use: {
+ baseURL: process.env.SAM_CONSOLE_URL || 'http://127.0.0.1:8091',
+ permissions: ['clipboard-read', 'clipboard-write'],
+ trace: 'retain-on-failure',
+ screenshot: 'only-on-failure',
+ },
+ projects: [
+ {
+ name: 'chromium',
+ use: { ...devices['Desktop Chrome'] },
+ },
+ ],
+});
diff --git a/tests/ui/run.sh b/tests/ui/run.sh
new file mode 100755
index 00000000..203b7ff3
--- /dev/null
+++ b/tests/ui/run.sh
@@ -0,0 +1,110 @@
+#!/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.
+#
+# 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.
+
+set -o errexit
+set -o nounset
+set -o pipefail
+
+REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
+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"
+
+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"
+
+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"
+
+cd "${REPO_ROOT}/tests/ui"
+npm ci --no-audit --no-fund
+# --with-deps needs root to install OS libraries; only CI runners allow that.
+if [[ -n "${CI:-}" ]]; then
+ npx playwright install --with-deps chromium
+else
+ npx playwright install chromium
+fi
+npx playwright test "$@"