-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMakefile
More file actions
985 lines (847 loc) Β· 38.6 KB
/
Copy pathMakefile
File metadata and controls
985 lines (847 loc) Β· 38.6 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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
.PHONY: setup install-deps generate-db init-db run-tests clean frontend-setup frontend-install frontend-start frontend-ios frontend-android frontend-web frontend-build frontend-clean \
test-coverage test-verbose test-race test-bench frontend-test-deps frontend-test frontend-test-coverage frontend-test-watch \
frontend-test-unit frontend-test-integration frontend-test-e2e frontend-test-performance frontend-test-smoke frontend-test-responsive \
coverage coverage-backend coverage-frontend coverage-gaps coverage-gaps-backend coverage-gaps-frontend coverage-templates \
coverage-backend-detailed coverage-frontend-detailed coverage-view coverage-clean coverage-badge \
test-all test-quick test-smoke test-comprehensive test-performance test-integration \
test-ci test-ci-fast test-pre-commit test-release test-debug test-clean test-load test-stress test-setup test-validate test-report test-full-report \
start-test-server kill-server kill-frontend \
docker-build-backend docker-build-frontend docker-build-all docker-push-backend docker-push-frontend docker-push-all docker-deploy \
k8s-deploy k8s-update-images k8s-force-update-images k8s-restart k8s-wait k8s-status k8s-pods k8s-endpoints k8s-logs-backend k8s-logs-frontend k8s-delete \
deploy-all deploy-quick deploy-backend deploy-frontend
# Setup the entire project (backend + frontend)
setup: install-deps generate-db frontend-setup
# Backend Setup Commands
# ======================
# Install Go dependencies
install-deps:
go mod tidy
go mod download
# Install sqlc for code generation
install-sqlc:
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
# Generate database code from SQL schema
generate-db: install-sqlc
sqlc generate
# Initialize the database with schema
init-db:
mysql -h $(DB_HOST) -u $(DB_USER) -p$(DB_PASSWORD) < sql/schema.sql
# Run database migrations using golang-migrate
migrate:
migrate -path migrations -database "mysql://root:Password123!@tcp(localhost:3306)/gogent?multiStatements=true" up
# Show migration status
migrate-status:
migrate -path migrations -database "mysql://root:Password123!@tcp(localhost:3306)/gogent?multiStatements=true" version
# Force migration version (use when dirty)
migrate-force:
migrate -path migrations -database "mysql://root:Password123!@tcp(localhost:3306)/gogent?multiStatements=true" force $(VERSION)
# Reset database migrations
migrate-reset:
migrate -path migrations -database "mysql://root:Password123!@tcp(localhost:3306)/gogent?multiStatements=true" drop -f
# Build migration tool
build-migrate:
go build -o bin/migrate ./cmd/migrate
# Generate protobuf Go code
generate-proto:
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
proto/gogent.proto
# Install protobuf tools
install-proto-tools:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# ==================== DOCKER COMMANDS ====================
# Variables for Docker deployment
DOCKER_REGISTRY = registry.digitalocean.com/resourceloop
BACKEND_IMAGE = $(DOCKER_REGISTRY)/agentlog/backend
FRONTEND_IMAGE = $(DOCKER_REGISTRY)/agentlog/frontend
GIT_HASH := $(shell git rev-parse --short HEAD 2>/dev/null || echo "latest")
TIMESTAMP := $(shell date +%Y%m%d-%H%M%S)
IMAGE_TAG := $(GIT_HASH)-$(TIMESTAMP)
# Build backend Docker image
docker-build-backend: ## Build backend Docker image
@echo "π³ Building backend Docker image for amd64 architecture..."
docker buildx build --platform linux/amd64 --load -f Dockerfile.backend -t $(BACKEND_IMAGE):$(IMAGE_TAG) .
docker tag $(BACKEND_IMAGE):$(IMAGE_TAG) $(BACKEND_IMAGE):latest
@echo "β
Backend image built: $(BACKEND_IMAGE):$(IMAGE_TAG)"
# Build frontend Docker image
docker-build-frontend: ## Build frontend Docker image
@echo "π³ Building frontend Docker image for amd64 architecture..."
docker buildx build --platform linux/amd64 --load -t $(FRONTEND_IMAGE):$(IMAGE_TAG) frontend/
docker tag $(FRONTEND_IMAGE):$(IMAGE_TAG) $(FRONTEND_IMAGE):latest
@echo "β
Frontend image built: $(FRONTEND_IMAGE):$(IMAGE_TAG)"
# Build both Docker images
docker-build-all: docker-build-backend docker-build-frontend ## Build both backend and frontend Docker images
@echo "β
All Docker images built successfully!"
# Push backend Docker image
docker-push-backend: ## Push backend Docker image to registry
@echo "π€ Pushing backend image to registry..."
docker push $(BACKEND_IMAGE):$(IMAGE_TAG)
docker push $(BACKEND_IMAGE):latest
@echo "β
Backend image pushed: $(BACKEND_IMAGE):$(IMAGE_TAG)"
# Push frontend Docker image
docker-push-frontend: ## Push frontend Docker image to registry
@echo "π€ Pushing frontend image to registry..."
docker push $(FRONTEND_IMAGE):$(IMAGE_TAG)
docker push $(FRONTEND_IMAGE):latest
@echo "β
Frontend image pushed: $(FRONTEND_IMAGE):$(IMAGE_TAG)"
# Push both Docker images
docker-push-all: docker-build-all docker-push-backend docker-push-frontend ## Push both Docker images to registry
@echo "β
All Docker images pushed successfully!"
# Build and push all images
docker-deploy: docker-push-all ## Build and push all Docker images
@echo "π Docker deployment complete!"
@echo "π Images deployed:"
@echo " Backend: $(BACKEND_IMAGE):$(IMAGE_TAG)"
@echo " Frontend: $(FRONTEND_IMAGE):$(IMAGE_TAG)"
# ==================== KUBERNETES COMMANDS ====================
# Update Kubernetes deployment image tags
k8s-update-images: ## Update K8s deployment files with new image tags
@echo "π Updating Kubernetes deployment files with new image tags..."
@echo "Backend image: $(BACKEND_IMAGE):$(IMAGE_TAG)"
@echo "Frontend image: $(FRONTEND_IMAGE):$(IMAGE_TAG)"
# Update backend deployment
sed -i.bak "s|registry.digitalocean.com/resourceloop/agentlog/backend:.*|$(BACKEND_IMAGE):$(IMAGE_TAG)|g" k8s/backend-deployment.yaml
# Update frontend deployment
sed -i.bak "s|registry.digitalocean.com/resourceloop/agentlog/frontend:.*|$(FRONTEND_IMAGE):$(IMAGE_TAG)|g" k8s/frontend-deployment.yaml
@echo "β
Kubernetes deployment files updated!"
# Deploy to Kubernetes
k8s-deploy: ## Deploy to Kubernetes cluster
@echo "π Deploying to Kubernetes..."
kubectl apply -f k8s/configmap.yaml
kubectl apply -f k8s/secrets/ || echo "β οΈ Secrets may already exist"
kubectl apply -f k8s/backend-deployment.yaml
kubectl apply -f k8s/backend-service.yaml
kubectl apply -f k8s/frontend-deployment.yaml
kubectl apply -f k8s/frontend-service.yaml
kubectl apply -f k8s/ingress.yaml
kubectl apply -f k8s/certificate.yaml || echo "β οΈ Certificate may already exist"
@echo "β
Kubernetes deployment complete!"
# Force update deployments with new image tags (without restarting)
k8s-force-update-images: ## Force update K8s deployments with new image tags
@echo "π Force updating Kubernetes deployments with new images..."
@echo "Backend image: $(BACKEND_IMAGE):$(IMAGE_TAG)"
@echo "Frontend image: $(FRONTEND_IMAGE):$(IMAGE_TAG)"
# Force update backend deployment image
kubectl set image deployment/agentlog-backend backend=$(BACKEND_IMAGE):$(IMAGE_TAG) -n agentlog
# Force update frontend deployment image
kubectl set image deployment/agentlog-frontend frontend=$(FRONTEND_IMAGE):$(IMAGE_TAG) -n agentlog
@echo "β
Deployments updated with new images!"
# Restart deployments to pick up new images
k8s-restart: ## Restart Kubernetes deployments to pick up new images
@echo "π Restarting Kubernetes deployments..."
kubectl rollout restart deployment/agentlog-backend -n agentlog
kubectl rollout restart deployment/agentlog-frontend -n agentlog
@echo "β
Deployments restarted!"
# Wait for deployments to be ready
k8s-wait: ## Wait for Kubernetes deployments to be ready
@echo "β³ Waiting for deployments to be ready..."
kubectl rollout status deployment/agentlog-backend -n agentlog --timeout=300s
kubectl rollout status deployment/agentlog-frontend -n agentlog --timeout=300s
@echo "β
All deployments are ready!"
# Show Kubernetes status
k8s-status: ## Show Kubernetes deployment status
@echo "π Kubernetes Status:"
@echo "===================="
@echo "Pods:"
kubectl get pods -n agentlog
@echo ""
@echo "Services:"
kubectl get services -n agentlog
@echo ""
@echo "Ingress:"
kubectl get ingress -n agentlog
@echo ""
@echo "Deployments:"
kubectl get deployments -n agentlog
# Show logs
k8s-logs-backend: ## Show backend logs
kubectl logs -f deployment/agentlog-backend -n agentlog
k8s-logs-frontend: ## Show frontend logs
kubectl logs -f deployment/agentlog-frontend -n agentlog
# Quick status check
k8s-pods: ## Show pod status
kubectl get pods -n agentlog
# Show services and ingress
k8s-endpoints: ## Show services and ingress endpoints
@echo "π Services:"
kubectl get services -n agentlog
@echo ""
@echo "π Ingress:"
kubectl get ingress -n agentlog
@echo ""
@echo "π Access URLs:"
@echo " Frontend: https://agentlog.scalebase.io"
@echo " Backend Health: https://agentlog.scalebase.io/health"
@echo " Backend API: https://agentlog.scalebase.io/api/*"
# Delete all Kubernetes resources
k8s-delete: ## Delete all Kubernetes resources
@echo "ποΈ Deleting Kubernetes resources..."
kubectl delete -f k8s/certificate.yaml || echo "β οΈ Certificate not found"
kubectl delete -f k8s/ingress.yaml || echo "β οΈ Ingress not found"
kubectl delete -f k8s/frontend-service.yaml || echo "β οΈ Frontend service not found"
kubectl delete -f k8s/frontend-deployment.yaml || echo "β οΈ Frontend deployment not found"
kubectl delete -f k8s/backend-service.yaml || echo "β οΈ Backend service not found"
kubectl delete -f k8s/backend-deployment.yaml || echo "β οΈ Backend deployment not found"
kubectl delete -f k8s/configmap.yaml || echo "β οΈ ConfigMap not found"
@echo "β
Kubernetes resources deleted!"
# ==================== COMPLETE DEPLOYMENT WORKFLOW ====================
# Complete deployment: build, push, update K8s, deploy, and wait
deploy-all: ## Complete deployment workflow with forced image updates
@echo "π Starting complete deployment workflow..."
@echo "π Will deploy images with tag: $(IMAGE_TAG)"
@echo ""
@echo "Step 1: Building and pushing Docker images..."
@$(MAKE) docker-deploy IMAGE_TAG="$(IMAGE_TAG)"
@echo ""
@echo "Step 2: Updating Kubernetes deployments..."
@$(MAKE) k8s-force-update-images IMAGE_TAG="$(IMAGE_TAG)"
@echo ""
@echo "Step 3: Waiting for rollout to complete..."
@$(MAKE) k8s-wait
@echo ""
@echo "π Complete deployment finished!"
@echo "π Deployed:"
@echo " Backend: $(BACKEND_IMAGE):$(IMAGE_TAG)"
@echo " Frontend: $(FRONTEND_IMAGE):$(IMAGE_TAG)"
@echo ""
@echo "π Check status:"
@echo " make k8s-status"
@echo " make k8s-endpoints"
@echo " make k8s-logs-backend"
@echo " make k8s-logs-frontend"
# Quick deployment (assumes images are already built) - now with forced updates
deploy-quick: k8s-force-update-images k8s-wait ## Quick deployment with forced image updates
@echo "β‘ Quick deployment complete!"
# Build and deploy backend only - with forced update
deploy-backend: docker-build-backend docker-push-backend ## Build and deploy backend only with forced update
@echo "π§ Updating backend deployment YAML with new image..."
sed -i.bak 's|registry.digitalocean.com/resourceloop/agentlog/backend:[^[:space:]]*|$(BACKEND_IMAGE):$(IMAGE_TAG)|g' k8s/backend-deployment.yaml
@echo "π§ Applying updated backend deployment..."
kubectl apply -f k8s/backend-deployment.yaml
kubectl rollout status deployment/agentlog-backend -n agentlog --timeout=300s
@echo "β
Backend deployment complete with image: $(BACKEND_IMAGE):$(IMAGE_TAG)"
# Build and deploy frontend only - with forced update
deploy-frontend: docker-build-frontend docker-push-frontend ## Build and deploy frontend only with forced update
@echo "π¨ Updating frontend deployment YAML with new image..."
sed -i.bak 's|registry.digitalocean.com/resourceloop/agentlog/frontend:[^[:space:]]*|$(FRONTEND_IMAGE):$(IMAGE_TAG)|g' k8s/frontend-deployment.yaml
@echo "π¨ Applying updated frontend deployment..."
kubectl apply -f k8s/frontend-deployment.yaml
kubectl rollout status deployment/agentlog-frontend -n agentlog --timeout=300s
@echo "β
Frontend deployment complete with image: $(FRONTEND_IMAGE):$(IMAGE_TAG)"
# Backend Testing Commands
# ========================
# Run backend tests
run-tests:
@echo "π§ͺ Running backend tests (loading env if present)..."
@if [ -f .env.local ]; then echo "β‘οΈ Loading .env.local"; set -a; . ./.env.local; set +a; fi; \
if [ -f .env ]; then echo "β‘οΈ Loading .env"; set -a; . ./.env; set +a; fi; \
if [ -z "$$TEST_MYSQL_DSN" ] && [ -n "$$DB_URL" ]; then export TEST_MYSQL_DSN="$$DB_URL"; echo "β
TEST_MYSQL_DSN set from DB_URL"; fi; \
# Reset and migrate the test database derived from TEST_MYSQL_DSN
DBNAME=$$(echo "$$TEST_MYSQL_DSN" | sed -E 's|.*/([^/?]+).*|\1|'); \
USER=$$(echo "$$TEST_MYSQL_DSN" | sed -E 's|^([^:]+):.*|\1|'); \
PASS=$$(echo "$$TEST_MYSQL_DSN" | sed -E 's|^[^:]+:([^@]+)@.*|\1|'); \
HOSTPORT=$$(echo "$$TEST_MYSQL_DSN" | sed -E 's|.*@tcp\(([^)]+)\)/.*|\1|'); \
HOST=$$(echo "$$HOSTPORT" | cut -d: -f1); \
PORT=$$(echo "$$HOSTPORT" | cut -d: -f2); \
if [ -n "$$DBNAME" ]; then \
if echo "$$DBNAME" | grep -q 'test$$'; then \
echo "π§Ή Resetting MySQL test database '$$DBNAME'..."; \
MYSQL_PWD=$${TEST_DB_PASSWORD:-$$PASS} mysql -h $${TEST_DB_HOST:-$$HOST} -P $${TEST_DB_PORT:-$${PORT:-3306}} -u $${TEST_DB_USER:-$$USER} -e "DROP DATABASE IF EXISTS \`$$DBNAME\`; CREATE DATABASE \`$$DBNAME\`;" || true; \
MIGRATE_DSN="mysql://$${TEST_DB_USER:-$$USER}:$${TEST_DB_PASSWORD:-$$PASS}@tcp($${TEST_DB_HOST:-$$HOST}:$${TEST_DB_PORT:-$${PORT:-3306}})/$$DBNAME?multiStatements=true"; \
echo "π¦ Running migrations on '$$DBNAME'..."; \
migrate -path migrations -database "$$MIGRATE_DSN" up || true; \
else \
echo "β οΈ Refusing to reset non-test database '$$DBNAME'. Name must end with 'test'."; \
fi; \
fi; \
GOCACHE=$$(pwd)/.gocache go test ./...
# Run tests with coverage (legacy - use 'make coverage' for comprehensive analysis)
test-coverage:
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
# Run backend tests with verbose output
test-verbose:
go test -v ./...
# Run backend tests with race detection
test-race:
go test -race ./...
# Run backend benchmarks
test-bench:
go test -bench=. ./...
# Frontend Testing Commands
# ==========================
# Install frontend test dependencies
frontend-test-deps:
@echo "π¦ Installing frontend test dependencies..."
cd frontend && yarn add --dev jest @types/jest ts-jest @testing-library/react-native @testing-library/jest-native react-test-renderer
# Run all frontend tests
frontend-test:
@echo "π§ͺ Running all frontend tests..."
cd frontend && yarn test --watchAll=false
# Run frontend tests with coverage
frontend-test-coverage:
@echo "π Running frontend tests with coverage..."
cd frontend && yarn test --coverage --watchAll=false
# Run frontend tests in watch mode
frontend-test-watch:
@echo "π Running frontend tests in watch mode..."
cd frontend && yarn test --watch
# Run specific test suites
frontend-test-unit:
@echo "π§ͺ Running frontend unit tests..."
cd frontend && yarn test src/__tests__/components.test.tsx --watchAll=false
frontend-test-integration:
@echo "π Running frontend integration tests..."
cd frontend && yarn test src/__tests__/integration.test.ts --watchAll=false
frontend-test-e2e:
@echo "π― Running frontend end-to-end tests..."
cd frontend && yarn test src/__tests__/e2e.test.ts --watchAll=false
frontend-test-performance:
@echo "β‘ Running frontend performance tests..."
cd frontend && yarn test src/__tests__/performance.test.ts --watchAll=false
frontend-test-smoke:
@echo "π¨ Running frontend smoke tests..."
cd frontend && yarn test src/__tests__/smoke.test.ts --watchAll=false
frontend-test-responsive:
@echo "π± Running frontend responsive tests..."
cd frontend && yarn test src/__tests__/responsive.e2e.test.tsx --watchAll=false
# Coverage Analysis Commands
# ===========================
# Comprehensive coverage analysis (backend + frontend + gaps)
coverage: start-test-server
@echo "π Running comprehensive coverage analysis..."
./scripts/coverage-analysis.sh
@$(MAKE) kill-server
# Backend-only coverage analysis
coverage-backend: start-test-server
@echo "π Running backend coverage analysis..."
./scripts/coverage-analysis.sh --backend-only
@$(MAKE) kill-server
# Frontend-only coverage analysis
coverage-frontend: start-test-server
@echo "π Running frontend coverage analysis..."
./scripts/coverage-analysis.sh --frontend-only
@$(MAKE) kill-server
# Analyze coverage gaps and provide recommendations
coverage-gaps: start-test-server
@echo "π Analyzing coverage gaps..."
./scripts/coverage-gaps-finder.sh
@$(MAKE) kill-server
# Analyze backend coverage gaps only
coverage-gaps-backend: start-test-server
@echo "π Analyzing backend coverage gaps..."
./scripts/coverage-gaps-finder.sh --backend-only
@$(MAKE) kill-server
# Analyze frontend coverage gaps only
coverage-gaps-frontend: start-test-server
@echo "π Analyzing frontend coverage gaps..."
./scripts/coverage-gaps-finder.sh --frontend-only
@$(MAKE) kill-server
# Create test templates for missing coverage
coverage-templates: start-test-server
@echo "π Creating test templates..."
./scripts/coverage-gaps-finder.sh --templates-only
@$(MAKE) kill-server
# Enhanced backend coverage with detailed reporting
coverage-backend-detailed: start-test-server
@echo "π Running detailed backend coverage analysis..."
go test -coverprofile=coverage.out -covermode=atomic ./...
go tool cover -html=coverage.out -o coverage.html
go tool cover -func=coverage.out | sort -k3 -nr
@echo "π Coverage report: coverage.html"
@$(MAKE) kill-server
# Enhanced frontend coverage with detailed reporting
coverage-frontend-detailed: start-test-server
@echo "π Running detailed frontend coverage analysis..."
cd frontend && yarn test --coverage --watchAll=false --coverageReporters=json,html,text,lcov
@echo "π Coverage report: frontend/coverage/index.html"
@$(MAKE) kill-server
# Open coverage reports in browser (macOS)
coverage-view:
@echo "π Opening coverage reports..."
@if [ -f "coverage-reports/unified-coverage-report.html" ]; then \
open coverage-reports/unified-coverage-report.html; \
else \
echo "β Unified coverage report not found. Run 'make coverage' first."; \
fi
@if [ -f "coverage.html" ]; then \
open coverage.html; \
fi
@if [ -f "frontend/coverage/index.html" ]; then \
open frontend/coverage/index.html; \
fi
# Clean coverage files
coverage-clean:
@echo "π§Ή Cleaning coverage files..."
rm -f coverage.out coverage.html backend-coverage.json
rm -rf frontend/coverage
rm -rf coverage-reports
rm -f coverage-gaps-summary.md
rm -rf test-templates
# Generate coverage badge (requires shields.io)
coverage-badge:
@echo "π·οΈ Generating coverage badge..."
@if [ -f "coverage.out" ]; then \
COVERAGE=$$(go tool cover -func=coverage.out | grep total | awk '{print $$3}' | sed 's/%//'); \
echo "Backend Coverage: $$COVERAGE%"; \
curl -s "https://img.shields.io/badge/Backend_Coverage-$$COVERAGE%25-$(if [ $$COVERAGE -ge 80 ]; then echo "brightgreen"; elif [ $$COVERAGE -ge 60 ]; then echo "yellow"; else echo "red"; fi)" > backend-coverage-badge.svg; \
fi
@if [ -f "frontend/coverage/coverage-summary.json" ]; then \
FRONTEND_COVERAGE=$$(node -p "require('./frontend/coverage/coverage-summary.json').total.lines.pct"); \
echo "Frontend Coverage: $$FRONTEND_COVERAGE%"; \
curl -s "https://img.shields.io/badge/Frontend_Coverage-$$FRONTEND_COVERAGE%25-$(if [ $$(echo "$$FRONTEND_COVERAGE >= 80" | bc) -eq 1 ]; then echo "brightgreen"; elif [ $$(echo "$$FRONTEND_COVERAGE >= 60" | bc) -eq 1 ]; then echo "yellow"; else echo "red"; fi)" > frontend-coverage-badge.svg; \
fi
# Comprehensive Testing Commands
# ===============================
# Run all tests (backend + frontend) with backend server
test-all: run-tests start-test-server frontend-test frontend-test-responsive kill-server
@echo "β
All tests completed!"
# Run quick validation tests
test-quick: test-smoke frontend-test-smoke
@echo "β
Quick validation completed!"
# Run smoke tests for fast validation
test-smoke:
@echo "π¨ Running backend smoke tests..."
go test -run TestSmoke ./... -v
# Run comprehensive test suite with coverage
test-comprehensive: test-coverage frontend-test-coverage
@echo "π Comprehensive test suite with coverage completed!"
# Run performance and load tests
test-performance: test-bench frontend-test-performance
@echo "β‘ Performance tests completed!"
# Run integration tests
test-integration: frontend-test-integration
@echo "π Integration tests completed!"
# Continuous Integration Testing
# ===============================
# Run CI test suite (optimized for CI/CD)
test-ci:
@echo "π€ Running CI test suite..."
@echo "Backend tests..."
go test -race -coverprofile=backend-coverage.out ./...
@echo "Frontend tests..."
cd frontend && yarn test --coverage --watchAll=false --ci
@echo "β
CI test suite completed!"
# Run tests with proper timeouts for CI
test-ci-fast:
@echo "π Running fast CI test suite..."
@echo "Backend smoke tests..."
go test -run TestSmoke ./... -timeout=30s
@echo "Frontend smoke tests..."
cd frontend && yarn test src/__tests__/smoke.test.ts --watchAll=false --testTimeout=10000
@echo "β
Fast CI test suite completed!"
# Development Testing Commands
# =============================
# Run tests before committing
test-pre-commit: test-quick
@echo "π Pre-commit validation..."
@echo "Checking backend formatting..."
go fmt ./...
@echo "Checking frontend linting..."
cd frontend && yarn lint --fix || echo "β οΈ Linting issues found"
@echo "β
Pre-commit checks completed!"
# Run full test suite for releases
test-release: test-comprehensive test-performance
@echo "π Release validation..."
@echo "Running security checks..."
@command -v gosec >/dev/null 2>&1 && gosec ./... || echo "β οΈ Install gosec for security scanning"
@echo "Checking dependencies..."
go mod verify
cd frontend && yarn audit --level moderate || echo "β οΈ Frontend dependency vulnerabilities found"
@echo "β
Release validation completed!"
# Debug and Development
# =====================
# Run tests with debug output
test-debug:
@echo "π Running tests with debug output..."
go test -v -race ./... 2>&1 | tee backend-test-debug.log
cd frontend && yarn test --verbose --watchAll=false 2>&1 | tee frontend-test-debug.log
# Clean test artifacts
test-clean:
@echo "π§Ή Cleaning test artifacts..."
rm -f coverage.out backend-coverage.out backend-test-debug.log frontend-test-debug.log
cd frontend && rm -rf coverage/ jest-coverage/ test-results/
@echo "β
Test artifacts cleaned!"
# Load Testing Commands
# ======================
# Run load tests (requires backend to be running)
test-load:
@echo "π Running load tests..."
@echo "β οΈ Make sure backend is running (make run-api)"
cd frontend && yarn test src/__tests__/performance.test.ts --testNamePattern="load|concurrent|stress" --watchAll=false
# Run stress tests
test-stress:
@echo "πͺ Running stress tests..."
@echo "β οΈ Make sure backend is running (make run-api)"
cd frontend && yarn test src/__tests__/performance.test.ts --testNamePattern="stress|sustained|burst" --watchAll=false
# Test Environment Setup
# =======================
# Setup test environment
test-setup: frontend-test-deps
@echo "π§ Setting up test environment..."
@echo "Installing backend test tools..."
go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest || echo "β οΈ Could not install gosec"
@echo "β
Test environment setup completed!"
# Validate test setup
test-validate:
@echo "π Validating test setup..."
@echo "Backend tools..."
@command -v go >/dev/null 2>&1 && echo "β
Go installed" || echo "β Go not found"
@echo "Frontend tools..."
@cd frontend && command -v yarn >/dev/null 2>&1 && echo "β
Yarn installed" || echo "β Yarn not found"
@cd frontend && test -f node_modules/.bin/jest && echo "β
Jest installed" || echo "β Jest not found"
@echo "Test configuration..."
@cd frontend && test -f jest.config.js && echo "β
Jest config found" || echo "β Jest config missing"
@test -f Makefile && echo "β
Makefile found" || echo "β Makefile missing"
# Generate comprehensive test report
test-report:
@echo "π Generating comprehensive test report..."
@chmod +x scripts/test-report.sh
@./scripts/test-report.sh
# Run tests and generate report (alias for test-report)
test-full-report: test-report
# Build the backend project
build:
go build -o bin/gogent ./cmd/gogent
# Backend Demo Commands
# ====================
# Run auto-demo (detects configuration)
run:
@lsof -ti:8080 | xargs kill -9 2>/dev/null || true
@sleep 1
go run cmd/gogent/*.go
# Run simple demo with mock responses
run-simple:
go run cmd/gogent/*.go --simple
# Run simple demo with real Gemini API (no database)
run-simple-api:
go run cmd/gogent/*.go --simple-api
# Start HTTP server for frontend integration (alias for run-server)
run-api: run-server
# Start HTTP server for frontend integration
run-server:
@echo "π§Ή Cleaning up any existing processes..."
@pkill -9 -f gogent 2>/dev/null || true
@pkill -9 -f "go run.*gogent" 2>/dev/null || true
@lsof -ti:8080 | xargs kill -9 2>/dev/null || true
@sleep 2
@echo "β
Port 8080 is now available"
@echo "π§ Loading environment configuration..."
@if [ -f "config.env" ]; then \
echo "π Using config.env for environment setup"; \
export $$(grep -v '^#' config.env | xargs); \
if [ -n "$$API_ENCRYPTION_KEY" ]; then \
export EXPO_PUBLIC_API_ENCRYPTION_KEY="$$API_ENCRYPTION_KEY"; \
echo "π Synchronized encryption keys"; \
fi; \
fi
@echo "π Starting GoGent HTTP Server..."
@if [ -f "config.env" ]; then \
export $$(grep -v '^#' config.env | xargs) && \
export EXPO_PUBLIC_API_ENCRYPTION_KEY="$$API_ENCRYPTION_KEY" && \
go run cmd/gogent/*.go --server; \
else \
go run cmd/gogent/*.go --server; \
fi
# Run real API demo with database logging (one-time execution)
run-api-demo:
go run cmd/gogent/*.go --real-api
# Run the database version (requires DB setup)
run-db:
go run cmd/gogent/*.go --database
# Show help
help:
go run cmd/gogent/*.go --help
# Start backend server for testing (background with health check)
start-test-server:
@echo "π§ͺ Starting backend server for integration tests..."
@# Clean up any existing processes first
@pkill -9 -f gogent 2>/dev/null || true
@pkill -9 -f "go run.*gogent" 2>/dev/null || true
@lsof -ti:8080 | xargs kill -9 2>/dev/null || true
@sleep 2
@echo "π Starting GoGent test server in background..."
@go run cmd/gogent/*.go --server > /tmp/gogent-test.log 2>&1 & echo $$! > /tmp/gogent-test.pid
@echo "β³ Waiting for server to be ready..."
@for i in 1 2 3 4 5 6 7 8 9 10; do \
if curl -s http://localhost:8080/test > /dev/null 2>&1; then \
echo "β
Backend server is ready for testing!"; \
break; \
elif [ $$i -eq 10 ]; then \
echo "β Server failed to start within 10 seconds"; \
echo "π Server logs:"; \
cat /tmp/gogent-test.log 2>/dev/null || echo "No logs available"; \
exit 1; \
else \
echo "π Attempt $$i/10: Server not ready yet, waiting..."; \
sleep 1; \
fi; \
done
# Kill all server processes and free port 8080
kill-server:
@echo "π§Ή Stopping all GoGent processes..."
@pkill -9 -f gogent 2>/dev/null || true
@pkill -9 -f "go run.*gogent" 2>/dev/null || true
@lsof -ti:8080 | xargs kill -9 2>/dev/null || true
@# Clean up test server files
@rm -f /tmp/gogent-test.pid /tmp/gogent-test.log 2>/dev/null || true
@echo "β
All processes stopped and port 8080 freed"
# Kill all frontend processes and free port 8081
kill-frontend:
@echo "π§Ή Stopping all frontend processes..."
@pkill -9 -f "expo start" 2>/dev/null || true
@pkill -9 -f "yarn start" 2>/dev/null || true
@pkill -9 -f "yarn dev" 2>/dev/null || true
@pkill -9 -f "metro" 2>/dev/null || true
@lsof -ti:8081 | xargs kill -9 2>/dev/null || true
@lsof -ti:8082 | xargs kill -9 2>/dev/null || true
@echo "β
All frontend processes stopped and ports 8081/8082 freed"
# Frontend Setup Commands
# =======================
# Setup frontend project
frontend-setup: frontend-install
@echo "π― Frontend Setup Complete!"
@echo ""
@echo "π± Next steps:"
@echo "1. Make sure the backend is running: 'make run-api'"
@echo "2. Start the frontend: 'make frontend-start'"
@echo "3. Run on iOS: 'make frontend-ios'"
@echo "4. Run on Android: 'make frontend-android'"
@echo ""
# Install frontend dependencies
frontend-install:
@echo "π¦ Installing frontend dependencies..."
cd frontend && yarn install
# Frontend Development Commands
# ============================
# Start Expo development server
frontend-start:
@echo "π Starting Expo development server..."
cd frontend && npx expo start --clear
# Run on iOS simulator
frontend-ios:
@echo "π± Starting iOS app..."
cd frontend && npx expo start --ios
# Run on Android simulator
frontend-android:
@echo "π€ Starting Android app..."
cd frontend && npx expo start --android
# Run on web browser (with cleanup)
frontend-web:
@echo "π§Ή Cleaning up any existing frontend processes..."
@pkill -9 -f "expo start" 2>/dev/null || true
@pkill -9 -f "yarn start" 2>/dev/null || true
@pkill -9 -f "yarn dev" 2>/dev/null || true
@pkill -9 -f "metro" 2>/dev/null || true
@lsof -ti:8081 | xargs kill -9 2>/dev/null || true
@lsof -ti:8082 | xargs kill -9 2>/dev/null || true
@sleep 2
@echo "β
Ports 8081/8082 are now available"
@echo "π Starting web app..."
cd frontend && npx expo start --web
# Build frontend for production
frontend-build:
@echo "π¨ Building frontend for production..."
cd frontend && yarn build
# Frontend Maintenance Commands
# =============================
# Clean frontend dependencies and cache
frontend-clean:
@echo "π§Ή Cleaning frontend..."
cd frontend && rm -rf node_modules yarn.lock
cd frontend && rm -rf .expo
# Reinstall frontend dependencies
frontend-reinstall: frontend-clean frontend-install
# Type check frontend
frontend-typecheck:
@echo "π Type checking frontend..."
cd frontend && yarn type-check
# Lint frontend code
frontend-lint:
@echo "π Linting frontend..."
cd frontend && yarn lint
# Fix frontend linting issues
frontend-lint-fix:
@echo "π§ Fixing frontend lint issues..."
cd frontend && yarn lint --fix
# Backend Maintenance Commands
# ============================
# Clean generated files
clean:
rm -rf internal/db
rm -f coverage.out coverage.html
# Format backend code
fmt:
go fmt ./...
# Lint backend code
lint:
golangci-lint run
# Full Project Commands
# ====================
# Clean everything (backend + frontend)
clean-all: clean frontend-clean
@echo "π§Ή Cleaned backend and frontend"
# Kill everything (backend + frontend processes)
kill-all: kill-server kill-frontend
@echo "π§Ή Stopped all processes (backend + frontend)"
# Install all dependencies (backend + frontend)
install-all: install-deps frontend-install
@echo "π¦ Installed all dependencies"
# Development setup (first time setup)
dev-setup: setup
cp config.example.env config.env
@echo "π― GoGent Full Stack Development Setup Complete!"
@echo ""
@echo "π Backend Setup:"
@echo "1. Edit config.env and add your GEMINI_API_KEY"
@echo "2. Get your API key from: https://aistudio.google.com/app/apikey"
@echo "3. For database features: set up MySQL and run 'make init-db'"
@echo ""
@echo "π± Frontend Setup:"
@echo "4. Backend must be running for full functionality"
@echo "5. Start frontend with: 'make frontend-start'"
@echo ""
@echo "π Quick start commands:"
@echo " make run-api # Start backend with real API + database"
@echo " make frontend-start # Start mobile app development server"
@echo " make frontend-ios # Run on iOS simulator"
@echo " make frontend-android # Run on Android simulator"
@echo ""
@echo "π Development commands:"
@echo " make help # Backend help"
@echo " make frontend-typecheck # Check TypeScript types"
@echo " make frontend-lint # Lint frontend code"
@echo " make clean-all # Clean everything"
# Status check - verify everything is set up correctly
status:
@echo "π GoGent Project Status Check"
@echo "================================"
@echo ""
@echo "π Backend Status:"
@go version 2>/dev/null && echo "β
Go installed" || echo "β Go not found"
@test -f config.env && echo "β
Config file exists" || echo "β Config file missing (run 'make dev-setup')"
@test -d internal/db && echo "β
Database code generated" || echo "β Database code missing (run 'make generate-db')"
@echo ""
@echo "π± Frontend Status:"
@cd frontend && yarn --version 2>/dev/null && echo "β
Yarn installed" || echo "β Yarn not found"
@cd frontend && test -d node_modules && echo "β
Frontend dependencies installed" || echo "β Frontend dependencies missing (run 'make frontend-install')"
@cd frontend && test -f yarn.lock && echo "β
Yarn lockfile exists" || echo "β No yarn lockfile"
@echo ""
@echo "π Ready to start:"
@echo " Backend: make run-api"
@echo " Frontend: make frontend-start"
# Show all available commands
commands:
@echo "π οΈ GoGent Available Commands"
@echo "============================"
@echo ""
@echo "π¦ Setup & Installation:"
@echo " dev-setup # First-time setup (backend + frontend)"
@echo " setup # Setup backend only"
@echo " frontend-setup # Setup frontend only"
@echo " install-all # Install all dependencies"
@echo " status # Check project status"
@echo ""
@echo "π§ Backend Commands:"
@echo " run # Auto-detect demo mode"
@echo " run-simple # Mock responses demo"
@echo " run-simple-api # Real API demo (no DB)"
@echo " run-api # Real API + database demo"
@echo " run-db # Database demo"
@echo " build # Build backend binary"
@echo " run-tests # Run backend tests"
@echo ""
@echo "π³ Docker Commands:"
@echo " docker-build-backend # Build backend Docker image"
@echo " docker-build-frontend # Build frontend Docker image (amd64)"
@echo " docker-build-all # Build both Docker images"
@echo " docker-push-backend # Push backend image to registry"
@echo " docker-push-frontend # Push frontend image to registry"
@echo " docker-push-all # Push both images to registry"
@echo " docker-deploy # Build and push all images"
@echo ""
@echo "βΈοΈ Kubernetes Commands:"
@echo " k8s-deploy # Deploy to Kubernetes cluster"
@echo " k8s-update-images # Update deployment files with new image tags"
@echo " k8s-force-update-images # Force update live deployments with new image tags"
@echo " k8s-restart # Restart deployments"
@echo " k8s-wait # Wait for deployments to be ready"
@echo " k8s-status # Show deployment status"
@echo " k8s-pods # Show pod status"
@echo " k8s-endpoints # Show services and ingress"
@echo " k8s-logs-backend # Show backend logs"
@echo " k8s-logs-frontend # Show frontend logs"
@echo " k8s-delete # Delete all Kubernetes resources"
@echo ""
@echo "π Complete Deployment:"
@echo " deploy-all # Complete deployment workflow"
@echo " deploy-quick # Quick deployment (no build)"
@echo " deploy-backend # Build and deploy backend only"
@echo " deploy-frontend # Build and deploy frontend only"
@echo ""
@echo "π Testing Commands:"
@echo " Backend Tests:"
@echo " run-tests # Run backend tests"
@echo " test-coverage # Run backend tests with coverage"
@echo " test-verbose # Run backend tests with verbose output"
@echo " test-race # Run backend tests with race detection"
@echo " test-bench # Run backend benchmarks"
@echo ""
@echo " Frontend Tests:"
@echo " frontend-test # Run all frontend tests"
@echo " frontend-test-coverage # Run frontend tests with coverage"
@echo " frontend-test-watch # Run frontend tests in watch mode"
@echo " frontend-test-unit # Run frontend unit tests"
@echo " frontend-test-integration # Run frontend integration tests"
@echo " frontend-test-e2e # Run frontend end-to-end tests"
@echo " frontend-test-performance # Run frontend performance tests"
@echo " frontend-test-smoke # Run frontend smoke tests"
@echo ""
@echo " Comprehensive Testing:"
@echo " test-all # Run all tests (backend + frontend)"
@echo " test-quick # Run quick validation tests"
@echo " test-comprehensive # Run comprehensive test suite with coverage"
@echo " test-performance # Run performance and load tests"
@echo " test-integration # Run integration tests"
@echo ""
@echo " CI/CD Testing:"
@echo " test-ci # Run CI test suite (optimized for CI/CD)"
@echo " test-ci-fast # Run fast CI test suite"
@echo ""
@echo " Development Testing:"
@echo " test-pre-commit # Run tests before committing"
@echo " test-release # Run full test suite for releases"
@echo " test-debug # Run tests with debug output"
@echo ""
@echo " Load Testing:"
@echo " test-load # Run load tests (requires backend running)"
@echo " test-stress # Run stress tests (requires backend running)"
@echo ""
@echo " Test Environment:"
@echo " test-setup # Setup test environment"
@echo " test-validate # Validate test setup"
@echo " test-clean # Clean test artifacts"
@echo ""
@echo " Test Reporting:"
@echo " test-report # Generate comprehensive test report"
@echo " test-full-report # Generate full test report (alias)"
@echo ""
@echo ""
@echo "π± Frontend Commands:"
@echo " frontend-start # Start Expo dev server"
@echo " frontend-ios # Run on iOS simulator"
@echo " frontend-android # Run on Android simulator"
@echo " frontend-web # Run in web browser (with cleanup)"
@echo " frontend-build # Build for production"
@echo " kill-frontend # Stop all frontend processes"
@echo ""
@echo "π§Ή Maintenance:"
@echo " clean-all # Clean everything"
@echo " kill-all # Stop all processes"
@echo " kill-server # Stop backend processes"
@echo " kill-frontend # Stop frontend processes"
@echo " frontend-clean # Clean frontend only"
@echo " frontend-reinstall # Reinstall frontend deps"
@echo " frontend-lint # Lint frontend code"
@echo " frontend-typecheck # Check TypeScript types"