-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
161 lines (142 loc) · 5.54 KB
/
Copy pathMakefile
File metadata and controls
161 lines (142 loc) · 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
.PHONY: backend-test backend-test-build test-clean test-teardown test-network test-postgres frontend-test frontend-test-build integration-test migration-create migration-upgrade migration-downgrade migration-stamp
# Default target
all: backend-test
# Create Docker network if it doesn't exist
test-network:
docker network create amazeeai_default 2>/dev/null || true
# Build the backend test container
backend-test-build:
docker build -t amazee-backend-test -f Dockerfile.test .
# Start PostgreSQL container for testing.
# Durability is off and data lives on tmpfs: the DB is throwaway, and the
# test suite is DDL/commit-heavy enough that fsync dominates otherwise.
test-postgres: test-network
docker run -d \
--name amazee-test-postgres \
--network amazeeai_default \
--tmpfs /var/lib/postgresql/data \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=postgres_service \
pgvector/pgvector:pg16 \
-c fsync=off -c synchronous_commit=off -c full_page_writes=off && \
i=0; until docker exec amazee-test-postgres pg_isready -U postgres >/dev/null 2>&1; do \
i=$$((i+1)); [ $$i -ge 60 ] && echo "postgres not ready after 60s" && exit 1; sleep 1; \
done; sleep 1
# Teardown: stop and remove test containers, network, and image
test-teardown:
docker stop amazee-test-postgres 2>/dev/null || true
docker rm amazee-test-postgres 2>/dev/null || true
docker network rm amazeeai_default 2>/dev/null || true
docker rmi amazee-backend-test 2>/dev/null || true
# Run backend tests for a specific regex
# Usage: make backend-test-regex regex="test_pattern"
backend-test-regex: backend-test-build test-postgres
@if [ -z "$(regex)" ]; then \
echo "Error: regex parameter is required. Usage: make backend-test-regex regex=\"test_pattern\""; \
exit 1; \
fi
@status=0; \
docker run --rm \
--network amazeeai_default \
-e DATABASE_URL="postgresql://postgres:postgres@amazee-test-postgres/postgres_service" \
-e SECRET_KEY="test-secret-key" \
-e POSTGRES_HOST="amazee-test-postgres" \
-e POSTGRES_USER="postgres" \
-e POSTGRES_PASSWORD="postgres" \
-e POSTGRES_DB="postgres_service" \
-e DYNAMODB_ROLE_NAME="test-role" \
-e SES_ROLE_NAME="test-role" \
-e TESTING="1" \
-e ENV_SUFFIX="test" \
-v $(PWD)/app:/app/app \
-v $(PWD)/scripts:/app/scripts \
-v $(PWD)/tests:/app/tests \
amazee-backend-test pytest -vv --ignore=tests/integration -k "$(regex)" || status=$$?; \
$(MAKE) test-clean; \
exit $$status
# Run backend tests in a new container
backend-test: backend-test-build test-postgres
@status=0; \
docker run --rm \
--network amazeeai_default \
-e DATABASE_URL="postgresql://postgres:postgres@amazee-test-postgres/postgres_service" \
-e SECRET_KEY="test-secret-key" \
-e POSTGRES_HOST="amazee-test-postgres" \
-e POSTGRES_USER="postgres" \
-e POSTGRES_PASSWORD="postgres" \
-e POSTGRES_DB="postgres_service" \
-e DYNAMODB_ROLE_NAME="test-role" \
-e SES_ROLE_NAME="test-role" \
-e TESTING="1" \
-e ENV_SUFFIX="test" \
-v $(PWD)/app:/app/app \
-v $(PWD)/scripts:/app/scripts \
-v $(PWD)/tests:/app/tests \
amazee-backend-test || status=$$?; \
$(MAKE) test-clean; \
exit $$status
# Run backend tests with coverage report
backend-test-cov: backend-test-build test-postgres
@status=0; \
docker run --rm \
--network amazeeai_default \
-e DATABASE_URL="postgresql://postgres:postgres@amazee-test-postgres/postgres_service" \
-e SECRET_KEY="test-secret-key" \
-e POSTGRES_HOST="amazee-test-postgres" \
-e POSTGRES_USER="postgres" \
-e POSTGRES_PASSWORD="postgres" \
-e POSTGRES_DB="postgres_service" \
-e DYNAMODB_ROLE_NAME="test-role" \
-e SES_ROLE_NAME="test-role" \
-e TESTING="1" \
-e ENV_SUFFIX="test" \
-v $(PWD)/app:/app/app \
-v $(PWD)/scripts:/app/scripts \
-v $(PWD)/tests:/app/tests \
amazee-backend-test pytest -v --cov=app --ignore=tests/integration tests/ || status=$$?; \
$(MAKE) test-clean; \
exit $$status
# Build the frontend test container
frontend-test-build:
cd frontend && docker build -t amazeeai-frontend-test -f Dockerfile .
# Run frontend tests
frontend-test: frontend-test-build
docker run --rm \
-e CI=true \
amazeeai-frontend-test npm test -- --ci
# Run all tests (backend and frontend)
test-all: backend-test frontend-test
# Integration tests against real LiteLLM instances (see
# litellm-integration-tests-plan.md). Runs under its own compose project so
# teardown can never touch the dev stack's containers or volumes.
# Override the proxy image with LITELLM_IMAGE / LITELLM_TAG, e.g.:
# make integration-test LITELLM_TAG=v1.95.0
INTEGRATION_COMPOSE = docker compose -p amazeeai-integration \
-f docker-compose.yml -f docker-compose.integration.yml
integration-test:
@status=0; \
$(INTEGRATION_COMPOSE) run --rm --build integration-test || status=$$?; \
$(INTEGRATION_COMPOSE) down -v --remove-orphans; \
exit $$status
# Clean up test containers and images
test-clean:
docker stop amazee-test-postgres 2>/dev/null || true
docker rm amazee-test-postgres 2>/dev/null || true
docker network rm amazeeai_default 2>/dev/null || true
docker rmi amazee-backend-test 2>/dev/null || true
docker rmi amazeeai-frontend-test 2>/dev/null || true
# Database migrations
migration-create:
@read -p "Enter migration message: " message; \
python3 scripts/manage_migrations.py create "$$message"
migration-upgrade:
python3 scripts/manage_migrations.py upgrade
migration-downgrade:
python3 scripts/manage_migrations.py downgrade
migration-stamp:
@read -p "Enter revision to stamp: " revision; \
python3 scripts/manage_migrations.py stamp "$$revision"
.PHONY: lint
lint:
ruff check