diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..448accc --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,497 @@ +# AGENTS.md – HMS Licht & Ton Build & Test Guide + +> **Projekt:** hms-licht-ton (ID 30) +> **Stack:** Nuxt 3 (Frontend) + FastAPI (Backend) + PostgreSQL + Redis +> **Deployment:** Coolify (Docker) auf coolify-01 + +--- + +## 1. Build & Test Commands + +### 1.1 Frontend (Nuxt 3) + +```bash +# Install dependencies +cd frontend && npm ci + +# Development server (http://localhost:3000) +cd frontend && npm run dev + +# Production build +cd frontend && npm run build + +# Preview production build +cd frontend && npm run preview + +# Generate static site (SSG pages) +cd frontend && npm run generate + +# Unit tests (Vitest) +cd frontend && npx vitest run --reporter verbose + +# Watch mode +cd frontend && npx vitest + +# Coverage report +cd frontend && npx vitest run --coverage + +# E2E tests (Playwright) +cd frontend && npx playwright test + +# Specific E2E test +cd frontend && npx playwright test --grep 'Mietkatalog' + +# Lint +cd frontend && npm run lint + +# Type check +cd frontend && npm run typecheck +``` + +### 1.2 Backend (FastAPI) + +```bash +# Install dependencies +cd backend && pip install -r requirements.txt + +# Development server (http://localhost:8000) +cd backend && uvicorn app.main:app --reload --host 0.0.0.0 --port 8000 + +# Run all tests +cd backend && python -m pytest tests/ -v + +# Run with coverage +cd backend && python -m pytest tests/ -v --cov=app --cov-report=term-missing + +# Specific test file +cd backend && python -m pytest tests/test_equipment_router.py -v + +# Specific test +cd backend && python -m pytest tests/test_rentman_import.py::test_paginated_import -v + +# Database migrations +cd backend && alembic upgrade head +cd backend && alembic revision --autogenerate -m "description" + +# Seed admin user +cd backend && python -m app.scripts.seed_admin +``` + +### 1.3 Docker / Full Stack + +```bash +# Build all containers +docker compose build + +# Start all services +docker compose up -d + +# View logs +docker compose logs -f backend +docker compose logs -f frontend + +# Health check +curl -s http://localhost:8000/api/health + +# Stop all services +docker compose down + +# Reset volumes (DESTRUCTIVE) +docker compose down -v +``` + +### 1.4 Integration Tests (Full Stack) + +```bash +# Start backend + DB + Redis +docker compose up -d backend postgres redis + +# Wait for health +curl -s http://localhost:8000/api/health | grep ok + +# Run backend tests +cd backend && python -m pytest tests/ -v + +# Start frontend +docker compose up -d frontend + +# Run E2E tests +cd frontend && npx playwright test +``` + +--- + +## 2. Test Rules (MANDATORY) + +### 2.1 TDD Principle + +- **Write tests first, then implementation.** Tests define the contract. +- Tests MUST be written before or alongside the implementation code. +- Never commit code without corresponding tests. +- Coverage target: **>= 80%** for all modules. + +### 2.2 Do NOT Modify Tests + +- **Never modify existing tests to make them pass.** +- If a test fails, fix the implementation, not the test. +- Tests are the source of truth for expected behavior. +- If a test is genuinely wrong, flag it in a PR and explain why. +- Only the original test author or a reviewer may modify tests. + +### 2.3 Test File Naming + +**Frontend:** +- Unit tests: `frontend/tests/unit/*.test.ts` +- E2E tests: `frontend/tests/e2e/*.spec.ts` +- Fixtures: `frontend/tests/fixtures/*` +- Mocks: `frontend/tests/mocks/*` + +**Backend:** +- Unit/Integration tests: `backend/tests/test_*.py` +- Fixtures: `backend/tests/conftest.py` +- Factories: `backend/tests/factories.py` +- Mocks: `backend/tests/mocks/` + +### 2.4 Test Categories + +| Category | Tool | Scope | When to Run | +|----------|------|-------|-------------| +| Unit | Vitest / Pytest | Functions, composables, stores, services | Every commit | +| Component | Vitest + Vue Test Utils | Vue components, props, emits | Every commit | +| Integration | Pytest + TestClient | API endpoints, DB operations | Every commit | +| E2E | Playwright | Full page flows, forms, navigation | Pre-merge, nightly | +| Smoke | curl scripts | API health, endpoints | Post-deploy | + +### 2.5 Mocking Rules + +- **Rentman API:** Always mock in tests. Never call live Rentman API. + - Use `unittest.mock.patch` or `responses` library + - Mock `GET /equipment` with paginated test data + - Mock `POST /projectrequests` with fake response IDs +- **SMTP:** Always mock email sending in tests. + - Mock `aiosmtplib.send` to capture sent emails + - Verify email content, not actual delivery +- **Database:** Use SQLite in-memory or test PostgreSQL instance. + - Never run tests against production database + - Use separate test database: `DATABASE_URL=sqlite+aiosqlite:///test.db` + +--- + +## 3. Coding Conventions + +### 3.1 Frontend (Vue 3 + TypeScript) + +```typescript +// Use Composition API with +``` + +**Rules:** +- Use `