-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add comprehensive test suite and production-ready tooling #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a6a7ee1
932fcd5
54e7982
c6b8b15
aee9edd
d942968
789ef4f
1a300f7
675796c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| [run] | ||
| source = fastapi_radar | ||
| omit = | ||
| */tests/* | ||
| */test_*.py | ||
| */__pycache__/* | ||
| */site-packages/* | ||
| */dashboard/node_modules/* | ||
| */dashboard/dist/* | ||
|
|
||
| [report] | ||
| precision = 2 | ||
| show_missing = True | ||
| skip_covered = False | ||
| exclude_lines = | ||
| pragma: no cover | ||
| def __repr__ | ||
| raise AssertionError | ||
| raise NotImplementedError | ||
| if __name__ == .__main__.: | ||
| if TYPE_CHECKING: | ||
| @abstractmethod | ||
| @abc.abstractmethod | ||
| pass | ||
|
|
||
| [html] | ||
| directory = htmlcov | ||
|
|
||
| [xml] | ||
| output = coverage.xml |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Pull Request | ||
|
|
||
| ## Description | ||
| <!-- Provide a brief description of the changes in this PR --> | ||
|
|
||
| ## Type of Change | ||
| <!-- Mark the relevant option with an "x" --> | ||
|
|
||
| - [ ] Bug fix (non-breaking change which fixes an issue) | ||
| - [ ] New feature (non-breaking change which adds functionality) | ||
| - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) | ||
| - [ ] Documentation update | ||
| - [ ] Performance improvement | ||
| - [ ] Code refactoring | ||
| - [ ] Test coverage improvement | ||
|
|
||
| ## Related Issue | ||
| <!-- Link to the issue this PR addresses --> | ||
| Fixes #(issue number) | ||
|
|
||
| ## Changes Made | ||
| <!-- List the main changes made in this PR --> | ||
|
|
||
| - | ||
| - | ||
| - | ||
|
|
||
| ## Testing | ||
| <!-- Describe the testing you've done --> | ||
|
|
||
| - [ ] All existing tests pass | ||
| - [ ] New tests added for new functionality | ||
| - [ ] Manual testing completed | ||
| - [ ] Test coverage >= 90% | ||
|
|
||
| ## Checklist | ||
| <!-- Ensure all items are checked before submitting --> | ||
|
|
||
| - [ ] My code follows the project's code style | ||
| - [ ] I have performed a self-review of my code | ||
| - [ ] I have commented my code, particularly in hard-to-understand areas | ||
| - [ ] I have made corresponding changes to the documentation | ||
| - [ ] My changes generate no new warnings | ||
| - [ ] I have added tests that prove my fix is effective or that my feature works | ||
| - [ ] New and existing unit tests pass locally with my changes | ||
| - [ ] Any dependent changes have been merged and published | ||
|
|
||
| ## Screenshots (if applicable) | ||
| <!-- Add screenshots to help explain your changes --> | ||
|
|
||
| ## Additional Notes | ||
| <!-- Any additional information that reviewers should know --> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,55 +10,133 @@ jobs: | |||||
| test: | ||||||
| runs-on: ubuntu-latest | ||||||
| strategy: | ||||||
| fail-fast: false | ||||||
| matrix: | ||||||
| python-version: ['3.9', '3.10', '3.11', '3.12'] | ||||||
|
|
||||||
| steps: | ||||||
| - uses: actions/checkout@v3 | ||||||
| - uses: actions/checkout@v4 | ||||||
|
|
||||||
| - name: Set up Python ${{ matrix.python-version }} | ||||||
| uses: actions/setup-python@v4 | ||||||
| uses: actions/setup-python@v5 | ||||||
| with: | ||||||
| python-version: ${{ matrix.python-version }} | ||||||
|
|
||||||
|
|
||||||
| - name: Cache Python dependencies | ||||||
| uses: actions/cache@v4 | ||||||
| with: | ||||||
| path: ~/.cache/pip | ||||||
| key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} | ||||||
| restore-keys: | | ||||||
| ${{ runner.os }}-pip- | ||||||
|
|
||||||
| - name: Install dependencies | ||||||
| run: | | ||||||
| python -m pip install --upgrade pip | ||||||
| pip install -e ".[dev]" | ||||||
|
|
||||||
| - name: Format check with Black | ||||||
| run: | | ||||||
| black --check fastapi_radar/ | ||||||
| black --check fastapi_radar/ tests/ | ||||||
|
|
||||||
| - name: Lint with flake8 | ||||||
| run: | | ||||||
| flake8 fastapi_radar/ --max-line-length=100 | ||||||
|
|
||||||
| flake8 fastapi_radar/ tests/ --max-line-length=100 --extend-ignore=E203,W503 | ||||||
|
|
||||||
| - name: Import sorting check with isort | ||||||
| run: | | ||||||
| isort --check-only --profile black fastapi_radar/ tests/ | ||||||
|
|
||||||
| - name: Type check with mypy | ||||||
| run: | | ||||||
| mypy fastapi_radar/ | ||||||
|
|
||||||
| - name: Test with pytest | ||||||
|
|
||||||
| - name: Security check with bandit | ||||||
| run: | | ||||||
| bandit -r fastapi_radar/ -c pyproject.toml | ||||||
|
|
||||||
| - name: Dependency security check with safety | ||||||
| run: | | ||||||
| pytest tests/ | ||||||
| safety check --json || true | ||||||
| continue-on-error: true | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allowing the Safety scan step to continue on error hides failures, so critical dependency vulnerabilities will not fail CI. Remove the Prompt for AI agents
Suggested change
|
||||||
|
|
||||||
| - name: Run tests with coverage | ||||||
| run: | | ||||||
| pytest tests/ \ | ||||||
| --cov=fastapi_radar \ | ||||||
| --cov-report=xml \ | ||||||
| --cov-report=html \ | ||||||
| --cov-report=term-missing \ | ||||||
| --cov-fail-under=80 \ | ||||||
| -v \ | ||||||
| --tb=short | ||||||
|
|
||||||
| - name: Upload coverage to Codecov | ||||||
| uses: codecov/codecov-action@v4 | ||||||
| if: matrix.python-version == '3.11' | ||||||
| with: | ||||||
| file: ./coverage.xml | ||||||
| flags: unittests | ||||||
| name: codecov-umbrella | ||||||
| fail_ci_if_error: false | ||||||
|
|
||||||
| - name: Upload coverage reports | ||||||
| uses: actions/upload-artifact@v4 | ||||||
| if: matrix.python-version == '3.11' | ||||||
| with: | ||||||
| name: coverage-report | ||||||
| path: htmlcov/ | ||||||
|
|
||||||
| - name: Generate test report | ||||||
| if: always() | ||||||
| run: | | ||||||
| echo "## Test Results" >> $GITHUB_STEP_SUMMARY | ||||||
| echo "" >> $GITHUB_STEP_SUMMARY | ||||||
| echo "Python ${{ matrix.python-version }}" >> $GITHUB_STEP_SUMMARY | ||||||
|
|
||||||
| build-dashboard: | ||||||
| runs-on: ubuntu-latest | ||||||
|
|
||||||
| steps: | ||||||
| - uses: actions/checkout@v3 | ||||||
| - uses: actions/checkout@v4 | ||||||
|
|
||||||
| - name: Setup Node.js | ||||||
| uses: actions/setup-node@v3 | ||||||
| uses: actions/setup-node@v4 | ||||||
| with: | ||||||
| node-version: '18' | ||||||
|
|
||||||
| cache: 'npm' | ||||||
| cache-dependency-path: fastapi_radar/dashboard/package-lock.json | ||||||
|
|
||||||
| - name: Build Dashboard | ||||||
| run: | | ||||||
| cd fastapi_radar/dashboard | ||||||
| npm ci | ||||||
| npm run build | ||||||
|
|
||||||
| - name: Verify Dashboard Build | ||||||
| run: | | ||||||
| test -f fastapi_radar/dashboard/dist/index.html | ||||||
|
|
||||||
| - name: Upload dashboard artifact | ||||||
| uses: actions/upload-artifact@v4 | ||||||
| with: | ||||||
| name: dashboard-build | ||||||
| path: fastapi_radar/dashboard/dist/ | ||||||
|
|
||||||
| quality-gate: | ||||||
| runs-on: ubuntu-latest | ||||||
| needs: [test, build-dashboard] | ||||||
| if: always() | ||||||
|
|
||||||
| steps: | ||||||
| - name: Check test results | ||||||
| run: | | ||||||
| if [ "${{ needs.test.result }}" != "success" ]; then | ||||||
| echo "Tests failed" | ||||||
| exit 1 | ||||||
| fi | ||||||
| if [ "${{ needs.build-dashboard.result }}" != "success" ]; then | ||||||
| echo "Dashboard build failed" | ||||||
| exit 1 | ||||||
| fi | ||||||
| echo "All quality checks passed!" | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,72 @@ | ||||||
| # Pre-commit hooks for code quality | ||||||
| # Install: pre-commit install | ||||||
| # Run manually: pre-commit run --all-files | ||||||
|
|
||||||
| repos: | ||||||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||||||
| rev: v4.5.0 | ||||||
| hooks: | ||||||
| - id: trailing-whitespace | ||||||
| - id: end-of-file-fixer | ||||||
| - id: check-yaml | ||||||
| - id: check-added-large-files | ||||||
| args: ['--maxkb=500'] | ||||||
| - id: check-json | ||||||
| - id: check-toml | ||||||
| - id: check-merge-conflict | ||||||
| - id: debug-statements | ||||||
| - id: mixed-line-ending | ||||||
|
|
||||||
| - repo: https://github.com/psf/black | ||||||
| rev: 23.12.1 | ||||||
| hooks: | ||||||
| - id: black | ||||||
| language_version: python3.9 | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Black hook forces Prompt for AI agents
Suggested change
|
||||||
| args: ['--line-length=100'] | ||||||
|
|
||||||
| - repo: https://github.com/pycqa/isort | ||||||
| rev: 5.13.2 | ||||||
| hooks: | ||||||
| - id: isort | ||||||
| args: ['--profile', 'black', '--line-length', '100'] | ||||||
|
|
||||||
| - repo: https://github.com/pycqa/flake8 | ||||||
| rev: 7.0.0 | ||||||
| hooks: | ||||||
| - id: flake8 | ||||||
| args: ['--max-line-length=100', '--extend-ignore=E203,W503'] | ||||||
|
|
||||||
| - repo: https://github.com/pre-commit/mirrors-mypy | ||||||
| rev: v1.8.0 | ||||||
| hooks: | ||||||
| - id: mypy | ||||||
| additional_dependencies: [ | ||||||
| 'types-requests', | ||||||
| 'sqlalchemy[mypy]', | ||||||
| 'pydantic', | ||||||
| ] | ||||||
| args: ['--config-file=mypy.ini'] | ||||||
|
|
||||||
| - repo: https://github.com/PyCQA/bandit | ||||||
| rev: 1.7.6 | ||||||
| hooks: | ||||||
| - id: bandit | ||||||
| args: ['-c', 'pyproject.toml'] | ||||||
| additional_dependencies: ['bandit[toml]'] | ||||||
|
|
||||||
| - repo: local | ||||||
| hooks: | ||||||
| - id: pytest-check | ||||||
| name: pytest-check | ||||||
| entry: pytest | ||||||
| language: system | ||||||
| pass_filenames: false | ||||||
| always_run: true | ||||||
| args: [ | ||||||
| 'tests/', | ||||||
| '-v', | ||||||
| '--tb=short', | ||||||
| '-x', # Stop on first failure | ||||||
| '--maxfail=5', # Stop after 5 failures | ||||||
| ] | ||||||
| stages: [push] # Only run on push, not on every commit | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,79 @@ | ||||||
| .PHONY: install test coverage lint format type-check security clean help | ||||||
|
|
||||||
| help: | ||||||
| @echo "FastAPI Radar - Development Commands" | ||||||
| @echo "" | ||||||
| @echo "Setup:" | ||||||
| @echo " make install Install dependencies" | ||||||
| @echo " make install-dev Install with dev dependencies" | ||||||
| @echo "" | ||||||
| @echo "Development:" | ||||||
| @echo " make format Format code with black and isort" | ||||||
| @echo " make lint Run flake8" | ||||||
| @echo " make type-check Run mypy" | ||||||
| @echo " make security Run security checks" | ||||||
| @echo " make check Run all checks (format, lint, type, security)" | ||||||
| @echo "" | ||||||
| @echo "Testing:" | ||||||
| @echo " make test Run tests" | ||||||
| @echo " make test-fast Run tests in parallel" | ||||||
| @echo " make coverage Run tests with coverage report" | ||||||
| @echo " make test-unit Run unit tests only" | ||||||
| @echo " make test-integration Run integration tests only" | ||||||
| @echo "" | ||||||
| @echo "Maintenance:" | ||||||
| @echo " make clean Remove cache and build files" | ||||||
| @echo " make pre-commit Install pre-commit hooks" | ||||||
|
|
||||||
| install: | ||||||
| pip install -e . | ||||||
|
|
||||||
| install-dev: | ||||||
| pip install -e ".[dev]" | ||||||
|
|
||||||
| test: | ||||||
| pytest tests/ -v | ||||||
|
|
||||||
| test-fast: | ||||||
| pytest tests/ -v -n auto | ||||||
|
|
||||||
| coverage: | ||||||
| pytest tests/ --cov=fastapi_radar --cov-report=html --cov-report=term-missing --cov-fail-under=90 | ||||||
|
|
||||||
| test-unit: | ||||||
| pytest tests/ -v -m unit | ||||||
|
|
||||||
| test-integration: | ||||||
| pytest tests/ -v -m integration | ||||||
|
|
||||||
| format: | ||||||
| black fastapi_radar/ tests/ | ||||||
| isort fastapi_radar/ tests/ | ||||||
|
|
||||||
| lint: | ||||||
| flake8 fastapi_radar/ tests/ --max-line-length=100 --extend-ignore=E203,W503 | ||||||
|
|
||||||
| type-check: | ||||||
| mypy fastapi_radar/ | ||||||
|
|
||||||
| security: | ||||||
| bandit -r fastapi_radar/ -c pyproject.toml | ||||||
| safety check || true | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove Prompt for AI agents
Suggested change
|
||||||
|
|
||||||
| check: format lint type-check security | ||||||
| @echo "All checks passed!" | ||||||
|
|
||||||
| pre-commit: | ||||||
| pre-commit install | ||||||
|
|
||||||
| clean: | ||||||
| rm -rf build/ | ||||||
| rm -rf dist/ | ||||||
| rm -rf *.egg-info | ||||||
| rm -rf htmlcov/ | ||||||
| rm -rf .coverage | ||||||
| rm -rf coverage.xml | ||||||
| rm -rf .pytest_cache/ | ||||||
| rm -rf .mypy_cache/ | ||||||
| find . -type d -name __pycache__ -exec rm -rf {} + | ||||||
| find . -type f -name "*.pyc" -delete | ||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
safety checkalways exits successfully because of|| true, so detected vulnerabilities will never block the build. Please remove the|| trueso the scan can fail when issues are found.Prompt for AI agents