name: Test on: [push] jobs: unit-test: runs-on: test steps: - uses: actions/checkout@v4 - name: Install & Run unit tests run: cd frontend && npm ci && npx vitest run --reporter=verbose e2e-test: runs-on: test needs: unit-test timeout-minutes: 15 steps: - uses: actions/checkout@v4 - name: Install frontend deps run: cd frontend && npm ci - name: Install backend deps run: python3 -m venv /tmp/ci-venv && /tmp/ci-venv/bin/pip install -q -r backend/requirements.txt - name: E2E tests run: | # Dynamic ports to avoid conflicts BE_PORT=$(shuf -i 9000-9999 -n 1) FE_PORT=$(shuf -i 4000-4999 -n 1) DB_FILE="/tmp/ci_oil_test_${BE_PORT}.db" echo "Using backend=$BE_PORT frontend=$FE_PORT db=$DB_FILE" # Known admin token for E2E tests ADMIN_TOKEN="cypress_ci_admin_token_e2e_$(echo $BE_PORT)" export ADMIN_TOKEN # Start backend DB_PATH="$DB_FILE" FRONTEND_DIR=/dev/null ADMIN_TOKEN="$ADMIN_TOKEN" \ /tmp/ci-venv/bin/uvicorn backend.main:app --port $BE_PORT & BE_PID=$! # Start frontend with proxy to dynamic backend port (cd frontend && VITE_API_PORT=$BE_PORT npx vite --port $FE_PORT) & FE_PID=$! # Wait for both servers (max 30s, fail fast) READY=0 for i in $(seq 1 30); do if curl -sf http://localhost:$BE_PORT/api/oils > /dev/null 2>&1 && \ curl -sf http://localhost:$FE_PORT/ > /dev/null 2>&1; then echo "Both servers ready in ${i}s" READY=1 break fi sleep 1 done if [ "$READY" = "0" ]; then echo "ERROR: Servers failed to start within 30s" kill $BE_PID $FE_PID 2>/dev/null rm -f "$DB_FILE" exit 1 fi # Run specs in smaller batches (≤6 per run) to avoid Electron memory # hangs seen when a single cypress run handles 10+ specs on the CI runner. cd frontend CYPRESS_CFG="video=false,defaultCommandTimeout=5000,pageLoadTimeout=10000,requestTimeout=5000,responseTimeout=10000,baseUrl=http://localhost:$FE_PORT,experimentalMemoryManagement=true,numTestsKeptInMemory=0" FAIL=0 run_batch() { local name="$1"; shift echo "=== $name ===" timeout 300 npx cypress run \ --spec "$1" \ --config "$CYPRESS_CFG" --env "ADMIN_TOKEN=$ADMIN_TOKEN" local rc=$? if [ $rc -ne 0 ]; then echo "!!! $name failed (rc=$rc)" FAIL=1 fi } run_batch "Batch 1a: API parity" \ "cypress/e2e/api-crud.cy.js,cypress/e2e/api-health.cy.js,cypress/e2e/oil-data-integrity.cy.js,cypress/e2e/recipe-cost-parity.cy.js,cypress/e2e/endpoint-parity.cy.js" run_batch "Batch 1b: features" \ "cypress/e2e/registration-flow.cy.js,cypress/e2e/pr27-features.cy.js,cypress/e2e/kit-export.cy.js" run_batch "Batch 2a: auth & nav" \ "cypress/e2e/auth-flow.cy.js,cypress/e2e/admin-flow.cy.js,cypress/e2e/navigation.cy.js,cypress/e2e/recipe-detail.cy.js,cypress/e2e/recipe-search.cy.js" run_batch "Batch 2b: user flows" \ "cypress/e2e/manage-recipes.cy.js,cypress/e2e/diary-flow.cy.js,cypress/e2e/favorites.cy.js,cypress/e2e/inventory-flow.cy.js,cypress/e2e/demo-walkthrough.cy.js" run_batch "Batch 3a: misc flows" \ "cypress/e2e/app-load.cy.js,cypress/e2e/account-settings.cy.js,cypress/e2e/audit-log-advanced.cy.js,cypress/e2e/batch-operations.cy.js,cypress/e2e/bug-tracker-flow.cy.js,cypress/e2e/category-modules.cy.js" run_batch "Batch 3b: pages & perf" \ "cypress/e2e/notification-flow.cy.js,cypress/e2e/oil-reference.cy.js,cypress/e2e/oil-smart-paste.cy.js,cypress/e2e/performance.cy.js,cypress/e2e/price-display.cy.js,cypress/e2e/projects-flow.cy.js" run_batch "Batch 3c: responsive & admin" \ "cypress/e2e/responsive.cy.js,cypress/e2e/search-advanced.cy.js,cypress/e2e/user-management-flow.cy.js,cypress/e2e/visual-check.cy.js" # Cleanup kill $BE_PID $FE_PID 2>/dev/null pkill -f "Cypress" 2>/dev/null || true rm -f "$DB_FILE" if [ $FAIL -ne 0 ]; then exit 1 fi build-check: runs-on: test steps: - uses: actions/checkout@v4 - name: Build frontend run: cd frontend && npm ci && npm run build