diff --git a/.claude/commands/cypress/cypress-run.md b/.claude/commands/cypress/cypress-run.md new file mode 100644 index 00000000..19c2de10 --- /dev/null +++ b/.claude/commands/cypress/cypress-run.md @@ -0,0 +1,593 @@ +--- +name: cypress-run +description: Display Cypress test commands - choose execution mode (headless recommended) +parameters: + - name: execution-mode + description: Choose execution mode - headless (recommended), headed, or interactive + required: true + type: string +--- + +# Cypress Test Commands + +**Prerequisites**: Run `/cypress-setup` first to configure your environment. + +**Note**: These commands assume you're already in the `web/cypress` directory (automatically set by `/cypress-setup`). + +--- + +## 🎯 Execution Modes + +1. **🤖 Headless** (Recommended) - Fast, automated testing without visible browser +2. **👁️ Headed** - Watch tests execute in visible browser for debugging +3. **🎮 Interactive** - Visual UI to pick and run tests manually + +--- + +**Instructions**: Based on the `execution-mode` parameter provided by the user: +- If `execution-mode` is "headless": Display ONLY the "🤖 Headless Mode Commands" section below +- If `execution-mode` is "headed": Display ONLY the "👁️ Headed Mode Commands" section below +- If `execution-mode` is "interactive": Display ONLY the "🎮 Interactive Mode" section below + +Copy the commands you want to run in your **"cypress-monitoring"** terminal. + +--- + +# 🎮 Interactive Mode + +**Cypress Interactive Test Runner** - Pick and run tests visually with Cypress UI. + +## What is Interactive Mode? + +Interactive mode opens the Cypress Test Runner UI where you can: +- ✅ Browse and select tests visually +- ✅ Watch tests run in real-time with time-travel debugging +- ✅ Inspect DOM snapshots at each step +- ✅ See detailed command logs +- ✅ Rerun tests with a single click +- ✅ Perfect for test development and debugging + +## Command + +**Open Cypress Interactive UI:** +```bash +npm run cypress:open +``` + +This opens a visual interface where you can: +1. Choose a browser (Chrome, Firefox, Edge, Electron) +2. Browse your test files +3. Click any test to run it +4. Watch it execute step-by-step +5. Debug failures interactively + +## Benefits + +- **Visual Testing**: See exactly what's happening +- **Fast Iteration**: Make changes and rerun instantly +- **Easy Debugging**: Inspect any step of your test +- **Browser DevTools**: Full access to browser debugging tools +- **Selector Playground**: Helps you write better selectors + +## When to Use + +- 🔍 Developing new tests +- 🐛 Debugging test failures +- 📚 Learning how tests work +- 🎨 Demonstrating tests to others + +--- + +# 🤖 Headless Mode Commands + +All commands below run tests in headless mode (no visible browser). + +## ⚡ Quick Start - Headless + +**Fast Smoke Test (1-2 min, excludes slow/demo/flaky):** +```bash +npm run test-cypress-fast +``` + +**Full Smoke Suite (5-10 min, excludes flaky):** +```bash +npm run test-cypress-smoke +``` + +**Console Test (headless):** +```bash +npm run test-cypress-console-headless +``` + +--- + +## 📦 Complete Test Suites - Headless (from package.json) + +### Monitoring Plugin Tests + +**All Monitoring Tests (excludes flaky):** +```bash +npm run test-cypress-monitoring +``` + +**Monitoring Dev Tests:** +```bash +npm run test-cypress-monitoring-dev +``` + +**Monitoring BVT (smoke only):** +```bash +npm run test-cypress-monitoring-bvt +``` + +**Monitoring Regression (excludes smoke and flaky):** +```bash +npm run test-cypress-monitoring-regression +``` + +### Feature-Specific Tests + +**Alerts (excludes flaky):** +```bash +npm run test-cypress-alerts +``` + +**Metrics (excludes flaky):** +```bash +npm run test-cypress-metrics +``` + +**Dashboards - Legacy (excludes flaky):** +```bash +npm run test-cypress-dashboards +``` + +**Perses Dashboards (excludes flaky):** +```bash +npm run test-cypress-perses +``` + +### COO (Observability Operator) Tests + +**COO - All Tests (excludes flaky):** +```bash +npm run test-cypress-coo +``` + +**COO BVT (smoke only):** +```bash +npm run test-cypress-coo-bvt +``` + +### Integration Tests + +**ACM (Advanced Cluster Management, excludes flaky):** +```bash +npm run test-cypress-acm +``` + +**Virtualization (30-40 min, excludes flaky):** +```bash +npm run test-cypress-virtualization +``` + +**Incidents (excludes flaky):** +```bash +npm run test-cypress-incidents +``` + +--- + +## 🏷️ Custom Tag Combinations - Headless + +**Base command for custom tags:** +```bash +npm run cypress:run -- --env grepTags="YOUR_TAGS_HERE" +``` + +### Popular Tag Combinations: + +**Alerts tests:** +```bash +npm run cypress:run -- --env grepTags="@alerts" +``` + +**Metrics tests:** +```bash +npm run cypress:run -- --env grepTags="@metrics" +``` + +**Dashboards tests:** +```bash +npm run cypress:run -- --env grepTags="@dashboards" +``` + +**Perses tests:** +```bash +npm run cypress:run -- --env grepTags="@perses" +``` + +**All smoke tests (fastest, excludes slow/flaky):** +```bash +npm run cypress:run -- --env grepTags="@smoke --@slow --@flaky" +``` + +**Monitoring without smoke tests:** +```bash +npm run cypress:run -- --env grepTags="@monitoring --@smoke" +``` + +**COO smoke tests:** +```bash +npm run cypress:run -- --env grepTags="@coo+@smoke" +``` + +**Virtualization smoke tests:** +```bash +npm run cypress:run -- --env grepTags="@virtualization+@smoke" +``` + +--- + +## 🎪 Specific Test Files - Headless + +### Monitoring Tests + +**Monitoring BVT (Admin):** +```bash +npm run cypress:run -- --spec "cypress/e2e/monitoring/00.bvt_admin.cy.ts" +``` + +**Monitoring BVT (Dev User):** +```bash +npm run cypress:run -- --spec "cypress/e2e/monitoring/00.bvt_dev.cy.ts" +``` + +**Alerts - Admin User:** +```bash +npm run cypress:run -- --spec "cypress/e2e/monitoring/regression/01.reg_alerts_admin.cy.ts" +``` + +**Alerts - Dev User:** +```bash +npm run cypress:run -- --spec "cypress/e2e/monitoring/regression/01.reg_alerts_dev.cy.ts" +``` + +**Metrics Tests:** +```bash +npm run cypress:run -- --spec "cypress/e2e/monitoring/regression/02.reg_metrics_admin_1.cy.ts" +``` + +```bash +npm run cypress:run -- --spec "cypress/e2e/monitoring/regression/02.reg_metrics_admin_2.cy.ts" +``` + +**Dashboards Tests:** +```bash +npm run cypress:run -- --spec "cypress/e2e/monitoring/regression/03.reg_legacy_dashboards_admin.cy.ts" +``` + +### COO Tests + +**COO BVT:** +```bash +npm run cypress:run -- --spec "cypress/e2e/coo/01.coo_bvt.cy.ts" +``` + +**COO Alerts (headed):** +```bash +npm run cypress:run -- --spec "cypress/e2e/coo/02.acm_alerting_ui.cy.ts" +``` + +### Perses Tests + +**Perses Dashboard:** +```bash +npm run cypress:run -- --spec "cypress/e2e/perses/01.coo_perses.cy.ts" +``` + +### Virtualization Tests + +**Virtualization - Alerts:** +```bash +npm run cypress:run -- --spec "cypress/e2e/virtualization/01.coo_ivt_alerts.cy.ts" +``` + +**Virtualization - Metrics 1:** +```bash +npm run cypress:run -- --spec "cypress/e2e/virtualization/02.coo_ivt_metrics_1.cy.ts" +``` + +**Virtualization - Metrics 2:** +```bash +npm run cypress:run -- --spec "cypress/e2e/virtualization/02.coo_ivt_metrics_2.cy.ts" +``` + +**Virtualization - Dashboards:** +```bash +npm run cypress:run -- --spec "cypress/e2e/virtualization/03.coo_ivt_legacy_dashboards.cy.ts" +``` + +**Virtualization - Perses:** +```bash +npm run cypress:run -- --spec "cypress/e2e/virtualization/04.coo_ivt_perses.cy.ts" +``` + +### Multiple Files + +**Run multiple spec files:** +```bash +npm run cypress:run -- --spec "cypress/e2e/monitoring/00.bvt_admin.cy.ts,cypress/e2e/coo/01.coo_bvt.cy.ts" +``` + +--- + +## 🔧 Advanced Headless Options + +**Run with Firefox (headless):** +```bash +npm run cypress:run -- --browser firefox +``` + +**Run with Edge (headless):** +```bash +npm run cypress:run -- --browser edge +``` + +**Disable video recording:** +```bash +npm run cypress:run -- --config video=false +``` + +**Disable screenshots:** +```bash +npm run cypress:run -- --config screenshotOnRunFailure=false +``` + +--- + +# 👁️ Headed Mode Commands + +All commands below open a visible browser window. + +## ⚡ Quick Start - Headed + +**Interactive Mode (Cypress UI, pick tests manually):** +```bash +npm run cypress:open +``` + +**Console Test (opens browser):** +```bash +npm run test-cypress-console +``` + +**Base headed mode command:** +```bash +npm run cypress:run -- --headed +``` + +--- + +## 📦 Complete Test Suites - Headed + +### Monitoring Plugin Tests + +**All Monitoring Tests (headed, excludes flaky):** +```bash +npm run cypress:run -- --headed --env grepTags="@monitoring --@flaky" +``` + +**Monitoring BVT (headed):** +```bash +npm run cypress:run -- --headed --env grepTags="@monitoring+@smoke" +``` + +**Monitoring Regression (headed):** +```bash +npm run cypress:run -- --headed --env grepTags="@monitoring --@smoke --@flaky" +``` + +### Feature-Specific Tests + +**Alerts (headed):** +```bash +npm run cypress:run -- --headed --env grepTags="@alerts --@flaky" +``` + +**Metrics (headed):** +```bash +npm run cypress:run -- --headed --env grepTags="@metrics --@flaky" +``` + +**Dashboards (headed):** +```bash +npm run cypress:run -- --headed --env grepTags="@dashboards --@flaky" +``` + +**Perses (headed):** +```bash +npm run cypress:run -- --headed --env grepTags="@perses --@flaky" +``` + +### COO Tests + +**COO All Tests (headed):** +```bash +npm run cypress:run -- --headed --env grepTags="@coo --@flaky" +``` + +**COO BVT (headed):** +```bash +npm run cypress:run -- --headed --env grepTags="@coo+@smoke" +``` + +### Integration Tests + +**Virtualization (headed, 30-40 min):** +```bash +npm run cypress:run -- --headed --env grepTags="@virtualization --@flaky" +``` + +**ACM (headed):** +```bash +npm run cypress:run -- --headed --env grepTags="@acm --@flaky" +``` + +**Incidents (headed):** +```bash +npm run cypress:run -- --headed --env grepTags="@incidents --@flaky" +``` + +--- + +## 🏷️ Custom Tag Combinations - Headed + +**Smoke tests (headed):** +```bash +npm run cypress:run -- --headed --env grepTags="@smoke --@slow --@flaky" +``` + +**Alerts smoke (headed):** +```bash +npm run cypress:run -- --headed --env grepTags="@alerts" +``` + +**Metrics smoke (headed):** +```bash +npm run cypress:run -- --headed --env grepTags="@metrics" +``` + +**Dashboards Tests:** +```bash +npm run cypress:run -- --headed --env grepTags="@dashboards" +``` + +--- + +## 🎪 Specific Test Files - Headed + +### Monitoring Tests + +**Monitoring BVT (headed):** +```bash +npm run cypress:run -- --headed --spec "cypress/e2e/monitoring/00.bvt_admin.cy.ts" +``` + +**Alerts Admin (headed):** +```bash +npm run cypress:run -- --headed --spec "cypress/e2e/monitoring/regression/01.reg_alerts_admin.cy.ts" +``` + +**Metrics (headed):** +```bash +npm run cypress:run -- --headed --spec "cypress/e2e/monitoring/regression/02.reg_metrics_admin_1.cy.ts" +``` + +```bash +npm run cypress:run -- --headed --spec "cypress/e2e/monitoring/regression/02.reg_metrics_admin_2.cy.ts" +``` + +**Dashboards (headed):** +```bash +npm run cypress:run -- --headed --spec "cypress/e2e/monitoring/regression/03.reg_legacy_dashboards.cy.ts" +``` + +### COO Tests + +**COO BVT (headed):** +```bash +npm run cypress:run -- --headed --spec "cypress/e2e/coo/01.coo_bvt.cy.ts" +``` + +**COO Alerts (headed):** +```bash +npm run cypress:run -- --headed --spec "cypress/e2e/coo/02.acm_alerting_ui.cy.ts" +``` + +### Virtualization Tests + +**Virtualization Alerts (headed):** +```bash +npm run cypress:run -- --headed --spec "cypress/e2e/virtualization/01.coo_ivt_alerts.cy.ts" +``` + +**Virtualization Metrics (headed):** +```bash +npm run cypress:run -- --headed --spec "cypress/e2e/virtualization/02.coo_ivt_metrics_1.cy.ts" +``` + +```bash +npm run cypress:run -- --headed --spec "cypress/e2e/virtualization/02.coo_ivt_metrics_2.cy.ts" +``` + +**Virtualization Dashboads (headed):** +```bash +npm run cypress:run -- --headed --spec "cypress/e2e/virtualization/03.coo_ivt_legacy_dashboards.cy.ts" +``` + +**Perses Dashboard (headed):** +```bash +npm run cypress:run -- --headed --spec "cypress/e2e/perses/01.coo_perses.cy.ts" +``` + +--- + +## 🔧 Advanced Headed Options + +**Headed with specific browser:** +```bash +npm run cypress:run -- --headed --browser chrome +npm run cypress:run -- --headed --browser firefox +npm run cypress:run -- --headed --browser edge +``` + +**Headed without video:** +```bash +npm run cypress:run -- --headed --config video=false +``` + +**Slow motion (for demos):** +```bash +cypress run --headed --slow 500 --spec "cypress/e2e/monitoring/00.bvt_admin.cy.ts" +``` + +--- + +## 📋 Available Tags Reference + +Use these tags with `--env grepTags`: + +- `@monitoring` - Core monitoring plugin tests +- `@monitoring-dev` - Developer user tests +- `@alerts` - Alert-related tests +- `@metrics` - Metrics explorer tests +- `@dashboards` - Legacy dashboard tests +- `@perses` - Perses dashboard tests +- `@coo` - Observability Operator tests +- `@acm` - Advanced Cluster Management tests +- `@virtualization` - OpenShift Virtualization tests +- `@incidents` - Incidents feature tests +- `@smoke` - Quick smoke tests +- `@slow` - Longer running tests +- `@flaky` - Known flaky tests +- `@demo` - Demo/showcase tests + +**Tag Operators:** +- `+` = AND (e.g., `@alerts+@smoke` = alerts AND smoke) +- `--` = NOT (e.g., `@monitoring --@flaky` = monitoring but NOT flaky) +- `,` = OR (e.g., `@alerts,@metrics` = alerts OR metrics) + +--- + +## 🔗 Related Commands + +- **`/cypress-setup`** - Configure testing environment + +--- + +## 📚 Documentation + +- `web/cypress/README.md` - Setup and execution guide +- `web/cypress/E2E_TEST_SCENARIOS.md` - Complete test catalog +- `web/cypress/CYPRESS_TESTING_GUIDE.md` - Testing best practices \ No newline at end of file diff --git a/.claude/commands/cypress/cypress-setup.md b/.claude/commands/cypress/cypress-setup.md new file mode 100644 index 00000000..15603fa4 --- /dev/null +++ b/.claude/commands/cypress/cypress-setup.md @@ -0,0 +1,383 @@ +--- +name: cypress-setup +description: Automated Cypress environment setup with minimal approvals +parameters: [] +--- + +# Cypress Setup (Automated) + +This command validates prerequisites, detects workspace, creates setup script, and opens terminal automatically - all with minimal approvals. + +--- + +## Execution Flow + +```bash +#!/bin/bash +set -euo pipefail + +echo "🔧 Cypress Setup" +echo "" + +# [1/4] Validate prerequisites +echo "[1/4] Validating prerequisites..." +if command -v node &> /dev/null; then + NODE_VERSION=$(node --version 2>/dev/null) + NODE_MAJOR=$(echo "$NODE_VERSION" | sed 's/v//' | cut -d'.' -f1) + if [ "$NODE_MAJOR" -ge 18 ]; then + echo " ✓ Node.js: $NODE_VERSION" + else + echo " ❌ Node.js too old (required: >= v18.0.0)" + echo "" + echo "Upgrade instructions:" + echo " macOS: brew install node@18" + echo " Linux: curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - && sudo apt-get install -y nodejs" + exit 1 + fi +else + echo " ❌ Node.js not found" + echo "" + echo "Installation instructions:" + echo " macOS: brew install node@18" + echo " Linux: curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - && sudo apt-get install -y nodejs" + exit 1 +fi + +if command -v npm &> /dev/null; then + echo " ✓ npm: $(npm --version)" +else + echo " ❌ npm not found" + exit 1 +fi + +# [2/4] Detect workspace +echo "[2/4] Detecting workspace..." +WORKSPACE_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || true) +if [ -z "$WORKSPACE_ROOT" ]; then + CURRENT_DIR=$(pwd) + if [ -d "$CURRENT_DIR/web/cypress" ]; then + WORKSPACE_ROOT="$CURRENT_DIR" + elif [ -d "$CURRENT_DIR/cypress" ] && [ -f "$CURRENT_DIR/package.json" ]; then + WORKSPACE_ROOT=$(dirname "$CURRENT_DIR") + elif [ -f "$CURRENT_DIR/configure-env.sh" ]; then + WORKSPACE_ROOT=$(dirname $(dirname "$CURRENT_DIR")) + else + echo " ❌ Could not detect workspace" + exit 1 + fi +fi + +WEB_DIR="$WORKSPACE_ROOT/web" +CYPRESS_DIR="$WEB_DIR/cypress" + +if [ ! -d "$CYPRESS_DIR" ]; then + echo " ❌ Invalid repository structure" + exit 1 +fi +echo " ✓ Workspace detected" + +# [3/4] Create setup script +echo "[3/4] Creating setup script..." +TEMP_SCRIPT="/tmp/cypress-setup-$$.sh" + +cat > "$TEMP_SCRIPT" 2>/dev/null << 'SCRIPT_END' +#!/bin/bash +set -euo pipefail + +SCRIPT_PATH="$0" +cleanup() { rm -f "$SCRIPT_PATH"; } +trap cleanup EXIT + +echo "🔧 Cypress Setup" +echo "" + +cd "WEB_DIR_PLACEHOLDER" + +echo "[1/6] Checking dependencies..." +if [ -d "node_modules" ]; then + echo " ✓ Dependencies installed" +else + npm install > /dev/null 2>&1 + echo " ✓ Dependencies installed" +fi + +cd cypress + +NEED_RECONFIGURE=0 + +if [ -f "./export-env.sh" ]; then + echo "[2/6] Validating existing configuration..." + + CYPRESS_BASE_URL=$(grep "^export CYPRESS_BASE_URL=" ./export-env.sh | cut -d"'" -f2) + CYPRESS_KUBECONFIG_PATH=$(grep "^export CYPRESS_KUBECONFIG_PATH=" ./export-env.sh | cut -d"'" -f2) + + if [[ -n "$CYPRESS_BASE_URL" && -n "$CYPRESS_KUBECONFIG_PATH" ]]; then + CLUSTER_VALID=1 + + if [[ ! -f "$CYPRESS_KUBECONFIG_PATH" ]]; then + CLUSTER_VALID=0 + elif command -v oc &> /dev/null; then + if ! oc --kubeconfig="$CYPRESS_KUBECONFIG_PATH" whoami --request-timeout=10s &> /dev/null 2>&1; then + CLUSTER_VALID=0 + fi + fi + + if command -v curl &> /dev/null; then + HTTP_CODE=$(curl -k -s -o /dev/null -w "%{http_code}" --max-time 10 "$CYPRESS_BASE_URL" 2>/dev/null || echo "000") + if ! echo "$HTTP_CODE" | grep -qE "200|301|302|403|401"; then + CLUSTER_VALID=0 + fi + fi + + if [ $CLUSTER_VALID -eq 1 ]; then + echo " ✓ Cluster still accessible" + source ./export-env.sh + NEED_RECONFIGURE=0 + else + echo " ⚠️ Cluster expired, reconfiguring..." + NEED_RECONFIGURE=1 + fi + else + NEED_RECONFIGURE=1 + fi +else + echo "[2/6] No configuration found" + NEED_RECONFIGURE=1 +fi + +if [ $NEED_RECONFIGURE -eq 1 ]; then + echo "[3/6] Running configuration..." + [ ! -x "./configure-env.sh" ] && chmod +x ./configure-env.sh + echo "" + ./configure-env.sh + [ $? -ne 0 ] && echo "❌ Configuration cancelled" && read -n 1 && exit 1 + [ ! -f "./export-env.sh" ] && echo "❌ No export-env.sh created" && read -n 1 && exit 1 + echo "[4/6] Loading environment..." + source ./export-env.sh +else + echo "[3/6] ✓ Using existing configuration" + echo "[4/6] ✓ Environment loaded" +fi + +echo "[5/6] Validating..." +VALIDATION_FAILED=0 +[[ -z "$CYPRESS_BASE_URL" ]] && echo " ✗ CYPRESS_BASE_URL missing" && VALIDATION_FAILED=1 +[[ -z "$CYPRESS_LOGIN_IDP" ]] && echo " ✗ CYPRESS_LOGIN_IDP missing" && VALIDATION_FAILED=1 +[[ -z "$CYPRESS_LOGIN_USERS" ]] && echo " ✗ CYPRESS_LOGIN_USERS missing" && VALIDATION_FAILED=1 +[[ -z "$CYPRESS_KUBECONFIG_PATH" ]] && echo " ✗ CYPRESS_KUBECONFIG_PATH missing" && VALIDATION_FAILED=1 + +if [ $VALIDATION_FAILED -eq 1 ]; then + echo "❌ Validation failed" && read -n 1 && exit 1 +fi + +echo "[6/6] Final cluster check..." +if [[ -f "$CYPRESS_KUBECONFIG_PATH" ]] && command -v oc &> /dev/null; then + if oc --kubeconfig="$CYPRESS_KUBECONFIG_PATH" whoami --request-timeout=10s &> /dev/null 2>&1; then + echo " ✓ Cluster accessible" + else + echo " ✗ Cluster authentication failed" && read -n 1 && exit 1 + fi +fi + +echo "" +echo "✅ Setup complete!" +echo "" +echo "Next: /cypress-run to see test commands" +echo "" +echo "Sourcing environment variables for this terminal session..." +SCRIPT_END + +sed -i.bak "s|WEB_DIR_PLACEHOLDER|$WEB_DIR|g" "$TEMP_SCRIPT" 2>/dev/null && rm -f "$TEMP_SCRIPT.bak" +chmod +x "$TEMP_SCRIPT" 2>/dev/null + +echo " ✓ Setup script created" + +# [4/4] Open terminal +echo "[4/4] Opening terminal..." + +TERMINAL_NAME="cypress-monitoring" +OS_TYPE=$(uname -s) + +# Create a wrapper script that sources export-env.sh after setup +WRAPPER_SCRIPT="/tmp/cypress-wrapper-$$.sh" +cat > "$WRAPPER_SCRIPT" 2>/dev/null << WRAPPER_END +#!/bin/bash +$TEMP_SCRIPT +cd "$CYPRESS_DIR" +if [ -f "./export-env.sh" ]; then + source ./export-env.sh + echo "" + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + echo "✅ Environment variables loaded:" + echo " • CYPRESS_BASE_URL=\$CYPRESS_BASE_URL" + echo " • CYPRESS_LOGIN_IDP=\$CYPRESS_LOGIN_IDP" + echo " • CYPRESS_KUBECONFIG_PATH=\$CYPRESS_KUBECONFIG_PATH" + echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + echo "" +fi +# Use user's default shell (typically zsh on macOS) +exec \$SHELL +WRAPPER_END +chmod +x "$WRAPPER_SCRIPT" 2>/dev/null + +if [[ "$OS_TYPE" == "Darwin" ]]; then + osascript </dev/null +tell application "Terminal" + set newTab to do script "$WRAPPER_SCRIPT" + set custom title of newTab to "$TERMINAL_NAME" + activate +end tell +APPLESCRIPT + echo " ✓ Terminal opened: 'cypress-monitoring'" +elif [[ "$OS_TYPE" == "Linux" ]]; then + if command -v gnome-terminal &> /dev/null; then + gnome-terminal --title="$TERMINAL_NAME" -- bash -c "$WRAPPER_SCRIPT" 2>/dev/null & + elif command -v konsole &> /dev/null; then + konsole --new-tab -p tabtitle="$TERMINAL_NAME" -e bash -c "$WRAPPER_SCRIPT" 2>/dev/null & + elif command -v xterm &> /dev/null; then + xterm -T "$TERMINAL_NAME" -e bash -c "$WRAPPER_SCRIPT" 2>/dev/null & + elif command -v xfce4-terminal &> /dev/null; then + xfce4-terminal --title="$TERMINAL_NAME" -e "bash -c '$WRAPPER_SCRIPT'" 2>/dev/null & + else + echo " ❌ No terminal found" + exit 1 + fi + echo " ✓ Terminal opened: 'cypress-monitoring'" +else + echo " ❌ Unsupported OS: $OS_TYPE" + exit 1 +fi + +echo "" +``` + +--- + +## What This Command Does + +1. **Validates Prerequisites** ✅ + - Checks Node.js >= v18 + - Checks npm installation + - **Auto-passes** if requirements met + - **Only stops** if prerequisites fail (shows install instructions) + +2. **Detects Workspace** ✅ + - Auto-detects from where you run the command + - Uses git or directory structure + - Validates cypress directory exists + - **No manual input needed** + +3. **Creates Setup Script** ✅ + - Generates temporary setup script + - Configures for detected workspace + - Sets up auto-cleanup + - **No approval needed** + +4. **Opens Terminal & Runs** ✅ + - Opens "cypress-monitoring" terminal + - Runs setup script automatically + - Validates existing config or runs configure-env.sh + - **Everything happens automatically** + +--- + +## Setup Script Flow (in New Terminal) + +The opened terminal runs these steps automatically: + +``` +[1/6] Checking dependencies... + ✓ Dependencies installed + +[2/6] Validating existing configuration... + ✓ Cluster still accessible + +[3/6] ✓ Using existing configuration +[4/6] ✓ Environment loaded +[5/6] Validating... +[6/6] Final cluster check... + ✓ Cluster accessible + +✅ Setup complete! + +Next: /cypress-run to see test commands +``` + +Or if reconfiguration is needed, it runs `configure-env.sh` interactively. + +--- + +## Differences from `/cypress-setup` + +| Feature | `/cypress-setup` | `/cypress-setup1` | +|---------|-----------------|-------------------| +| **Prerequisite Check** | Manual approval | Auto-pass/fail only | +| **Workspace Detection** | Manual approval | Automatic | +| **Script Creation** | Manual approval | Automatic | +| **Terminal Opening** | Manual approval | Automatic | +| **Total Approvals** | 1 combined | 1 combined | +| **User Experience** | More explicit steps | Fully automated | + +Both have **one approval**, but `/cypress-setup1` does everything automatically without showing intermediate steps. + +--- + +## Usage + +Simply run from anywhere in the monitoring-plugin repository: + +``` +/cypress-setup1 +``` + +**What you'll see:** +``` +🔧 Cypress Setup + +[1/4] Validating prerequisites... + ✓ Node.js: v18.x.x + ✓ npm: 9.x.x +[2/4] Detecting workspace... + ✓ Workspace detected +[3/4] Creating setup script... + ✓ Setup script created +[4/4] Opening terminal... + ✓ Terminal opened: 'cypress-monitoring' +``` + +Then the "cypress-monitoring" terminal opens and completes setup automatically! + +--- + +## Prerequisites + +- Node.js >= v18.0.0 +- npm +- OpenShift cluster access +- `oc` CLI (optional but recommended) + +--- + +## Platform Support + +- **macOS**: Uses `Terminal.app` with AppleScript +- **Linux**: Supports `gnome-terminal`, `konsole`, `xterm`, `xfce4-terminal` + +--- + +## Benefits + +✅ **Minimal Approvals** - One approval for everything +✅ **Auto-Detection** - Finds workspace automatically +✅ **Auto-Validation** - Only stops if prerequisites fail +✅ **Clean Output** - Progress indicators only +✅ **Self-Cleaning** - Temp script auto-deletes +✅ **Smart Reuse** - Validates and reuses existing config when possible + +--- + +## Related Commands + +- **`/cypress-setup`** - Original setup with explicit steps +- **`/cypress-run`** - See available test commands + diff --git a/web/cypress/CYPRESS_TESTING_GUIDE.md b/web/cypress/CYPRESS_TESTING_GUIDE.md index 91d9223f..697caf6f 100644 --- a/web/cypress/CYPRESS_TESTING_GUIDE.md +++ b/web/cypress/CYPRESS_TESTING_GUIDE.md @@ -157,21 +157,21 @@ export const runAlertTests = (perspective: string) => { cd web/cypress # Run all regression tests -npm run cypress:run --spec "cypress/e2e/**/regression/**" +npm run cypress:run -- --spec "cypress/e2e/**/regression/**" # Run specific feature regression -npm run cypress:run --spec "cypress/e2e/monitoring/regression/01.reg_alerts_admin.cy.ts" -npm run cypress:run --spec "cypress/e2e/monitoring/regression/02.reg_metrics_admin.cy.ts" -npm run cypress:run --spec "cypress/e2e/monitoring/regression/03.reg_legacy_dashboards_admin.cy.ts" +npm run cypress:run -- --spec "cypress/e2e/monitoring/regression/01.reg_alerts_admin.cy.ts" +npm run cypress:run -- --spec "cypress/e2e/monitoring/regression/02.reg_metrics_admin.cy.ts" +npm run cypress:run -- --spec "cypress/e2e/monitoring/regression/03.reg_legacy_dashboards_admin.cy.ts" # Run BVT (Build Verification Tests) -npm run cypress:run --spec "cypress/e2e/monitoring/00.bvt_admin.cy.ts" +npm run cypress:run -- --spec "cypress/e2e/monitoring/00.bvt_admin.cy.ts" # Run COO tests -npm run cypress:run --spec "cypress/e2e/coo/01.coo_bvt.cy.ts" +npm run cypress:run -- --spec "cypress/e2e/coo/01.coo_bvt.cy.ts" # Run ACM Alerting tests -npm run cypress:run --spec "cypress/e2e/coo/02.acm_alerting_ui.cy.ts" +npm run cypress:run -- --spec "cypress/e2e/coo/02.acm_alerting_ui.cy.ts" # Interactive mode (GUI) npm run cypress:open diff --git a/web/cypress/README.md b/web/cypress/README.md index 0eea7c06..e0b4e648 100644 --- a/web/cypress/README.md +++ b/web/cypress/README.md @@ -212,22 +212,22 @@ npm run cypress:run ```bash # COO BVT tests -npm run cypress:run --spec "cypress/e2e/coo/01.coo_bvt.cy.ts" +npm run cypress:run -- --spec "cypress/e2e/coo/01.coo_bvt.cy.ts" # ACM Alerting tests -npm run cypress:run --spec "cypress/e2e/coo/02.acm_alerting_ui.cy.ts" +npm run cypress:run -- --spec "cypress/e2e/coo/02.acm_alerting_ui.cy.ts" # Monitoring BVT tests -npm run cypress:run --spec "cypress/e2e/monitoring/00.bvt_admin.cy.ts" +npm run cypress:run -- --spec "cypress/e2e/monitoring/00.bvt_admin.cy.ts" # All Monitoring Regression tests -npm run cypress:run --spec "cypress/e2e/monitoring/regression/**" +npm run cypress:run -- --spec "cypress/e2e/monitoring/regression/**" # All Virtualization IVT tests -npm run cypress:run --spec "cypress/e2e/virtualization/**" +npm run cypress:run -- --spec "cypress/e2e/virtualization/**" # Incidents tests (requires CYPRESS_TIMEZONE and optionally CYPRESS_MOCK_NEW_METRICS) -npm run cypress:run --spec "cypress/e2e/**/incidents*.cy.ts" +npm run cypress:run -- --spec "cypress/e2e/**/incidents*.cy.ts" ``` **Note**: Incidents tests require `CYPRESS_TIMEZONE` to be set to match your cluster's timezone configuration. See [Incidents Testing Configuration](#incidents-testing-configuration) for details. diff --git a/web/cypress/configure-env.sh b/web/cypress/configure-env.sh index b98116db..782d517b 100755 --- a/web/cypress/configure-env.sh +++ b/web/cypress/configure-env.sh @@ -295,7 +295,11 @@ main() { # User declined current, try to find kubeconfigs from Downloads if [[ -d "$HOME/Downloads" ]]; then local kubeconfig_files - mapfile -t kubeconfig_files < <(ls -t "$HOME/Downloads"/*kubeconfig* 2>/dev/null | head -10) + # Use 'while read' instead of 'mapfile' for bash 3.x compatibility (macOS) + kubeconfig_files=() + while IFS= read -r file; do + kubeconfig_files+=("$file") + done < <(ls -t "$HOME/Downloads"/*kubeconfig* 2>/dev/null | head -10) if [[ ${#kubeconfig_files[@]} -gt 0 ]]; then echo "" @@ -357,7 +361,11 @@ main() { # No current kubeconfig set, try to find kubeconfigs from Downloads if [[ -d "$HOME/Downloads" ]]; then local kubeconfig_files - mapfile -t kubeconfig_files < <(ls -t "$HOME/Downloads"/*kubeconfig* 2>/dev/null | head -10) + # Use 'while read' instead of 'mapfile' for bash 3.x compatibility (macOS) + kubeconfig_files=() + while IFS= read -r file; do + kubeconfig_files+=("$file") + done < <(ls -t "$HOME/Downloads"/*kubeconfig* 2>/dev/null | head -10) if [[ ${#kubeconfig_files[@]} -gt 0 ]]; then echo "" @@ -534,27 +542,27 @@ main() { echo "" echo "Configured values:" - echo " CYPRESS_BASE_URL=$CYPRESS_BASE_URL" - echo " CYPRESS_LOGIN_IDP=${CYPRESS_LOGIN_IDP:-$login_idp}" - echo " CYPRESS_LOGIN_USERS=${CYPRESS_LOGIN_USERS:-$login_users}" - echo " CYPRESS_KUBECONFIG_PATH=${CYPRESS_KUBECONFIG_PATH:-$kubeconfig}" - [[ -n "${CYPRESS_MP_IMAGE-}$mp_image" ]] && echo " CYPRESS_MP_IMAGE=${CYPRESS_MP_IMAGE:-$mp_image}" - [[ -n "${CYPRESS_COO_NAMESPACE-}$coo_namespace" ]] && echo " CYPRESS_COO_NAMESPACE=${CYPRESS_COO_NAMESPACE:-$coo_namespace}" - echo " CYPRESS_SKIP_COO_INSTALL=${CYPRESS_SKIP_COO_INSTALL:-$skip_coo_install}" - echo " CYPRESS_COO_UI_INSTALL=${CYPRESS_COO_UI_INSTALL:-$coo_ui_install}" - [[ -n "${CYPRESS_KONFLUX_COO_BUNDLE_IMAGE-}$konflux_bundle" ]] && echo " CYPRESS_KONFLUX_COO_BUNDLE_IMAGE=${CYPRESS_KONFLUX_COO_BUNDLE_IMAGE:-$konflux_bundle}" - [[ -n "${CYPRESS_CUSTOM_COO_BUNDLE_IMAGE-}$custom_coo_bundle" ]] && echo " CYPRESS_CUSTOM_COO_BUNDLE_IMAGE=${CYPRESS_CUSTOM_COO_BUNDLE_IMAGE:-$custom_coo_bundle}" - [[ -n "${CYPRESS_MCP_CONSOLE_IMAGE-}$mcp_console_image" ]] && echo " CYPRESS_MCP_CONSOLE_IMAGE=${CYPRESS_MCP_CONSOLE_IMAGE:-$mcp_console_image}" - [[ -n "${CYPRESS_TIMEZONE-}$timezone" ]] && echo " CYPRESS_TIMEZONE=${CYPRESS_TIMEZONE:-$timezone}" - echo " CYPRESS_MOCK_NEW_METRICS=${CYPRESS_MOCK_NEW_METRICS:-$mock_new_metrics}" - echo " CYPRESS_SESSION=${CYPRESS_SESSION:-$session}" - echo " CYPRESS_DEBUG=${CYPRESS_DEBUG:-$debug}" - echo " CYPRESS_SKIP_ALL_INSTALL=${CYPRESS_SKIP_ALL_INSTALL:-$skip_all_install}" - echo " CYPRESS_SKIP_KBV_INSTALL=${CYPRESS_SKIP_KBV_INSTALL:-$skip_kbv_install}" - echo " CYPRESS_KBV_UI_INSTALL=${CYPRESS_KBV_UI_INSTALL:-$kbv_ui_install}" - [[ -n "${CYPRESS_KONFLUX_KBV_BUNDLE_IMAGE-}$konflux_kbv_bundle" ]] && echo " CYPRESS_KONFLUX_KBV_BUNDLE_IMAGE=${CYPRESS_KONFLUX_KBV_BUNDLE_IMAGE:-$konflux_kbv_bundle}" - [[ -n "${CYPRESS_CUSTOM_KBV_BUNDLE_IMAGE-}$custom_kbv_bundle" ]] && echo " CYPRESS_CUSTOM_KBV_BUNDLE_IMAGE=${CYPRESS_CUSTOM_KBV_BUNDLE_IMAGE:-$custom_kbv_bundle}" - [[ -n "${CYPRESS_FBC_STAGE_KBV_IMAGE-}$fbc_stage_kbv_image" ]] && echo " CYPRESS_FBC_STAGE_KBV_IMAGE=${CYPRESS_FBC_STAGE_KBV_IMAGE:-$fbc_stage_kbv_image}" + echo " CYPRESS_BASE_URL=$base_url" + echo " CYPRESS_LOGIN_IDP=$login_idp" + echo " CYPRESS_LOGIN_USERS=$login_users" + echo " CYPRESS_KUBECONFIG_PATH=$kubeconfig" + [[ -n "$mp_image" ]] && echo " CYPRESS_MP_IMAGE=$mp_image" + [[ -n "$coo_namespace" ]] && echo " CYPRESS_COO_NAMESPACE=$coo_namespace" + echo " CYPRESS_SKIP_COO_INSTALL=$skip_coo_install" + echo " CYPRESS_COO_UI_INSTALL=$coo_ui_install" + [[ -n "$konflux_bundle" ]] && echo " CYPRESS_KONFLUX_COO_BUNDLE_IMAGE=$konflux_bundle" + [[ -n "$custom_coo_bundle" ]] && echo " CYPRESS_CUSTOM_COO_BUNDLE_IMAGE=$custom_coo_bundle" + [[ -n "$mcp_console_image" ]] && echo " CYPRESS_MCP_CONSOLE_IMAGE=$mcp_console_image" + [[ -n "$timezone" ]] && echo " CYPRESS_TIMEZONE=$timezone" + echo " CYPRESS_MOCK_NEW_METRICS=$mock_new_metrics" + echo " CYPRESS_SESSION=$session" + echo " CYPRESS_DEBUG=$debug" + echo " CYPRESS_SKIP_ALL_INSTALL=$skip_all_install" + echo " CYPRESS_SKIP_KBV_INSTALL=$skip_kbv_install" + echo " CYPRESS_KBV_UI_INSTALL=$kbv_ui_install" + [[ -n "$konflux_kbv_bundle" ]] && echo " CYPRESS_KONFLUX_KBV_BUNDLE_IMAGE=$konflux_kbv_bundle" + [[ -n "$custom_kbv_bundle" ]] && echo " CYPRESS_CUSTOM_KBV_BUNDLE_IMAGE=$custom_kbv_bundle" + [[ -n "$fbc_stage_kbv_image" ]] && echo " CYPRESS_FBC_STAGE_KBV_IMAGE=$fbc_stage_kbv_image" } main "$@"