Fix Cypress: disable allowCypressEnv, hardcode test token, fix CI server wait
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 12s
Test / e2e-test (push) Failing after 20s
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 12s
Test / e2e-test (push) Failing after 20s
- cypress.config.js: set allowCypressEnv: false
- Replace Cypress.env('ADMIN_TOKEN') with hardcoded test DB token
- CI: use fixed venv path, retry loop for server readiness
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -11,10 +11,7 @@ jobs:
|
|||||||
run: cd frontend && npm ci
|
run: cd frontend && npm ci
|
||||||
|
|
||||||
- name: Run unit tests
|
- name: Run unit tests
|
||||||
run: |
|
run: cd frontend && npx vitest run --reporter=verbose
|
||||||
cd frontend
|
|
||||||
npx vitest run --reporter=verbose 2>&1 | tee /tmp/vitest-${{ github.sha }}.log
|
|
||||||
echo "Results saved to /tmp/vitest-${{ github.sha }}.log"
|
|
||||||
|
|
||||||
e2e-test:
|
e2e-test:
|
||||||
runs-on: test
|
runs-on: test
|
||||||
@@ -26,30 +23,36 @@ jobs:
|
|||||||
run: cd frontend && npm ci
|
run: cd frontend && npm ci
|
||||||
|
|
||||||
- name: Install backend
|
- name: Install backend
|
||||||
run: python3 -m venv /tmp/ci-venv-$$ && . /tmp/ci-venv-$$/bin/activate && pip install -q -r backend/requirements.txt
|
run: python3 -m venv /tmp/ci-venv && /tmp/ci-venv/bin/pip install -q -r backend/requirements.txt
|
||||||
|
|
||||||
- name: Start servers
|
- name: Start servers
|
||||||
run: |
|
run: |
|
||||||
. /tmp/ci-venv-*/bin/activate
|
/tmp/ci-venv/bin/uvicorn backend.main:app --port 8000 &
|
||||||
DB_PATH=/tmp/ci_oil_${{ github.run_id }}.db FRONTEND_DIR=/dev/null \
|
cd frontend && npx vite --port 5173 &
|
||||||
nohup uvicorn backend.main:app --port 8000 > /tmp/backend.log 2>&1 &
|
# Wait for both servers
|
||||||
cd frontend && nohup npx vite --port 5173 > /tmp/frontend.log 2>&1 &
|
for i in $(seq 1 30); do
|
||||||
sleep 4
|
curl -sf http://localhost:8000/api/version > /dev/null 2>&1 && \
|
||||||
|
curl -sf http://localhost:5173/ > /dev/null 2>&1 && break
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
curl -sf http://localhost:8000/api/version
|
curl -sf http://localhost:8000/api/version
|
||||||
curl -sf -o /dev/null http://localhost:5173/
|
curl -sf -o /dev/null http://localhost:5173/
|
||||||
|
env:
|
||||||
|
DB_PATH: /tmp/ci_oil_test.db
|
||||||
|
FRONTEND_DIR: /dev/null
|
||||||
|
|
||||||
- name: Run E2E tests
|
- name: Run E2E tests
|
||||||
run: |
|
run: |
|
||||||
cd frontend
|
cd frontend
|
||||||
SPECS=$(ls cypress/e2e/*.cy.js | grep -v demo | grep -v visual | grep -v check | tr '\n' ',')
|
SPECS=$(ls cypress/e2e/*.cy.js | grep -v demo | grep -v visual | grep -v check | tr '\n' ',')
|
||||||
npx cypress run --spec "$SPECS" --config video=false 2>&1 | tee /tmp/cypress-${{ github.sha }}.log
|
npx cypress run --spec "$SPECS" --config video=false
|
||||||
|
|
||||||
- name: Cleanup
|
- name: Cleanup
|
||||||
if: always()
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
pkill -f "uvicorn backend" || true
|
pkill -f "uvicorn backend" || true
|
||||||
pkill -f "node.*vite" || true
|
pkill -f "node.*vite" || true
|
||||||
rm -f /tmp/ci_oil_${{ github.run_id }}.db
|
rm -f /tmp/ci_oil_test.db
|
||||||
|
|
||||||
build-check:
|
build-check:
|
||||||
runs-on: test
|
runs-on: test
|
||||||
|
|||||||
@@ -9,5 +9,6 @@ export default defineConfig({
|
|||||||
viewportHeight: 800,
|
viewportHeight: 800,
|
||||||
video: true,
|
video: true,
|
||||||
videoCompression: false,
|
videoCompression: false,
|
||||||
|
allowCypressEnv: false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,48 +1,39 @@
|
|||||||
describe('Admin Flow', () => {
|
describe('Admin Flow', () => {
|
||||||
|
const ADMIN_TOKEN = 'c86ae7afbe10fabe3c1d5e1a7fee74feaadfd5dc7be2ab62'
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const token = Cypress.env('ADMIN_TOKEN')
|
|
||||||
if (!token) {
|
|
||||||
cy.log('ADMIN_TOKEN not set, skipping admin tests')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cy.visit('/', {
|
cy.visit('/', {
|
||||||
onBeforeLoad(win) {
|
onBeforeLoad(win) {
|
||||||
win.localStorage.setItem('oil_auth_token', token)
|
win.localStorage.setItem('oil_auth_token', ADMIN_TOKEN)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// Wait for app to load with admin privileges
|
|
||||||
cy.get('.nav-tab', { timeout: 10000 }).should('have.length.gte', 6)
|
cy.get('.nav-tab', { timeout: 10000 }).should('have.length.gte', 6)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('shows admin-only tabs', () => {
|
it('shows admin-only tabs', () => {
|
||||||
if (!Cypress.env('ADMIN_TOKEN')) return
|
|
||||||
cy.get('.nav-tab').contains('操作日志').should('be.visible')
|
cy.get('.nav-tab').contains('操作日志').should('be.visible')
|
||||||
cy.get('.nav-tab').contains('Bug').should('be.visible')
|
cy.get('.nav-tab').contains('Bug').should('be.visible')
|
||||||
cy.get('.nav-tab').contains('用户管理').should('be.visible')
|
cy.get('.nav-tab').contains('用户管理').should('be.visible')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can access manage recipes page', () => {
|
it('can access manage recipes page', () => {
|
||||||
if (!Cypress.env('ADMIN_TOKEN')) return
|
|
||||||
cy.get('.nav-tab').contains('管理配方').click()
|
cy.get('.nav-tab').contains('管理配方').click()
|
||||||
cy.url().should('include', '/manage')
|
cy.url().should('include', '/manage')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can access audit log page', () => {
|
it('can access audit log page', () => {
|
||||||
if (!Cypress.env('ADMIN_TOKEN')) return
|
|
||||||
cy.get('.nav-tab').contains('操作日志').click()
|
cy.get('.nav-tab').contains('操作日志').click()
|
||||||
cy.url().should('include', '/audit')
|
cy.url().should('include', '/audit')
|
||||||
cy.contains('操作日志').should('be.visible')
|
cy.contains('操作日志').should('be.visible')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can access user management page', () => {
|
it('can access user management page', () => {
|
||||||
if (!Cypress.env('ADMIN_TOKEN')) return
|
|
||||||
cy.get('.nav-tab').contains('用户管理').click()
|
cy.get('.nav-tab').contains('用户管理').click()
|
||||||
cy.url().should('include', '/users')
|
cy.url().should('include', '/users')
|
||||||
cy.contains('用户管理').should('be.visible')
|
cy.contains('用户管理').should('be.visible')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can access bug tracker page', () => {
|
it('can access bug tracker page', () => {
|
||||||
if (!Cypress.env('ADMIN_TOKEN')) return
|
|
||||||
cy.get('.nav-tab').contains('Bug').click()
|
cy.get('.nav-tab').contains('Bug').click()
|
||||||
cy.url().should('include', '/bugs')
|
cy.url().should('include', '/bugs')
|
||||||
cy.contains('Bug').should('be.visible')
|
cy.contains('Bug').should('be.visible')
|
||||||
|
|||||||
@@ -46,12 +46,7 @@ describe('API Health Check', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('GET /api/me returns authenticated user with valid token', () => {
|
it('GET /api/me returns authenticated user with valid token', () => {
|
||||||
// Use the admin token from env or skip
|
const token = 'c86ae7afbe10fabe3c1d5e1a7fee74feaadfd5dc7be2ab62'
|
||||||
const token = Cypress.env('ADMIN_TOKEN')
|
|
||||||
if (!token) {
|
|
||||||
cy.log('ADMIN_TOKEN not set, skipping auth test')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cy.request({
|
cy.request({
|
||||||
url: '/api/me',
|
url: '/api/me',
|
||||||
headers: { Authorization: `Bearer ${token}` }
|
headers: { Authorization: `Bearer ${token}` }
|
||||||
|
|||||||
Reference in New Issue
Block a user