-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
323 lines (262 loc) · 9.99 KB
/
Makefile
File metadata and controls
323 lines (262 loc) · 9.99 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
.PHONY: setup setup-week2 migrate migrate-down migrate-status run run-backend run-compliance test test-backend test-compliance test-unit test-integration test-e2e lint lint-compliance generate build build-compliance build-all clean tidy tools tools-compliance docker-up docker-up-standalone docker-logs docker-down help
# Default database URL
DATABASE_URL ?= postgresql://kovra:kovra_dev@localhost:5455/kovra?sslmode=disable
# Scripts directory
SCRIPTS_DIR := scripts
TEST_DATABASE_URL ?= postgresql://test:test@localhost:5433/test?sslmode=disable
# Service directories
BACKEND_DIR := backend
COMPLIANCE_DIR := compliance
# Development setup (Week 1: single TigerBeetle node)
setup:
@./scripts/setup.sh week1
# Week 2 setup (3-node TigerBeetle cluster)
setup-week2:
@./scripts/setup.sh week2
# Quick status check
status:
@echo "Container Status:"
@docker compose ps
@echo ""
@echo "TigerBeetle Data:"
@docker volume ls | grep tigerbeetle || echo "No TigerBeetle volumes found"
# Diagnose infrastructure issues
diagnose:
@./scripts/diagnose.sh
# Reset everything (delete all data!)
reset:
@echo "⚠️ WARNING: This will delete ALL data!"
@bash -c 'read -p "Are you sure? [y/N] " -n 1 -r; \
echo; \
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
docker compose --profile week1 --profile week2 down -v; \
docker volume rm -f kovra_tigerbeetle_data kovra_tigerbeetle_0_data kovra_tigerbeetle_1_data kovra_tigerbeetle_2_data 2>/dev/null || true; \
echo "✓ All data deleted. Run make setup to start fresh."; \
else \
echo "Cancelled."; \
exit 1; \
fi'
# Stop all services
down:
docker-compose --profile week1 --profile week2 down
# Database migrations
migrate:
goose -dir migrations postgres "$(DATABASE_URL)" up
migrate-down:
goose -dir migrations postgres "$(DATABASE_URL)" down
migrate-down-all:
goose -dir migrations postgres "$(DATABASE_URL)" down-to 0
migrate-status:
goose -dir migrations postgres "$(DATABASE_URL)" status
migrate-create:
@read -p "Migration name: " name; \
goose -dir migrations create $$name sql
# Run application (legacy - defaults to backend)
run: run-backend
# Run backend (Go)
run-backend:
@echo "Starting Go backend..."
cd $(BACKEND_DIR) && go run cmd/api/main.go
# Run backend with hot reload (air)
run-backend-air:
@echo "Starting Go backend with air (hot reload)..."
cd $(BACKEND_DIR) && air -c .air.toml
# Run compliance (Python)
run-compliance:
@echo "Starting Python compliance service..."
cd $(COMPLIANCE_DIR) && uvicorn app.main:app --reload --port 8000
# ============================================
# TESTING - Enterprise Grade Test Structure
# ============================================
# Run all tests (both services)
test: test-backend test-compliance
# Run backend tests
test-backend:
@echo "Running Go backend tests..."
cd $(BACKEND_DIR) && go test -v ./tests/... ./internal/...
# Run compliance tests
test-compliance:
@echo "Running Python compliance tests..."
cd $(COMPLIANCE_DIR) && pytest tests/ -v
# Run tests with coverage (backend only for now)
test-coverage:
cd $(BACKEND_DIR) && go test -coverprofile=coverage.out ./tests/... ./internal/...
cd $(BACKEND_DIR) && go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: backend/coverage.html"
# --------------------------------------------
# Unit Tests (Fast, Isolated, No External Deps)
# --------------------------------------------
test-unit:
@echo "Running Go backend unit tests..."
cd $(BACKEND_DIR) && go test -v -short ./tests/unit/...
test-unit-parallel:
@echo "Running Go backend unit tests in parallel..."
cd $(BACKEND_DIR) && go test -v -short -parallel=8 ./tests/unit/...
# --------------------------------------------
# Integration Tests (Requires Database)
# --------------------------------------------
test-integration:
@echo "Running Go backend integration tests..."
cd $(BACKEND_DIR) && TEST_DATABASE_URL="$(DATABASE_URL)" go test -v ./tests/integration/...
test-integration-setup:
@echo "Setting up test database..."
@docker run -d --name kovra-test-db \
-e POSTGRES_USER=test \
-e POSTGRES_PASSWORD=test \
-e POSTGRES_DB=test \
-p 5433:5432 \
postgres:15-alpine || echo "Test DB already running"
@echo "Waiting for test DB..."
@sleep 3
test-integration-teardown:
@echo "Tearing down test database..."
docker stop kovra-test-db || true
docker rm kovra-test-db || true
# --------------------------------------------
# E2E Tests (Full System)
# --------------------------------------------
test-e2e:
@echo "Running Go backend E2E tests..."
cd $(BACKEND_DIR) && TEST_DATABASE_URL="$(DATABASE_URL)" go test -v ./tests/e2e/...
demo-week1:
@echo "Running Week 1 demo..."
cd $(BACKEND_DIR) && TEST_DATABASE_URL="$(DATABASE_URL)" go test -v -run TestWeek1Demo ./tests/e2e/...
demo-week2:
@echo "Running Week 2 demo..."
cd $(BACKEND_DIR) && TEST_DATABASE_URL="$(DATABASE_URL)" go test -v -run TestWeek2Demo ./tests/e2e/...
# --------------------------------------------
# Simulation Tests (Deterministic)
# --------------------------------------------
test-simulation:
@echo "Running deterministic simulation tests (without synctest)..."
cd $(BACKEND_DIR) && go test -v -timeout=10m ./tests/simulation/...
test-simulation-synctest:
@echo "Running simulation tests with synctest (Go 1.24+)..."
cd $(BACKEND_DIR) && GOEXPERIMENT=synctest go test -v -timeout=10m ./tests/simulation/...
test-simulation-gosim:
@echo "Running simulation tests with gosim..."
cd $(BACKEND_DIR) && go run github.com/jellevandenhooff/gosim/cmd/gosim test -v ./tests/simulation/...
test-simulation-race:
@echo "Running simulation tests with race detector..."
cd $(BACKEND_DIR) && go test -v -race ./tests/simulation/...
test-simulation-seed:
@echo "Running simulation with specific seed..."
cd $(BACKEND_DIR) && go test -v -seed=42 ./tests/simulation/...
# --------------------------------------------
# Test Utilities
# --------------------------------------------
test-verbose:
cd $(BACKEND_DIR) && go test -v -count=1 ./tests/...
test-count:
@echo "Running tests multiple times for flakiness detection..."
cd $(BACKEND_DIR) && go test -count=5 ./tests/unit/...
test-race:
@echo "Running tests with race detector..."
cd $(BACKEND_DIR) && go test -race ./tests/...
# Benchmarks
bench:
cd $(BACKEND_DIR) && go test -bench=. -benchmem ./tests/...
# Code generation (run from backend directory)
generate:
cd $(BACKEND_DIR) && sqlc generate
# Linting (backend only for now)
lint:
cd $(BACKEND_DIR) && golangci-lint run
# Build backend
build:
cd $(BACKEND_DIR) && go build -o ../bin/kovra-api cmd/api/main.go
# Build compliance
build-compliance:
cd $(COMPLIANCE_DIR) && docker build -t kovra-compliance .
# Build all
build-all: build build-compliance
# Clean
clean:
rm -rf bin/
cd $(BACKEND_DIR) && rm -f coverage.out coverage.html
# Install Go tools (for backend)
tools:
cd $(BACKEND_DIR) && go install github.com/pressly/goose/v3/cmd/goose@latest
cd $(BACKEND_DIR) && go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
cd $(BACKEND_DIR) && go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Tidy Go dependencies
tidy:
cd $(BACKEND_DIR) && go mod tidy
# Install Python dependencies (for compliance)
tools-compliance:
cd $(COMPLIANCE_DIR) && pip install -r requirements.txt
# Format Python code
format-compliance:
cd $(COMPLIANCE_DIR) && black app/ tests/ --line-length 88
# Lint Python code
lint-compliance:
cd $(COMPLIANCE_DIR) && flake8 app/ tests/ --max-line-length 88
# ============================================
# Docker Compose Helpers
# ============================================
# Start all services
docker-up:
docker compose up -d
# Start without compliance (standalone mode)
docker-up-standalone:
COMPLIANCE_MODE=standalone docker compose up -d backend postgres redis tigerbeetle
# Start specific service
docker-up-backend:
docker compose up -d backend
docker-up-compliance:
docker compose up -d compliance
# View logs
docker-logs:
docker compose logs -f
docker-logs-backend:
docker compose logs -f backend
docker-logs-compliance:
docker compose logs -f compliance
# Stop all
docker-down:
docker compose down
# ============================================
# Help
# ============================================
help:
@echo "Kovra Payment Platform - Available Commands"
@echo ""
@echo "=== Development ==="
@echo " make run - Run Go backend (default)"
@echo " make run-backend - Run Go backend"
@echo " make run-compliance - Run Python compliance service"
@echo ""
@echo "=== Docker ==="
@echo " make docker-up - Start all services"
@echo " make docker-up-standalone- Start backend only (no compliance)"
@echo " make docker-logs - View all logs"
@echo " make docker-down - Stop all services"
@echo ""
@echo "=== Testing ==="
@echo " make test - Run all tests (backend + compliance)"
@echo " make test-backend - Run Go backend tests"
@echo " make test-compliance - Run Python compliance tests"
@echo " make test-unit - Run unit tests only"
@echo " make test-integration - Run integration tests"
@echo " make test-e2e - Run E2E tests"
@echo ""
@echo "=== Build ==="
@echo " make build - Build Go backend binary"
@echo " make build-compliance - Build compliance Docker image"
@echo " make build-all - Build both services"
@echo ""
@echo "=== Code Quality ==="
@echo " make lint - Lint Go code"
@echo " make lint-compliance - Lint Python code"
@echo " make generate - Generate SQLC code"
@echo " make tidy - Tidy Go dependencies"
@echo ""
@echo "=== Database ==="
@echo " make migrate - Run database migrations"
@echo " make migrate-status - Check migration status"
@echo ""
@echo "=== Infrastructure ==="
@echo " make setup - Setup development environment"
@echo " make setup-week2 - Setup with TigerBeetle cluster"
@echo " make status - Check container status"
@echo " make reset - Reset all data (WARNING: destructive)"