Skip to content
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

fix: Backend testing, code coverage, logging, bugs, swaggerUI #1238

Open
wants to merge 64 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
f5ab3e2
Update .env.template
vincentkoc Nov 2, 2024
c280cce
Update main.py
vincentkoc Nov 2, 2024
5da5f93
Update storage.py
vincentkoc Nov 2, 2024
4625324
Update vad.py
vincentkoc Nov 2, 2024
28ebe30
Update _client.py
vincentkoc Nov 2, 2024
30dc548
Create .python-version
vincentkoc Nov 2, 2024
9b0d0cf
Update Backend_Setup.mdx
vincentkoc Nov 2, 2024
65ec6ea
Update README.md
vincentkoc Nov 2, 2024
23335ba
Update README.md
vincentkoc Nov 2, 2024
dd01626
Update .python-version
vincentkoc Nov 2, 2024
6c19358
chore: removed recordings stored in the repo
vincentkoc Nov 3, 2024
feb66aa
chore: add mising inits for modules
vincentkoc Nov 3, 2024
b949907
chore: add pytest
vincentkoc Nov 3, 2024
69615d3
chore: makefile
vincentkoc Nov 3, 2024
15d8e7b
Create __init__.py
vincentkoc Nov 3, 2024
aa99097
Create validation.py
vincentkoc Nov 3, 2024
9552d88
Create test-credentials.json
vincentkoc Nov 3, 2024
02501ba
Create test_uploads.py
vincentkoc Nov 3, 2024
50e2b0e
Create test_auth.py
vincentkoc Nov 3, 2024
40bd599
Create __init__.py
vincentkoc Nov 3, 2024
aac18cf
Create conftest.py
vincentkoc Nov 3, 2024
4318f54
Update main.py
vincentkoc Nov 3, 2024
8e79066
fix: tests finalised and all passing for now
vincentkoc Nov 3, 2024
9854706
Update .gitignore
vincentkoc Nov 3, 2024
44867fb
Update pytest.ini
vincentkoc Nov 3, 2024
bb9118f
Create .python-version
vincentkoc Nov 3, 2024
321725f
inits
vincentkoc Nov 3, 2024
e7bae48
passing unit tests
vincentkoc Nov 3, 2024
551a543
Update storage.py
vincentkoc Nov 3, 2024
e277ce5
feat: swagger and flask middleware
vincentkoc Nov 3, 2024
3680ca0
Update .env.template
vincentkoc Nov 3, 2024
57f8ec2
Create auth.py
vincentkoc Nov 3, 2024
b7ad33d
Update README.md
vincentkoc Nov 3, 2024
28f6222
Create auth.py
vincentkoc Nov 3, 2024
dc2da4a
Update main.py
vincentkoc Nov 3, 2024
a50d554
fix: tests on swagger
vincentkoc Nov 3, 2024
3179d60
chore: silence warning
vincentkoc Nov 3, 2024
e3799d5
Update auth.py
vincentkoc Nov 3, 2024
78784cd
Update _client.py
vincentkoc Nov 3, 2024
c5d831d
Update processing_memories.py
vincentkoc Nov 3, 2024
4827007
fix: database clients collectors
vincentkoc Nov 3, 2024
e2b126a
fix: added unit test
vincentkoc Nov 3, 2024
57eecdd
Update chat.py
vincentkoc Nov 3, 2024
1625e25
Update __init__.py
vincentkoc Nov 3, 2024
7fb80d7
Update facts.py
vincentkoc Nov 3, 2024
6335840
Update memories.py
vincentkoc Nov 3, 2024
9088495
Update tasks.py
vincentkoc Nov 3, 2024
78fd507
Update chat.py
vincentkoc Nov 3, 2024
4e7bdd0
Update memory.py
vincentkoc Nov 3, 2024
7e96894
feat: database tests
vincentkoc Nov 3, 2024
051aba8
Update conftest.py
vincentkoc Nov 3, 2024
52d3d30
feat: tests
vincentkoc Nov 3, 2024
9045f8a
Update requirements.txt
vincentkoc Nov 3, 2024
79dd529
rm rate limiter
vincentkoc Nov 3, 2024
3acb669
Update backend/middleware/auth.py
vincentkoc Nov 3, 2024
0f930e0
Update backend/database/memories.py
vincentkoc Nov 3, 2024
9de33c4
Update conftest.py
vincentkoc Nov 3, 2024
d5eb491
Update conftest.py
vincentkoc Nov 3, 2024
ff6cd14
Update conftest.py
vincentkoc Nov 3, 2024
3933d6b
Update backend/database/memories.py
vincentkoc Nov 3, 2024
99cd042
Update backend/database/memories.py
vincentkoc Nov 3, 2024
25ac872
Update memories.py
vincentkoc Nov 3, 2024
34333c8
Update backend/database/memories.py
vincentkoc Nov 3, 2024
6e730ab
Merge branch 'vk_backend_python_uplift' of github.com:vincentkoc/Omi …
vincentkoc Nov 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ yarn.lock
build/
dist/

