From 4cc3c014eefde47f84b337cba431a9615fb11459 Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 29 Apr 2025 09:43:42 -0600 Subject: [PATCH 01/14] web testin --- .github/workflows/web-testing.yml | 182 ++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 .github/workflows/web-testing.yml diff --git a/.github/workflows/web-testing.yml b/.github/workflows/web-testing.yml new file mode 100644 index 000000000..f3e178c26 --- /dev/null +++ b/.github/workflows/web-testing.yml @@ -0,0 +1,182 @@ +name: Web App E2E Testing + +on: + pull_request: + branches: + - main + paths: + - 'web/**' + - '.github/workflows/web_testing.yml' # Also run if the workflow file itself changes + +jobs: + test: + runs-on: blacksmith-16vcpu-ubuntu-2204 # Using a powerful runner as requested + + # Service container for Redis + services: + redis: + image: redis + ports: + - 6379:6379 + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js # Assuming frontend tests use Node + uses: actions/setup-node@v4 + with: + node-version: '20' # Specify your Node version + + - name: Install Supabase CLI + run: npm install --global supabase@latest + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Cache Rust dependencies + uses: Swatinem/rust-cache@v2 + + - name: Install Diesel CLI + run: cargo install diesel_cli --no-default-features --features postgres + + - name: Start Supabase + id: supabase_start + # Supabase start needs Docker + # Run in background, pipe output to file, then process file + run: | + supabase start &> supabase_output.log & + echo "Waiting for Supabase services to initialize..." + sleep 30 # Initial wait time, adjust as needed + + # Wait for DB to be connectable - adjust port if supabase start uses a different default + n=0 + until [ "$n" -ge 30 ] || pg_isready -h 127.0.0.1 -p 54322 -U postgres; do + n=$((n+1)) + echo "Waiting for DB... Attempt $n/30" + sleep 2 + done + if ! pg_isready -h 127.0.0.1 -p 54322 -U postgres; then + echo "::error::Supabase DB did not become ready in time." + cat supabase_output.log + exit 1 + fi + + echo "Supabase services seem ready. Extracting config..." + cat supabase_output.log + + # Extract variables from supabase start output + # These grep patterns might need adjustment based on actual supabase cli output format + echo "DB_URL=$(grep 'DB URL:' supabase_output.log | sed 's/.*DB URL: *//')" >> $GITHUB_ENV + echo "SUPABASE_URL=$(grep 'API URL:' supabase_output.log | sed 's/.*API URL: *//')" >> $GITHUB_ENV + echo "SUPABASE_ANON_KEY=$(grep 'anon key:' supabase_output.log | sed 's/.*anon key: *//')" >> $GITHUB_ENV + echo "SUPABASE_SERVICE_ROLE_KEY=$(grep 'service_role key:' supabase_output.log | sed 's/.*service_role key: *//')" >> $GITHUB_ENV + echo "JWT_SECRET=$(grep 'JWT secret:' supabase_output.log | sed 's/.*JWT secret: *//')" >> $GITHUB_ENV + + # Check if variables were extracted + if [ -z "${DB_URL}" ] || [ -z "${SUPABASE_URL}" ] || [ -z "${SUPABASE_ANON_KEY}" ] || [ -z "${SUPABASE_SERVICE_ROLE_KEY}" ] || [ -z "${JWT_SECRET}" ]; then + echo "::error::Failed to extract Supabase configuration from output." + cat supabase_output.log + exit 1 + fi + + echo "Supabase started and configured." + + - name: Run Migrations + working-directory: ./api + run: diesel migration run + env: + # Use the DB URL extracted from supabase start + DATABASE_URL: ${{ env.DB_URL }} + + - name: Seed Database + run: | + # Extract connection details from DB_URL (format: postgres://USER:PASS@HOST:PORT/DBNAME) + PGUSER=$(echo "${{ env.DB_URL }}" | awk -F '[/:]' '{print $4}') + PGPASSWORD=$(echo "${{ env.DB_URL }}" | awk -F '[:@]' '{print $3}') + PGHOST=$(echo "${{ env.DB_URL }}" | awk -F '[@:]' '{print $4}') + PGPORT=$(echo "${{ env.DB_URL }}" | awk -F '[:/]' '{print $6}') + PGDATABASE=$(echo "${{ env.DB_URL }}" | awk -F '/' '{print $NF}') + + PGPASSWORD=$PGPASSWORD psql -h $PGHOST -p $PGPORT -U $PGUSER -d $PGDATABASE -f ./api/libs/database/seed.sql + env: + DATABASE_URL: ${{ env.DB_URL }} + + - name: Build API Server + working-directory: ./api + run: cargo build --release # Build release for potentially faster execution + + - name: Run API Server + working-directory: ./api + run: ./target/release/server & # Run the built binary in the background + env: + # Core Supabase/DB/Redis vars (Dynamically set) + DATABASE_URL: ${{ env.DB_URL }} + POOLER_URL: ${{ env.DB_URL }} # Uses the same DB URL from supabase start + REDIS_URL: redis://localhost:6379 # Corrected to localhost for service container access from runner + JWT_SECRET: ${{ env.JWT_SECRET }} + SUPABASE_URL: ${{ env.SUPABASE_URL }} + SUPABASE_SERVICE_ROLE_KEY: ${{ env.SUPABASE_SERVICE_ROLE_KEY }} + + # Non-sensitive / Default values + ENVIRONMENT: development + BUSTER_URL: http://localhost:3000 # Assuming frontend runs here + BUSTER_WH_TOKEN: buster-wh-token # Non-sensitive token + LOG_LEVEL: debug # As provided + PORT: 3001 # Default API port + + # Sensitive values from Secrets (Ensure these exist in GitHub Secrets) + OPENAI_API_KEY: ${{ secrets.GH_ACTIONS_OPENAI_API_KEY }} # Use secrets + RESEND_API_KEY: ${{ secrets.GH_ACTIONS_RESEND_API_KEY }} # Use secrets + COHERE_API_KEY: ${{ secrets.GH_ACTIONS_COHERE_API_KEY }} # Use secrets + LLM_API_KEY: ${{ secrets.GH_ACTIONS_LLM_API_KEY }} # Use secrets + LLM_BASE_URL: ${{ secrets.GH_ACTIONS_LLM_BASE_URL }} # Use secrets + + RUST_LOG: ${{ env.LOG_LEVEL }} # Use LOG_LEVEL for RUST_LOG + + - name: Wait for API Server + run: | + echo "Waiting for API server to be ready..." + n=0 + until [ "$n" -ge 30 ] || curl -f http://localhost:3001/health; do + n=$((n+1)) + echo "Waiting for API... Attempt $n/30" + sleep 2 + done + if ! curl -f http://localhost:3001/health; then + echo "::error::API server did not become ready in time." + # Consider fetching logs from the background process if possible + exit 1 + fi + echo "API server is ready." + + # Placeholder for frontend tests + - name: Run Frontend E2E Tests + working-directory: ./web # Assuming tests are run from the web directory + run: | + echo "Running web E2E tests..." + # Add your actual test command here, e.g.: + # npm install + # npm run build # If needed + # npm run test:e2e + env: + # Pass necessary env vars to the frontend tests + NEXT_PUBLIC_API_URL: http://localhost:3001 # API server runs locally in the workflow + NEXT_PUBLIC_URL: http://localhost:3000 # Default from provided env + NEXT_PUBLIC_SUPABASE_URL: ${{ env.SUPABASE_URL }} # Dynamic from supabase start + NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ env.SUPABASE_ANON_KEY }} # Dynamic from supabase start + NEXT_PUBLIC_WEB_SOCKET_URL: ws://localhost:3001 # WS likely points to the API server + # Add any other NEXT_PUBLIC_ or test-specific vars needed + + - name: Stop Supabase + if: always() # Ensure Supabase is stopped even if tests fail + run: supabase stop From 9945d4aa4ec536df2ea7ff63961ee806ec67c9bd Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 29 Apr 2025 08:46:36 -0700 Subject: [PATCH 02/14] Update .github/workflows/web-testing.yml Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- .github/workflows/web-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/web-testing.yml b/.github/workflows/web-testing.yml index f3e178c26..6dbc1b533 100644 --- a/.github/workflows/web-testing.yml +++ b/.github/workflows/web-testing.yml @@ -6,7 +6,7 @@ on: - main paths: - 'web/**' - - '.github/workflows/web_testing.yml' # Also run if the workflow file itself changes + - '.github/workflows/web-testing.yml' # Also run if the workflow file itself changes jobs: test: From 9d6675a643ab91eaa552eae8e96e462a75aabb16 Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 29 Apr 2025 08:46:53 -0700 Subject: [PATCH 03/14] Update .github/workflows/web-testing.yml Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- .github/workflows/web-testing.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/web-testing.yml b/.github/workflows/web-testing.yml index 6dbc1b533..3416f7e66 100644 --- a/.github/workflows/web-testing.yml +++ b/.github/workflows/web-testing.yml @@ -117,7 +117,9 @@ jobs: - name: Run API Server working-directory: ./api - run: ./target/release/server & # Run the built binary in the background + run: | + ./target/release/server & + echo "API_PID=$!" >> $GITHUB_ENV # Store PID for later cleanup env: # Core Supabase/DB/Redis vars (Dynamically set) DATABASE_URL: ${{ env.DB_URL }} From e0da15c05f7a88dc065f7448b157141d40814986 Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 29 Apr 2025 09:51:10 -0600 Subject: [PATCH 04/14] api testing env --- .github/workflows/api-testing.yml | 137 ++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 .github/workflows/api-testing.yml diff --git a/.github/workflows/api-testing.yml b/.github/workflows/api-testing.yml new file mode 100644 index 000000000..f454fd7cf --- /dev/null +++ b/.github/workflows/api-testing.yml @@ -0,0 +1,137 @@ +name: API Testing + +on: + pull_request: + branches: + - main + paths: + - 'api/**' + - '.github/workflows/api-testing.yml' # Also run if the workflow file itself changes + +jobs: + test: + runs-on: blacksmith-16vcpu-ubuntu-2204 # Using a powerful runner as requested + + # Service container for Redis + services: + redis: + image: redis + ports: + - 6379:6379 + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + # Node.js setup removed - not needed for cargo test + + - name: Install Supabase CLI + run: npm install --global supabase@latest + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Cache Rust dependencies + uses: Swatinem/rust-cache@v2 + + - name: Install Diesel CLI + run: cargo install diesel_cli --no-default-features --features postgres + + - name: Start Supabase + id: supabase_start + # Supabase start needs Docker + # Run in background, pipe output to file, then process file + run: | + supabase start &> supabase_output.log & + echo "Waiting for Supabase services to initialize..." + sleep 30 # Initial wait time, adjust as needed + + # Wait for DB to be connectable - adjust port if supabase start uses a different default + n=0 + until [ "$n" -ge 30 ] || pg_isready -h 127.0.0.1 -p 54322 -U postgres; do + n=$((n+1)) + echo "Waiting for DB... Attempt $n/30" + sleep 2 + done + if ! pg_isready -h 127.0.0.1 -p 54322 -U postgres; then + echo "::error::Supabase DB did not become ready in time." + cat supabase_output.log + exit 1 + fi + + echo "Supabase services seem ready. Extracting config..." + cat supabase_output.log + + # Extract variables from supabase start output + # These grep patterns might need adjustment based on actual supabase cli output format + echo "DB_URL=$(grep 'DB URL:' supabase_output.log | sed 's/.*DB URL: *//')" >> $GITHUB_ENV + echo "SUPABASE_URL=$(grep 'API URL:' supabase_output.log | sed 's/.*API URL: *//')" >> $GITHUB_ENV + echo "SUPABASE_ANON_KEY=$(grep 'anon key:' supabase_output.log | sed 's/.*anon key: *//')" >> $GITHUB_ENV + echo "SUPABASE_SERVICE_ROLE_KEY=$(grep 'service_role key:' supabase_output.log | sed 's/.*service_role key: *//')" >> $GITHUB_ENV + echo "JWT_SECRET=$(grep 'JWT secret:' supabase_output.log | sed 's/.*JWT secret: *//')" >> $GITHUB_ENV + + # Check if variables were extracted + if [ -z "${DB_URL}" ] || [ -z "${SUPABASE_URL}" ] || [ -z "${SUPABASE_ANON_KEY}" ] || [ -z "${SUPABASE_SERVICE_ROLE_KEY}" ] || [ -z "${JWT_SECRET}" ]; then + echo "::error::Failed to extract Supabase configuration from output." + cat supabase_output.log + exit 1 + fi + + echo "Supabase started and configured." + + - name: Run Migrations + working-directory: ./api + run: diesel migration run + env: + # Use the DB URL extracted from supabase start + DATABASE_URL: ${{ env.DB_URL }} + + - name: Seed Database + run: | + # Extract connection details from DB_URL (format: postgres://USER:PASS@HOST:PORT/DBNAME) + PGUSER=$(echo "${{ env.DB_URL }}" | awk -F '[/:]' '{print $4}') + PGPASSWORD=$(echo "${{ env.DB_URL }}" | awk -F '[:@]' '{print $3}') + PGHOST=$(echo "${{ env.DB_URL }}" | awk -F '[@:]' '{print $4}') + PGPORT=$(echo "${{ env.DB_URL }}" | awk -F '[:/]' '{print $6}') + PGDATABASE=$(echo "${{ env.DB_URL }}" | awk -F '/' '{print $NF}') + + PGPASSWORD=$PGPASSWORD psql -h $PGHOST -p $PGPORT -U $PGUSER -d $PGDATABASE -f ./api/libs/database/seed.sql + env: + DATABASE_URL: ${{ env.DB_URL }} + + # Removed Build API Server step - cargo test builds implicitly + # Removed Run API Server step - cargo test runs tests directly + # Removed Wait for API Server step - not needed as server isn't run separately + + - name: Run API Tests + working-directory: ./api # Tests run from the api directory + run: cargo test --workspace # Run tests for all packages in the api workspace + env: + # Pass necessary env vars to the tests, using values from supabase start + DATABASE_URL: ${{ env.DB_URL }} + REDIS_URL: redis://localhost:6379 # Connect to the Redis service container + JWT_SECRET: ${{ env.JWT_SECRET }} + SUPABASE_URL: ${{ env.SUPABASE_URL }} + SUPABASE_SERVICE_ROLE_KEY: ${{ env.SUPABASE_SERVICE_ROLE_KEY }} + RUST_LOG: debug # Or adjust as needed + + # Sensitive values from Secrets (Ensure these exist in GitHub Secrets if tests need them) + # Example: needed if tests make external calls + OPENAI_API_KEY: ${{ secrets.GH_ACTIONS_OPENAI_API_KEY }} + RESEND_API_KEY: ${{ secrets.GH_ACTIONS_RESEND_API_KEY }} + COHERE_API_KEY: ${{ secrets.GH_ACTIONS_COHERE_API_KEY }} + LLM_API_KEY: ${{ secrets.GH_ACTIONS_LLM_API_KEY }} + LLM_BASE_URL: ${{ secrets.GH_ACTIONS_LLM_BASE_URL }} + + - name: Stop Supabase + if: always() # Ensure Supabase is stopped even if tests fail + run: supabase stop From 39199e2d5fb7be271825fc93f84a2d97b74bb8b4 Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 29 Apr 2025 09:57:48 -0600 Subject: [PATCH 05/14] modularize the testing a bit... --- .../actions/setup-test-environment/action.yml | 109 +++++++++++ .github/actions/stop-supabase/action.yml | 9 + .github/workflows/api-testing.yml | 111 ++--------- .github/workflows/cli-testing.yml | 81 ++++++++ .github/workflows/web-testing.yml | 174 ++++++------------ 5 files changed, 268 insertions(+), 216 deletions(-) create mode 100644 .github/actions/setup-test-environment/action.yml create mode 100644 .github/actions/stop-supabase/action.yml create mode 100644 .github/workflows/cli-testing.yml diff --git a/.github/actions/setup-test-environment/action.yml b/.github/actions/setup-test-environment/action.yml new file mode 100644 index 000000000..e36ec7d8d --- /dev/null +++ b/.github/actions/setup-test-environment/action.yml @@ -0,0 +1,109 @@ +name: 'Setup Test Environment' +description: 'Installs tools, starts Supabase, runs migrations/seeds, and exports env vars.' + +outputs: + database-url: + description: 'Supabase DB Connection URL' + value: ${{ steps.start_supabase.outputs.db_url }} + supabase-url: + description: 'Supabase API URL' + value: ${{ steps.start_supabase.outputs.supabase_url }} + supabase-anon-key: + description: 'Supabase Anon Key' + value: ${{ steps.start_supabase.outputs.supabase_anon_key }} + supabase-service-role-key: + description: 'Supabase Service Role Key' + value: ${{ steps.start_supabase.outputs.supabase_service_role_key }} + jwt-secret: + description: 'Supabase JWT Secret' + value: ${{ steps.start_supabase.outputs.jwt_secret }} + +runs: + using: "composite" + steps: + - name: Install Supabase CLI + shell: bash + run: npm install --global supabase@latest + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Cache Rust dependencies + uses: Swatinem/rust-cache@v2 + + - name: Install Diesel CLI + shell: bash + run: cargo install diesel_cli --no-default-features --features postgres + + - name: Start Supabase & Set Outputs + id: start_supabase + shell: bash + run: | + supabase start &> supabase_output.log & + echo "Waiting for Supabase services to initialize..." + sleep 30 # Initial wait time, adjust as needed + + # Wait for DB to be connectable + n=0 + until [ "$n" -ge 30 ] || pg_isready -h 127.0.0.1 -p 54322 -U postgres; do + n=$((n+1)) + echo "Waiting for DB... Attempt $n/30" + sleep 2 + done + if ! pg_isready -h 127.0.0.1 -p 54322 -U postgres; then + echo "::error::Supabase DB did not become ready in time." + cat supabase_output.log + exit 1 + fi + + echo "Supabase services seem ready. Extracting config..." + cat supabase_output.log + + # Extract variables and set them as outputs + DB_URL_VAL=$(grep 'DB URL:' supabase_output.log | sed 's/.*DB URL: *//') + SUPABASE_URL_VAL=$(grep 'API URL:' supabase_output.log | sed 's/.*API URL: *//') + SUPABASE_ANON_KEY_VAL=$(grep 'anon key:' supabase_output.log | sed 's/.*anon key: *//') + SUPABASE_SERVICE_ROLE_KEY_VAL=$(grep 'service_role key:' supabase_output.log | sed 's/.*service_role key: *//') + JWT_SECRET_VAL=$(grep 'JWT secret:' supabase_output.log | sed 's/.*JWT secret: *//') + + # Check if variables were extracted + if [ -z "$DB_URL_VAL" ] || [ -z "$SUPABASE_URL_VAL" ] || [ -z "$SUPABASE_ANON_KEY_VAL" ] || [ -z "$SUPABASE_SERVICE_ROLE_KEY_VAL" ] || [ -z "$JWT_SECRET_VAL" ]; then + echo "::error::Failed to extract Supabase configuration from output." + cat supabase_output.log + exit 1 + fi + + echo "::set-output name=db_url::$DB_URL_VAL" + echo "::set-output name=supabase_url::$SUPABASE_URL_VAL" + echo "::set-output name=supabase_anon_key::$SUPABASE_ANON_KEY_VAL" + echo "::set-output name=supabase_service_role_key::$SUPABASE_SERVICE_ROLE_KEY_VAL" + echo "::set-output name=jwt_secret::$JWT_SECRET_VAL" + + echo "Supabase started and configured." + + - name: Run Migrations + working-directory: ./api # Assuming migrations are always relative to api + shell: bash + run: diesel migration run + env: + # Use the output from the previous step + DATABASE_URL: ${{ steps.start_supabase.outputs.db_url }} + + - name: Seed Database + shell: bash + run: | + # Extract connection details from DB_URL + DB_URL_VAL="${{ steps.start_supabase.outputs.db_url }}" + PGUSER=$(echo "$DB_URL_VAL" | awk -F '[/:]' '{print $4}') + PGPASSWORD=$(echo "$DB_URL_VAL" | awk -F '[:@]' '{print $3}') + PGHOST=$(echo "$DB_URL_VAL" | awk -F '[@:]' '{print $4}') + PGPORT=$(echo "$DB_URL_VAL" | awk -F '[:/]' '{print $6}') + PGDATABASE=$(echo "$DB_URL_VAL" | awk -F '/' '{print $NF}') + + PGPASSWORD=$PGPASSWORD psql -h $PGHOST -p $PGPORT -U $PGUSER -d $PGDATABASE -f ./api/libs/database/seed.sql + env: + DATABASE_URL: ${{ steps.start_supabase.outputs.db_url }} \ No newline at end of file diff --git a/.github/actions/stop-supabase/action.yml b/.github/actions/stop-supabase/action.yml new file mode 100644 index 000000000..5119bcdc8 --- /dev/null +++ b/.github/actions/stop-supabase/action.yml @@ -0,0 +1,9 @@ +name: 'Stop Supabase' +description: 'Stops the Supabase local environment.' + +runs: + using: "composite" + steps: + - name: Stop Supabase instance + shell: bash + run: supabase stop \ No newline at end of file diff --git a/.github/workflows/api-testing.yml b/.github/workflows/api-testing.yml index f454fd7cf..34e6cee7c 100644 --- a/.github/workflows/api-testing.yml +++ b/.github/workflows/api-testing.yml @@ -6,13 +6,15 @@ on: - main paths: - 'api/**' - - '.github/workflows/api-testing.yml' # Also run if the workflow file itself changes + - '.github/workflows/api-testing.yml' + - '.github/actions/setup-test-environment/action.yml' # Rerun if common setup changes + - '.github/actions/stop-supabase/action.yml' jobs: test: - runs-on: blacksmith-16vcpu-ubuntu-2204 # Using a powerful runner as requested + runs-on: blacksmith-16vcpu-ubuntu-2204 - # Service container for Redis + # Service container for Redis (needed by the setup action) services: redis: image: redis @@ -28,110 +30,31 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - # Node.js setup removed - not needed for cargo test + # Node.js setup removed - - name: Install Supabase CLI - run: npm install --global supabase@latest - - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - profile: minimal - override: true - - - name: Cache Rust dependencies - uses: Swatinem/rust-cache@v2 - - - name: Install Diesel CLI - run: cargo install diesel_cli --no-default-features --features postgres - - - name: Start Supabase - id: supabase_start - # Supabase start needs Docker - # Run in background, pipe output to file, then process file - run: | - supabase start &> supabase_output.log & - echo "Waiting for Supabase services to initialize..." - sleep 30 # Initial wait time, adjust as needed - - # Wait for DB to be connectable - adjust port if supabase start uses a different default - n=0 - until [ "$n" -ge 30 ] || pg_isready -h 127.0.0.1 -p 54322 -U postgres; do - n=$((n+1)) - echo "Waiting for DB... Attempt $n/30" - sleep 2 - done - if ! pg_isready -h 127.0.0.1 -p 54322 -U postgres; then - echo "::error::Supabase DB did not become ready in time." - cat supabase_output.log - exit 1 - fi - - echo "Supabase services seem ready. Extracting config..." - cat supabase_output.log - - # Extract variables from supabase start output - # These grep patterns might need adjustment based on actual supabase cli output format - echo "DB_URL=$(grep 'DB URL:' supabase_output.log | sed 's/.*DB URL: *//')" >> $GITHUB_ENV - echo "SUPABASE_URL=$(grep 'API URL:' supabase_output.log | sed 's/.*API URL: *//')" >> $GITHUB_ENV - echo "SUPABASE_ANON_KEY=$(grep 'anon key:' supabase_output.log | sed 's/.*anon key: *//')" >> $GITHUB_ENV - echo "SUPABASE_SERVICE_ROLE_KEY=$(grep 'service_role key:' supabase_output.log | sed 's/.*service_role key: *//')" >> $GITHUB_ENV - echo "JWT_SECRET=$(grep 'JWT secret:' supabase_output.log | sed 's/.*JWT secret: *//')" >> $GITHUB_ENV - - # Check if variables were extracted - if [ -z "${DB_URL}" ] || [ -z "${SUPABASE_URL}" ] || [ -z "${SUPABASE_ANON_KEY}" ] || [ -z "${SUPABASE_SERVICE_ROLE_KEY}" ] || [ -z "${JWT_SECRET}" ]; then - echo "::error::Failed to extract Supabase configuration from output." - cat supabase_output.log - exit 1 - fi - - echo "Supabase started and configured." - - - name: Run Migrations - working-directory: ./api - run: diesel migration run - env: - # Use the DB URL extracted from supabase start - DATABASE_URL: ${{ env.DB_URL }} - - - name: Seed Database - run: | - # Extract connection details from DB_URL (format: postgres://USER:PASS@HOST:PORT/DBNAME) - PGUSER=$(echo "${{ env.DB_URL }}" | awk -F '[/:]' '{print $4}') - PGPASSWORD=$(echo "${{ env.DB_URL }}" | awk -F '[:@]' '{print $3}') - PGHOST=$(echo "${{ env.DB_URL }}" | awk -F '[@:]' '{print $4}') - PGPORT=$(echo "${{ env.DB_URL }}" | awk -F '[:/]' '{print $6}') - PGDATABASE=$(echo "${{ env.DB_URL }}" | awk -F '/' '{print $NF}') - - PGPASSWORD=$PGPASSWORD psql -h $PGHOST -p $PGPORT -U $PGUSER -d $PGDATABASE -f ./api/libs/database/seed.sql - env: - DATABASE_URL: ${{ env.DB_URL }} - - # Removed Build API Server step - cargo test builds implicitly - # Removed Run API Server step - cargo test runs tests directly - # Removed Wait for API Server step - not needed as server isn't run separately + - name: Setup Test Environment + id: setup_env # Give an ID to reference outputs + uses: ./.github/actions/setup-test-environment - name: Run API Tests working-directory: ./api # Tests run from the api directory run: cargo test --workspace # Run tests for all packages in the api workspace env: - # Pass necessary env vars to the tests, using values from supabase start - DATABASE_URL: ${{ env.DB_URL }} + # Pass necessary env vars from setup action outputs + DATABASE_URL: ${{ steps.setup_env.outputs.database-url }} REDIS_URL: redis://localhost:6379 # Connect to the Redis service container - JWT_SECRET: ${{ env.JWT_SECRET }} - SUPABASE_URL: ${{ env.SUPABASE_URL }} - SUPABASE_SERVICE_ROLE_KEY: ${{ env.SUPABASE_SERVICE_ROLE_KEY }} + JWT_SECRET: ${{ steps.setup_env.outputs.jwt-secret }} + SUPABASE_URL: ${{ steps.setup_env.outputs.supabase-url }} + SUPABASE_SERVICE_ROLE_KEY: ${{ steps.setup_env.outputs.supabase-service-role-key }} RUST_LOG: debug # Or adjust as needed - # Sensitive values from Secrets (Ensure these exist in GitHub Secrets if tests need them) - # Example: needed if tests make external calls + # Sensitive values from Secrets OPENAI_API_KEY: ${{ secrets.GH_ACTIONS_OPENAI_API_KEY }} RESEND_API_KEY: ${{ secrets.GH_ACTIONS_RESEND_API_KEY }} COHERE_API_KEY: ${{ secrets.GH_ACTIONS_COHERE_API_KEY }} LLM_API_KEY: ${{ secrets.GH_ACTIONS_LLM_API_KEY }} LLM_BASE_URL: ${{ secrets.GH_ACTIONS_LLM_BASE_URL }} - - name: Stop Supabase + - name: Stop Supabase # Use the cleanup action + uses: ./.github/actions/stop-supabase if: always() # Ensure Supabase is stopped even if tests fail - run: supabase stop diff --git a/.github/workflows/cli-testing.yml b/.github/workflows/cli-testing.yml new file mode 100644 index 000000000..ac8caeaad --- /dev/null +++ b/.github/workflows/cli-testing.yml @@ -0,0 +1,81 @@ +name: CLI Testing + +on: + pull_request: + branches: + - main + paths: + - 'cli/**' # Trigger on changes in the cli directory + - '.github/workflows/cli-testing.yml' # Also run if the workflow file itself changes + - '.github/actions/setup-test-environment/action.yml' # Rerun if common setup changes + - '.github/actions/stop-supabase/action.yml' + +jobs: + test: + runs-on: blacksmith-16vcpu-ubuntu-2204 # Using a powerful runner as requested + + # Service container for Redis (needed by the setup action) + services: + redis: + image: redis + ports: + - 6379:6379 + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + # Node.js setup removed - not needed for cargo test + + - name: Install Supabase CLI + run: npm install --global supabase@latest + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Cache Rust dependencies + uses: Swatinem/rust-cache@v2 + # Consider a different cache key if CLI dependencies are separate + # with: + # key: ${{ runner.os }}-cargo-cli-${{ hashFiles('**/cli/Cargo.lock') }} + + - name: Install Diesel CLI + run: cargo install diesel_cli --no-default-features --features postgres + + - name: Setup Test Environment + id: setup_env # Give an ID to reference outputs + uses: ./.github/actions/setup-test-environment + + - name: Run CLI Tests + working-directory: ./cli # Tests run from the cli directory + run: cargo test --workspace # Run tests for all packages in the cli workspace + env: + # Pass necessary env vars from setup action outputs + DATABASE_URL: ${{ steps.setup_env.outputs.database-url }} + REDIS_URL: redis://localhost:6379 # Connect to the Redis service container + JWT_SECRET: ${{ steps.setup_env.outputs.jwt-secret }} + SUPABASE_URL: ${{ steps.setup_env.outputs.supabase-url }} + SUPABASE_SERVICE_ROLE_KEY: ${{ steps.setup_env.outputs.supabase-service-role-key }} + RUST_LOG: debug # Or adjust as needed + + # Add any other environment variables your CLI tests might require + + # Sensitive values from Secrets (if needed by CLI tests) + OPENAI_API_KEY: ${{ secrets.GH_ACTIONS_OPENAI_API_KEY }} + RESEND_API_KEY: ${{ secrets.GH_ACTIONS_RESEND_API_KEY }} + COHERE_API_KEY: ${{ secrets.GH_ACTIONS_COHERE_API_KEY }} + LLM_API_KEY: ${{ secrets.GH_ACTIONS_LLM_API_KEY }} + LLM_BASE_URL: ${{ secrets.GH_ACTIONS_LLM_BASE_URL }} + + - name: Stop Supabase # Use the cleanup action + uses: ./.github/actions/stop-supabase + if: always() # Ensure Supabase is stopped even if tests fail diff --git a/.github/workflows/web-testing.yml b/.github/workflows/web-testing.yml index 3416f7e66..d0a847c2f 100644 --- a/.github/workflows/web-testing.yml +++ b/.github/workflows/web-testing.yml @@ -6,13 +6,15 @@ on: - main paths: - 'web/**' - - '.github/workflows/web-testing.yml' # Also run if the workflow file itself changes + - '.github/workflows/web-testing.yml' + - '.github/actions/setup-test-environment/action.yml' # Rerun if common setup changes + - '.github/actions/stop-supabase/action.yml' jobs: test: - runs-on: blacksmith-16vcpu-ubuntu-2204 # Using a powerful runner as requested - - # Service container for Redis + runs-on: blacksmith-16vcpu-ubuntu-2204 + + # Service container for Redis (needed by the setup action and potentially API) services: redis: image: redis @@ -28,126 +30,54 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Set up Node.js # Assuming frontend tests use Node + - name: Set up Node.js # Still needed for frontend build/test commands uses: actions/setup-node@v4 with: - node-version: '20' # Specify your Node version + node-version: '20' - - name: Install Supabase CLI - run: npm install --global supabase@latest - - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - profile: minimal - override: true - - - name: Cache Rust dependencies - uses: Swatinem/rust-cache@v2 - - - name: Install Diesel CLI - run: cargo install diesel_cli --no-default-features --features postgres - - - name: Start Supabase - id: supabase_start - # Supabase start needs Docker - # Run in background, pipe output to file, then process file - run: | - supabase start &> supabase_output.log & - echo "Waiting for Supabase services to initialize..." - sleep 30 # Initial wait time, adjust as needed - - # Wait for DB to be connectable - adjust port if supabase start uses a different default - n=0 - until [ "$n" -ge 30 ] || pg_isready -h 127.0.0.1 -p 54322 -U postgres; do - n=$((n+1)) - echo "Waiting for DB... Attempt $n/30" - sleep 2 - done - if ! pg_isready -h 127.0.0.1 -p 54322 -U postgres; then - echo "::error::Supabase DB did not become ready in time." - cat supabase_output.log - exit 1 - fi - - echo "Supabase services seem ready. Extracting config..." - cat supabase_output.log - - # Extract variables from supabase start output - # These grep patterns might need adjustment based on actual supabase cli output format - echo "DB_URL=$(grep 'DB URL:' supabase_output.log | sed 's/.*DB URL: *//')" >> $GITHUB_ENV - echo "SUPABASE_URL=$(grep 'API URL:' supabase_output.log | sed 's/.*API URL: *//')" >> $GITHUB_ENV - echo "SUPABASE_ANON_KEY=$(grep 'anon key:' supabase_output.log | sed 's/.*anon key: *//')" >> $GITHUB_ENV - echo "SUPABASE_SERVICE_ROLE_KEY=$(grep 'service_role key:' supabase_output.log | sed 's/.*service_role key: *//')" >> $GITHUB_ENV - echo "JWT_SECRET=$(grep 'JWT secret:' supabase_output.log | sed 's/.*JWT secret: *//')" >> $GITHUB_ENV - - # Check if variables were extracted - if [ -z "${DB_URL}" ] || [ -z "${SUPABASE_URL}" ] || [ -z "${SUPABASE_ANON_KEY}" ] || [ -z "${SUPABASE_SERVICE_ROLE_KEY}" ] || [ -z "${JWT_SECRET}" ]; then - echo "::error::Failed to extract Supabase configuration from output." - cat supabase_output.log - exit 1 - fi - - echo "Supabase started and configured." - - - name: Run Migrations - working-directory: ./api - run: diesel migration run - env: - # Use the DB URL extracted from supabase start - DATABASE_URL: ${{ env.DB_URL }} - - - name: Seed Database - run: | - # Extract connection details from DB_URL (format: postgres://USER:PASS@HOST:PORT/DBNAME) - PGUSER=$(echo "${{ env.DB_URL }}" | awk -F '[/:]' '{print $4}') - PGPASSWORD=$(echo "${{ env.DB_URL }}" | awk -F '[:@]' '{print $3}') - PGHOST=$(echo "${{ env.DB_URL }}" | awk -F '[@:]' '{print $4}') - PGPORT=$(echo "${{ env.DB_URL }}" | awk -F '[:/]' '{print $6}') - PGDATABASE=$(echo "${{ env.DB_URL }}" | awk -F '/' '{print $NF}') - - PGPASSWORD=$PGPASSWORD psql -h $PGHOST -p $PGPORT -U $PGUSER -d $PGDATABASE -f ./api/libs/database/seed.sql - env: - DATABASE_URL: ${{ env.DB_URL }} + - name: Setup Test Environment + id: setup_env # Give an ID to reference outputs + uses: ./.github/actions/setup-test-environment + # Build/Run/Wait steps remain for web testing as it needs the API server running - name: Build API Server working-directory: ./api - run: cargo build --release # Build release for potentially faster execution + run: cargo build --release + env: + # Potentially needed if build process requires env vars, though unlikely + DATABASE_URL: ${{ steps.setup_env.outputs.database-url }} - name: Run API Server working-directory: ./api - run: | - ./target/release/server & - echo "API_PID=$!" >> $GITHUB_ENV # Store PID for later cleanup + run: ./target/release/server & # Run in background env: - # Core Supabase/DB/Redis vars (Dynamically set) - DATABASE_URL: ${{ env.DB_URL }} - POOLER_URL: ${{ env.DB_URL }} # Uses the same DB URL from supabase start - REDIS_URL: redis://localhost:6379 # Corrected to localhost for service container access from runner - JWT_SECRET: ${{ env.JWT_SECRET }} - SUPABASE_URL: ${{ env.SUPABASE_URL }} - SUPABASE_SERVICE_ROLE_KEY: ${{ env.SUPABASE_SERVICE_ROLE_KEY }} - + # Core Supabase/DB/Redis vars from setup action outputs + DATABASE_URL: ${{ steps.setup_env.outputs.database-url }} + POOLER_URL: ${{ steps.setup_env.outputs.database-url }} # Assuming pooler uses same DB + REDIS_URL: redis://localhost:6379 # Use localhost as it runs on the runner accessing the service + JWT_SECRET: ${{ steps.setup_env.outputs.jwt-secret }} + SUPABASE_URL: ${{ steps.setup_env.outputs.supabase-url }} + SUPABASE_SERVICE_ROLE_KEY: ${{ steps.setup_env.outputs.supabase-service-role-key }} + # Non-sensitive / Default values ENVIRONMENT: development - BUSTER_URL: http://localhost:3000 # Assuming frontend runs here - BUSTER_WH_TOKEN: buster-wh-token # Non-sensitive token - LOG_LEVEL: debug # As provided - PORT: 3001 # Default API port + BUSTER_URL: http://localhost:3000 + BUSTER_WH_TOKEN: buster-wh-token + LOG_LEVEL: debug + PORT: 3001 # API server port + RUST_LOG: debug - # Sensitive values from Secrets (Ensure these exist in GitHub Secrets) - OPENAI_API_KEY: ${{ secrets.GH_ACTIONS_OPENAI_API_KEY }} # Use secrets - RESEND_API_KEY: ${{ secrets.GH_ACTIONS_RESEND_API_KEY }} # Use secrets - COHERE_API_KEY: ${{ secrets.GH_ACTIONS_COHERE_API_KEY }} # Use secrets - LLM_API_KEY: ${{ secrets.GH_ACTIONS_LLM_API_KEY }} # Use secrets - LLM_BASE_URL: ${{ secrets.GH_ACTIONS_LLM_BASE_URL }} # Use secrets + # Sensitive values from Secrets + OPENAI_API_KEY: ${{ secrets.GH_ACTIONS_OPENAI_API_KEY }} + RESEND_API_KEY: ${{ secrets.GH_ACTIONS_RESEND_API_KEY }} + COHERE_API_KEY: ${{ secrets.GH_ACTIONS_COHERE_API_KEY }} + LLM_API_KEY: ${{ secrets.GH_ACTIONS_LLM_API_KEY }} + LLM_BASE_URL: ${{ secrets.GH_ACTIONS_LLM_BASE_URL }} - RUST_LOG: ${{ env.LOG_LEVEL }} # Use LOG_LEVEL for RUST_LOG - name: Wait for API Server run: | - echo "Waiting for API server to be ready..." + echo "Waiting for API server (localhost:3001) to be ready..." n=0 until [ "$n" -ge 30 ] || curl -f http://localhost:3001/health; do n=$((n+1)) @@ -156,29 +86,29 @@ jobs: done if ! curl -f http://localhost:3001/health; then echo "::error::API server did not become ready in time." - # Consider fetching logs from the background process if possible exit 1 fi echo "API server is ready." - # Placeholder for frontend tests - name: Run Frontend E2E Tests - working-directory: ./web # Assuming tests are run from the web directory + working-directory: ./web run: | echo "Running web E2E tests..." # Add your actual test command here, e.g.: - # npm install - # npm run build # If needed - # npm run test:e2e + npm install # Or yarn install, pnpm install + npm run build # If needed + npm run test:e2e env: - # Pass necessary env vars to the frontend tests - NEXT_PUBLIC_API_URL: http://localhost:3001 # API server runs locally in the workflow - NEXT_PUBLIC_URL: http://localhost:3000 # Default from provided env - NEXT_PUBLIC_SUPABASE_URL: ${{ env.SUPABASE_URL }} # Dynamic from supabase start - NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ env.SUPABASE_ANON_KEY }} # Dynamic from supabase start - NEXT_PUBLIC_WEB_SOCKET_URL: ws://localhost:3001 # WS likely points to the API server - # Add any other NEXT_PUBLIC_ or test-specific vars needed + # API runs on localhost within the runner + NEXT_PUBLIC_API_URL: http://localhost:3001 + NEXT_PUBLIC_URL: http://localhost:3000 # Assuming default URL for the app itself + # Use Supabase details from the setup action outputs + NEXT_PUBLIC_SUPABASE_URL: ${{ steps.setup_env.outputs.supabase-url }} + NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ steps.setup_env.outputs.supabase-anon-key }} + NEXT_PUBLIC_WEB_SOCKET_URL: ws://localhost:3001 # Assuming WS connects to API - - name: Stop Supabase + # Pass any other required NEXT_PUBLIC_ variables + + - name: Stop Supabase # Use the cleanup action + uses: ./.github/actions/stop-supabase if: always() # Ensure Supabase is stopped even if tests fail - run: supabase stop From 5385d76d11a03e4345d0da45aef66ac888abf580 Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 29 Apr 2025 09:00:12 -0700 Subject: [PATCH 06/14] Update .github/actions/stop-supabase/action.yml Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- .github/actions/stop-supabase/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/stop-supabase/action.yml b/.github/actions/stop-supabase/action.yml index 5119bcdc8..6888c5a03 100644 --- a/.github/actions/stop-supabase/action.yml +++ b/.github/actions/stop-supabase/action.yml @@ -6,4 +6,4 @@ runs: steps: - name: Stop Supabase instance shell: bash - run: supabase stop \ No newline at end of file + run: supabase stop --no-backup \ No newline at end of file From 6d0b7b4f208a6f63e87d96cd035eab8ac6a26af8 Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 29 Apr 2025 09:00:36 -0700 Subject: [PATCH 07/14] Update .github/actions/setup-test-environment/action.yml Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- .github/actions/setup-test-environment/action.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/actions/setup-test-environment/action.yml b/.github/actions/setup-test-environment/action.yml index e36ec7d8d..2ef053fc8 100644 --- a/.github/actions/setup-test-environment/action.yml +++ b/.github/actions/setup-test-environment/action.yml @@ -77,11 +77,11 @@ runs: exit 1 fi - echo "::set-output name=db_url::$DB_URL_VAL" - echo "::set-output name=supabase_url::$SUPABASE_URL_VAL" - echo "::set-output name=supabase_anon_key::$SUPABASE_ANON_KEY_VAL" - echo "::set-output name=supabase_service_role_key::$SUPABASE_SERVICE_ROLE_KEY_VAL" - echo "::set-output name=jwt_secret::$JWT_SECRET_VAL" + echo "db_url=$DB_URL_VAL" >> $GITHUB_OUTPUT + echo "supabase_url=$SUPABASE_URL_VAL" >> $GITHUB_OUTPUT + echo "supabase_anon_key=$SUPABASE_ANON_KEY_VAL" >> $GITHUB_OUTPUT + echo "supabase_service_role_key=$SUPABASE_SERVICE_ROLE_KEY_VAL" >> $GITHUB_OUTPUT + echo "jwt_secret=$JWT_SECRET_VAL" >> $GITHUB_OUTPUT echo "Supabase started and configured." From a735c8bc57e08ba29c0b0eb9a62fdc7cf14b8eab Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 29 Apr 2025 09:00:43 -0700 Subject: [PATCH 08/14] Update .github/workflows/web-testing.yml Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- .github/workflows/web-testing.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/web-testing.yml b/.github/workflows/web-testing.yml index d0a847c2f..f65754e8e 100644 --- a/.github/workflows/web-testing.yml +++ b/.github/workflows/web-testing.yml @@ -49,7 +49,9 @@ jobs: - name: Run API Server working-directory: ./api - run: ./target/release/server & # Run in background + run: | + ./target/release/server & # Run in background + echo $! > /tmp/api-server.pid # Store PID for later cleanup env: # Core Supabase/DB/Redis vars from setup action outputs DATABASE_URL: ${{ steps.setup_env.outputs.database-url }} From 0c5c9eafff788a442316d4a5a47e9f76c500723c Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 29 Apr 2025 10:12:27 -0600 Subject: [PATCH 09/14] ok trying again with env setup --- .../actions/setup-test-environment/action.yml | 94 +++++-------------- .github/workflows/api-testing.yml | 11 +-- .github/workflows/cli-testing.yml | 37 +------- .github/workflows/web-testing.yml | 22 ++--- 4 files changed, 42 insertions(+), 122 deletions(-) diff --git a/.github/actions/setup-test-environment/action.yml b/.github/actions/setup-test-environment/action.yml index 2ef053fc8..6d094b67d 100644 --- a/.github/actions/setup-test-environment/action.yml +++ b/.github/actions/setup-test-environment/action.yml @@ -1,29 +1,13 @@ name: 'Setup Test Environment' -description: 'Installs tools, starts Supabase, runs migrations/seeds, and exports env vars.' - -outputs: - database-url: - description: 'Supabase DB Connection URL' - value: ${{ steps.start_supabase.outputs.db_url }} - supabase-url: - description: 'Supabase API URL' - value: ${{ steps.start_supabase.outputs.supabase_url }} - supabase-anon-key: - description: 'Supabase Anon Key' - value: ${{ steps.start_supabase.outputs.supabase_anon_key }} - supabase-service-role-key: - description: 'Supabase Service Role Key' - value: ${{ steps.start_supabase.outputs.supabase_service_role_key }} - jwt-secret: - description: 'Supabase JWT Secret' - value: ${{ steps.start_supabase.outputs.jwt_secret }} +description: 'Installs tools, starts Supabase, runs migrations, and seeds the database.' runs: using: "composite" steps: - - name: Install Supabase CLI - shell: bash - run: npm install --global supabase@latest + - name: Setup Supabase CLI + uses: supabase/setup-cli@v1 + with: + version: latest # Or pin to a specific version - name: Install Rust uses: actions-rs/toolchain@v1 @@ -39,71 +23,37 @@ runs: shell: bash run: cargo install diesel_cli --no-default-features --features postgres - - name: Start Supabase & Set Outputs - id: start_supabase + - name: Start Supabase shell: bash run: | - supabase start &> supabase_output.log & - echo "Waiting for Supabase services to initialize..." - sleep 30 # Initial wait time, adjust as needed + echo "Starting Supabase..." + supabase start - # Wait for DB to be connectable - n=0 - until [ "$n" -ge 30 ] || pg_isready -h 127.0.0.1 -p 54322 -U postgres; do - n=$((n+1)) - echo "Waiting for DB... Attempt $n/30" - sleep 2 - done - if ! pg_isready -h 127.0.0.1 -p 54322 -U postgres; then - echo "::error::Supabase DB did not become ready in time." - cat supabase_output.log + echo "Waiting a bit for services to stabilize after start..." + sleep 15 # Adjust if needed, Supabase start should block but sometimes a small delay helps + + echo "Checking Supabase status..." + supabase status + if [ $? -ne 0 ]; then + echo "::error::Supabase failed to start correctly." + # Attempt to fetch logs if possible (might not be available easily with setup-cli) + # supabase logs --project-ref local # This might need project-ref exit 1 fi - echo "Supabase services seem ready. Extracting config..." - cat supabase_output.log - - # Extract variables and set them as outputs - DB_URL_VAL=$(grep 'DB URL:' supabase_output.log | sed 's/.*DB URL: *//') - SUPABASE_URL_VAL=$(grep 'API URL:' supabase_output.log | sed 's/.*API URL: *//') - SUPABASE_ANON_KEY_VAL=$(grep 'anon key:' supabase_output.log | sed 's/.*anon key: *//') - SUPABASE_SERVICE_ROLE_KEY_VAL=$(grep 'service_role key:' supabase_output.log | sed 's/.*service_role key: *//') - JWT_SECRET_VAL=$(grep 'JWT secret:' supabase_output.log | sed 's/.*JWT secret: *//') - - # Check if variables were extracted - if [ -z "$DB_URL_VAL" ] || [ -z "$SUPABASE_URL_VAL" ] || [ -z "$SUPABASE_ANON_KEY_VAL" ] || [ -z "$SUPABASE_SERVICE_ROLE_KEY_VAL" ] || [ -z "$JWT_SECRET_VAL" ]; then - echo "::error::Failed to extract Supabase configuration from output." - cat supabase_output.log - exit 1 - fi - - echo "db_url=$DB_URL_VAL" >> $GITHUB_OUTPUT - echo "supabase_url=$SUPABASE_URL_VAL" >> $GITHUB_OUTPUT - echo "supabase_anon_key=$SUPABASE_ANON_KEY_VAL" >> $GITHUB_OUTPUT - echo "supabase_service_role_key=$SUPABASE_SERVICE_ROLE_KEY_VAL" >> $GITHUB_OUTPUT - echo "jwt_secret=$JWT_SECRET_VAL" >> $GITHUB_OUTPUT - - echo "Supabase started and configured." + echo "Supabase started." - name: Run Migrations working-directory: ./api # Assuming migrations are always relative to api shell: bash run: diesel migration run env: - # Use the output from the previous step - DATABASE_URL: ${{ steps.start_supabase.outputs.db_url }} + DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres - name: Seed Database shell: bash run: | - # Extract connection details from DB_URL - DB_URL_VAL="${{ steps.start_supabase.outputs.db_url }}" - PGUSER=$(echo "$DB_URL_VAL" | awk -F '[/:]' '{print $4}') - PGPASSWORD=$(echo "$DB_URL_VAL" | awk -F '[:@]' '{print $3}') - PGHOST=$(echo "$DB_URL_VAL" | awk -F '[@:]' '{print $4}') - PGPORT=$(echo "$DB_URL_VAL" | awk -F '[:/]' '{print $6}') - PGDATABASE=$(echo "$DB_URL_VAL" | awk -F '/' '{print $NF}') - - PGPASSWORD=$PGPASSWORD psql -h $PGHOST -p $PGPORT -U $PGUSER -d $PGDATABASE -f ./api/libs/database/seed.sql + # Use hardcoded default credentials for local Supabase + PGPASSWORD=postgres psql -h 127.0.0.1 -p 54322 -U postgres -d postgres -f ./api/libs/database/seed.sql env: - DATABASE_URL: ${{ steps.start_supabase.outputs.db_url }} \ No newline at end of file + DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres # Also set here just in case seed script needs it \ No newline at end of file diff --git a/.github/workflows/api-testing.yml b/.github/workflows/api-testing.yml index 34e6cee7c..b22a5e3ca 100644 --- a/.github/workflows/api-testing.yml +++ b/.github/workflows/api-testing.yml @@ -33,19 +33,18 @@ jobs: # Node.js setup removed - name: Setup Test Environment - id: setup_env # Give an ID to reference outputs uses: ./.github/actions/setup-test-environment - name: Run API Tests working-directory: ./api # Tests run from the api directory run: cargo test --workspace # Run tests for all packages in the api workspace env: - # Pass necessary env vars from setup action outputs - DATABASE_URL: ${{ steps.setup_env.outputs.database-url }} + # Use hardcoded default values and secrets + DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres REDIS_URL: redis://localhost:6379 # Connect to the Redis service container - JWT_SECRET: ${{ steps.setup_env.outputs.jwt-secret }} - SUPABASE_URL: ${{ steps.setup_env.outputs.supabase-url }} - SUPABASE_SERVICE_ROLE_KEY: ${{ steps.setup_env.outputs.supabase-service-role-key }} + JWT_SECRET: ${{ secrets.GH_ACTIONS_SUPABASE_JWT_SECRET }} # Use secret + SUPABASE_URL: http://127.0.0.1:54321 # Default local URL + SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.GH_ACTIONS_SUPABASE_SERVICE_ROLE_KEY }} # Use secret RUST_LOG: debug # Or adjust as needed # Sensitive values from Secrets diff --git a/.github/workflows/cli-testing.yml b/.github/workflows/cli-testing.yml index ac8caeaad..02252cd48 100644 --- a/.github/workflows/cli-testing.yml +++ b/.github/workflows/cli-testing.yml @@ -32,50 +32,23 @@ jobs: # Node.js setup removed - not needed for cargo test - - name: Install Supabase CLI - run: npm install --global supabase@latest - - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - profile: minimal - override: true - - - name: Cache Rust dependencies - uses: Swatinem/rust-cache@v2 - # Consider a different cache key if CLI dependencies are separate - # with: - # key: ${{ runner.os }}-cargo-cli-${{ hashFiles('**/cli/Cargo.lock') }} - - - name: Install Diesel CLI - run: cargo install diesel_cli --no-default-features --features postgres - - name: Setup Test Environment - id: setup_env # Give an ID to reference outputs uses: ./.github/actions/setup-test-environment - name: Run CLI Tests working-directory: ./cli # Tests run from the cli directory run: cargo test --workspace # Run tests for all packages in the cli workspace env: - # Pass necessary env vars from setup action outputs - DATABASE_URL: ${{ steps.setup_env.outputs.database-url }} + # Use hardcoded default values and secrets + DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres REDIS_URL: redis://localhost:6379 # Connect to the Redis service container - JWT_SECRET: ${{ steps.setup_env.outputs.jwt-secret }} - SUPABASE_URL: ${{ steps.setup_env.outputs.supabase-url }} - SUPABASE_SERVICE_ROLE_KEY: ${{ steps.setup_env.outputs.supabase-service-role-key }} + JWT_SECRET: ${{ secrets.GH_ACTIONS_SUPABASE_JWT_SECRET }} # Use secret + SUPABASE_URL: http://127.0.0.1:54321 # Default local URL + SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.GH_ACTIONS_SUPABASE_SERVICE_ROLE_KEY }} # Use secret RUST_LOG: debug # Or adjust as needed # Add any other environment variables your CLI tests might require - # Sensitive values from Secrets (if needed by CLI tests) - OPENAI_API_KEY: ${{ secrets.GH_ACTIONS_OPENAI_API_KEY }} - RESEND_API_KEY: ${{ secrets.GH_ACTIONS_RESEND_API_KEY }} - COHERE_API_KEY: ${{ secrets.GH_ACTIONS_COHERE_API_KEY }} - LLM_API_KEY: ${{ secrets.GH_ACTIONS_LLM_API_KEY }} - LLM_BASE_URL: ${{ secrets.GH_ACTIONS_LLM_BASE_URL }} - - name: Stop Supabase # Use the cleanup action uses: ./.github/actions/stop-supabase if: always() # Ensure Supabase is stopped even if tests fail diff --git a/.github/workflows/web-testing.yml b/.github/workflows/web-testing.yml index f65754e8e..07d24c6b0 100644 --- a/.github/workflows/web-testing.yml +++ b/.github/workflows/web-testing.yml @@ -36,7 +36,6 @@ jobs: node-version: '20' - name: Setup Test Environment - id: setup_env # Give an ID to reference outputs uses: ./.github/actions/setup-test-environment # Build/Run/Wait steps remain for web testing as it needs the API server running @@ -45,7 +44,7 @@ jobs: run: cargo build --release env: # Potentially needed if build process requires env vars, though unlikely - DATABASE_URL: ${{ steps.setup_env.outputs.database-url }} + DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres - name: Run API Server working-directory: ./api @@ -53,13 +52,13 @@ jobs: ./target/release/server & # Run in background echo $! > /tmp/api-server.pid # Store PID for later cleanup env: - # Core Supabase/DB/Redis vars from setup action outputs - DATABASE_URL: ${{ steps.setup_env.outputs.database-url }} - POOLER_URL: ${{ steps.setup_env.outputs.database-url }} # Assuming pooler uses same DB + # Core Supabase/DB/Redis vars - use hardcoded values and secrets + DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres + POOLER_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres # Assuming pooler uses same DB REDIS_URL: redis://localhost:6379 # Use localhost as it runs on the runner accessing the service - JWT_SECRET: ${{ steps.setup_env.outputs.jwt-secret }} - SUPABASE_URL: ${{ steps.setup_env.outputs.supabase-url }} - SUPABASE_SERVICE_ROLE_KEY: ${{ steps.setup_env.outputs.supabase-service-role-key }} + JWT_SECRET: ${{ secrets.GH_ACTIONS_SUPABASE_JWT_SECRET }} # Use secret + SUPABASE_URL: http://127.0.0.1:54321 # Default local URL + SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.GH_ACTIONS_SUPABASE_SERVICE_ROLE_KEY }} # Use secret # Non-sensitive / Default values ENVIRONMENT: development @@ -76,7 +75,6 @@ jobs: LLM_API_KEY: ${{ secrets.GH_ACTIONS_LLM_API_KEY }} LLM_BASE_URL: ${{ secrets.GH_ACTIONS_LLM_BASE_URL }} - - name: Wait for API Server run: | echo "Waiting for API server (localhost:3001) to be ready..." @@ -104,9 +102,9 @@ jobs: # API runs on localhost within the runner NEXT_PUBLIC_API_URL: http://localhost:3001 NEXT_PUBLIC_URL: http://localhost:3000 # Assuming default URL for the app itself - # Use Supabase details from the setup action outputs - NEXT_PUBLIC_SUPABASE_URL: ${{ steps.setup_env.outputs.supabase-url }} - NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ steps.setup_env.outputs.supabase-anon-key }} + # Use Supabase details - default URL and secret anon key + NEXT_PUBLIC_SUPABASE_URL: http://127.0.0.1:54321 # Default local URL + NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.GH_ACTIONS_SUPABASE_ANON_KEY }} # Use secret NEXT_PUBLIC_WEB_SOCKET_URL: ws://localhost:3001 # Assuming WS connects to API # Pass any other required NEXT_PUBLIC_ variables From 19eea365a4496f227aec2ac114be98868ee3e0e1 Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 29 Apr 2025 10:37:37 -0600 Subject: [PATCH 10/14] api, cli, web, tsting env and some rust fixes --- .github/workflows/api-testing.yml | 5 +- .github/workflows/cli-testing.yml | 5 +- .github/workflows/web-testing.yml | 7 +- api/libs/database/tests/common/assets.rs | 111 +++++++++--------- api/libs/database/tests/common/db.rs | 1 + .../tests/metrics/update_metric_test.rs | 1 + 6 files changed, 69 insertions(+), 61 deletions(-) diff --git a/.github/workflows/api-testing.yml b/.github/workflows/api-testing.yml index b22a5e3ca..1da9b483b 100644 --- a/.github/workflows/api-testing.yml +++ b/.github/workflows/api-testing.yml @@ -13,6 +13,7 @@ on: jobs: test: runs-on: blacksmith-16vcpu-ubuntu-2204 + environment: testing # Service container for Redis (needed by the setup action) services: @@ -42,9 +43,9 @@ jobs: # Use hardcoded default values and secrets DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres REDIS_URL: redis://localhost:6379 # Connect to the Redis service container - JWT_SECRET: ${{ secrets.GH_ACTIONS_SUPABASE_JWT_SECRET }} # Use secret + JWT_SECRET: 'super-secret-jwt-token-with-at-least-32-characters-long' # Use default local value SUPABASE_URL: http://127.0.0.1:54321 # Default local URL - SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.GH_ACTIONS_SUPABASE_SERVICE_ROLE_KEY }} # Use secret + SUPABASE_SERVICE_ROLE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' # Use default local value RUST_LOG: debug # Or adjust as needed # Sensitive values from Secrets diff --git a/.github/workflows/cli-testing.yml b/.github/workflows/cli-testing.yml index 02252cd48..2e9939775 100644 --- a/.github/workflows/cli-testing.yml +++ b/.github/workflows/cli-testing.yml @@ -13,6 +13,7 @@ on: jobs: test: runs-on: blacksmith-16vcpu-ubuntu-2204 # Using a powerful runner as requested + environment: testing # Add the environment key # Service container for Redis (needed by the setup action) services: @@ -42,9 +43,9 @@ jobs: # Use hardcoded default values and secrets DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres REDIS_URL: redis://localhost:6379 # Connect to the Redis service container - JWT_SECRET: ${{ secrets.GH_ACTIONS_SUPABASE_JWT_SECRET }} # Use secret + JWT_SECRET: 'super-secret-jwt-token-with-at-least-32-characters-long' # Use default local value SUPABASE_URL: http://127.0.0.1:54321 # Default local URL - SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.GH_ACTIONS_SUPABASE_SERVICE_ROLE_KEY }} # Use secret + SUPABASE_SERVICE_ROLE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' # Use default local value RUST_LOG: debug # Or adjust as needed # Add any other environment variables your CLI tests might require diff --git a/.github/workflows/web-testing.yml b/.github/workflows/web-testing.yml index 07d24c6b0..9b69b8436 100644 --- a/.github/workflows/web-testing.yml +++ b/.github/workflows/web-testing.yml @@ -13,6 +13,7 @@ on: jobs: test: runs-on: blacksmith-16vcpu-ubuntu-2204 + environment: testing # Service container for Redis (needed by the setup action and potentially API) services: @@ -56,9 +57,9 @@ jobs: DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres POOLER_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres # Assuming pooler uses same DB REDIS_URL: redis://localhost:6379 # Use localhost as it runs on the runner accessing the service - JWT_SECRET: ${{ secrets.GH_ACTIONS_SUPABASE_JWT_SECRET }} # Use secret + JWT_SECRET: 'super-secret-jwt-token-with-at-least-32-characters-long' # Use default local value SUPABASE_URL: http://127.0.0.1:54321 # Default local URL - SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.GH_ACTIONS_SUPABASE_SERVICE_ROLE_KEY }} # Use secret + SUPABASE_SERVICE_ROLE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' # Use default local value # Non-sensitive / Default values ENVIRONMENT: development @@ -104,7 +105,7 @@ jobs: NEXT_PUBLIC_URL: http://localhost:3000 # Assuming default URL for the app itself # Use Supabase details - default URL and secret anon key NEXT_PUBLIC_SUPABASE_URL: http://127.0.0.1:54321 # Default local URL - NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.GH_ACTIONS_SUPABASE_ANON_KEY }} # Use secret + NEXT_PUBLIC_SUPABASE_ANON_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODIzNDMwOTZ9.7UIsMFfHYKxH7bUJCRfxd6lr7CSXGF7UxtZQO10FMMo' # Use default local value NEXT_PUBLIC_WEB_SOCKET_URL: ws://localhost:3001 # Assuming WS connects to API # Pass any other required NEXT_PUBLIC_ variables diff --git a/api/libs/database/tests/common/assets.rs b/api/libs/database/tests/common/assets.rs index 46f6dfee1..ce740efcc 100644 --- a/api/libs/database/tests/common/assets.rs +++ b/api/libs/database/tests/common/assets.rs @@ -3,12 +3,14 @@ use chrono::Utc; use database::enums::{AssetPermissionRole, AssetType, Verification}; use database::models::{Chat, Collection, DashboardFile, MetricFile}; use database::schema::{chats, collections, dashboard_files, metric_files}; +use database::types::metric_yml::{ + BarAndLineAxis, BarLineChartConfig, BaseChartConfig, ChartConfig, +}; use database::types::{DashboardYml, MetricYml, VersionHistory}; -use database::types::metric_yml::{BaseChartConfig, BarAndLineAxis, BarLineChartConfig, ChartConfig}; use diesel_async::RunQueryDsl; use indexmap; -use uuid::Uuid; use std::collections::HashMap; +use uuid::Uuid; use crate::common::db::TestDb; use crate::common::permissions::PermissionTestHelpers; @@ -18,13 +20,10 @@ pub struct AssetTestHelpers; impl AssetTestHelpers { /// Creates a test metric file - pub async fn create_test_metric( - test_db: &TestDb, - name: &str, - ) -> Result { + pub async fn create_test_metric(test_db: &TestDb, name: &str) -> Result { let mut conn = test_db.diesel_conn().await?; let metric_id = Uuid::new_v4(); - + // Create a simple metric content let content = MetricYml { name: name.to_string(), @@ -34,11 +33,15 @@ impl AssetTestHelpers { chart_config: create_default_chart_config(), dataset_ids: Vec::new(), }; - + let metric_file = MetricFile { id: metric_id, name: format!("{}-{}", test_db.test_id, name), - file_name: format!("{}-{}.yml", test_db.test_id, name.to_lowercase().replace(" ", "_")), + file_name: format!( + "{}-{}.yml", + test_db.test_id, + name.to_lowercase().replace(" ", "_") + ), content, verification: Verification::Verified, evaluation_obj: None, @@ -56,34 +59,35 @@ impl AssetTestHelpers { data_metadata: None, public_password: None, }; - + diesel::insert_into(metric_files::table) .values(&metric_file) .execute(&mut conn) .await?; - + Ok(metric_file) } - + /// Creates a test dashboard file - pub async fn create_test_dashboard( - test_db: &TestDb, - name: &str, - ) -> Result { + pub async fn create_test_dashboard(test_db: &TestDb, name: &str) -> Result { let mut conn = test_db.diesel_conn().await?; let dashboard_id = Uuid::new_v4(); - + // Create a simple dashboard content let content = DashboardYml { name: name.to_string(), description: Some(format!("Test dashboard description for {}", name)), rows: Vec::new(), }; - + let dashboard_file = DashboardFile { id: dashboard_id, name: format!("{}-{}", test_db.test_id, name), - file_name: format!("{}-{}.yml", test_db.test_id, name.to_lowercase().replace(" ", "_")), + file_name: format!( + "{}-{}.yml", + test_db.test_id, + name.to_lowercase().replace(" ", "_") + ), content, filter: None, organization_id: test_db.organization_id, @@ -97,23 +101,20 @@ impl AssetTestHelpers { version_history: VersionHistory(HashMap::new()), public_password: None, }; - + diesel::insert_into(dashboard_files::table) .values(&dashboard_file) .execute(&mut conn) .await?; - + Ok(dashboard_file) } - + /// Creates a test collection - pub async fn create_test_collection( - test_db: &TestDb, - name: &str, - ) -> Result { + pub async fn create_test_collection(test_db: &TestDb, name: &str) -> Result { let mut conn = test_db.diesel_conn().await?; let collection_id = Uuid::new_v4(); - + let collection = Collection { id: collection_id, name: format!("{}-{}", test_db.test_id, name), @@ -125,23 +126,20 @@ impl AssetTestHelpers { deleted_at: None, organization_id: test_db.organization_id, }; - + diesel::insert_into(collections::table) .values(&collection) .execute(&mut conn) .await?; - + Ok(collection) } - + /// Creates a test chat - pub async fn create_test_chat( - test_db: &TestDb, - title: &str, - ) -> Result { + pub async fn create_test_chat(test_db: &TestDb, title: &str) -> Result { let mut conn = test_db.diesel_conn().await?; let chat_id = Uuid::new_v4(); - + let chat = Chat { id: chat_id, title: format!("{}-{}", test_db.test_id, title), @@ -156,16 +154,17 @@ impl AssetTestHelpers { public_expiry_date: None, most_recent_file_id: None, most_recent_file_type: None, + most_recent_version_number: None, }; - + diesel::insert_into(chats::table) .values(&chat) .execute(&mut conn) .await?; - + Ok(chat) } - + /// Creates a test metric with owner permission pub async fn create_test_metric_with_permission( test_db: &TestDb, @@ -174,7 +173,7 @@ impl AssetTestHelpers { role: AssetPermissionRole, ) -> Result { let metric = Self::create_test_metric(test_db, name).await?; - + // Add permission PermissionTestHelpers::create_user_permission( test_db, @@ -182,11 +181,12 @@ impl AssetTestHelpers { AssetType::MetricFile, user_id, role, - ).await?; - + ) + .await?; + Ok(metric) } - + /// Creates a test dashboard with owner permission pub async fn create_test_dashboard_with_permission( test_db: &TestDb, @@ -195,7 +195,7 @@ impl AssetTestHelpers { role: AssetPermissionRole, ) -> Result { let dashboard = Self::create_test_dashboard(test_db, name).await?; - + // Add permission PermissionTestHelpers::create_user_permission( test_db, @@ -203,11 +203,12 @@ impl AssetTestHelpers { AssetType::DashboardFile, user_id, role, - ).await?; - + ) + .await?; + Ok(dashboard) } - + /// Creates a test collection with owner permission pub async fn create_test_collection_with_permission( test_db: &TestDb, @@ -216,7 +217,7 @@ impl AssetTestHelpers { role: AssetPermissionRole, ) -> Result { let collection = Self::create_test_collection(test_db, name).await?; - + // Add permission PermissionTestHelpers::create_user_permission( test_db, @@ -224,11 +225,12 @@ impl AssetTestHelpers { AssetType::Collection, user_id, role, - ).await?; - + ) + .await?; + Ok(collection) } - + /// Creates a test chat with owner permission pub async fn create_test_chat_with_permission( test_db: &TestDb, @@ -237,7 +239,7 @@ impl AssetTestHelpers { role: AssetPermissionRole, ) -> Result { let chat = Self::create_test_chat(test_db, title).await?; - + // Add permission PermissionTestHelpers::create_user_permission( test_db, @@ -245,8 +247,9 @@ impl AssetTestHelpers { AssetType::Chat, user_id, role, - ).await?; - + ) + .await?; + Ok(chat) } } @@ -281,4 +284,4 @@ fn create_default_chart_config() -> ChartConfig { bar_show_total_at_top: None, line_group_type: None, }) -} \ No newline at end of file +} diff --git a/api/libs/database/tests/common/db.rs b/api/libs/database/tests/common/db.rs index c623a8a2c..aab8714bd 100644 --- a/api/libs/database/tests/common/db.rs +++ b/api/libs/database/tests/common/db.rs @@ -93,6 +93,7 @@ impl TestDb { created_at: Utc::now(), updated_at: Utc::now(), deleted_at: None, + payment_required: false, }; let mut conn = self.diesel_conn().await?; diff --git a/api/libs/handlers/tests/metrics/update_metric_test.rs b/api/libs/handlers/tests/metrics/update_metric_test.rs index 438593de6..9aecf8705 100644 --- a/api/libs/handlers/tests/metrics/update_metric_test.rs +++ b/api/libs/handlers/tests/metrics/update_metric_test.rs @@ -41,6 +41,7 @@ impl TestSetup { created_at: chrono::Utc::now(), updated_at: chrono::Utc::now(), deleted_at: None, + payment_required: false, }; // Create user with specified role From 5d4b4e8124258f926d82c767db672590107f6858 Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 29 Apr 2025 10:57:04 -0600 Subject: [PATCH 11/14] always run tests --- .../actions/setup-test-environment/action.yml | 4 +- .github/workflows/api-testing.yml | 5 - .github/workflows/cli-testing.yml | 71 ++++++++-- .github/workflows/web-testing.yml | 121 +++++++++--------- 4 files changed, 124 insertions(+), 77 deletions(-) diff --git a/.github/actions/setup-test-environment/action.yml b/.github/actions/setup-test-environment/action.yml index 6d094b67d..1ca6fa15d 100644 --- a/.github/actions/setup-test-environment/action.yml +++ b/.github/actions/setup-test-environment/action.yml @@ -17,7 +17,7 @@ runs: override: true - name: Cache Rust dependencies - uses: Swatinem/rust-cache@v2 + uses: useblacksmith/rust-cache@v3 - name: Install Diesel CLI shell: bash @@ -27,7 +27,7 @@ runs: shell: bash run: | echo "Starting Supabase..." - supabase start + supabase start --exclude postgrest,studio echo "Waiting a bit for services to stabilize after start..." sleep 15 # Adjust if needed, Supabase start should block but sometimes a small delay helps diff --git a/.github/workflows/api-testing.yml b/.github/workflows/api-testing.yml index 1da9b483b..a226c8082 100644 --- a/.github/workflows/api-testing.yml +++ b/.github/workflows/api-testing.yml @@ -4,11 +4,6 @@ on: pull_request: branches: - main - paths: - - 'api/**' - - '.github/workflows/api-testing.yml' - - '.github/actions/setup-test-environment/action.yml' # Rerun if common setup changes - - '.github/actions/stop-supabase/action.yml' jobs: test: diff --git a/.github/workflows/cli-testing.yml b/.github/workflows/cli-testing.yml index 2e9939775..8cce9d53b 100644 --- a/.github/workflows/cli-testing.yml +++ b/.github/workflows/cli-testing.yml @@ -4,19 +4,15 @@ on: pull_request: branches: - main - paths: - - 'cli/**' # Trigger on changes in the cli directory - - '.github/workflows/cli-testing.yml' # Also run if the workflow file itself changes - - '.github/actions/setup-test-environment/action.yml' # Rerun if common setup changes - - '.github/actions/stop-supabase/action.yml' jobs: test: runs-on: blacksmith-16vcpu-ubuntu-2204 # Using a powerful runner as requested - environment: testing # Add the environment key + environment: testing - # Service container for Redis (needed by the setup action) + # Service containers services: + # Redis needed by API redis: image: redis ports: @@ -27,28 +23,77 @@ jobs: --health-timeout 5s --health-retries 5 + # API service built from Dockerfile + api: + image: local-api-test:latest # Use the locally built image + ports: + - 3001:3001 + options: >- + --health-cmd "curl -f http://localhost:3001/health || exit 1" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + env: + # Core Supabase/DB/Redis vars - use service names or host IP + # Runner host IP is often 172.17.0.1, Supabase runs directly on host via setup action + DATABASE_URL: postgres://postgres:postgres@172.17.0.1:54322/postgres + POOLER_URL: postgres://postgres:postgres@172.17.0.1:54322/postgres + REDIS_URL: redis://redis:6379 # Connect to redis service container + JWT_SECRET: 'super-secret-jwt-token-with-at-least-32-characters-long' # Use default local value + SUPABASE_URL: http://172.17.0.1:54321 # Default local URL on host + SUPABASE_SERVICE_ROLE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' # Use default local value + + # Non-sensitive / Default values + ENVIRONMENT: development + # BUSTER_URL might not be relevant for CLI tests + LOG_LEVEL: debug + PORT: 3001 # API server port within container + RUST_LOG: debug + + # Sensitive values from Secrets (passed to API container) + OPENAI_API_KEY: ${{ secrets.GH_ACTIONS_OPENAI_API_KEY }} + RESEND_API_KEY: ${{ secrets.GH_ACTIONS_RESEND_API_KEY }} + COHERE_API_KEY: ${{ secrets.GH_ACTIONS_COHERE_API_KEY }} + LLM_API_KEY: ${{ secrets.GH_ACTIONS_LLM_API_KEY }} + LLM_BASE_URL: ${{ secrets.GH_ACTIONS_LLM_BASE_URL }} + steps: - name: Checkout code uses: actions/checkout@v4 - # Node.js setup removed - not needed for cargo test + # --- Build API Docker Image with Blacksmith Caching --- + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: Setup Test Environment + - name: Build and Load API Docker Image + uses: useblacksmith/build-push-action@v1 + with: + context: ./api + file: ./api/Dockerfile + push: false # Do not push, load locally for service container + load: true # Load the image into the runner's Docker daemon + tags: local-api-test:latest # Tag for the service definition + + # --- Setup Supabase Environment on Host --- + - name: Setup Test Environment # Runs Supabase, migrations, seeding on host uses: ./.github/actions/setup-test-environment - name: Run CLI Tests working-directory: ./cli # Tests run from the cli directory run: cargo test --workspace # Run tests for all packages in the cli workspace env: - # Use hardcoded default values and secrets + # Point to services on host (DB/Supabase/Redis) and API container DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres - REDIS_URL: redis://localhost:6379 # Connect to the Redis service container + REDIS_URL: redis://localhost:6379 # Tests run on host, connect to exposed Redis port JWT_SECRET: 'super-secret-jwt-token-with-at-least-32-characters-long' # Use default local value - SUPABASE_URL: http://127.0.0.1:54321 # Default local URL + SUPABASE_URL: http://127.0.0.1:54321 # Tests run on host SUPABASE_SERVICE_ROLE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' # Use default local value RUST_LOG: debug # Or adjust as needed + BUSTER_API_URL: http://api:3001 # Point CLI tests to the API service container - # Add any other environment variables your CLI tests might require + # Secrets are passed to the API container, not needed directly by CLI tests - name: Stop Supabase # Use the cleanup action uses: ./.github/actions/stop-supabase diff --git a/.github/workflows/web-testing.yml b/.github/workflows/web-testing.yml index 9b69b8436..5d8e0024b 100644 --- a/.github/workflows/web-testing.yml +++ b/.github/workflows/web-testing.yml @@ -4,19 +4,15 @@ on: pull_request: branches: - main - paths: - - 'web/**' - - '.github/workflows/web-testing.yml' - - '.github/actions/setup-test-environment/action.yml' # Rerun if common setup changes - - '.github/actions/stop-supabase/action.yml' jobs: test: runs-on: blacksmith-16vcpu-ubuntu-2204 environment: testing - # Service container for Redis (needed by the setup action and potentially API) + # Service containers services: + # Redis needed by API redis: image: redis ports: @@ -27,46 +23,32 @@ jobs: --health-timeout 5s --health-retries 5 - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Node.js # Still needed for frontend build/test commands - uses: actions/setup-node@v4 - with: - node-version: '20' - - - name: Setup Test Environment - uses: ./.github/actions/setup-test-environment - - # Build/Run/Wait steps remain for web testing as it needs the API server running - - name: Build API Server - working-directory: ./api - run: cargo build --release + # API service built from Dockerfile + api: + image: local-api-test:latest # Use the locally built image + ports: + - 3001:3001 + options: >- + --health-cmd "curl -f http://localhost:3001/health || exit 1" + --health-interval 10s + --health-timeout 5s + --health-retries 5 env: - # Potentially needed if build process requires env vars, though unlikely - DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres - - - name: Run API Server - working-directory: ./api - run: | - ./target/release/server & # Run in background - echo $! > /tmp/api-server.pid # Store PID for later cleanup - env: - # Core Supabase/DB/Redis vars - use hardcoded values and secrets - DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres - POOLER_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres # Assuming pooler uses same DB - REDIS_URL: redis://localhost:6379 # Use localhost as it runs on the runner accessing the service + # Core Supabase/DB/Redis vars - use service names or host IP + # Runner host IP is often 172.17.0.1, Supabase runs directly on host via setup action + DATABASE_URL: postgres://postgres:postgres@172.17.0.1:54322/postgres + POOLER_URL: postgres://postgres:postgres@172.17.0.1:54322/postgres + REDIS_URL: redis://redis:6379 # Connect to redis service container JWT_SECRET: 'super-secret-jwt-token-with-at-least-32-characters-long' # Use default local value - SUPABASE_URL: http://127.0.0.1:54321 # Default local URL + SUPABASE_URL: http://172.17.0.1:54321 # Default local URL on host SUPABASE_SERVICE_ROLE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' # Use default local value # Non-sensitive / Default values ENVIRONMENT: development - BUSTER_URL: http://localhost:3000 + BUSTER_URL: http://localhost:3000 # This likely refers to the web app URL, keep as localhost BUSTER_WH_TOKEN: buster-wh-token LOG_LEVEL: debug - PORT: 3001 # API server port + PORT: 3001 # API server port within container RUST_LOG: debug # Sensitive values from Secrets @@ -76,20 +58,45 @@ jobs: LLM_API_KEY: ${{ secrets.GH_ACTIONS_LLM_API_KEY }} LLM_BASE_URL: ${{ secrets.GH_ACTIONS_LLM_BASE_URL }} - - name: Wait for API Server - run: | - echo "Waiting for API server (localhost:3001) to be ready..." - n=0 - until [ "$n" -ge 30 ] || curl -f http://localhost:3001/health; do - n=$((n+1)) - echo "Waiting for API... Attempt $n/30" - sleep 2 - done - if ! curl -f http://localhost:3001/health; then - echo "::error::API server did not become ready in time." - exit 1 - fi - echo "API server is ready." + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js (Blacksmith Cache) + uses: useblacksmith/setup-node@v5 + with: + node-version: '20' + + - name: Mount NPM Cache (Sticky Disk) + uses: useblacksmith/stickydisk@v1 + with: + key: ${{ github.repository }}-npm-cache # Unique key per repository + path: ~/.npm + + - name: Mount node_modules (Sticky Disk) + uses: useblacksmith/stickydisk@v1 + with: + key: ${{ github.repository }}-node-modules # Unique key per repository + path: ./web/node_modules # Mount directly into the web directory's node_modules + + # --- Setup Supabase Environment --- + - name: Setup Test Environment # Runs Supabase, migrations, seeding on host + uses: ./.github/actions/setup-test-environment + + # --- Build API Docker Image with Blacksmith Caching --- + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and Load API Docker Image + uses: useblacksmith/build-push-action@v1 + with: + context: ./api + file: ./api/Dockerfile + push: false # Do not push, load locally for service container + load: true # Load the image into the runner's Docker daemon + tags: local-api-test:latest # Tag for the service definition - name: Run Frontend E2E Tests working-directory: ./web @@ -100,13 +107,13 @@ jobs: npm run build # If needed npm run test:e2e env: - # API runs on localhost within the runner - NEXT_PUBLIC_API_URL: http://localhost:3001 + # Point to the API service container + NEXT_PUBLIC_API_URL: http://api:3001 NEXT_PUBLIC_URL: http://localhost:3000 # Assuming default URL for the app itself - # Use Supabase details - default URL and secret anon key - NEXT_PUBLIC_SUPABASE_URL: http://127.0.0.1:54321 # Default local URL + # Use Supabase details - pointing to Supabase running on the HOST (127.0.0.1) + NEXT_PUBLIC_SUPABASE_URL: http://127.0.0.1:54321 # Default local URL on host NEXT_PUBLIC_SUPABASE_ANON_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODIzNDMwOTZ9.7UIsMFfHYKxH7bUJCRfxd6lr7CSXGF7UxtZQO10FMMo' # Use default local value - NEXT_PUBLIC_WEB_SOCKET_URL: ws://localhost:3001 # Assuming WS connects to API + NEXT_PUBLIC_WEB_SOCKET_URL: ws://api:3001 # Point WS to API service container # Pass any other required NEXT_PUBLIC_ variables From 6aa1442b06f4bf0532eb4dd087794e49c1b0d030 Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 29 Apr 2025 11:02:08 -0600 Subject: [PATCH 12/14] dockerfile added to test env --- .github/workflows/cli-testing.yml | 75 +++++++++++++++-------------- .github/workflows/web-testing.yml | 80 +++++++++++++++++-------------- 2 files changed, 83 insertions(+), 72 deletions(-) diff --git a/.github/workflows/cli-testing.yml b/.github/workflows/cli-testing.yml index 8cce9d53b..26ab07aa4 100644 --- a/.github/workflows/cli-testing.yml +++ b/.github/workflows/cli-testing.yml @@ -23,40 +23,6 @@ jobs: --health-timeout 5s --health-retries 5 - # API service built from Dockerfile - api: - image: local-api-test:latest # Use the locally built image - ports: - - 3001:3001 - options: >- - --health-cmd "curl -f http://localhost:3001/health || exit 1" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - env: - # Core Supabase/DB/Redis vars - use service names or host IP - # Runner host IP is often 172.17.0.1, Supabase runs directly on host via setup action - DATABASE_URL: postgres://postgres:postgres@172.17.0.1:54322/postgres - POOLER_URL: postgres://postgres:postgres@172.17.0.1:54322/postgres - REDIS_URL: redis://redis:6379 # Connect to redis service container - JWT_SECRET: 'super-secret-jwt-token-with-at-least-32-characters-long' # Use default local value - SUPABASE_URL: http://172.17.0.1:54321 # Default local URL on host - SUPABASE_SERVICE_ROLE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' # Use default local value - - # Non-sensitive / Default values - ENVIRONMENT: development - # BUSTER_URL might not be relevant for CLI tests - LOG_LEVEL: debug - PORT: 3001 # API server port within container - RUST_LOG: debug - - # Sensitive values from Secrets (passed to API container) - OPENAI_API_KEY: ${{ secrets.GH_ACTIONS_OPENAI_API_KEY }} - RESEND_API_KEY: ${{ secrets.GH_ACTIONS_RESEND_API_KEY }} - COHERE_API_KEY: ${{ secrets.GH_ACTIONS_COHERE_API_KEY }} - LLM_API_KEY: ${{ secrets.GH_ACTIONS_LLM_API_KEY }} - LLM_BASE_URL: ${{ secrets.GH_ACTIONS_LLM_BASE_URL }} - steps: - name: Checkout code uses: actions/checkout@v4 @@ -80,6 +46,41 @@ jobs: - name: Setup Test Environment # Runs Supabase, migrations, seeding on host uses: ./.github/actions/setup-test-environment + # --- Start API Container Manually --- + - name: Start API Container + run: | + docker run -d --name local-api -p 3001:3001 \ + --network=host \ + -e DATABASE_URL='postgres://postgres:postgres@127.0.0.1:54322/postgres' \ + -e POOLER_URL='postgres://postgres:postgres@127.0.0.1:54322/postgres' \ + -e REDIS_URL='redis://127.0.0.1:6379' \ + -e JWT_SECRET='super-secret-jwt-token-with-at-least-32-characters-long' \ + -e SUPABASE_URL='http://127.0.0.1:54321' \ + -e SUPABASE_SERVICE_ROLE_KEY='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' \ + -e ENVIRONMENT='development' \ + -e LOG_LEVEL='debug' \ + -e PORT='3001' \ + -e RUST_LOG='debug' \ + -e OPENAI_API_KEY='${{ secrets.GH_ACTIONS_OPENAI_API_KEY }}' \ + -e RESEND_API_KEY='${{ secrets.GH_ACTIONS_RESEND_API_KEY }}' \ + -e COHERE_API_KEY='${{ secrets.GH_ACTIONS_COHERE_API_KEY }}' \ + -e LLM_API_KEY='${{ secrets.GH_ACTIONS_LLM_API_KEY }}' \ + -e LLM_BASE_URL='${{ secrets.GH_ACTIONS_LLM_BASE_URL }}' \ + local-api-test:latest + + - name: Wait for API Health Check + run: | + echo "Waiting for API to be healthy..." + for i in {1..30}; do # Wait up to 30 seconds + if curl -f http://localhost:3001/health; then + echo "API is healthy!" + exit 0 + fi + sleep 1 + done + echo "API did not become healthy in time." + exit 1 + - name: Run CLI Tests working-directory: ./cli # Tests run from the cli directory run: cargo test --workspace # Run tests for all packages in the cli workspace @@ -91,10 +92,14 @@ jobs: SUPABASE_URL: http://127.0.0.1:54321 # Tests run on host SUPABASE_SERVICE_ROLE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' # Use default local value RUST_LOG: debug # Or adjust as needed - BUSTER_API_URL: http://api:3001 # Point CLI tests to the API service container + BUSTER_API_URL: http://localhost:3001 # Point CLI tests to the manually started API container # Secrets are passed to the API container, not needed directly by CLI tests - name: Stop Supabase # Use the cleanup action uses: ./.github/actions/stop-supabase if: always() # Ensure Supabase is stopped even if tests fail + + - name: Stop API Container # Cleanup manually started container + if: always() + run: docker stop local-api && docker rm local-api diff --git a/.github/workflows/web-testing.yml b/.github/workflows/web-testing.yml index 5d8e0024b..7bedd9ec7 100644 --- a/.github/workflows/web-testing.yml +++ b/.github/workflows/web-testing.yml @@ -23,41 +23,6 @@ jobs: --health-timeout 5s --health-retries 5 - # API service built from Dockerfile - api: - image: local-api-test:latest # Use the locally built image - ports: - - 3001:3001 - options: >- - --health-cmd "curl -f http://localhost:3001/health || exit 1" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - env: - # Core Supabase/DB/Redis vars - use service names or host IP - # Runner host IP is often 172.17.0.1, Supabase runs directly on host via setup action - DATABASE_URL: postgres://postgres:postgres@172.17.0.1:54322/postgres - POOLER_URL: postgres://postgres:postgres@172.17.0.1:54322/postgres - REDIS_URL: redis://redis:6379 # Connect to redis service container - JWT_SECRET: 'super-secret-jwt-token-with-at-least-32-characters-long' # Use default local value - SUPABASE_URL: http://172.17.0.1:54321 # Default local URL on host - SUPABASE_SERVICE_ROLE_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' # Use default local value - - # Non-sensitive / Default values - ENVIRONMENT: development - BUSTER_URL: http://localhost:3000 # This likely refers to the web app URL, keep as localhost - BUSTER_WH_TOKEN: buster-wh-token - LOG_LEVEL: debug - PORT: 3001 # API server port within container - RUST_LOG: debug - - # Sensitive values from Secrets - OPENAI_API_KEY: ${{ secrets.GH_ACTIONS_OPENAI_API_KEY }} - RESEND_API_KEY: ${{ secrets.GH_ACTIONS_RESEND_API_KEY }} - COHERE_API_KEY: ${{ secrets.GH_ACTIONS_COHERE_API_KEY }} - LLM_API_KEY: ${{ secrets.GH_ACTIONS_LLM_API_KEY }} - LLM_BASE_URL: ${{ secrets.GH_ACTIONS_LLM_BASE_URL }} - steps: - name: Checkout code uses: actions/checkout@v4 @@ -98,6 +63,43 @@ jobs: load: true # Load the image into the runner's Docker daemon tags: local-api-test:latest # Tag for the service definition + # --- Start API Container Manually --- + - name: Start API Container + run: | + docker run -d --name local-api -p 3001:3001 \ + --network=host \ + -e DATABASE_URL='postgres://postgres:postgres@127.0.0.1:54322/postgres' \ + -e POOLER_URL='postgres://postgres:postgres@127.0.0.1:54322/postgres' \ + -e REDIS_URL='redis://127.0.0.1:6379' \ + -e JWT_SECRET='super-secret-jwt-token-with-at-least-32-characters-long' \ + -e SUPABASE_URL='http://127.0.0.1:54321' \ + -e SUPABASE_SERVICE_ROLE_KEY='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MjM0MzA5Nn0.EGgMpd9zvvHPCOq4DJRLwzJ1iS3GV4AEyzguXGcbEIY' \ + -e ENVIRONMENT='development' \ + -e BUSTER_URL='http://localhost:3000' \ + -e BUSTER_WH_TOKEN='buster-wh-token' \ + -e LOG_LEVEL='debug' \ + -e PORT='3001' \ + -e RUST_LOG='debug' \ + -e OPENAI_API_KEY='${{ secrets.GH_ACTIONS_OPENAI_API_KEY }}' \ + -e RESEND_API_KEY='${{ secrets.GH_ACTIONS_RESEND_API_KEY }}' \ + -e COHERE_API_KEY='${{ secrets.GH_ACTIONS_COHERE_API_KEY }}' \ + -e LLM_API_KEY='${{ secrets.GH_ACTIONS_LLM_API_KEY }}' \ + -e LLM_BASE_URL='${{ secrets.GH_ACTIONS_LLM_BASE_URL }}' \ + local-api-test:latest + + - name: Wait for API Health Check + run: | + echo "Waiting for API to be healthy..." + for i in {1..30}; do # Wait up to 30 seconds + if curl -f http://localhost:3001/health; then + echo "API is healthy!" + exit 0 + fi + sleep 1 + done + echo "API did not become healthy in time." + exit 1 + - name: Run Frontend E2E Tests working-directory: ./web run: | @@ -108,15 +110,19 @@ jobs: npm run test:e2e env: # Point to the API service container - NEXT_PUBLIC_API_URL: http://api:3001 + NEXT_PUBLIC_API_URL: http://localhost:3001 NEXT_PUBLIC_URL: http://localhost:3000 # Assuming default URL for the app itself # Use Supabase details - pointing to Supabase running on the HOST (127.0.0.1) NEXT_PUBLIC_SUPABASE_URL: http://127.0.0.1:54321 # Default local URL on host NEXT_PUBLIC_SUPABASE_ANON_KEY: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODIzNDMwOTZ9.7UIsMFfHYKxH7bUJCRfxd6lr7CSXGF7UxtZQO10FMMo' # Use default local value - NEXT_PUBLIC_WEB_SOCKET_URL: ws://api:3001 # Point WS to API service container + NEXT_PUBLIC_WEB_SOCKET_URL: ws://localhost:3001 # Point WS to API service container # Pass any other required NEXT_PUBLIC_ variables - name: Stop Supabase # Use the cleanup action uses: ./.github/actions/stop-supabase if: always() # Ensure Supabase is stopped even if tests fail + + - name: Stop API Container # Cleanup manually started container + if: always() + run: docker stop local-api && docker rm local-api From 9905f16ed1ba29794936d9617bbecc9fe1e019d0 Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 29 Apr 2025 11:24:34 -0600 Subject: [PATCH 13/14] a few optimizations --- .github/workflows/api-testing.yml | 15 ++++++++++++++- .github/workflows/cli-testing.yml | 8 ++------ .github/workflows/web-testing.yml | 7 +------ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.github/workflows/api-testing.yml b/.github/workflows/api-testing.yml index a226c8082..84d970a04 100644 --- a/.github/workflows/api-testing.yml +++ b/.github/workflows/api-testing.yml @@ -7,7 +7,7 @@ on: jobs: test: - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: blacksmith-32vcpu-ubuntu-2204 environment: testing # Service container for Redis (needed by the setup action) @@ -31,10 +31,23 @@ jobs: - name: Setup Test Environment uses: ./.github/actions/setup-test-environment + - name: Mount Cargo Home Cache (Sticky Disk) + uses: useblacksmith/stickydisk@v1 + with: + key: ${{ github.repository }}-cargo-home # Unique key per repository + path: ~/.cargo # Cache cargo registry/git data + + - name: Mount API Target Cache (Sticky Disk) + uses: useblacksmith/stickydisk@v1 + with: + key: ${{ github.repository }}-api-target # Unique key per repository + path: ./api/target # Cache build artifacts + - name: Run API Tests working-directory: ./api # Tests run from the api directory run: cargo test --workspace # Run tests for all packages in the api workspace env: + RUST_TEST_THREADS: 24 # Use hardcoded default values and secrets DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres REDIS_URL: redis://localhost:6379 # Connect to the Redis service container diff --git a/.github/workflows/cli-testing.yml b/.github/workflows/cli-testing.yml index 26ab07aa4..12fb2f0cb 100644 --- a/.github/workflows/cli-testing.yml +++ b/.github/workflows/cli-testing.yml @@ -7,7 +7,7 @@ on: jobs: test: - runs-on: blacksmith-16vcpu-ubuntu-2204 # Using a powerful runner as requested + runs-on: blacksmith-32vcpu-ubuntu-2204 # Using a powerful runner as requested environment: testing # Service containers @@ -28,11 +28,6 @@ jobs: uses: actions/checkout@v4 # --- Build API Docker Image with Blacksmith Caching --- - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Build and Load API Docker Image uses: useblacksmith/build-push-action@v1 with: @@ -85,6 +80,7 @@ jobs: working-directory: ./cli # Tests run from the cli directory run: cargo test --workspace # Run tests for all packages in the cli workspace env: + RUST_TEST_THREADS: 24 # Point to services on host (DB/Supabase/Redis) and API container DATABASE_URL: postgres://postgres:postgres@127.0.0.1:54322/postgres REDIS_URL: redis://localhost:6379 # Tests run on host, connect to exposed Redis port diff --git a/.github/workflows/web-testing.yml b/.github/workflows/web-testing.yml index 7bedd9ec7..76b635f78 100644 --- a/.github/workflows/web-testing.yml +++ b/.github/workflows/web-testing.yml @@ -7,7 +7,7 @@ on: jobs: test: - runs-on: blacksmith-16vcpu-ubuntu-2204 + runs-on: blacksmith-32vcpu-ubuntu-2204 environment: testing # Service containers @@ -49,11 +49,6 @@ jobs: uses: ./.github/actions/setup-test-environment # --- Build API Docker Image with Blacksmith Caching --- - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Build and Load API Docker Image uses: useblacksmith/build-push-action@v1 with: From 09eae9eacb4cfc5079e7eb5fd53b5c60d62c29ee Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 29 Apr 2025 13:41:40 -0600 Subject: [PATCH 14/14] api testing had the rust tool chain removed --- .github/workflows/api-testing.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/api-testing.yml b/.github/workflows/api-testing.yml index 84d970a04..9ee4aff8c 100644 --- a/.github/workflows/api-testing.yml +++ b/.github/workflows/api-testing.yml @@ -43,6 +43,11 @@ jobs: key: ${{ github.repository }}-api-target # Unique key per repository path: ./api/target # Cache build artifacts + - name: Set up Rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: stable # Or specify a version + - name: Run API Tests working-directory: ./api # Tests run from the api directory run: cargo test --workspace # Run tests for all packages in the api workspace