diff --git a/.github/actions/e2e-m1-test/action.yml b/.github/actions/e2e-m1-test/action.yml new file mode 100644 index 00000000..4223674c --- /dev/null +++ b/.github/actions/e2e-m1-test/action.yml @@ -0,0 +1,33 @@ +name: Run Milestone 1 E2E test +description: Download the built binary and run one Milestone 1 E2E test script. + +inputs: + script: + description: Script filename under scripts/e2e/ (for example m1-up-001.sh) + required: true + +runs: + using: composite + steps: + - name: Download built binary + # actions/download-artifact@v4.1.7 + uses: actions/download-artifact@65a9edc128165405c983346fd356e6d4c448ac4 + with: + name: canton-devkit-binary + path: bin + + - name: Make scripts executable + shell: bash + run: chmod +x bin/canton-devkit scripts/e2e/*.sh + + - name: Run test + shell: bash + run: scripts/e2e/${{ inputs.script }} + + - name: Dump container state on failure + if: failure() + shell: bash + run: | + docker ps -a || true + docker compose ls || true + docker volume ls || true diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index c4c6910b..2825cf1a 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -10,7 +10,7 @@ - [ ] `make test` - [ ] `make lint` -- [ ] `scripts/e2e-milestone1.sh` +- [ ] `scripts/e2e/run-all.sh` - [ ] ## Checklist diff --git a/.github/workflows/e2e-test-devkit-functions.yml b/.github/workflows/e2e-test-devkit-functions.yml index addcf8e6..0eedc638 100644 --- a/.github/workflows/e2e-test-devkit-functions.yml +++ b/.github/workflows/e2e-test-devkit-functions.yml @@ -1,16 +1,20 @@ name: "E2E: canton-devkit Functions" -# Shell-based end-to-end tests. Each milestone adds a job to this -# workflow. Currently: Milestone 1 (LocalNet CLI lifecycle). +# Shell-based end-to-end tests. Milestone 1 runs one job per test so a +# failed case can be re-run without replaying the whole suite. # # Triggers: # - schedule: nightly at 04:00 UTC (offset from integration.yml's 03:00). # - workflow_dispatch: manual trigger for ad-hoc validation. # - pull_request: only when the PR carries the `run-e2e` label. -# - push to main: when scripts/e2e-milestone1.sh changes. +# - push to main: when Milestone 1 E2E scripts or workflow change. +# +# The run-e2e gate lives on the setup job only. Downstream jobs inherit +# skip/cancel behavior via needs; cleanup uses needs.setup.result so it +# does not run on label-less PR pushes. # # Platform: Linux only (self-hosted Proxmox e2e runner). macOS runners -# lack Docker; run scripts/e2e-milestone1.sh locally for macOS validation. +# lack Docker; run scripts/e2e/run-all.sh locally for macOS validation. on: schedule: @@ -22,14 +26,16 @@ on: branches: - main paths: - - scripts/e2e-milestone1.sh + - scripts/e2e/** + - .github/workflows/e2e-test-devkit-functions.yml + - .github/actions/e2e-m1-test/** permissions: contents: read jobs: - e2e: - name: e2e-milestone1 + setup: + name: setup if: | github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || @@ -37,8 +43,7 @@ jobs: (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'run-e2e')) runs-on: [self-hosted, Linux, X64, proxmox, e2e] - timeout-minutes: 60 - + timeout-minutes: 20 steps: - name: Check out repository # actions/checkout@v5 @@ -54,6 +59,14 @@ jobs: - name: Build binary run: make build + - name: Upload built binary + # actions/upload-artifact@v4.6.2 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 + with: + name: canton-devkit-binary + path: bin/canton-devkit + retention-days: 1 + - name: Verify Docker daemon run: | docker version @@ -63,34 +76,203 @@ jobs: run: | for name in e2e-test-default e2e-named-test e2e-version-test e2e-bad-version; do docker compose -p "canton-${name}" down --volumes 2>/dev/null || true - # `compose down --volumes` only removes volumes Compose itself - # created; volumes left by a prior run get re-adopted as - # external and survive. On this persistent self-hosted runner - # that strands canton-_postgres / _domain-upgrade-dump and - # trips M1-CLN-001's "volumes remain after clean" check. Remove - # them explicitly by project-name prefix to guarantee a clean slate. docker volume ls -q --filter "name=^canton-${name}_" \ | xargs -r docker volume rm -f 2>/dev/null || true rm -f "$HOME/.canton-devkit/localnet/${name}/.lock" done - - name: Run E2E Milestone 1 tests - run: scripts/e2e-milestone1.sh + m1-inst-003: + name: M1-INST-003 + needs: setup + runs-on: [self-hosted, Linux, X64, proxmox, e2e] + timeout-minutes: 10 + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd + - uses: ./.github/actions/e2e-m1-test + with: + script: m1-inst-003.sh - - name: Dump container + compose state on failure - if: failure() - run: | - docker ps -a || true - docker compose ls || true - docker volume ls || true + m1-doc-001: + name: M1-DOC-001 + needs: setup + runs-on: [self-hosted, Linux, X64, proxmox, e2e] + timeout-minutes: 10 + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd + - uses: ./.github/actions/e2e-m1-test + with: + script: m1-doc-001.sh + + m1-doc-002: + name: M1-DOC-002 + needs: setup + runs-on: [self-hosted, Linux, X64, proxmox, e2e] + timeout-minutes: 10 + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd + - uses: ./.github/actions/e2e-m1-test + with: + script: m1-doc-002.sh - - name: Force cleanup on failure - if: always() + m1-up-001: + name: M1-UP-001 + needs: [setup, m1-inst-003, m1-doc-001, m1-doc-002] + runs-on: [self-hosted, Linux, X64, proxmox, e2e] + timeout-minutes: 20 + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd + - uses: ./.github/actions/e2e-m1-test + with: + script: m1-up-001.sh + + m1-sts-001: + name: M1-STS-001 + needs: m1-up-001 + runs-on: [self-hosted, Linux, X64, proxmox, e2e] + timeout-minutes: 10 + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd + - uses: ./.github/actions/e2e-m1-test + with: + script: m1-sts-001.sh + + m1-log-001: + name: M1-LOG-001 + needs: m1-sts-001 + runs-on: [self-hosted, Linux, X64, proxmox, e2e] + timeout-minutes: 10 + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd + - uses: ./.github/actions/e2e-m1-test + with: + script: m1-log-001.sh + + m1-env-001: + name: M1-ENV-001 + needs: m1-log-001 + runs-on: [self-hosted, Linux, X64, proxmox, e2e] + timeout-minutes: 10 + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd + - uses: ./.github/actions/e2e-m1-test + with: + script: m1-env-001.sh + + m1-rst-001: + name: M1-RST-001 + needs: m1-env-001 + runs-on: [self-hosted, Linux, X64, proxmox, e2e] + timeout-minutes: 20 + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd + - uses: ./.github/actions/e2e-m1-test + with: + script: m1-rst-001.sh + + m1-stp-001: + name: M1-STP-001 + needs: m1-rst-001 + runs-on: [self-hosted, Linux, X64, proxmox, e2e] + timeout-minutes: 20 + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd + - uses: ./.github/actions/e2e-m1-test + with: + script: m1-stp-001.sh + + m1-snp-001: + name: M1-SNP-001 + needs: m1-stp-001 + runs-on: [self-hosted, Linux, X64, proxmox, e2e] + timeout-minutes: 25 + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd + - uses: ./.github/actions/e2e-m1-test + with: + script: m1-snp-001.sh + + m1-dwn-001: + name: M1-DWN-001 + needs: m1-snp-001 + runs-on: [self-hosted, Linux, X64, proxmox, e2e] + timeout-minutes: 20 + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd + - uses: ./.github/actions/e2e-m1-test + with: + script: m1-dwn-001.sh + + m1-rmv-001: + name: M1-RMV-001 + needs: m1-dwn-001 + runs-on: [self-hosted, Linux, X64, proxmox, e2e] + timeout-minutes: 20 + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd + - uses: ./.github/actions/e2e-m1-test + with: + script: m1-rmv-001.sh + + m1-up-002: + name: M1-UP-002 + needs: m1-rmv-001 + runs-on: [self-hosted, Linux, X64, proxmox, e2e] + timeout-minutes: 20 + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd + - uses: ./.github/actions/e2e-m1-test + with: + script: m1-up-002.sh + + m1-up-003: + name: M1-UP-003 + needs: m1-up-002 + runs-on: [self-hosted, Linux, X64, proxmox, e2e] + timeout-minutes: 20 + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd + - uses: ./.github/actions/e2e-m1-test + with: + script: m1-up-003.sh + + m1-lst-001: + name: M1-LST-001 + needs: m1-up-003 + runs-on: [self-hosted, Linux, X64, proxmox, e2e] + timeout-minutes: 10 + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd + - uses: ./.github/actions/e2e-m1-test + with: + script: m1-lst-001.sh + + cleanup: + name: cleanup + needs: + - setup + - m1-inst-003 + - m1-doc-001 + - m1-doc-002 + - m1-up-001 + - m1-sts-001 + - m1-log-001 + - m1-env-001 + - m1-rst-001 + - m1-stp-001 + - m1-snp-001 + - m1-dwn-001 + - m1-rmv-001 + - m1-up-002 + - m1-up-003 + - m1-lst-001 + if: always() && !cancelled() && needs.setup.result != 'skipped' + runs-on: [self-hosted, Linux, X64, proxmox, e2e] + timeout-minutes: 10 + steps: + - name: Force cleanup run: | for name in e2e-test-default e2e-named-test e2e-version-test e2e-bad-version; do docker compose -p "canton-${name}" down --volumes 2>/dev/null || true - # Also drop adopted/external volumes Compose won't remove, so the - # next run on this persistent runner starts from a clean slate. docker volume ls -q --filter "name=^canton-${name}_" \ | xargs -r docker volume rm -f 2>/dev/null || true done diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 9e84977d..04368aa5 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -3,21 +3,21 @@ name: Static Analysis on: pull_request: paths: - - "scripts/e2e-milestone1.sh" + - "scripts/e2e/**" - ".github/workflows/static-analysis.yml" push: branches: - main paths: - - "scripts/e2e-milestone1.sh" + - "scripts/e2e/**" - ".github/workflows/static-analysis.yml" permissions: contents: read jobs: - e2e-milestone1-shell: - name: e2e-milestone1.sh syntax + e2e-shell: + name: e2e scripts syntax runs-on: [self-hosted, Linux] steps: @@ -25,5 +25,8 @@ jobs: # actions/checkout@v5 uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd - - name: Validate e2e-milestone1.sh syntax - run: bash -n scripts/e2e-milestone1.sh + - name: Validate Milestone 1 E2E script syntax + run: | + for script in scripts/e2e/*.sh; do + bash -n "$script" + done diff --git a/docs/tests/e2e-test-milestone-1.md b/docs/tests/e2e-test-milestone-1.md index a9682f26..e0a661c0 100644 --- a/docs/tests/e2e-test-milestone-1.md +++ b/docs/tests/e2e-test-milestone-1.md @@ -822,7 +822,7 @@ $CLI clean --name e2e-test-b --force 2>/dev/null || true **Binary version:** dev **Splice version (default/latest):** 0.6.4 **Splice version (explicit):** 0.6.3 -**Script:** `scripts/e2e-milestone1.sh` +**Script:** `scripts/e2e/run-all.sh` (full suite) or `scripts/e2e/m1-*.sh` (individual tests) ### CLI Syntax Adaptations @@ -860,7 +860,7 @@ The test plan assumes command syntax that differs from the actual CLI implementa | M1-LOG-001 | **PASS** | <10s | Full logs: 308 lines. Service-filtered (`canton`): 20 lines. | | M1-ENV-001 | **PASS** | <1s | `export CANTON_*` format. Contains JWT (redacted), audience, port variables. | | M1-RST-001 | **PASS** | ~5-8 min | Full restart + single-service (`--service canton`) restart. Readiness wait is slow post-restart. | -| M1-STP-001 | **NOT RUN** | — | Added after this run (PR #201 standalone `stop`/`start`). Covered by `scripts/e2e-milestone1.sh`. | +| M1-STP-001 | **NOT RUN** | — | Added after this run (PR #201 standalone `stop`/`start`). Covered by `scripts/e2e/run-all.sh`. | | M1-SNP-001 | **PASS*** | ~10 min | Snapshot: 78 MB .tgz. Restore + re-up works but splice re-sync can exceed 5 min (crash-consistent, not app-consistent). | | M1-DWN-001 | **PASS** | ~5s | Containers stopped, non-devkit containers unaffected. | | M1-CLN-001 | **PASS*** | ~10 min | See finding below. `clean --force` on running instance removes all resources (containers, volumes, networks). | diff --git a/scripts/e2e-milestone1.sh b/scripts/e2e-milestone1.sh deleted file mode 100755 index e472f558..00000000 --- a/scripts/e2e-milestone1.sh +++ /dev/null @@ -1,613 +0,0 @@ -#!/usr/bin/env bash -# E2E Test Suite — Milestone 1: LocalNet Management CLI -# -# Platform: macOS (Apple Silicon) -# CLI mode: canton-devkit localnet (standalone — no DPM) -# -# Skipped tests: -# M1-INST-001 Install via DPM component (DPM excluded) -# M1-INST-002 Install standalone binary (binary already built) -# M1-DOC-003 Doctor — insufficient resources (requires Docker Desktop config changes) -# M1-ISO-001 Two named instances (resource-heavy, skipped by request) -# -# Usage: -# scripts/e2e-milestone1.sh -# CDK=./canton-devkit scripts/e2e-milestone1.sh -# -# Exit 0 = all tests passed; 1 = one or more failures. - -set -u - -CDK="${CDK:-bin/canton-devkit}" -SPLICE_VERSION="0.6.12" -SNAPSHOT_PATH="/tmp/e2e-m1-snapshot.tgz" - -# Helper: invoke the localnet subcommand via the CDK binary. -# Usage: cli [args...] -cli() { "$CDK" localnet "$@"; } - -# Wrapper around `timeout` that uses --foreground on Linux so the -# timeout signal only hits the child process, not the parent shell. -if [[ "$(uname -s)" == "Linux" ]]; then - timed() { local s="$1"; shift; timeout --foreground "$s" "$@"; } -else - timed() { local s="$1"; shift; timeout "$s" "$@"; } -fi - -# ── Counters & results ────────────────────────────────────────────── -PASS=0 -FAIL=0 -SKIP=0 -declare -a RESULTS=() - -pass() { - PASS=$((PASS + 1)) - RESULTS+=("✓ PASS $1") - printf '\033[1;32m ✓ PASS %s\033[0m\n' "$1" -} - -fail() { - FAIL=$((FAIL + 1)) - RESULTS+=("✗ FAIL $1 — $2") - printf '\033[1;31m ✗ FAIL %s — %s\033[0m\n' "$1" "$2" -} - -skip() { - SKIP=$((SKIP + 1)) - RESULTS+=("- SKIP $1 — $2") - printf '\033[2m - SKIP %s — %s\033[0m\n' "$1" "$2" -} - -section() { - echo "" - printf '\033[1;36m━━ %s\033[0m\n' "$1" -} - -# ── Cleanup trap ──────────────────────────────────────────────────── -cleanup() { - echo "" - section "CLEANUP" - for name in e2e-test-default e2e-named-test e2e-version-test e2e-bad-version; do - cli remove "$name" --force 2>/dev/null || true - # Belt-and-suspenders: remove containers+volumes directly in case - # `remove` missed them (known down→remove orphan-volume bug). - docker compose -p "canton-${name}" down --volumes 2>/dev/null || true - done - rm -f "$SNAPSHOT_PATH" - print_summary -} -trap cleanup EXIT - -# ── Summary ───────────────────────────────────────────────────────── -print_summary() { - echo "" - echo "═══════════════════════════════════════════════════════" - echo " E2E Milestone 1 Results" - printf ' PASSED: %d FAILED: %d SKIPPED: %d\n' "$PASS" "$FAIL" "$SKIP" - echo "═══════════════════════════════════════════════════════" - for r in "${RESULTS[@]}"; do - echo " $r" - done - echo "═══════════════════════════════════════════════════════" - write_step_summary -} - -# Emit a GitHub Actions job summary (markdown table) when running in CI. -# No-op outside GitHub Actions so local/macOS runs are unaffected. -write_step_summary() { - [ -n "${GITHUB_STEP_SUMMARY:-}" ] || return 0 - - { - echo "## E2E Milestone 1 Results" - echo "" - echo "**Passed:** ${PASS}    **Failed:** ${FAIL}    **Skipped:** ${SKIP}" - echo "" - echo "| Result | Test |" - echo "| :----: | :--- |" - for r in "${RESULTS[@]}"; do - # RESULTS entries look like: - # "✓ PASS " - # "✗ FAIL — " - # "- SKIP — " - case "$r" in - "✓ PASS"*) icon="✅"; rest="${r#✓ PASS }" ;; - "✗ FAIL"*) icon="❌"; rest="${r#✗ FAIL }" ;; - "- SKIP"*) icon="⏭️"; rest="${r#- SKIP }" ;; - *) icon=""; rest="$r" ;; - esac - # Keep only the test id/name; drop any " — reason" suffix. - test="${rest%% — *}" - printf '| %s | %s |\n' "$icon" "$test" - done - } >> "$GITHUB_STEP_SUMMARY" -} - -# ── Preflight ─────────────────────────────────────────────────────── -if [ ! -x "$CDK" ]; then - echo "ERROR: binary not found at $CDK — run 'make build' first" - exit 1 -fi - -docker info >/dev/null 2>&1 || { - echo "ERROR: Docker daemon not reachable" - exit 1 -} - -# Best-effort pre-clean -cli down e2e-test-default 2>/dev/null || true -cli down e2e-named-test 2>/dev/null || true -cli down e2e-version-test 2>/dev/null || true -cli remove e2e-test-default --force 2>/dev/null || true -cli remove e2e-named-test --force 2>/dev/null || true -cli remove e2e-version-test --force 2>/dev/null || true - -echo "Canton DevKit E2E — Milestone 1" -echo "Platform: macOS ($(uname -m))" -echo "Binary: $CDK" -echo "Docker: $(docker --version 2>/dev/null)" -echo "" - -# ═════════════════════════════════════════════════════════════════════ -# PHASE 1: No-instance tests -# ═════════════════════════════════════════════════════════════════════ - -section "PHASE 1: Binary & preflight checks" - -# ── M1-INST-003: Verify binary on all platforms ───────────────────── -TEST_ID="M1-INST-003" -( - set -e - - # Step 1: version output matches semver or "dev" - "$CDK" --version 2>&1 | grep -qE "([0-9]+\.[0-9]+\.[0-9]+|dev)" - - # Step 2: help includes all visible M1 lifecycle + inspection commands. - # start/stop are now first-class lifecycle commands (previously up/down - # aliases); pause/resume, restart, and remove are listed in --help. - HELP=$(cli --help 2>&1) - for cmd in up start stop down restart pause resume remove status logs snapshot restore doctor env list creds; do - echo "$HELP" | grep -qiE "$cmd" - done - # 'unpause' is an alias of 'resume' — verify its --help resolves. - cli unpause --help >/dev/null 2>&1 - # 'remove' — verify its --help resolves. - cli remove --help >/dev/null 2>&1 - - # Step 3: binary is a compiled executable (platform-specific) - case "$(uname -s)" in - Darwin) file "$CDK" 2>/dev/null | grep -qiE "Mach-O" ;; - Linux) file "$CDK" 2>/dev/null | grep -qiE "ELF" ;; - *) file "$CDK" 2>/dev/null | grep -qiE "(Mach-O|ELF|PE32)" ;; - esac -) -if [ $? -eq 0 ]; then - pass "$TEST_ID: Verify binary" -else - fail "$TEST_ID: Verify binary" "version/help/file check failed" -fi - -# ── M1-DOC-001: Doctor — all checks pass ──────────────────────────── -TEST_ID="M1-DOC-001" -( - set -e - - # Step 1: doctor exits 0 - OUTPUT=$(cli doctor 2>&1) - - # Step 2: output mentions expected check categories - echo "$OUTPUT" | grep -qiE "(docker cli|docker daemon|compose|port|disk|memory)" - - # Step 3: no hard failures (✗ prefix indicates failure in doctor output) - if echo "$OUTPUT" | grep -qE "^ ✗"; then - exit 1 - fi -) -if [ $? -eq 0 ]; then - pass "$TEST_ID: Doctor — all checks pass" -else - fail "$TEST_ID: Doctor — all checks pass" "doctor reported failures" -fi - -# ── M1-DOC-002: Doctor — Docker not installed ──────────────────────── -TEST_ID="M1-DOC-002" -( - set -e - - # Build a PATH that excludes any directory containing a `docker` binary. - MINIMAL_PATH="" - IFS=':' read -ra DIRS <<< "$PATH" - for dir in "${DIRS[@]}"; do - if [ -d "$dir" ] && ! [ -x "$dir/docker" ]; then - MINIMAL_PATH="${MINIMAL_PATH:+$MINIMAL_PATH:}$dir" - fi - done - - # Doctor should fail with non-zero exit - if PATH="$MINIMAL_PATH" "$CDK" localnet doctor >/dev/null 2>&1; then - exit 1 # doctor should have failed - fi - - OUTPUT=$(PATH="$MINIMAL_PATH" "$CDK" localnet doctor 2>&1 || true) - - # Verify remediation hint - echo "$OUTPUT" | grep -qiE "(install docker|docker not found|docker desktop|docker cli)" -) -if [ $? -eq 0 ]; then - pass "$TEST_ID: Doctor — Docker not installed" -else - fail "$TEST_ID: Doctor — Docker not installed" "doctor didn't fail or missing remediation message" -fi - -# ═════════════════════════════════════════════════════════════════════ -# PHASE 2: Default instance lifecycle -# ═════════════════════════════════════════════════════════════════════ - -section "PHASE 2: Default instance lifecycle (e2e-test-default)" - -# ── M1-UP-001: LocalNet up (default) ──────────────────────────────── -TEST_ID="M1-UP-001" -echo " Starting e2e-test-default (may take 3-5 minutes)..." -( - # Step 1: up exits 0 - timed 600 "$CDK" localnet up e2e-test-default \ - || { echo "FAIL step 1: up exited $?" >&2; exit 1; } - - # Brief settle for registry state flush - sleep 2 - - # Step 2: status shows running - cli status e2e-test-default 2>&1 | grep -qiE "(healthy|ready|running)" \ - || { echo "FAIL step 2: status missing healthy/ready/running" >&2; exit 1; } - - # Step 3: Docker containers belong to the compose project - docker ps --filter "label=com.docker.compose.project=canton-e2e-test-default" --format '{{.Names}}' | grep -qE "e2e-test-default" \ - || { echo "FAIL step 3: no containers with compose project label" >&2; exit 1; } - - # Step 4: compose project listed - docker compose ls 2>/dev/null | grep -qE "e2e-test-default" \ - || { echo "FAIL step 4: compose project not listed" >&2; exit 1; } -) -if [ $? -eq 0 ]; then - pass "$TEST_ID: LocalNet up (default)" -else - fail "$TEST_ID: LocalNet up (default)" "up/status/docker check failed" -fi - -# ── M1-STS-001: Status shows healthy services ─────────────────────── -TEST_ID="M1-STS-001" -( - # Step 1: status exits 0 and includes required info - OUTPUT=$(cli status e2e-test-default 2>&1) \ - || { echo "FAIL step 1: status exited $?" >&2; exit 1; } - echo "$OUTPUT" | grep -qiE "(healthy|running|ready)" \ - || { echo "FAIL step 1: status missing healthy/running/ready" >&2; exit 1; } - - # Step 2: status for non-existent instance fails - if cli status nonexistent-localnet-xyz >/dev/null 2>&1; then - echo "FAIL step 2: status for non-existent instance should fail" >&2; exit 1 - fi -) -if [ $? -eq 0 ]; then - pass "$TEST_ID: Status shows healthy services" -else - fail "$TEST_ID: Status shows healthy services" "status output missing expected fields or non-existent check failed" -fi - -# ── M1-LOG-001: Logs — full and service-filtered ──────────────────── -TEST_ID="M1-LOG-001" -( - # Step 1: full logs (non-empty) - LOG_OUTPUT=$("$CDK" localnet logs e2e-test-default --tail 50 2>&1) || true - LINE_COUNT=$(echo "$LOG_OUTPUT" | wc -l | tr -d ' ') - [ "$LINE_COUNT" -gt 1 ] \ - || { echo "FAIL step 1: full logs empty (got $LINE_COUNT lines, first line: '$(echo "$LOG_OUTPUT" | head -1)')" >&2; exit 1; } - - # Step 2: service-filtered logs (use "canton" — a known compose service) - SVC_OUTPUT=$("$CDK" localnet logs e2e-test-default --service canton --tail 20 2>&1) || true - SVC_LINES=$(echo "$SVC_OUTPUT" | wc -l | tr -d ' ') - [ "$SVC_LINES" -gt 1 ] \ - || { echo "FAIL step 2: service-filtered logs empty (got $SVC_LINES lines)" >&2; exit 1; } - - # Step 3: non-existent service should error or return empty - if "$CDK" localnet logs e2e-test-default --service nonexistent-service-xyz --tail 5 >/dev/null 2>&1; then - true - fi -) -if [ $? -eq 0 ]; then - pass "$TEST_ID: Logs — full and service-filtered" -else - fail "$TEST_ID: Logs — full and service-filtered" "logs output unexpected" -fi - -# ── M1-ENV-001: Env export outputs valid config ───────────────────── -TEST_ID="M1-ENV-001" -( - # Step 1: env exits 0 - OUTPUT=$(cli env e2e-test-default 2>&1) \ - || { echo "FAIL step 1: env exited $?" >&2; exit 1; } - - # Step 2: KEY=value format (export KEY='value' or KEY="value") - echo "$OUTPUT" | grep -qE "^(export )?[A-Z_]+=" \ - || { echo "FAIL step 2: no KEY=value lines in env output" >&2; exit 1; } - - # Step 3: expected variable names - echo "$OUTPUT" | grep -qiE "(LEDGER|JSON_API|ADMIN|PARTICIPANT|CANTON)" \ - || { echo "FAIL step 3: env output missing expected variable names" >&2; exit 1; } -) -if [ $? -eq 0 ]; then - pass "$TEST_ID: Env export outputs valid config" -else - fail "$TEST_ID: Env export outputs valid config" "env output format/content unexpected" -fi - -# ── M1-RST-001: Restart full + single service ─────────────────────── -TEST_ID="M1-RST-001" -echo " Restarting e2e-test-default (may take a few minutes)..." -( - # Step 1: full restart - timed 600 "$CDK" localnet restart e2e-test-default \ - || { echo "FAIL step 1: full restart exited $?" >&2; exit 1; } - - cli status e2e-test-default 2>&1 | grep -qiE "(healthy|ready|running)" \ - || { echo "FAIL step 1: not healthy after full restart" >&2; exit 1; } - - # Step 2: single-service restart - timed 600 "$CDK" localnet restart e2e-test-default --service canton \ - || { echo "FAIL step 2: single-service restart exited $?" >&2; exit 1; } - - # Canton service may need a moment to pass health checks after restart - ok=false - for i in 1 2 3 4 5; do - if cli status e2e-test-default 2>&1 | grep -qiE "(healthy|ready|running)"; then - ok=true; break - fi - sleep 5 - done - $ok || { echo "FAIL step 2: not healthy after single-service restart" >&2; exit 1; } -) -if [ $? -eq 0 ]; then - pass "$TEST_ID: Restart full + single service" -else - fail "$TEST_ID: Restart full + single service" "restart or post-restart health check failed" -fi - -# ── M1-STP-001: Stop keeps containers; start brings them back ─────── -# PR #201: `stop`/`start` are standalone commands (no longer up/down -# aliases). `stop` = docker compose stop (containers preserved on disk), -# `start` = docker compose start (fast path, no recreate). -TEST_ID="M1-STP-001" -echo " Stop/start cycle (may take a few minutes)..." -( - # Step 1: stop the running instance - cli stop e2e-test-default \ - || { echo "FAIL step 1: stop exited $?" >&2; exit 1; } - - # Allow container processes to exit - sleep 5 - - # Step 2: containers are stopped but NOT removed — they must still be - # present in `docker ps -a` yet absent from the running set (`docker ps`). - docker ps -a --filter "label=com.docker.compose.project=canton-e2e-test-default" --format '{{.Names}}' | grep -qE "e2e-test-default" \ - || { echo "FAIL step 2: containers removed by stop (should be preserved)" >&2; exit 1; } - if docker ps --filter "label=com.docker.compose.project=canton-e2e-test-default" --format '{{.Names}}' | grep -qE "e2e-test-default"; then - echo "FAIL step 2: containers still running after stop" >&2; exit 1 - fi - - # Step 3: start brings the instance back to healthy (fast compose-start path) - timed 600 "$CDK" localnet start e2e-test-default \ - || { echo "FAIL step 3: start exited $?" >&2; exit 1; } - - # Canton may need a moment to pass health checks after start - ok=false - for i in 1 2 3 4 5; do - if cli status e2e-test-default 2>&1 | grep -qiE "(healthy|ready|running)"; then - ok=true; break - fi - sleep 5 - done - $ok || { echo "FAIL step 3: not healthy after start" >&2; exit 1; } -) -if [ $? -eq 0 ]; then - pass "$TEST_ID: Stop keeps containers; start restores them" -else - fail "$TEST_ID: Stop keeps containers; start restores them" "stop/start cycle failed" -fi - -# ── M1-SNP-001: Snapshot and restore ──────────────────────────────── -TEST_ID="M1-SNP-001" -echo " Snapshot/restore cycle (may take a few minutes)..." -( - # Step 1: create snapshot - cli snapshot e2e-test-default --to "$SNAPSHOT_PATH" \ - || { echo "FAIL step 1: snapshot command failed" >&2; exit 1; } - [ -f "$SNAPSHOT_PATH" ] && [ -s "$SNAPSHOT_PATH" ] \ - || { echo "FAIL step 1: snapshot file missing or empty" >&2; exit 1; } - - # Step 2: tear down (use remove --force directly; down→remove leaves orphaned - # volumes due to a known registry-deregistration bug). - cli remove e2e-test-default --force 2>/dev/null || true - # Belt-and-suspenders: ensure Docker resources are gone - docker compose -p "canton-e2e-test-default" down --volumes 2>/dev/null || true - - # Step 3: restore - cli restore e2e-test-default --from "$SNAPSHOT_PATH" \ - || { echo "FAIL step 3: restore command failed" >&2; exit 1; } - - # Step 4: bring up and verify it starts (post-restore may need extra time for re-sync) - timed 600 "$CDK" localnet up e2e-test-default || { - # Tolerate timeout if services are at least partially up - cli status e2e-test-default 2>&1 | grep -qiE "(partial|syncing|healthy|running)" \ - || { echo "FAIL step 4: post-restore up failed and services not even partially up" >&2; exit 1; } - } -) -if [ $? -eq 0 ]; then - pass "$TEST_ID: Snapshot and restore" -else - fail "$TEST_ID: Snapshot and restore" "snapshot/restore cycle failed" -fi - -# ── M1-DWN-001: Down stops instance cleanly ───────────────────────── -TEST_ID="M1-DWN-001" -( - # Ensure instance has running containers (may be in degraded state after restore) - if ! docker ps --filter "label=com.docker.compose.project=canton-e2e-test-default" --format '{{.Names}}' | grep -qE "e2e-test-default"; then - timed 600 "$CDK" localnet up e2e-test-default \ - || { echo "FAIL: could not bring instance up for down test" >&2; exit 1; } - sleep 2 - fi - - # Record non-devkit container count. - # grep -c already prints "0" on no match; do not append `|| echo "0"` - # because grep -c exits non-zero on an empty/no-match input, which would - # fire the fallback and produce a two-line value ("0\n0") that breaks the - # `[ ... -eq ... ]` integer comparison below. - NON_DEVKIT_BEFORE=$(docker ps --format '{{.Names}}' | grep -cv "e2e-test") - - # Step 1: down exits 0 - cli down e2e-test-default \ - || { echo "FAIL step 1: down exited $?" >&2; exit 1; } - - # Allow containers to fully stop (compose down may return before - # Docker daemon has removed all containers) - sleep 5 - - # Step 2: no devkit containers for this instance - if docker ps --filter "label=com.docker.compose.project=canton-e2e-test-default" --format '{{.Names}}' | grep -qE "e2e-test-default"; then - echo "FAIL step 2: containers still running after down" >&2 - docker ps --filter "label=com.docker.compose.project=canton-e2e-test-default" --format '{{.Names}}' >&2 - exit 1 - fi - - # Step 3: non-devkit containers unaffected - NON_DEVKIT_AFTER=$(docker ps --format '{{.Names}}' | grep -cv "e2e-test") - [ "$NON_DEVKIT_BEFORE" -eq "$NON_DEVKIT_AFTER" ] \ - || { echo "FAIL step 3: non-devkit container count changed ($NON_DEVKIT_BEFORE → $NON_DEVKIT_AFTER)" >&2; exit 1; } -) -if [ $? -eq 0 ]; then - pass "$TEST_ID: Down stops instance cleanly" -else - fail "$TEST_ID: Down stops instance cleanly" "down failed or containers remain" -fi - -# ── M1-RMV-001: Remove deletes all resources ──────────────────────── -TEST_ID="M1-RMV-001" -echo " Remove test (up + remove --force cycle)..." -( - # Step 1: start an instance (reuse if already running) - cli status e2e-test-default 2>&1 | grep -qiE "(healthy|ready|running)" || \ - timed 600 "$CDK" localnet up e2e-test-default \ - || { echo "FAIL step 1: could not bring instance up for remove test" >&2; exit 1; } - - # Step 2: remove --force on the running instance (tears down + removes volumes) - cli remove e2e-test-default --force \ - || { echo "FAIL step 2: remove --force exited $?" >&2; exit 1; } - - # Step 3: verify all resources removed - if docker ps -a --filter "label=com.docker.compose.project=canton-e2e-test-default" --format '{{.Names}}' | grep -qE "e2e-test-default"; then - echo "FAIL step 3a: containers remain after remove" >&2; exit 1 - fi - if docker volume ls --format '{{.Name}}' | grep -qE "e2e-test-default"; then - echo "FAIL step 3b: volumes remain after remove" >&2; exit 1 - fi - if docker network ls --format '{{.Name}}' | grep -qE "e2e-test-default"; then - echo "FAIL step 3c: networks remain after remove" >&2; exit 1 - fi -) -if [ $? -eq 0 ]; then - pass "$TEST_ID: Remove deletes all resources" -else - fail "$TEST_ID: Remove deletes all resources" "remove failed or resources remain" - # Force-remove leftover resources so Phase 3 doesn't compete with a - # stale instance for memory / ports. - docker compose -p "canton-e2e-test-default" down --volumes 2>/dev/null || true -fi - -# ═════════════════════════════════════════════════════════════════════ -# PHASE 3: Named instance & version tests -# ═════════════════════════════════════════════════════════════════════ - -section "PHASE 3: Named instance & version tests" - -# ── M1-UP-002: LocalNet up with name ──────────────────────────────── -TEST_ID="M1-UP-002" -echo " Starting e2e-named-test (may take 3-5 minutes)..." -( - # Step 1: up with explicit name - timed 600 "$CDK" localnet up e2e-named-test \ - || { echo "FAIL step 1: up exited $?" >&2; exit 1; } - - sleep 2 - - # Step 2: docker containers use the name - docker ps --filter "label=com.docker.compose.project=canton-e2e-named-test" --format '{{.Names}}' | grep -qE "e2e-named-test" \ - || { echo "FAIL step 2: no containers with compose project label" >&2; exit 1; } - - # Step 3: status references the name - cli status e2e-named-test 2>&1 | grep -qiE "e2e-named-test" \ - || { echo "FAIL step 3: status output missing instance name" >&2; exit 1; } -) -if [ $? -eq 0 ]; then - pass "$TEST_ID: LocalNet up with name" -else - fail "$TEST_ID: LocalNet up with name" "named instance failed" -fi - -# Tear down e2e-named-test before starting the next instance -cli remove e2e-named-test --force 2>/dev/null || true -docker compose -p "canton-e2e-named-test" down --volumes 2>/dev/null || true - -# ── M1-UP-003: LocalNet up with --version ─────────────────────────── -TEST_ID="M1-UP-003" -echo " Starting e2e-version-test with --version $SPLICE_VERSION (may take 3-5 minutes)..." -( - # Step 1: up with explicit version - timed 600 "$CDK" localnet up e2e-version-test --version "$SPLICE_VERSION" \ - || { echo "FAIL step 1: up --version exited $?" >&2; exit 1; } - - sleep 2 - - # Step 2: status reflects the version - cli status e2e-version-test 2>&1 | grep -qE "$SPLICE_VERSION" \ - || { echo "FAIL step 2: status missing version $SPLICE_VERSION" >&2; exit 1; } - - # Step 3: invalid version should fail - if "$CDK" localnet up e2e-bad-version --version "0.0.0-nonexistent" >/dev/null 2>&1; then - cli remove e2e-bad-version --force 2>/dev/null || true - echo "FAIL step 3: invalid version should have been rejected" >&2; exit 1 - fi -) -if [ $? -eq 0 ]; then - pass "$TEST_ID: LocalNet up with --version" -else - fail "$TEST_ID: LocalNet up with --version" "version test failed" -fi - -# ── M1-LST-001: List discovers running instances ──────────────────── -# Adapted: single-instance check (two concurrent instances need >12 GB Docker memory). -TEST_ID="M1-LST-001" -( - # Step 1: list shows running instance(s) - OUTPUT=$(cli list 2>&1) - - # At least one of our test instances should appear - echo "$OUTPUT" | grep -qE "e2e-(named-test|version-test)" \ - || { echo "FAIL step 1: no test instances in list output" >&2; exit 1; } - - # Step 2: verify list output has expected columns - echo "$OUTPUT" | grep -qiE "(NAME|SPLICE|STATUS)" \ - || { echo "FAIL step 2: list output missing expected columns" >&2; exit 1; } -) -if [ $? -eq 0 ]; then - pass "$TEST_ID: List discovers running instances" -else - fail "$TEST_ID: List discovers running instances" "list output missing expected instances" -fi - -# ═════════════════════════════════════════════════════════════════════ -# Exit (cleanup trap handles teardown + summary) -# ═════════════════════════════════════════════════════════════════════ - -if [ "$FAIL" -gt 0 ]; then - exit 1 -fi -exit 0 diff --git a/scripts/e2e/lib.sh b/scripts/e2e/lib.sh new file mode 100755 index 00000000..6ea2b12d --- /dev/null +++ b/scripts/e2e/lib.sh @@ -0,0 +1,188 @@ +#!/usr/bin/env bash +# Shared helpers for Milestone 1 E2E tests. +# shellcheck shell=bash + +CDK="${CDK:-bin/canton-devkit}" +SPLICE_VERSION="${SPLICE_VERSION:-0.6.12}" +SNAPSHOT_PATH="${SNAPSHOT_PATH:-/tmp/e2e-m1-snapshot.tgz}" + +E2E_INSTANCE_NAMES=(e2e-test-default e2e-named-test e2e-version-test e2e-bad-version) + +# Helper: invoke the localnet subcommand via the CDK binary. +cli() { "$CDK" localnet "$@"; } + +# Wrapper around `timeout` that uses --foreground on Linux so the +# timeout signal only hits the child process, not the parent shell. +if [[ "$(uname -s)" == "Linux" ]]; then + timed() { local s="$1"; shift; timeout --foreground "$s" "$@"; } +else + timed() { local s="$1"; shift; timeout "$s" "$@"; } +fi + +# Aggregate-mode counters (run-all.sh sets E2E_AGGREGATE=1). +: "${PASS:=0}" +: "${FAIL:=0}" +: "${SKIP:=0}" +if [ -z "${E2E_LIB_LOADED:-}" ]; then + declare -a RESULTS=() + E2E_LIB_LOADED=1 +fi + +e2e_is_aggregate_mode() { + [ "${E2E_AGGREGATE:-0}" = "1" ] +} + +pass() { + PASS=$((PASS + 1)) + RESULTS+=("PASS $1") + printf ' PASS %s\n' "$1" +} + +fail() { + FAIL=$((FAIL + 1)) + RESULTS+=("FAIL $1 -- $2") + printf ' FAIL %s -- %s\n' "$1" "$2" >&2 +} + +skip() { + SKIP=$((SKIP + 1)) + RESULTS+=("SKIP $1 -- $2") + printf ' SKIP %s -- %s\n' "$1" "$2" +} + +section() { + echo "" + printf '== %s\n' "$1" +} + +e2e_require_binary() { + if [ ! -x "$CDK" ]; then + echo "ERROR: binary not found at $CDK -- run 'make build' first" >&2 + exit 1 + fi +} + +e2e_require_docker() { + docker info >/dev/null 2>&1 || { + echo "ERROR: Docker daemon not reachable" >&2 + exit 1 + } +} + +# Bring instance to a usable state; no-op when already healthy. +ensure_instance() { + local name="$1" + local status_out + + status_out=$(cli status "$name" 2>&1 || true) + if echo "$status_out" | grep -qiE "(healthy|ready|running|partial|syncing)"; then + return 0 + fi + + if docker ps -a --filter "label=com.docker.compose.project=canton-${name}" --format '{{.Names}}' \ + | grep -qE "${name}"; then + timed 600 "$CDK" localnet start "$name" \ + || { echo "ensure_instance: start ${name} failed" >&2; return 1; } + else + timed 600 "$CDK" localnet up "$name" \ + || { echo "ensure_instance: up ${name} failed" >&2; return 1; } + fi + + sleep 2 +} + +wait_for_healthy() { + local name="$1" + local i ok=false + + for i in 1 2 3 4 5; do + if cli status "$name" 2>&1 | grep -qiE "(healthy|ready|running)"; then + ok=true + break + fi + sleep 5 + done + $ok +} + +e2e_preclean_instances() { + local name + for name in "${E2E_INSTANCE_NAMES[@]}"; do + cli down "$name" 2>/dev/null || true + cli remove "$name" --force 2>/dev/null || true + done +} + +e2e_force_cleanup_instances() { + local name + for name in "${E2E_INSTANCE_NAMES[@]}"; do + cli remove "$name" --force 2>/dev/null || true + docker compose -p "canton-${name}" down --volumes 2>/dev/null || true + done + rm -f "$SNAPSHOT_PATH" +} + +print_summary() { + echo "" + echo "=======================================================" + echo " E2E Milestone 1 Results" + printf ' PASSED: %d FAILED: %d SKIPPED: %d\n' "$PASS" "$FAIL" "$SKIP" + echo "=======================================================" + local r + for r in "${RESULTS[@]}"; do + echo " $r" + done + echo "=======================================================" + write_step_summary +} + +write_step_summary() { + [ -n "${GITHUB_STEP_SUMMARY:-}" ] || return 0 + + { + echo "## E2E Milestone 1 Results" + echo "" + echo "**Passed:** ${PASS}    **Failed:** ${FAIL}    **Skipped:** ${SKIP}" + echo "" + echo "| Result | Test |" + echo "| :----: | :--- |" + for r in "${RESULTS[@]}"; do + case "$r" in + PASS*) icon="OK"; rest="${r#PASS }" ;; + FAIL*) icon="FAIL"; rest="${r#FAIL }" ;; + SKIP*) icon="SKIP"; rest="${r#SKIP }" ;; + *) icon=""; rest="$r" ;; + esac + test="${rest%% -- *}" + printf '| %s | %s |\n' "$icon" "$test" + done + } >> "$GITHUB_STEP_SUMMARY" +} + +# Run a test function in aggregate mode (pass/fail counters). +e2e_run_with_result() { + local test_id="$1" + local label="$2" + local fn="$3" + + if ( set -e; "$fn" ); then + pass "${test_id}: ${label}" + return 0 + fi + fail "${test_id}: ${label}" "${4:-test failed}" + return 1 +} + +# Run a test function in standalone mode (exit 0/1). +e2e_run_standalone() { + local test_id="$1" + local fn="$2" + + echo "${test_id}" + if ( set -e; "$fn" ); then + echo "PASS ${test_id}" + exit 0 + fi + echo "FAIL ${test_id}" >&2 + exit 1 +} diff --git a/scripts/e2e/m1-doc-001.sh b/scripts/e2e/m1-doc-001.sh new file mode 100755 index 00000000..afad4056 --- /dev/null +++ b/scripts/e2e/m1-doc-001.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -u + +E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=lib.sh +source "${E2E_DIR}/lib.sh" + +e2e_require_binary +e2e_require_docker + +TEST_ID="M1-DOC-001" + +run_test() { + local OUTPUT + OUTPUT=$(cli doctor 2>&1) + echo "$OUTPUT" | grep -qiE "(docker cli|docker daemon|compose|port|disk|memory)" + ! echo "$OUTPUT" | grep -qE "^ ✗" +} + +if e2e_is_aggregate_mode; then + e2e_run_with_result "$TEST_ID" "Doctor -- all checks pass" run_test "doctor reported failures" +else + e2e_run_standalone "$TEST_ID" run_test +fi diff --git a/scripts/e2e/m1-doc-002.sh b/scripts/e2e/m1-doc-002.sh new file mode 100755 index 00000000..e81ec83e --- /dev/null +++ b/scripts/e2e/m1-doc-002.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -u + +E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=lib.sh +source "${E2E_DIR}/lib.sh" + +e2e_require_binary + +TEST_ID="M1-DOC-002" + +run_test() { + local MINIMAL_PATH="" dir OUTPUT + IFS=':' read -ra DIRS <<< "$PATH" + for dir in "${DIRS[@]}"; do + if [ -d "$dir" ] && ! [ -x "$dir/docker" ]; then + MINIMAL_PATH="${MINIMAL_PATH:+$MINIMAL_PATH:}$dir" + fi + done + + if PATH="$MINIMAL_PATH" "$CDK" localnet doctor >/dev/null 2>&1; then + return 1 + fi + + OUTPUT=$(PATH="$MINIMAL_PATH" "$CDK" localnet doctor 2>&1 || true) + echo "$OUTPUT" | grep -qiE "(install docker|docker not found|docker desktop|docker cli)" +} + +if e2e_is_aggregate_mode; then + e2e_run_with_result "$TEST_ID" "Doctor -- Docker not installed" run_test "doctor did not fail or missing remediation message" +else + e2e_run_standalone "$TEST_ID" run_test +fi diff --git a/scripts/e2e/m1-dwn-001.sh b/scripts/e2e/m1-dwn-001.sh new file mode 100755 index 00000000..68eea4bc --- /dev/null +++ b/scripts/e2e/m1-dwn-001.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +set -u + +E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=lib.sh +source "${E2E_DIR}/lib.sh" + +e2e_require_binary +e2e_require_docker + +TEST_ID="M1-DWN-001" + +run_test() { + if ! docker ps --filter "label=com.docker.compose.project=canton-e2e-test-default" --format '{{.Names}}' | grep -qE "e2e-test-default"; then + timed 600 "$CDK" localnet up e2e-test-default \ + || { echo "FAIL: could not bring instance up for down test" >&2; return 1; } + sleep 2 + fi + + local NON_DEVKIT_BEFORE NON_DEVKIT_AFTER + NON_DEVKIT_BEFORE=$(docker ps --format '{{.Names}}' | grep -cv "e2e-test") + + cli down e2e-test-default \ + || { echo "FAIL step 1: down exited $?" >&2; return 1; } + + sleep 5 + + if docker ps --filter "label=com.docker.compose.project=canton-e2e-test-default" --format '{{.Names}}' | grep -qE "e2e-test-default"; then + echo "FAIL step 2: containers still running after down" >&2 + docker ps --filter "label=com.docker.compose.project=canton-e2e-test-default" --format '{{.Names}}' >&2 + return 1 + fi + + NON_DEVKIT_AFTER=$(docker ps --format '{{.Names}}' | grep -cv "e2e-test") + [ "$NON_DEVKIT_BEFORE" -eq "$NON_DEVKIT_AFTER" ] \ + || { echo "FAIL step 3: non-devkit container count changed ($NON_DEVKIT_BEFORE -> $NON_DEVKIT_AFTER)" >&2; return 1; } +} + +if e2e_is_aggregate_mode; then + e2e_run_with_result "$TEST_ID" "Down stops instance cleanly" run_test "down failed or containers remain" +else + e2e_run_standalone "$TEST_ID" run_test +fi diff --git a/scripts/e2e/m1-env-001.sh b/scripts/e2e/m1-env-001.sh new file mode 100755 index 00000000..369cf634 --- /dev/null +++ b/scripts/e2e/m1-env-001.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -u + +E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=lib.sh +source "${E2E_DIR}/lib.sh" + +e2e_require_binary +e2e_require_docker + +TEST_ID="M1-ENV-001" + +run_test() { + ensure_instance e2e-test-default || return 1 + + local OUTPUT + OUTPUT=$(cli env e2e-test-default 2>&1) \ + || { echo "FAIL step 1: env exited $?" >&2; return 1; } + + echo "$OUTPUT" | grep -qE "^(export )?[A-Z_]+=" \ + || { echo "FAIL step 2: no KEY=value lines in env output" >&2; return 1; } + + echo "$OUTPUT" | grep -qiE "(LEDGER|JSON_API|ADMIN|PARTICIPANT|CANTON)" \ + || { echo "FAIL step 3: env output missing expected variable names" >&2; return 1; } +} + +if e2e_is_aggregate_mode; then + e2e_run_with_result "$TEST_ID" "Env export outputs valid config" run_test "env output format/content unexpected" +else + e2e_run_standalone "$TEST_ID" run_test +fi diff --git a/scripts/e2e/m1-inst-003.sh b/scripts/e2e/m1-inst-003.sh new file mode 100755 index 00000000..83a24967 --- /dev/null +++ b/scripts/e2e/m1-inst-003.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -u + +E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=lib.sh +source "${E2E_DIR}/lib.sh" + +e2e_require_binary +e2e_require_docker + +TEST_ID="M1-INST-003" + +run_test() { + "$CDK" --version 2>&1 | grep -qE "([0-9]+\.[0-9]+\.[0-9]+|dev)" + + local HELP + HELP=$(cli --help 2>&1) + local cmd + for cmd in up start stop down restart pause resume remove status logs snapshot restore doctor env list creds; do + echo "$HELP" | grep -qiE "$cmd" + done + cli unpause --help >/dev/null 2>&1 + cli remove --help >/dev/null 2>&1 + + case "$(uname -s)" in + Darwin) file "$CDK" 2>/dev/null | grep -qiE "Mach-O" ;; + Linux) file "$CDK" 2>/dev/null | grep -qiE "ELF" ;; + *) file "$CDK" 2>/dev/null | grep -qiE "(Mach-O|ELF|PE32)" ;; + esac +} + +if e2e_is_aggregate_mode; then + e2e_run_with_result "$TEST_ID" "Verify binary" run_test "version/help/file check failed" +else + e2e_run_standalone "$TEST_ID" run_test +fi diff --git a/scripts/e2e/m1-log-001.sh b/scripts/e2e/m1-log-001.sh new file mode 100755 index 00000000..56740195 --- /dev/null +++ b/scripts/e2e/m1-log-001.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -u + +E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=lib.sh +source "${E2E_DIR}/lib.sh" + +e2e_require_binary +e2e_require_docker + +TEST_ID="M1-LOG-001" + +run_test() { + ensure_instance e2e-test-default || return 1 + + local LOG_OUTPUT LINE_COUNT SVC_OUTPUT SVC_LINES + LOG_OUTPUT=$("$CDK" localnet logs e2e-test-default --tail 50 2>&1) || true + LINE_COUNT=$(echo "$LOG_OUTPUT" | wc -l | tr -d ' ') + [ "$LINE_COUNT" -gt 1 ] \ + || { echo "FAIL step 1: full logs empty (got $LINE_COUNT lines)" >&2; return 1; } + + SVC_OUTPUT=$("$CDK" localnet logs e2e-test-default --service canton --tail 20 2>&1) || true + SVC_LINES=$(echo "$SVC_OUTPUT" | wc -l | tr -d ' ') + [ "$SVC_LINES" -gt 1 ] \ + || { echo "FAIL step 2: service-filtered logs empty (got $SVC_LINES lines)" >&2; return 1; } + + "$CDK" localnet logs e2e-test-default --service nonexistent-service-xyz --tail 5 >/dev/null 2>&1 || true +} + +if e2e_is_aggregate_mode; then + e2e_run_with_result "$TEST_ID" "Logs -- full and service-filtered" run_test "logs output unexpected" +else + e2e_run_standalone "$TEST_ID" run_test +fi diff --git a/scripts/e2e/m1-lst-001.sh b/scripts/e2e/m1-lst-001.sh new file mode 100755 index 00000000..0ef319d9 --- /dev/null +++ b/scripts/e2e/m1-lst-001.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +set -u + +E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=lib.sh +source "${E2E_DIR}/lib.sh" + +e2e_require_binary +e2e_require_docker + +TEST_ID="M1-LST-001" + +run_test() { + ensure_instance e2e-version-test || return 1 + + local OUTPUT + OUTPUT=$(cli list 2>&1) + + echo "$OUTPUT" | grep -qE "e2e-(named-test|version-test)" \ + || { echo "FAIL step 1: no test instances in list output" >&2; return 1; } + + echo "$OUTPUT" | grep -qiE "(NAME|SPLICE|STATUS)" \ + || { echo "FAIL step 2: list output missing expected columns" >&2; return 1; } +} + +if e2e_is_aggregate_mode; then + e2e_run_with_result "$TEST_ID" "List discovers running instances" run_test "list output missing expected instances" +else + e2e_run_standalone "$TEST_ID" run_test +fi diff --git a/scripts/e2e/m1-rmv-001.sh b/scripts/e2e/m1-rmv-001.sh new file mode 100755 index 00000000..efa92c04 --- /dev/null +++ b/scripts/e2e/m1-rmv-001.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +set -u + +E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=lib.sh +source "${E2E_DIR}/lib.sh" + +e2e_require_binary +e2e_require_docker + +TEST_ID="M1-RMV-001" + +run_test() { + echo " Remove test (up + remove --force cycle)..." + cli status e2e-test-default 2>&1 | grep -qiE "(healthy|ready|running)" || \ + timed 600 "$CDK" localnet up e2e-test-default \ + || { echo "FAIL step 1: could not bring instance up for remove test" >&2; return 1; } + + cli remove e2e-test-default --force \ + || { echo "FAIL step 2: remove --force exited $?" >&2; return 1; } + + if docker ps -a --filter "label=com.docker.compose.project=canton-e2e-test-default" --format '{{.Names}}' | grep -qE "e2e-test-default"; then + echo "FAIL step 3a: containers remain after remove" >&2 + return 1 + fi + if docker volume ls --format '{{.Name}}' | grep -qE "e2e-test-default"; then + echo "FAIL step 3b: volumes remain after remove" >&2 + return 1 + fi + if docker network ls --format '{{.Name}}' | grep -qE "e2e-test-default"; then + echo "FAIL step 3c: networks remain after remove" >&2 + return 1 + fi +} + +if e2e_is_aggregate_mode; then + if ! e2e_run_with_result "$TEST_ID" "Remove deletes all resources" run_test "remove failed or resources remain"; then + docker compose -p "canton-e2e-test-default" down --volumes 2>/dev/null || true + fi +else + if ( set -e; run_test ); then + echo "PASS ${TEST_ID}" + exit 0 + fi + docker compose -p "canton-e2e-test-default" down --volumes 2>/dev/null || true + echo "FAIL ${TEST_ID}" >&2 + exit 1 +fi diff --git a/scripts/e2e/m1-rst-001.sh b/scripts/e2e/m1-rst-001.sh new file mode 100755 index 00000000..7fbd47d6 --- /dev/null +++ b/scripts/e2e/m1-rst-001.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -u + +E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=lib.sh +source "${E2E_DIR}/lib.sh" + +e2e_require_binary +e2e_require_docker + +TEST_ID="M1-RST-001" + +run_test() { + ensure_instance e2e-test-default || return 1 + + echo " Restarting e2e-test-default (may take a few minutes)..." + timed 600 "$CDK" localnet restart e2e-test-default \ + || { echo "FAIL step 1: full restart exited $?" >&2; return 1; } + + cli status e2e-test-default 2>&1 | grep -qiE "(healthy|ready|running)" \ + || { echo "FAIL step 1: not healthy after full restart" >&2; return 1; } + + timed 600 "$CDK" localnet restart e2e-test-default --service canton \ + || { echo "FAIL step 2: single-service restart exited $?" >&2; return 1; } + + wait_for_healthy e2e-test-default \ + || { echo "FAIL step 2: not healthy after single-service restart" >&2; return 1; } +} + +if e2e_is_aggregate_mode; then + e2e_run_with_result "$TEST_ID" "Restart full + single service" run_test "restart or post-restart health check failed" +else + e2e_run_standalone "$TEST_ID" run_test +fi diff --git a/scripts/e2e/m1-snp-001.sh b/scripts/e2e/m1-snp-001.sh new file mode 100755 index 00000000..81d70cd3 --- /dev/null +++ b/scripts/e2e/m1-snp-001.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -u + +E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=lib.sh +source "${E2E_DIR}/lib.sh" + +e2e_require_binary +e2e_require_docker + +TEST_ID="M1-SNP-001" + +run_test() { + ensure_instance e2e-test-default || return 1 + + echo " Snapshot/restore cycle (may take a few minutes)..." + cli snapshot e2e-test-default --to "$SNAPSHOT_PATH" \ + || { echo "FAIL step 1: snapshot command failed" >&2; return 1; } + [ -f "$SNAPSHOT_PATH" ] && [ -s "$SNAPSHOT_PATH" ] \ + || { echo "FAIL step 1: snapshot file missing or empty" >&2; return 1; } + + cli remove e2e-test-default --force 2>/dev/null || true + docker compose -p "canton-e2e-test-default" down --volumes 2>/dev/null || true + + cli restore e2e-test-default --from "$SNAPSHOT_PATH" \ + || { echo "FAIL step 3: restore command failed" >&2; return 1; } + + timed 600 "$CDK" localnet up e2e-test-default || { + cli status e2e-test-default 2>&1 | grep -qiE "(partial|syncing|healthy|running)" \ + || { echo "FAIL step 4: post-restore up failed and services not even partially up" >&2; return 1; } + } +} + +if e2e_is_aggregate_mode; then + e2e_run_with_result "$TEST_ID" "Snapshot and restore" run_test "snapshot/restore cycle failed" +else + e2e_run_standalone "$TEST_ID" run_test +fi diff --git a/scripts/e2e/m1-stp-001.sh b/scripts/e2e/m1-stp-001.sh new file mode 100755 index 00000000..b4233847 --- /dev/null +++ b/scripts/e2e/m1-stp-001.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +set -u + +E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=lib.sh +source "${E2E_DIR}/lib.sh" + +e2e_require_binary +e2e_require_docker + +TEST_ID="M1-STP-001" + +run_test() { + ensure_instance e2e-test-default || return 1 + + echo " Stop/start cycle (may take a few minutes)..." + cli stop e2e-test-default \ + || { echo "FAIL step 1: stop exited $?" >&2; return 1; } + + sleep 5 + + docker ps -a --filter "label=com.docker.compose.project=canton-e2e-test-default" --format '{{.Names}}' | grep -qE "e2e-test-default" \ + || { echo "FAIL step 2: containers removed by stop (should be preserved)" >&2; return 1; } + if docker ps --filter "label=com.docker.compose.project=canton-e2e-test-default" --format '{{.Names}}' | grep -qE "e2e-test-default"; then + echo "FAIL step 2: containers still running after stop" >&2 + return 1 + fi + + timed 600 "$CDK" localnet start e2e-test-default \ + || { echo "FAIL step 3: start exited $?" >&2; return 1; } + + wait_for_healthy e2e-test-default \ + || { echo "FAIL step 3: not healthy after start" >&2; return 1; } +} + +if e2e_is_aggregate_mode; then + e2e_run_with_result "$TEST_ID" "Stop keeps containers; start restores them" run_test "stop/start cycle failed" +else + e2e_run_standalone "$TEST_ID" run_test +fi diff --git a/scripts/e2e/m1-sts-001.sh b/scripts/e2e/m1-sts-001.sh new file mode 100755 index 00000000..40b24274 --- /dev/null +++ b/scripts/e2e/m1-sts-001.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -u + +E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=lib.sh +source "${E2E_DIR}/lib.sh" + +e2e_require_binary +e2e_require_docker + +TEST_ID="M1-STS-001" + +run_test() { + ensure_instance e2e-test-default || return 1 + + local OUTPUT + OUTPUT=$(cli status e2e-test-default 2>&1) \ + || { echo "FAIL step 1: status exited $?" >&2; return 1; } + echo "$OUTPUT" | grep -qiE "(healthy|running|ready)" \ + || { echo "FAIL step 1: status missing healthy/running/ready" >&2; return 1; } + + if cli status nonexistent-localnet-xyz >/dev/null 2>&1; then + echo "FAIL step 2: status for non-existent instance should fail" >&2 + return 1 + fi +} + +if e2e_is_aggregate_mode; then + e2e_run_with_result "$TEST_ID" "Status shows healthy services" run_test "status output missing expected fields or non-existent check failed" +else + e2e_run_standalone "$TEST_ID" run_test +fi diff --git a/scripts/e2e/m1-up-001.sh b/scripts/e2e/m1-up-001.sh new file mode 100755 index 00000000..ee5e322d --- /dev/null +++ b/scripts/e2e/m1-up-001.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -u + +E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=lib.sh +source "${E2E_DIR}/lib.sh" + +e2e_require_binary +e2e_require_docker + +TEST_ID="M1-UP-001" + +run_test() { + echo " Starting e2e-test-default (may take 3-5 minutes)..." + timed 600 "$CDK" localnet up e2e-test-default \ + || { echo "FAIL step 1: up exited $?" >&2; return 1; } + + sleep 2 + + cli status e2e-test-default 2>&1 | grep -qiE "(healthy|ready|running)" \ + || { echo "FAIL step 2: status missing healthy/ready/running" >&2; return 1; } + + docker ps --filter "label=com.docker.compose.project=canton-e2e-test-default" --format '{{.Names}}' | grep -qE "e2e-test-default" \ + || { echo "FAIL step 3: no containers with compose project label" >&2; return 1; } + + docker compose ls 2>/dev/null | grep -qE "e2e-test-default" \ + || { echo "FAIL step 4: compose project not listed" >&2; return 1; } +} + +if e2e_is_aggregate_mode; then + e2e_run_with_result "$TEST_ID" "LocalNet up (default)" run_test "up/status/docker check failed" +else + e2e_run_standalone "$TEST_ID" run_test +fi diff --git a/scripts/e2e/m1-up-002.sh b/scripts/e2e/m1-up-002.sh new file mode 100755 index 00000000..8a3dc9fa --- /dev/null +++ b/scripts/e2e/m1-up-002.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -u + +E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=lib.sh +source "${E2E_DIR}/lib.sh" + +e2e_require_binary +e2e_require_docker + +TEST_ID="M1-UP-002" + +run_test() { + echo " Starting e2e-named-test (may take 3-5 minutes)..." + timed 600 "$CDK" localnet up e2e-named-test \ + || { echo "FAIL step 1: up exited $?" >&2; return 1; } + + sleep 2 + + docker ps --filter "label=com.docker.compose.project=canton-e2e-named-test" --format '{{.Names}}' | grep -qE "e2e-named-test" \ + || { echo "FAIL step 2: no containers with compose project label" >&2; return 1; } + + cli status e2e-named-test 2>&1 | grep -qiE "e2e-named-test" \ + || { echo "FAIL step 3: status output missing instance name" >&2; return 1; } + + cli remove e2e-named-test --force 2>/dev/null || true + docker compose -p "canton-e2e-named-test" down --volumes 2>/dev/null || true +} + +if e2e_is_aggregate_mode; then + e2e_run_with_result "$TEST_ID" "LocalNet up with name" run_test "named instance failed" +else + e2e_run_standalone "$TEST_ID" run_test +fi diff --git a/scripts/e2e/m1-up-003.sh b/scripts/e2e/m1-up-003.sh new file mode 100755 index 00000000..86e2a27b --- /dev/null +++ b/scripts/e2e/m1-up-003.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -u + +E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=lib.sh +source "${E2E_DIR}/lib.sh" + +e2e_require_binary +e2e_require_docker + +TEST_ID="M1-UP-003" + +run_test() { + echo " Starting e2e-version-test with --version $SPLICE_VERSION (may take 3-5 minutes)..." + timed 600 "$CDK" localnet up e2e-version-test --version "$SPLICE_VERSION" \ + || { echo "FAIL step 1: up --version exited $?" >&2; return 1; } + + sleep 2 + + cli status e2e-version-test 2>&1 | grep -qE "$SPLICE_VERSION" \ + || { echo "FAIL step 2: status missing version $SPLICE_VERSION" >&2; return 1; } + + if "$CDK" localnet up e2e-bad-version --version "0.0.0-nonexistent" >/dev/null 2>&1; then + cli remove e2e-bad-version --force 2>/dev/null || true + echo "FAIL step 3: invalid version should have been rejected" >&2 + return 1 + fi +} + +if e2e_is_aggregate_mode; then + e2e_run_with_result "$TEST_ID" "LocalNet up with --version" run_test "version test failed" +else + e2e_run_standalone "$TEST_ID" run_test +fi diff --git a/scripts/e2e/run-all.sh b/scripts/e2e/run-all.sh new file mode 100755 index 00000000..8a883c42 --- /dev/null +++ b/scripts/e2e/run-all.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash +# Run all Milestone 1 E2E tests in order (local / full-suite use). +# +# Platform: macOS (Apple Silicon) and Linux +# CLI mode: canton-devkit localnet (standalone -- no DPM) +# +# Skipped tests: +# M1-INST-001 Install via DPM component (DPM excluded) +# M1-INST-002 Install standalone binary (binary already built) +# M1-DOC-003 Doctor -- insufficient resources (requires Docker Desktop config changes) +# M1-ISO-001 Two named instances (resource-heavy, skipped by request) +# +# Usage: +# scripts/e2e/run-all.sh +# CDK=./canton-devkit scripts/e2e/run-all.sh +# +# Individual tests (CI jobs): +# scripts/e2e/m1-up-001.sh +# +# Exit 0 = all tests passed; 1 = one or more failures. + +set -u + +export E2E_AGGREGATE=1 + +E2E_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +# shellcheck source=lib.sh +source "${E2E_DIR}/lib.sh" + +cleanup() { + echo "" + section "CLEANUP" + e2e_force_cleanup_instances + print_summary +} +trap cleanup EXIT + +e2e_require_binary +e2e_require_docker +e2e_preclean_instances + +echo "Canton DevKit E2E -- Milestone 1" +echo "Platform: $(uname -s) ($(uname -m))" +echo "Binary: $CDK" +echo "Docker: $(docker --version 2>/dev/null)" +echo "" + +section "PHASE 1: Binary and preflight checks" +# shellcheck source=m1-inst-003.sh +source "${E2E_DIR}/m1-inst-003.sh" +# shellcheck source=m1-doc-001.sh +source "${E2E_DIR}/m1-doc-001.sh" +# shellcheck source=m1-doc-002.sh +source "${E2E_DIR}/m1-doc-002.sh" + +section "PHASE 2: Default instance lifecycle (e2e-test-default)" +# shellcheck source=m1-up-001.sh +source "${E2E_DIR}/m1-up-001.sh" +# shellcheck source=m1-sts-001.sh +source "${E2E_DIR}/m1-sts-001.sh" +# shellcheck source=m1-log-001.sh +source "${E2E_DIR}/m1-log-001.sh" +# shellcheck source=m1-env-001.sh +source "${E2E_DIR}/m1-env-001.sh" +# shellcheck source=m1-rst-001.sh +source "${E2E_DIR}/m1-rst-001.sh" +# shellcheck source=m1-stp-001.sh +source "${E2E_DIR}/m1-stp-001.sh" +# shellcheck source=m1-snp-001.sh +source "${E2E_DIR}/m1-snp-001.sh" +# shellcheck source=m1-dwn-001.sh +source "${E2E_DIR}/m1-dwn-001.sh" +# shellcheck source=m1-rmv-001.sh +source "${E2E_DIR}/m1-rmv-001.sh" + +section "PHASE 3: Named instance and version tests" +# shellcheck source=m1-up-002.sh +source "${E2E_DIR}/m1-up-002.sh" +# shellcheck source=m1-up-003.sh +source "${E2E_DIR}/m1-up-003.sh" +# shellcheck source=m1-lst-001.sh +source "${E2E_DIR}/m1-lst-001.sh" + +if [ "$FAIL" -gt 0 ]; then + exit 1 +fi +exit 0