# Coverage
*/coverage/
*/htmlcov/
*.coverage

# Android specific
**/android/**/build/
**/android/.gradle
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
43 changes: 33 additions & 10 deletions backend/.env.template
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
HUGGINGFACE_TOKEN=
BUCKET_SPEECH_PROFILES=
BUCKET_BACKUPS=
# Google Cloud Authentication
GOOGLE_APPLICATION_CREDENTIALS=google-credentials.json

# Google Cloud Storage Buckets
BUCKET_SPEECH_PROFILES= # Required: For storing user speech profiles
BUCKET_MEMORIES_RECORDINGS= # Required: For storing memory recordings
BUCKET_POSTPROCESSING= # Optional: For post-processing audio files
BUCKET_TEMPORAL_SYNC_LOCAL= # Optional: For temporary sync files
BUCKET_BACKUPS= # Optional: For backup storage

# Security & Server Configuration
ADMIN_KEY=
SWAGGER_UI=false
Comment on lines +12 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add security recommendations for ADMIN_KEY.

The ADMIN_KEY is a sensitive security parameter but lacks guidance on requirements.

-ADMIN_KEY=
+ADMIN_KEY=                        # Required: Use a strong random string of at least 32 characters
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ADMIN_KEY=
SWAGGER_UI=false
ADMIN_KEY= # Required: Use a strong random string of at least 32 characters
SWAGGER_UI=false


# Firebase Authentication for Swagger UI (Optional)
# Found in Firebase Console > Project Settings > General > Web API Key (Config)
FIREBASE_API_KEY=your-api-key
FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_STORAGE_BUCKET=your-project.appspot.com
FIREBASE_MESSAGING_SENDER_ID=your-messaging-sender-id
FIREBASE_APP_ID=your-app-id
Comment on lines +17 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance security by adding warning about Firebase credentials.

The Firebase credentials are sensitive and should include a warning about their protection.

-FIREBASE_API_KEY=your-api-key
-FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
-FIREBASE_PROJECT_ID=your-project-id
-FIREBASE_STORAGE_BUCKET=your-project.appspot.com
-FIREBASE_MESSAGING_SENDER_ID=your-messaging-sender-id
-FIREBASE_APP_ID=your-app-id
+# WARNING: These credentials should never be committed to version control
+FIREBASE_API_KEY=your-api-key                           # Found in Firebase Console > Project Settings
+FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com       # Format: your-project.firebaseapp.com
+FIREBASE_PROJECT_ID=your-project-id                     # Example: my-app-123
+FIREBASE_STORAGE_BUCKET=your-project.appspot.com        # Format: your-project.appspot.com
+FIREBASE_MESSAGING_SENDER_ID=your-messaging-sender-id    # Example: 123456789012
+FIREBASE_APP_ID=your-app-id                            # Format: 1:123456789012:web:abcdef123456
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
FIREBASE_API_KEY=your-api-key
FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_STORAGE_BUCKET=your-project.appspot.com
FIREBASE_MESSAGING_SENDER_ID=your-messaging-sender-id
FIREBASE_APP_ID=your-app-id
# WARNING: These credentials should never be committed to version control
FIREBASE_API_KEY=your-api-key # Found in Firebase Console > Project Settings
FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com # Format: your-project.firebaseapp.com
FIREBASE_PROJECT_ID=your-project-id # Example: my-app-123
FIREBASE_STORAGE_BUCKET=your-project.appspot.com # Format: your-project.appspot.com
FIREBASE_MESSAGING_SENDER_ID=your-messaging-sender-id # Example: 123456789012
FIREBASE_APP_ID=your-app-id # Format: 1:123456789012:web:abcdef123456


# OpenAI Authentication
OPENAI_API_KEY=

# GitHub Authentication Used for Package Updates
GITHUB_TOKEN=

# Hugging Face Authentication
HUGGINGFACE_TOKEN=

# Database Configuration
PINECONE_API_KEY=
PINECONE_INDEX_NAME=

REDIS_DB_HOST=
REDIS_DB_PORT=
REDIS_DB_PASSWORD=

