From 8e3f6fe6e263411afe4b1286c049ac89b3b3521c Mon Sep 17 00:00:00 2001 From: HalFinneyIsMyHomeBoy Date: Mon, 8 Dec 2025 14:32:23 -0600 Subject: [PATCH 1/2] Update GitHub Actions workflow to require local Docker-based Nostr relay for testing scripts. Remove redundant tests that are already covered by the local relay. Fix test-all.sh to require local relay and add more detailed error messages. --- .github/workflows/bbmtlib-test.yml | 100 +++++++++++++---------------- BBMTLib/scripts/test-all.sh | 24 +++---- 2 files changed, 58 insertions(+), 66 deletions(-) diff --git a/.github/workflows/bbmtlib-test.yml b/.github/workflows/bbmtlib-test.yml index 0631edf..ffa3a6f 100644 --- a/.github/workflows/bbmtlib-test.yml +++ b/.github/workflows/bbmtlib-test.yml @@ -1,10 +1,6 @@ name: BBMTLib Tests on: - push: - paths: - - 'BBMTLib/**' - - '.github/workflows/bbmtlib-test.yml' pull_request: paths: - 'BBMTLib/**' @@ -102,11 +98,55 @@ jobs: sudo apt-get update sudo apt-get install -y jq + - name: Verify Docker is available + run: | + if ! command -v docker >/dev/null 2>&1; then + echo "❌ Docker is required for running tests with local relay" + exit 1 + fi + docker --version + echo "✓ Docker is available" + + - name: Start local Nostr relay + run: | + echo "Starting local Docker-based Nostr relay..." + chmod +x scripts/*.sh + if ! ./scripts/start-local-relay.sh; then + echo "❌ Failed to start local relay. Tests require a local Docker-based relay." + echo "Relay container status:" + docker ps -a | grep bbmtlib-test-relay || echo "No relay container found" + exit 1 + fi + echo "✓ Local relay is running at ws://localhost:7777" + + # Verify relay is actually accessible + if ! docker ps --format '{{.Names}}' | grep -q "^bbmtlib-test-relay$"; then + echo "❌ Relay container is not running" + exit 1 + fi + - name: Run comprehensive script tests + env: + RELAYS: "ws://localhost:7777" + REQUIRE_LOCAL_RELAY: "true" run: | echo "Running comprehensive test suite for all scripts..." + echo "Using local relay: $RELAYS" + echo "Local relay is required - tests will fail if relay is unavailable" + + # Verify relay is still running before tests + if ! docker ps --format '{{.Names}}' | grep -q "^bbmtlib-test-relay$"; then + echo "❌ Local relay container is not running. Tests cannot proceed." + exit 1 + fi + ./scripts/test-all.sh - continue-on-error: true + + - name: Stop local Nostr relay + if: always() + run: | + echo "Stopping local relay..." + ./scripts/stop-local-relay.sh || true - name: Run vet run: go vet ./... @@ -140,53 +180,3 @@ jobs: fail_ci_if_error: false continue-on-error: true - integration-test: - name: Integration Tests (Optional) - runs-on: ubuntu-latest - needs: test - - defaults: - run: - working-directory: ./BBMTLib - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: '1.24.2' - cache-dependency-path: BBMTLib/go.sum - - - name: Install dependencies - run: go mod download - - - name: Install jq (for JSON validation) - run: | - sudo apt-get update - sudo apt-get install -y jq - - - name: Install Docker (for local relay) - run: | - # Docker is pre-installed in GitHub Actions ubuntu-latest - # Just verify it's available - docker --version || echo "Docker not available, tests will use external relays" - - - name: Run comprehensive script tests (with local relay) - env: - TIMEOUT: "120" - run: | - echo "Running comprehensive test suite with local Nostr relay..." - echo "The test script will automatically start a local relay using Docker" - echo "If Docker is unavailable, it will fall back to external relays" - - # Make scripts executable - chmod +x scripts/*.sh - - # Run comprehensive test script - # The script will handle starting/stopping the local relay automatically - ./scripts/test-all.sh - continue-on-error: true - timeout-minutes: 15 - diff --git a/BBMTLib/scripts/test-all.sh b/BBMTLib/scripts/test-all.sh index f2f69d4..2223f13 100755 --- a/BBMTLib/scripts/test-all.sh +++ b/BBMTLib/scripts/test-all.sh @@ -318,7 +318,7 @@ start_local_relay() { return 0 else - echo "⚠ Failed to start local relay, falling back to external relays" + echo "❌ Failed to start local relay" echo " Check /tmp/relay-start.log for details" if [ -f /tmp/relay-start.log ]; then echo " Last 10 lines of relay startup log:" @@ -625,9 +625,10 @@ else RELAYS_TO_USE="$LOCAL_RELAY_URL" echo "Using local relay: $RELAYS_TO_USE" else - RELAYS_TO_USE="${RELAYS:-wss://nostr.hifish.org,wss://nostr.xxi.quest,wss://bbw-nostr.xyz}" - echo "Using external relays: $RELAYS_TO_USE" - echo " (Note: Tests may fail due to relay connectivity)" + print_failure "nostr-keygen.sh: Local relay is required but could not be started" + echo " This test requires a local Docker-based relay to run." + echo " Please ensure Docker is available and the relay can be started." + exit 1 fi # Try to run with a short timeout @@ -719,13 +720,14 @@ else fi if [ -f "$KEYGEN_OUTPUT_DIR/party1-keyshare.json" ] && [ -f "$KEYGEN_OUTPUT_DIR/party2-keyshare.json" ]; then - # Use local relay if available, otherwise fall back to external + # Use local relay (required) if [ "$USE_LOCAL_RELAY" = "true" ] && [ -n "$LOCAL_RELAY_URL" ]; then RELAYS_TO_USE="$LOCAL_RELAY_URL" echo " Using local relay for keysign: $RELAYS_TO_USE" else - RELAYS_TO_USE="${RELAYS:-wss://bbw-nostr.xyz}" - echo " Using external relay for keysign: $RELAYS_TO_USE" + print_failure "nostr-keysign.sh: Local relay is required but not available" + echo " This test requires a local Docker-based relay to run." + exit 1 fi export OUTPUT_DIR="$KEYGEN_OUTPUT_DIR" @@ -786,14 +788,14 @@ else print_failure "nostr-keygen-3party.sh: Syntax error" fi - # Use local relay if available + # Use local relay (required) if [ "$USE_LOCAL_RELAY" = "true" ] && [ -n "$LOCAL_RELAY_URL" ]; then RELAYS_TO_USE="$LOCAL_RELAY_URL" echo "Using local relay: $RELAYS_TO_USE" else - RELAYS_TO_USE="${RELAYS:-wss://nostr.hifish.org,wss://nostr.xxi.quest,wss://bbw-nostr.xyz}" - echo "Using external relays: $RELAYS_TO_USE" - echo " (Note: Tests may fail due to relay connectivity)" + print_failure "nostr-keygen-3party.sh: Local relay is required but not available" + echo " This test requires a local Docker-based relay to run." + exit 1 fi # Try to run with a short timeout From 9f8816cc63bd9a0e816da75b6b6fa8d3365232a1 Mon Sep 17 00:00:00 2001 From: HalFinneyIsMyHomeBoy Date: Mon, 8 Dec 2025 14:36:27 -0600 Subject: [PATCH 2/2] Cache nostr-rs-relay docker --- .github/workflows/bbmtlib-test.yml | 11 +++++++++++ BBMTLib/scripts/start-local-relay.sh | 17 +++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.github/workflows/bbmtlib-test.yml b/.github/workflows/bbmtlib-test.yml index ffa3a6f..74b788e 100644 --- a/.github/workflows/bbmtlib-test.yml +++ b/.github/workflows/bbmtlib-test.yml @@ -107,6 +107,17 @@ jobs: docker --version echo "✓ Docker is available" + - name: Pull Nostr relay Docker image + run: | + # Pre-pull the image so Docker can use its built-in cache + # Docker on GitHub Actions automatically caches images between runs + echo "Pulling nostr-rs-relay Docker image..." + docker pull scsibug/nostr-rs-relay:latest || { + echo "❌ Failed to pull nostr-rs-relay image" + exit 1 + } + echo "✓ Nostr relay image ready (Docker will cache this for subsequent runs)" + - name: Start local Nostr relay run: | echo "Starting local Docker-based Nostr relay..." diff --git a/BBMTLib/scripts/start-local-relay.sh b/BBMTLib/scripts/start-local-relay.sh index cad1c3b..5be9cee 100755 --- a/BBMTLib/scripts/start-local-relay.sh +++ b/BBMTLib/scripts/start-local-relay.sh @@ -58,12 +58,17 @@ mkdir -p "$DATA_DIR_ABS" chmod 777 "$DATA_DIR_ABS" || true # Pull the latest nostr-rs-relay image (or use a specific tag) -echo "Pulling nostr-rs-relay Docker image..." -docker pull scsibug/nostr-rs-relay:latest || { - echo -e "${YELLOW}Warning: Failed to pull image, trying to build from source...${NC}" - # If pull fails, we could build from source, but for now just exit - exit 1 -} +# Check if image already exists to avoid unnecessary pulls +if docker images --format '{{.Repository}}:{{.Tag}}' | grep -q "^scsibug/nostr-rs-relay:latest$"; then + echo "✓ nostr-rs-relay image already exists, skipping pull" +else + echo "Pulling nostr-rs-relay Docker image..." + docker pull scsibug/nostr-rs-relay:latest || { + echo -e "${YELLOW}Warning: Failed to pull image, trying to build from source...${NC}" + # If pull fails, we could build from source, but for now just exit + exit 1 + } +fi # Start the relay container # Remove :Z flag (SELinux context) as it's not needed in GitHub Actions and can cause issues