# Speech-to-Text Services
SONIOX_API_KEY=
DEEPGRAM_API_KEY=

ADMIN_KEY=
OPENAI_API_KEY=

GITHUB_TOKEN=

# Integration Services
WORKFLOW_API_KEY=
HUME_API_KEY=
HUME_CALLBACK_URL=
Comment on lines +1 to 47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Based on the results, I can generate the final response as there are clear discrepancies between the .env.template and actual environment variable usage in the codebase.

Several environment variables are used in the codebase but missing from the template

The following environment variables are used but not documented in .env.template:

  • HOSTED_VAD_API_URL
  • HOSTED_SPEECH_PROFILE_API_URL
  • SPEECHMATICS_API_KEY
  • GROQ_API_KEY
  • PYANNOTE_API_KEY
  • GOOGLE_MAPS_API_KEY
  • MULTION_API_KEY
  • MULTION_ORG_ID
  • NOTION_AUTH_URL, NOTION_OAUTH_CLIENT_ID, NOTION_OAUTH_CLIENT_SECRET, NOTION_OAUTH_REDIRECT_URI
  • FRIEND_API_URL
  • HOSTED_PUSHER_API_URL
  • LOCAL_DEVELOPMENT
  • SKIP_HEAVY_INIT
  • SKIP_VAD_INIT
  • TESTING
  • NO_SOCKET_TIMEOUT

Additionally, some bucket names in the template don't match the code:

  • Template uses BUCKET_SPEECH_PROFILES but code uses BUCKET_PROFILES
  • Template uses BUCKET_TEMPORAL_SYNC_LOCAL but code uses BUCKET_SYNC
🔗 Analysis chain

Verify the completeness of environment variables.

Let's ensure all required environment variables are properly documented in the README and that there are no discrepancies between the template and actual usage in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for environment variable usage in the codebase that might be missing from the template

# Search for os.getenv and os.environ usage in Python files
echo "Checking for environment variable usage in Python files..."
rg -t py "(os\.getenv|os\.environ\.get)\(['\"](\w+)['\"]" -g '!tests/*' --no-filename | sort -u

# Search for process.env usage in JavaScript/TypeScript files (if any exist in the backend)
echo "Checking for environment variable usage in JS/TS files..."
rg -t js -t ts "process\.env\.(\w+)" --no-filename | sort -u

# Check if README mentions all environment variables
echo "Checking README for environment variable documentation..."
rg -t md "ENV|environment|variable" backend/README.md

Length of output: 5077


HOSTED_PUSHER_API_URL=
1 change: 1 addition & 0 deletions backend/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
157 changes: 157 additions & 0 deletions backend/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Variables
PYTHON = python3
VENV = .venv
PIP = $(VENV)/bin/pip
PYTHON_VENV = $(VENV)/bin/python
PYTEST = $(VENV)/bin/pytest
UVICORN = $(VENV)/bin/uvicorn
FLAKE8 = $(VENV)/bin/flake8
BLACK = $(VENV)/bin/black
BANDIT = $(VENV)/bin/bandit
SAFETY = $(VENV)/bin/safety
MYPY = $(VENV)/bin/mypy

# Environment Setup
.PHONY: setup
setup: $(VENV)/bin/activate install-deps install-test-deps

$(VENV)/bin/activate:
$(PYTHON) -m venv $(VENV)
$(PIP) install --upgrade pip

.PHONY: install-deps
install-deps:
$(PIP) install -r requirements.txt

.PHONY: install-test-deps
install-test-deps:
$(PIP) install pytest pytest-cov pytest-asyncio httpx

# Development
.PHONY: run
run:
ENABLE_SWAGGER=true $(UVICORN) main:app --reload --env-file .env

.PHONY: clean
clean:
find . -type d -name "__pycache__" -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
find . -type f -name "*.pyo" -delete
find . -type f -name "*.pyd" -delete
find . -type f -name ".coverage" -delete
find . -type d -name "*.egg-info" -exec rm -rf {} +
find . -type d -name "*.egg" -exec rm -rf {} +
find . -type d -name ".pytest_cache" -exec rm -rf {} +
find . -type d -name ".mypy_cache" -exec rm -rf {} +
find . -type f -name ".DS_Store" -delete
rm -rf build/
rm -rf dist/
rm -rf .coverage
rm -rf htmlcov/
rm -rf .pytest_cache/
rm -rf .mypy_cache/

# Testing
.PHONY: test
test:
PYTHONPATH=. pytest tests/ -v

.PHONY: test-security
test-security:
$(PYTEST) tests/security/ -v

.PHONY: coverage
coverage:
$(PYTEST) --cov=. tests/ --cov-report=html

Comment on lines +54 to +66
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance test execution and coverage configuration.

Consider adding parallel test execution and coverage thresholds:

+# Test Configuration
+COVERAGE_MIN ?= 80
+PYTEST_WORKERS ?= auto
+
 # Testing
 .PHONY: test
 test:
-	PYTHONPATH=. pytest tests/ -v
+	PYTHONPATH=. $(PYTEST) tests/ -v -n $(PYTEST_WORKERS)
 
 .PHONY: coverage
 coverage:
-	$(PYTEST) --cov=. tests/ --cov-report=html
+	$(PYTEST) --cov=. tests/ --cov-report=html --cov-report=term-missing --cov-fail-under=$(COVERAGE_MIN)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Testing
.PHONY: test
test:
PYTHONPATH=. pytest tests/ -v
.PHONY: test-security
test-security:
$(PYTEST) tests/security/ -v
.PHONY: coverage
coverage:
$(PYTEST) --cov=. tests/ --cov-report=html
# Test Configuration
COVERAGE_MIN ?= 80
PYTEST_WORKERS ?= auto
# Testing
.PHONY: test
test:
PYTHONPATH=. $(PYTEST) tests/ -v -n $(PYTEST_WORKERS)
.PHONY: test-security
test-security:
$(PYTEST) tests/security/ -v
.PHONY: coverage
coverage:
$(PYTEST) --cov=. tests/ --cov-report=html --cov-report=term-missing --cov-fail-under=$(COVERAGE_MIN)

# Code Quality
.PHONY: lint
lint:
$(FLAKE8) .
$(BLACK) . --check
$(MYPY) .

.PHONY: format
format:
$(BLACK) .

# Security Checks
.PHONY: security
security:
$(BANDIT) -r . -x tests/,$(VENV)/
$(SAFETY) check

.PHONY: security-audit
security-audit: security test-security
@echo "Running comprehensive security audit..."
@echo "Checking for sensitive data in git history..."
@git log -p | grep -i "password\|secret\|key\|token" || true

Comment on lines +67 to +89
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve security audit implementation.

The security audit implementation has potential issues:

  1. The git history check could expose sensitive data in the logs
  2. The security checks could be more comprehensive
 .PHONY: security-audit
 security-audit: security test-security
 	@echo "Running comprehensive security audit..."
-	@echo "Checking for sensitive data in git history..."
-	@git log -p | grep -i "password\|secret\|key\|token" || true
+	@echo "Checking for sensitive data patterns..."
+	@$(BANDIT) -r . -ll --confidence-level high
+	@$(SAFETY) check --full-report
+	@echo "Note: For git history checks, use dedicated tools like 'gitleaks' offline"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Code Quality
.PHONY: lint
lint:
$(FLAKE8) .
$(BLACK) . --check
$(MYPY) .
.PHONY: format
format:
$(BLACK) .
# Security Checks
.PHONY: security
security:
$(BANDIT) -r . -x tests/,$(VENV)/
$(SAFETY) check
.PHONY: security-audit
security-audit: security test-security
@echo "Running comprehensive security audit..."
@echo "Checking for sensitive data in git history..."
@git log -p | grep -i "password\|secret\|key\|token" || true
# Code Quality
.PHONY: lint
lint:
$(FLAKE8) .
$(BLACK) . --check
$(MYPY) .
.PHONY: format
format:
$(BLACK) .
# Security Checks
.PHONY: security
security:
$(BANDIT) -r . -x tests/,$(VENV)/
$(SAFETY) check
.PHONY: security-audit
security-audit: security test-security
@echo "Running comprehensive security audit..."
@echo "Checking for sensitive data patterns..."
@$(BANDIT) -r . -ll --confidence-level high
@$(SAFETY) check --full-report
@echo "Note: For git history checks, use dedicated tools like 'gitleaks' offline"

# Dependencies
.PHONY: deps-update
deps-update:
$(PIP) install -U pip
$(PIP) install -U -r requirements.txt

.PHONY: deps-check
deps-check:
$(SAFETY) check
$(PIP) list --outdated

Comment on lines +90 to +100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance dependency management safety.

Consider adding requirements lock file handling and vulnerability database updates:

 # Dependencies
+REQUIREMENTS_IN = requirements.in
+REQUIREMENTS_TXT = requirements.txt
+
 .PHONY: deps-update
 deps-update:
+	$(PIP) install -U pip-tools
+	$(PIP) install -U safety
+	safety check --update-db
-	$(PIP) install -U pip
-	$(PIP) install -U -r requirements.txt
+	pip-compile --upgrade $(REQUIREMENTS_IN)
+	$(PIP) install -r $(REQUIREMENTS_TXT)

Committable suggestion skipped: line range outside the PR's diff.

# Docker
.PHONY: docker-build
docker-build:
docker build -t backend .

.PHONY: docker-run
docker-run:
docker run -p 8000:8000 --env-file .env backend

# Deployment
.PHONY: deploy-check
deploy-check: lint test security
@echo "Pre-deployment checks passed!"

.PHONY: deploy
deploy: deploy-check
@echo "Deploying to Cloud Run..."
gcloud run deploy

Comment on lines +101 to +119
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance Docker and deployment configuration.

The Docker and deployment targets could be more configurable:

+# Deployment Configuration
+DOCKER_TAG ?= latest
+DEPLOY_ENV ?= staging
+GCP_REGION ?= us-central1
+GCP_PROJECT ?= $(shell gcloud config get-value project)
+
 # Docker
 .PHONY: docker-build
 docker-build:
-	docker build -t backend .
+	docker build -t backend:$(DOCKER_TAG) \
+		--build-arg BUILD_ENV=$(DEPLOY_ENV) \
+		--build-arg VERSION=$$(git describe --tags --always) \
+		.
 
 .PHONY: deploy
 deploy: deploy-check
 	@echo "Deploying to Cloud Run..."
-	gcloud run deploy
+	gcloud run deploy backend \
+		--image backend:$(DOCKER_TAG) \
+		--platform managed \
+		--region $(GCP_REGION) \
+		--project $(GCP_PROJECT) \
+		--set-env-vars "DEPLOY_ENV=$(DEPLOY_ENV)"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Docker
.PHONY: docker-build
docker-build:
docker build -t backend .
.PHONY: docker-run
docker-run:
docker run -p 8000:8000 --env-file .env backend
# Deployment
.PHONY: deploy-check
deploy-check: lint test security
@echo "Pre-deployment checks passed!"
.PHONY: deploy
deploy: deploy-check
@echo "Deploying to Cloud Run..."
gcloud run deploy
# Deployment Configuration
DOCKER_TAG ?= latest
DEPLOY_ENV ?= staging
GCP_REGION ?= us-central1
GCP_PROJECT ?= $(shell gcloud config get-value project)
# Docker
.PHONY: docker-build
docker-build:
docker build -t backend:$(DOCKER_TAG) \
--build-arg BUILD_ENV=$(DEPLOY_ENV) \
--build-arg VERSION=$$(git describe --tags --always) \
.
.PHONY: docker-run
docker-run:
docker run -p 8000:8000 --env-file .env backend
# Deployment
.PHONY: deploy-check
deploy-check: lint test security
@echo "Pre-deployment checks passed!"
.PHONY: deploy
deploy: deploy-check
@echo "Deploying to Cloud Run..."
gcloud run deploy backend \
--image backend:$(DOCKER_TAG) \
--platform managed \
--region $(GCP_REGION) \
--project $(GCP_PROJECT) \
--set-env-vars "DEPLOY_ENV=$(DEPLOY_ENV)"

# Environment
.PHONY: env-check
env-check:
@if [ ! -f .env ]; then \
echo "Error: .env file not found"; \
echo "Creating from template..."; \
cp .env.template .env; \
fi
@echo "Checking required environment variables..."
@grep -v '^#' .env.template | grep '=' | cut -d '=' -f1 | while read -r var; do \
if ! grep -q "^$$var=" .env; then \
echo "Warning: $$var is not set in .env file"; \
fi \
done

# Help
.PHONY: help
help:
@echo "Available commands:"
@echo " setup - Create virtual environment and install dependencies"
@echo " run - Run development server"
@echo " clean - Remove all build, test, and coverage files"
@echo " test - Run all tests"
@echo " test-security - Run security tests"
@echo " coverage - Run tests with coverage report"
@echo " lint - Run code quality checks"
@echo " format - Format code with Black"
@echo " security - Run security checks"
@echo " security-audit - Run comprehensive security audit"
@echo " deps-update - Update dependencies"
@echo " deps-check - Check for outdated dependencies"
@echo " docker-build - Build Docker image"
@echo " docker-run - Run Docker container"
@echo " deploy-check - Run pre-deployment checks"
@echo " deploy - Deploy to Cloud Run"
@echo " env-check - Check environment variables"

.DEFAULT_GOAL := help
Loading