Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
1729 lines (1539 loc) · 77.5 KB
/
Copy pathMakefile
File metadata and controls
1729 lines (1539 loc) · 77.5 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
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Makefile
# Variables
ADMIN_FRONTEND_DIR := ui/admin-frontend
FORCE_BUILD := false
SKIP_FRONTEND := false
SKIP_DOCS := false
# Detect if enterprise submodule exists and is initialized
ENTERPRISE_EXISTS := $(shell test -f enterprise/.git && echo "yes" || echo "no")
ifeq ($(ENTERPRISE_EXISTS),yes)
BUILD_TAGS := -tags enterprise
EDITION := ent
$(info 🏢 Building Enterprise Edition)
else
BUILD_TAGS :=
EDITION := ce
$(info 🌍 Building Community Edition)
endif
# The root go.mod does not require the private enterprise module, so that the
# module graph plugin authors inherit resolves from the public proxy.
# Enterprise builds and tests of the root module find it through
# enterprise.work: prefix those go commands with $(call root_gowork,<tags>),
# which sets GOWORK when <tags> include enterprise. Never use it for
# microgateway/ or the plugin modules, which are not in that workspace.
ENT_GOWORK := GOWORK=$(CURDIR)/enterprise.work
root_gowork = $(if $(findstring enterprise,$(1)),$(ENT_GOWORK))
# Version information (from git tags)
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME ?= $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
# Build flags for production (optimized, stripped, with version info)
PROD_LDFLAGS := -ldflags="-w -s -X main.Version=$(VERSION) -X main.BuildHash=$(BUILD_HASH) -X main.BuildTime=$(BUILD_TIME)" -trimpath
# Build flags for development (with version info, no stripping)
DEV_LDFLAGS := -ldflags="-X main.Version=$(VERSION) -X main.BuildHash=$(BUILD_HASH) -X main.BuildTime=$(BUILD_TIME)"
# Default target
.DEFAULT_GOAL := help
all: build
# Help target
help:
@echo "Tyk AI Studio Build Targets"
@echo ""
@echo "Current edition: $(EDITION)"
@echo ""
@echo "🐳 Docker Development (RECOMMENDED - with hot reloading):"
@echo " make dev - Start minimal env (Studio + Frontend + Postgres)"
@echo " make dev-full - Start full stack (+ Gateway + Plugins)"
@echo " make dev-ent - Start enterprise minimal env"
@echo " make dev-full-ent - Start enterprise full stack (no plugin builds)"
@echo " make dev-full-ent-plugins - Same, plus build/watch all plugins"
@echo " make dev-down - Stop development environment"
@echo " make dev-help - Show all development commands"
@echo ""
@echo "Development (single platform, fast):"
@echo " make build-native - Build for current platform with CGO (auto-detect edition)"
@echo " make build-native-ce - Build CE for current platform with CGO"
@echo " make build-native-ent - Build ENT for current platform with CGO"
@echo " make build-local - Alias for build-native (backward compatible)"
@echo ""
@echo "Development flags:"
@echo " SKIP_FRONTEND=true - Skip frontend build (for faster iteration)"
@echo " SKIP_DOCS=true - Skip docs build (for faster iteration)"
@echo " Example: make build-native-ce SKIP_FRONTEND=true SKIP_DOCS=true"
@echo ""
@echo "Production (multi-platform, optimized, CGO-enabled):"
@echo " make build-prod - Build all platforms with CGO (auto-detect edition)"
@echo " make build-prod-ce - Build CE for all platforms with CGO"
@echo " make build-prod-ent - Build ENT for all platforms with CGO"
@echo ""
@echo "Platform-specific (CGO-enabled):"
@echo " make build-linux-amd64 - Linux AMD64 with CGO"
@echo " make build-linux-arm64 - Linux ARM64 with CGO (requires cross-compiler)"
@echo " make build-darwin-amd64 - Darwin AMD64 with CGO"
@echo " make build-darwin-arm64 - Darwin ARM64 with CGO"
@echo ""
@echo "Plugin Development:"
@echo " make tools - Build development tools (plugin-scaffold)"
@echo " make plugin-new - Scaffold a new plugin (NAME=x TYPE=y [CAPABILITIES=a,b])"
@echo " make plugin-help - Show plugin scaffolding help"
@echo " make plugins - Build all example plugins"
@echo " make plugin-publish - Build, sign, push a plugin + index it (NAME=x [VERSION=y])"
@echo " make plugin-verify - Check a published plugin's digest and signature (NAME=x|all)"
@echo " (guide: docs/site/docs/plugins-publishing.md)"
@echo ""
@echo "Packaging (RPM/DEB via GoReleaser + nfpm):"
@echo " make package - Build all packages (auto-detect edition)"
@echo " make package-ce - Build CE packages (both components)"
@echo " make package-ent - Build ENT packages (both components)"
@echo " make package-help - Show all packaging targets"
@echo " make test-package-smoke - Build CE packages and run smoke tests"
@echo ""
@echo "Other targets:"
@echo " make test - Run tests"
@echo " make clean - Clean build artifacts"
@echo " make show-edition - Show current edition info"
@echo ""
@echo "Integration Tests (requires Docker):"
@echo " make test-integration - Run all integration tests"
@echo " make test-integration-plugin-cache - Run cache plugin integration tests"
@echo " make test-integration-plugin-cache-full - Run all cache plugin tests (with cluster+syslog)"
@echo " make test-integration-plugin-cache-coverage - Run with coverage report"
@echo " make test-integration-plugin-github-rag - Run github-rag-ingest Vault integration tests"
@echo ""
# Build target (default to production multi-platform builds)
build: build-prod
# Build frontend (can be skipped with SKIP_FRONTEND=true)
build-frontend:
ifeq ($(SKIP_FRONTEND),true)
@echo "⏭️ Skipping frontend build (SKIP_FRONTEND=true)"
else
@echo "🔨 Building frontend..."
cd $(ADMIN_FRONTEND_DIR) && npm run build
endif
# Build documentation site (can be skipped with SKIP_DOCS=true)
build-docs:
ifeq ($(SKIP_DOCS),true)
@echo "⏭️ Skipping docs build (SKIP_DOCS=true)"
else
@echo "📚 Building documentation..."
cd docs/site && npm ci && npm run docs:build
endif
# ============================================================================
# Development Builds (single platform, fast, CGO enabled)
# ============================================================================
# Build for native platform (auto-detect edition)
build-native: ent-link build-frontend build-docs
@echo "🔨 Building $(EDITION) for native platform with CGO..."
@mkdir -p bin
$(call root_gowork,$(BUILD_TAGS)) CGO_ENABLED=1 go build $(BUILD_TAGS) $(DEV_LDFLAGS) -o bin/midsommar-$(EDITION)
cd microgateway && $(MAKE) build
cp microgateway/dist/microgateway-$(EDITION) bin/mgw-$(EDITION)
chmod +x bin/*
@echo "✅ Native build complete: bin/midsommar-$(EDITION) and bin/mgw-$(EDITION)"
# Build CE for native platform
build-native-ce: build-frontend build-docs
@echo "🔨 Building CE for native platform with CGO..."
@mkdir -p bin
CGO_ENABLED=1 go build $(DEV_LDFLAGS) -o bin/midsommar-ce
cd microgateway && $(MAKE) build-community
cp microgateway/dist/microgateway-ce bin/mgw-ce
chmod +x bin/*
@echo "✅ Native CE build complete"
# Build ENT for native platform
build-native-ent: ent-link build-frontend build-docs
@if [ ! -f enterprise/.git ]; then \
echo "❌ ERROR: Enterprise submodule not initialized."; \
echo "Run: make init-enterprise"; \
exit 1; \
fi
@echo "🔨 Building ENT for native platform with CGO..."
@mkdir -p bin
$(ENT_GOWORK) CGO_ENABLED=1 go build -tags enterprise $(DEV_LDFLAGS) -o bin/midsommar-ent
cd microgateway && $(MAKE) build-enterprise
cp microgateway/dist/microgateway-ent bin/mgw-ent
chmod +x bin/*
@echo "✅ Native ENT build complete"
# ============================================================================
# Production Builds (multi-platform, optimized, CGO enabled)
# ============================================================================
# Build production artifacts for all platforms (auto-detect edition)
build-prod: ent-link build-frontend
@echo "🏗️ Building production $(EDITION) artifacts..."
@mkdir -p bin
$(MAKE) build-linux-amd64 EDITION=$(EDITION) BUILD_TAGS="$(BUILD_TAGS)"
$(MAKE) build-linux-arm64 EDITION=$(EDITION) BUILD_TAGS="$(BUILD_TAGS)"
$(MAKE) build-darwin-amd64 EDITION=$(EDITION) BUILD_TAGS="$(BUILD_TAGS)"
$(MAKE) build-darwin-arm64 EDITION=$(EDITION) BUILD_TAGS="$(BUILD_TAGS)"
cd microgateway && $(MAKE) build-prod EDITION=$(EDITION)
cp microgateway/dist/microgateway-$(EDITION)-linux-amd64 bin/mgw-$(EDITION)-linux-amd64 2>/dev/null || true
cp microgateway/dist/microgateway-$(EDITION)-linux-arm64 bin/mgw-$(EDITION)-linux-arm64 2>/dev/null || true
cp microgateway/dist/microgateway-$(EDITION)-darwin-amd64 bin/mgw-$(EDITION)-darwin-amd64 2>/dev/null || true
cp microgateway/dist/microgateway-$(EDITION)-darwin-arm64 bin/mgw-$(EDITION)-darwin-arm64 2>/dev/null || true
chmod +x bin/* 2>/dev/null || true
@echo "✅ Production build complete"
# Build production CE for all platforms
build-prod-ce: build-frontend
@echo "🏗️ Building production CE artifacts..."
@mkdir -p bin
$(MAKE) build-linux-amd64 EDITION=ce BUILD_TAGS=""
$(MAKE) build-linux-arm64 EDITION=ce BUILD_TAGS=""
$(MAKE) build-darwin-amd64 EDITION=ce BUILD_TAGS=""
$(MAKE) build-darwin-arm64 EDITION=ce BUILD_TAGS=""
cd microgateway && $(MAKE) build-prod-ce
cp microgateway/dist/microgateway-ce-linux-amd64 bin/mgw-ce-linux-amd64 2>/dev/null || true
cp microgateway/dist/microgateway-ce-linux-arm64 bin/mgw-ce-linux-arm64 2>/dev/null || true
cp microgateway/dist/microgateway-ce-darwin-amd64 bin/mgw-ce-darwin-amd64 2>/dev/null || true
cp microgateway/dist/microgateway-ce-darwin-arm64 bin/mgw-ce-darwin-arm64 2>/dev/null || true
chmod +x bin/* 2>/dev/null || true
@echo "✅ Production CE build complete"
# Build production ENT for all platforms
build-prod-ent: ent-link build-frontend
@if [ ! -f enterprise/.git ]; then \
echo "❌ ERROR: Enterprise submodule not initialized."; \
echo "Run: make init-enterprise"; \
exit 1; \
fi
@echo "🏗️ Building production ENT artifacts..."
@mkdir -p bin
$(MAKE) build-linux-amd64 EDITION=ent BUILD_TAGS="-tags enterprise"
$(MAKE) build-linux-arm64 EDITION=ent BUILD_TAGS="-tags enterprise"
$(MAKE) build-darwin-amd64 EDITION=ent BUILD_TAGS="-tags enterprise"
$(MAKE) build-darwin-arm64 EDITION=ent BUILD_TAGS="-tags enterprise"
cd microgateway && $(MAKE) build-prod-ent
cp microgateway/dist/microgateway-ent-linux-amd64 bin/mgw-ent-linux-amd64 2>/dev/null || true
cp microgateway/dist/microgateway-ent-linux-arm64 bin/mgw-ent-linux-arm64 2>/dev/null || true
cp microgateway/dist/microgateway-ent-darwin-amd64 bin/mgw-ent-darwin-amd64 2>/dev/null || true
cp microgateway/dist/microgateway-ent-darwin-arm64 bin/mgw-ent-darwin-arm64 2>/dev/null || true
chmod +x bin/* 2>/dev/null || true
@echo "✅ Production ENT build complete"
# ============================================================================
# Platform-Specific Builds (CGO enabled)
# ============================================================================
# Linux AMD64 with CGO
build-linux-amd64: ent-link
@echo "Building midsommar $(EDITION) for linux/amd64 with CGO..."
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
$(call root_gowork,$(BUILD_TAGS)) go build $(BUILD_TAGS) $(PROD_LDFLAGS) \
-o bin/midsommar-$(EDITION)-linux-amd64
# Linux ARM64 with CGO (requires cross-compiler)
build-linux-arm64: ent-link
@echo "Building midsommar $(EDITION) for linux/arm64 with CGO..."
@if ! which aarch64-linux-gnu-gcc > /dev/null 2>&1; then \
echo "⚠️ Warning: aarch64-linux-gnu-gcc not found"; \
echo " Install: sudo apt-get install gcc-aarch64-linux-gnu (Ubuntu/Debian)"; \
echo " Or: brew install FiloSottile/musl-cross/musl-cross (macOS)"; \
echo " Attempting build anyway..."; \
fi
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 \
CC=aarch64-linux-gnu-gcc \
$(call root_gowork,$(BUILD_TAGS)) go build $(BUILD_TAGS) $(PROD_LDFLAGS) \
-o bin/midsommar-$(EDITION)-linux-arm64
# Darwin AMD64 with CGO
build-darwin-amd64: ent-link
@echo "Building midsommar $(EDITION) for darwin/amd64 with CGO..."
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 \
$(call root_gowork,$(BUILD_TAGS)) go build $(BUILD_TAGS) $(PROD_LDFLAGS) \
-o bin/midsommar-$(EDITION)-darwin-amd64
# Darwin ARM64 with CGO
build-darwin-arm64: ent-link
@echo "Building midsommar $(EDITION) for darwin/arm64 with CGO..."
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 \
$(call root_gowork,$(BUILD_TAGS)) go build $(BUILD_TAGS) $(PROD_LDFLAGS) \
-o bin/midsommar-$(EDITION)-darwin-arm64
# ============================================================================
# FIPS 140-3 Builds (Go Cryptographic Module v1.0.0, CMVP #5247)
# ============================================================================
# GOFIPS140 pins the frozen, CMVP-validated module; the binaries default to
# fips140=on. The fips tag is Tyk's marker for FIPS builds. Each binary is
# checked with scripts/fips-verify.sh. Release packages come from goreleaser
# (ci/goreleaser/*.yml, fips-* build ids).
FIPS_GOFIPS140 := v1.0.0
comma := ,
FIPS_TAGS = -tags $(if $(filter ent,$(EDITION)),fips$(comma)enterprise,fips)
.PHONY: build-fips build-linux-amd64-fips build-linux-arm64-fips
# Build FIPS Studio and microgateway binaries for the native platform
build-fips: ent-link build-frontend build-docs
@echo "🔐 Building FIPS $(EDITION) for native platform..."
@mkdir -p bin
$(call root_gowork,$(FIPS_TAGS)) GOFIPS140=$(FIPS_GOFIPS140) CGO_ENABLED=1 go build $(FIPS_TAGS) $(PROD_LDFLAGS) -o bin/midsommar-$(EDITION)-fips
scripts/fips-verify.sh --edition $(EDITION) --fips bin/midsommar-$(EDITION)-fips
cd microgateway && $(MAKE) build-fips EDITION=$(EDITION)
cp microgateway/dist/microgateway-$(EDITION)-fips bin/mgw-$(EDITION)-fips
@echo "✅ FIPS build complete: bin/midsommar-$(EDITION)-fips and bin/mgw-$(EDITION)-fips"
# Linux AMD64 FIPS with CGO
build-linux-amd64-fips: ent-link
@mkdir -p bin
GOFIPS140=$(FIPS_GOFIPS140) CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
$(call root_gowork,$(FIPS_TAGS)) go build $(FIPS_TAGS) $(PROD_LDFLAGS) \
-o bin/midsommar-$(EDITION)-fips-linux-amd64
scripts/fips-verify.sh --edition $(EDITION) --fips bin/midsommar-$(EDITION)-fips-linux-amd64
# Linux ARM64 FIPS with CGO (requires cross-compiler)
build-linux-arm64-fips: ent-link
@mkdir -p bin
GOFIPS140=$(FIPS_GOFIPS140) CGO_ENABLED=1 GOOS=linux GOARCH=arm64 \
CC=aarch64-linux-gnu-gcc \
$(call root_gowork,$(FIPS_TAGS)) go build $(FIPS_TAGS) $(PROD_LDFLAGS) \
-o bin/midsommar-$(EDITION)-fips-linux-arm64
scripts/fips-verify.sh --edition $(EDITION) --fips bin/midsommar-$(EDITION)-fips-linux-arm64
# ============================================================================
# Backward Compatibility Targets
# ============================================================================
# Build for local development (alias for build-native)
build-local: build-native
# Legacy build-community (now uses explicit CGO builds)
build-community: build-prod-ce
@echo "Note: build-community now builds production artifacts with CGO"
@echo "For quick local builds, use: make build-native-ce"
# Legacy build-enterprise (now uses explicit CGO builds)
build-enterprise: build-prod-ent
@echo "Note: build-enterprise now builds production artifacts with CGO"
@echo "For quick local builds, use: make build-native-ent"
# ============================================================================
# Package Building (RPM/DEB using GoReleaser + nfpm)
# ============================================================================
# These targets use the SAME GoReleaser configs and Docker image as CI,
# ensuring local packages are identical to release packages.
#
# Builds run inside the tykio/golang-cross Docker container (same as CI)
# because CGO cross-compilation requires Linux cross-compiler toolchains.
#
# Prerequisites:
# Docker must be running
#
# Usage:
# make package Build all packages (auto-detect edition)
# make package-studio Build AI Studio packages only
# make package-microgateway Build Microgateway packages only
# make package-ce Build CE packages for both components
# make package-ent Build ENT packages for both components
# ============================================================================
GOLANG_CROSS_IMAGE ?= tykio/golang-cross:1.26-bullseye
GORELEASER_FLAGS ?= --snapshot --skip=sign --skip=publish --clean
# Internal helper: run goreleaser inside the cross-compilation Docker container.
# Usage: $(call run_goreleaser,<goreleaser-config>,<goflags>)
# EDITION (ent when the goflags carry the enterprise tag, else ce) names the
# packages: the goreleaser templates add -ee for ent.
# This matches CI exactly: same image, same env vars, same goreleaser invocation.
# NOTE: does NOT use --clean to allow building both components into the same dist/.
# Use `make clean-dist` to reset before a fresh build.
# The container runs as root and the checkout belongs to the host user, so
# git refuses it ("dubious ownership") and goreleaser and Go's VCS stamping
# fail: mark it safe, as release.yml's build script does.
define run_goreleaser
docker run --rm --platform linux/amd64 \
-e CGO_ENABLED=1 \
-e GOFLAGS='$(2)' \
-e EDITION='$(if $(findstring enterprise,$(2)),ent,ce)' \
-e PACKAGECLOUD_REPO=local/dev \
-e DEBVERS='unused' \
-e RPMVERS='unused' \
-e GOCACHE=/cache/go-build \
-e GOMODCACHE=/go/pkg/mod \
-v $(CURDIR):/go/src/github.com/TykTechnologies/midsommar \
-v $(HOME)/go/pkg/mod:/go/pkg/mod \
-v $(HOME)/.cache/go-build:/cache/go-build \
-w /go/src/github.com/TykTechnologies/midsommar \
$(GOLANG_CROSS_IMAGE) \
sh -c 'git config --global --add safe.directory /go/src/github.com/TykTechnologies/midsommar && \
goreleaser release -f $(1) $(GORELEASER_FLAGS)'
endef
# merge_staging copies the studio packages saved in .dist-staging/ back into
# dist/ after the microgateway run. goreleaser writes dist/ as root inside
# the container, so on Linux hosts and CI runners the user cannot write to
# it: copy through the same container.
define merge_staging
docker run --rm --platform linux/amd64 \
-v $(CURDIR):/go/src/github.com/TykTechnologies/midsommar \
-w /go/src/github.com/TykTechnologies/midsommar \
$(GOLANG_CROSS_IMAGE) \
sh -c 'cp .dist-staging/* dist/'
endef
clean-dist:
rm -rf dist/
.PHONY: package package-studio package-microgateway package-ce package-ent
.PHONY: package-studio-ce package-studio-ent package-microgateway-ce package-microgateway-ent
.PHONY: package-help test-package-smoke test-package-smoke-ent
# Build all packages for current edition
package: clean-dist package-studio package-microgateway
@echo "✅ All packages built in dist/"
@ls -la dist/*.deb dist/*.rpm 2>/dev/null || echo "No packages found"
# Build AI Studio packages (current edition)
package-studio: build-frontend build-docs
@echo "📦 Building AI Studio $(EDITION) packages..."
$(call run_goreleaser,ci/goreleaser/goreleaser.yml,$(BUILD_TAGS))
@echo "✅ AI Studio packages:"
@ls -la dist/tyk-ai-studio*.deb dist/tyk-ai-studio*.rpm 2>/dev/null
# Build Microgateway packages (current edition)
package-microgateway:
@echo "📦 Building Microgateway $(EDITION) packages..."
$(call run_goreleaser,ci/goreleaser/goreleaser-microgateway.yml,$(BUILD_TAGS))
@echo "✅ Microgateway packages:"
@ls -la dist/tyk-microgateway*.deb dist/tyk-microgateway*.rpm 2>/dev/null
# CE variants
# GoReleaser uses --clean which wipes dist/ each run. For combined builds,
# we save studio packages to .dist-staging/ (outside dist/) then merge after mgw build.
package-ce: build-frontend build-docs
@echo "📦 Building all CE packages..."
$(call run_goreleaser,ci/goreleaser/goreleaser.yml,)
@mkdir -p .dist-staging && cp dist/*.deb dist/*.rpm .dist-staging/ 2>/dev/null || true
$(call run_goreleaser,ci/goreleaser/goreleaser-microgateway.yml,)
$(call merge_staging)
@rm -rf .dist-staging
@echo "✅ CE packages:"
@ls dist/*.deb dist/*.rpm 2>/dev/null
# ENT variants
package-ent: build-frontend build-docs
@if [ ! -f enterprise/.git ]; then \
echo "❌ ERROR: Enterprise submodule not initialized. Run: make init-enterprise"; \
exit 1; \
fi
@echo "📦 Building all ENT packages..."
$(call run_goreleaser,ci/goreleaser/goreleaser.yml,-tags=enterprise)
@mkdir -p .dist-staging && cp dist/*.deb dist/*.rpm .dist-staging/ 2>/dev/null || true
$(call run_goreleaser,ci/goreleaser/goreleaser-microgateway.yml,-tags=enterprise)
$(call merge_staging)
@rm -rf .dist-staging
@echo "✅ ENT packages:"
@ls dist/*.deb dist/*.rpm 2>/dev/null
# Package smoke tests
test-package-smoke: package-ce
@echo "🧪 Running package smoke tests (CE)..."
docker compose -f tests/packaging/compose.yml up -d --build --wait || \
(docker compose -f tests/packaging/compose.yml logs; docker compose -f tests/packaging/compose.yml down -v; exit 1)
cd tests/packaging && npm ci && npx playwright install --with-deps chromium && npx playwright test --reporter=list || \
(docker compose -f ../../tests/packaging/compose.yml logs; docker compose -f ../../tests/packaging/compose.yml down -v; exit 1)
docker compose -f tests/packaging/compose.yml down -v
@echo "✅ Package smoke tests passed"
$(MAKE) test-fips-smoke
# FIPS 140-3 runtime smoke test (tests/fipssmoke) of the -fips packages in
# dist/: as the -fips container images (ci/Dockerfile*.fips.distroless) and
# as installed .debs (tests/packaging/Dockerfile.deb-smoke PACKAGES=fips).
# Run by test-package-smoke[-ent]; on its own it needs dist/ from a package
# build. FIPS_SMOKE_ARCH picks the packages (default amd64).
.PHONY: test-fips-smoke
FIPS_SMOKE_ARCH ?= amd64
test-fips-smoke:
@echo "🧪 Running FIPS 140-3 smoke tests ($(FIPS_SMOKE_ARCH))..."
docker build -t fips-smoke-studio:local -f ci/Dockerfile.fips.distroless --build-arg TARGETARCH=$(FIPS_SMOKE_ARCH) dist
docker build -t fips-smoke-gateway:local -f ci/Dockerfile.microgateway.fips.distroless --build-arg TARGETARCH=$(FIPS_SMOKE_ARCH) dist
tests/fipssmoke/run.sh image fips-smoke-studio:local fips-smoke-gateway:local
docker build -t fips-smoke-deb:local -f tests/packaging/Dockerfile.deb-smoke --build-arg TARGETARCH=$(FIPS_SMOKE_ARCH) --build-arg PACKAGES=fips .
tests/fipssmoke/run.sh deb fips-smoke-deb:local
@echo "✅ FIPS smoke tests passed"
test-package-smoke-ent: package-ent
@echo "🧪 Running package smoke tests (ENT)..."
@# Source license from dev/.env.secrets if available
$(eval export TYK_AI_LICENSE=$(shell grep -s '^TYK_AI_LICENSE=' dev/.env.secrets | cut -d= -f2-))
@if [ -z "$$TYK_AI_LICENSE" ]; then \
echo "⚠️ Warning: TYK_AI_LICENSE not set. ENT smoke tests may fail."; \
echo " Set it in dev/.env.secrets or export TYK_AI_LICENSE=..."; \
fi
docker compose -f tests/packaging/compose.yml up -d --build --wait || \
(docker compose -f tests/packaging/compose.yml logs; docker compose -f tests/packaging/compose.yml down -v; exit 1)
cd tests/packaging && npm ci && npx playwright install --with-deps chromium && npx playwright test --reporter=list || \
(docker compose -f ../../tests/packaging/compose.yml logs; docker compose -f ../../tests/packaging/compose.yml down -v; exit 1)
docker compose -f tests/packaging/compose.yml down -v
@echo "✅ Package smoke tests passed"
$(MAKE) test-fips-smoke
# Package help
package-help:
@echo "Package Building Targets (all run inside Docker for cross-compilation)"
@echo ""
@echo " make package Build all packages (auto-detect edition)"
@echo " make package-studio Build AI Studio packages"
@echo " make package-microgateway Build Microgateway packages"
@echo " make package-ce Build all CE packages"
@echo " make package-ent Build all ENT packages"
@echo " make package-studio-ce Build AI Studio CE packages"
@echo " make package-studio-ent Build AI Studio ENT packages"
@echo " make package-microgateway-ce Build Microgateway CE packages"
@echo " make package-microgateway-ent Build Microgateway ENT packages"
@echo " make test-package-smoke Build CE packages and run smoke tests"
@echo " make test-package-smoke-ent Build ENT packages and run smoke tests"
@echo ""
@echo "Packages output to dist/ directory"
@echo "Override Docker image: GOLANG_CROSS_IMAGE=... make package"
# Build all plugins
plugins:
@echo "Building studio plugins..."
@failed_plugins=""; \
for plugin in examples/plugins/studio/*/; do \
if [ -d "$$plugin/server" ]; then \
plugin_name=$$(basename "$$plugin"); \
echo "Building studio plugin: $$plugin_name"; \
if (cd "$$plugin/server" && go build -o ../$$plugin_name); then \
echo " ✓ Successfully built $$plugin_name"; \
else \
echo " ✗ Failed to build $$plugin_name"; \
failed_plugins="$$failed_plugins $$plugin_name"; \
fi; \
fi; \
done; \
echo "Building gateway plugins..."; \
for plugin in examples/plugins/gateway/*/; do \
if [ -f "$$plugin/main.go" ]; then \
plugin_name=$$(basename "$$plugin"); \
echo "Building gateway plugin: $$plugin_name"; \
if (cd microgateway && go build -o "../$$plugin/$$plugin_name" "../$$plugin"); then \
echo " ✓ Successfully built $$plugin_name"; \
else \
echo " ✗ Failed to build $$plugin_name"; \
failed_plugins="$$failed_plugins $$plugin_name"; \
fi; \
fi; \
done; \
if [ -n "$$failed_plugins" ]; then \
echo ""; \
echo "⚠️ Some plugins failed to build:$$failed_plugins"; \
echo "The following plugins built successfully can be used."; \
else \
echo ""; \
echo "✅ All plugins built successfully!"; \
fi
# ============================================================================
# Plugin Scaffolding
# ============================================================================
# Usage:
# make plugin-new NAME=my-plugin TYPE=studio
# make plugin-new NAME=my-plugin TYPE=studio CAPABILITIES=studio_ui,post_auth,on_response
# make plugin-new NAME=my-enricher TYPE=gateway
# make plugin-new NAME=my-assistant TYPE=agent
# make plugin-help
.PHONY: plugin-new plugin-help tools
# Build all development tools
tools: bin/plugin-scaffold
@echo "✅ Development tools built successfully"
@echo " - bin/plugin-scaffold (plugin scaffolding)"
# Build the scaffolding tool (rebuilds only if source changes)
bin/plugin-scaffold: $(wildcard cmd/plugin-scaffold/*.go)
@echo "Building plugin-scaffold tool..."
@mkdir -p bin
@go build -o bin/plugin-scaffold ./cmd/plugin-scaffold
# Scaffold a new plugin
plugin-new: bin/plugin-scaffold
@if [ -z "$(NAME)" ] || [ -z "$(TYPE)" ]; then \
echo "Usage: make plugin-new NAME=my-plugin TYPE=studio|gateway|agent|data-collector [CAPABILITIES=cap1,cap2]"; \
echo ""; \
echo "Run 'make plugin-help' for more information."; \
exit 1; \
fi
@./bin/plugin-scaffold -name="$(NAME)" -type="$(TYPE)" -capabilities="$(CAPABILITIES)"
# Show plugin scaffolding help
plugin-help: bin/plugin-scaffold
@./bin/plugin-scaffold -help
# ============================================================================
# Schema snapshots
# ============================================================================
.PHONY: schema-golden
schema-golden: ## Regenerate the schema snapshot goldens (SQLite + postgres:16 in Docker) after a model change
@scripts/schema-golden.sh
# ============================================================================
# API docs
# ============================================================================
.PHONY: swagger
SWAG_VERSION ?= v1.16.4
swagger: ## Regenerate docs/swagger from the handler annotations (general info in api/api.go)
@go run github.com/swaggo/swag/cmd/swag@$(SWAG_VERSION) init -g api/api.go -o docs/swagger --overridesFile docs/swagger/.swaggo
# ============================================================================
# gorm: AI Studio's own copy (see third_party/README.md)
# ============================================================================
.PHONY: gorm-vendor gorm-verify
gorm-vendor: ## Rebuild third_party/gorm.io from the pins in third_party/gorm-pin/go.mod
@scripts/gorm-vendor.sh
gorm-verify: ## Check third_party/gorm.io matches its pins and nothing imports gorm.io
@scripts/gorm-verify.sh
.PHONY: vet
vet: ent-link ## go vet the root, microgateway and enterprise modules in both editions, excluding third_party/ (VET_EDITION=ce|ent|all)
@scripts/vet.sh $(or $(VET_EDITION),all)
.PHONY: ent-link
ent-link: ## Link enterprise tests and registrations of core packages in from enterprise/_coretests (no-op without the submodule)
@scripts/enterprise-link-tests.sh
.PHONY: tidy
tidy: ## go mod tidy the root module (unlinks the enterprise files first, which tidy cannot resolve, and relinks them)
@scripts/enterprise-link-tests.sh --unlink
GOWORK=off go mod tidy
@scripts/enterprise-link-tests.sh
.PHONY: sdk-consumer-check
sdk-consumer-check: ## Check a plugin importing the SDK resolves its whole module graph from the public Go proxy
@scripts/sdk-consumer-check.sh
.PHONY: agent-tracing-docs agent-tracing-docs-verify
agent-tracing-docs: ## Regenerate the OTel attribute tables in docs/site/docs/agent-tracing.md from the enterprise mapping profile
@cd enterprise && UPDATE_DOCS=1 go test -tags enterprise -count=1 -run TestAttributeTableDocInSync ./features/agenttracing/otelexport/
agent-tracing-docs-verify: ## Check those tables match the mapping profile (no-op without the enterprise submodule)
@if [ -d enterprise/features/agenttracing/otelexport ]; then \
cd enterprise && go test -tags enterprise -count=1 -run TestAttributeTableDocInSync ./features/agenttracing/otelexport/; \
else echo "agent-tracing-docs-verify: no enterprise submodule, skipped"; fi
.PHONY: enterprise-import-guard
enterprise-import-guard: ## Check no public package imports the private enterprise module
@scripts/enterprise-import-guard.sh
.PHONY: fips-guard
fips-guard: ## Check first-party Go code adds no non-FIPS-approved crypto (allowlist: scripts/fips-guard.allowlist)
@scripts/fips-guard.sh --self-test
@scripts/fips-guard.sh
.PHONY: logging-guard
logging-guard: ## Check the control-plane packages log only through the logger package (an embedding host's logger)
@scripts/logging-guard.sh
.PHONY: langchaingo-verify
langchaingo-verify: ## Check nothing builds with upstream github.com/tmc/langchaingo (use third_party/langchaingo)
@scripts/langchaingo-verify.sh
# PLUGIN_MOD_ROOTS limits the directories searched (default: examples,
# enterprise/plugins, community/plugins, tyk-internal/plugins where present).
.PHONY: plugins-mod-check
plugins-mod-check: ## Check every in-repo plugin module's go.mod is tidy against this tree (PLUGIN_MOD_BUILD=1 also builds them)
@scripts/plugins-mod-check.sh $(if $(PLUGIN_MOD_BUILD),--build) $(PLUGIN_MOD_ROOTS)
# ============================================================================
# Plugin Release (build -> sign -> push -> marketplace index entry)
# ============================================================================
# One command takes a plugin from source to a signed, indexed marketplace
# release. The version comes from the plugin's manifest.json and is used
# verbatim as the OCI tag, and the digest written into the marketplace entry is
# read back from the registry - so the tag, the binary and the index entry
# cannot drift apart.
#
# Usage:
# make plugin-publish NAME=llm-cache SIGN_KEY=~/keys/plugin-ci.key
# make plugin-publish NAME=llm-cache DRY_RUN=1 # print the plan, push nothing
# make plugin-publish NAME=llm-cache YES=1 # no confirmation prompt (CI)
# make plugin-publish NAME=llm-cache NO_PUSH=1 # commit the entry, don't push it
# make plugin-verify NAME=llm-cache [VERSION=1.0.1] PUB_KEY=~/keys/plugin-ci.pub
#
# Variables: NAME (required), VERSION, REG, PLATFORMS, SIGN_KEY, PUB_KEY,
# MIN_STUDIO_VERSION, DRY_RUN, YES, NO_PUSH, FORCE, SKIP_SIGN,
# SKIP_UI, SKIP_MARKETPLACE
#
# Full guide: docs/site/docs/plugins-publishing.md
.PHONY: plugin-publish plugin-verify
# This Makefile defines its own VERSION (the git describe of the platform), so
# only forward VERSION to the script when it was set on the command line - and
# blank it in the recipe environment so the platform version can never be
# mistaken for a plugin version.
PLUGIN_VERSION_FLAG :=
ifeq ($(origin VERSION),command line)
PLUGIN_VERSION_FLAG := --version "$(VERSION)"
endif
plugin-publish:
@if [ -z "$(NAME)" ]; then \
echo "Usage: make plugin-publish NAME=<plugin> [VERSION=x.y.z] SIGN_KEY=/path/to/plugin-ci.key"; \
echo ""; \
echo "Plugins are looked up under community/plugins, enterprise/plugins,"; \
echo "tyk-internal/plugins and examples/plugins."; \
echo "Add DRY_RUN=1 to see the full plan without pushing anything."; \
echo ""; \
echo "Full guide: docs/site/docs/plugins-publishing.md"; \
echo "All flags: ./tools/publish-plugin.sh --help"; \
exit 1; \
fi
@env VERSION= ./tools/publish-plugin.sh publish "$(NAME)" $(PLUGIN_VERSION_FLAG)
plugin-verify:
@if [ -z "$(NAME)" ]; then \
echo "Usage: make plugin-verify NAME=<plugin>|all [VERSION=x.y.z] [PUB_KEY=/path/to/plugin-ci.pub]"; \
echo ""; \
echo "NAME=all audits every published entry in both marketplace repos."; \
echo "Full guide: docs/site/docs/plugins-publishing.md"; \
exit 1; \
fi
@env VERSION= ./tools/publish-plugin.sh verify "$(NAME)" $(PLUGIN_VERSION_FLAG)
# Test target (legacy - use test-all for more control)
test: ent-link
$(call root_gowork,$(BUILD_TAGS)) go test $(BUILD_TAGS) ./...
cd microgateway && go test $(BUILD_TAGS) ./...
# ============================================================================
# Unified Testing System
# ============================================================================
# Usage:
# make test-all # Run unit + integration tests (auto-detect edition)
# make test-all EDITION=ent # Run with enterprise edition
# make test-quick # Unit tests only (fast feedback)
# make test-ci # CI tests with coverage
# make test-all TEST_COMPONENTS="studio" # Test only studio
# make test-all TEST_TYPES="unit" # Unit tests only
#
# Components: studio, microgateway, frontend, plugins
# Types: unit, integration, e2e
# Editions: ce, ent
# Test configuration variables (can be overridden)
TEST_COMPONENTS ?= studio microgateway frontend plugins enterprise
TEST_TYPES ?= unit integration
TEST_EDITION ?= $(EDITION)
TEST_VERBOSE ?= false
TEST_COVERAGE ?= false
TEST_TIMEOUT ?= 30m
# Determine build tags based on edition
ifeq ($(TEST_EDITION),ent)
TEST_BUILD_TAGS := -tags enterprise
else
TEST_BUILD_TAGS :=
endif
# Verbose flag
ifeq ($(TEST_VERBOSE),true)
TEST_VERBOSE_FLAG := -v
else
TEST_VERBOSE_FLAG :=
endif
# Coverage flag
ifeq ($(TEST_COVERAGE),true)
TEST_COVERAGE_FLAG := -coverprofile=coverage.out -covermode=atomic
else
TEST_COVERAGE_FLAG :=
endif
# Primary unified test target
.PHONY: test-all
test-all: ## Run all tests with configurable options
@echo "=========================================="
@echo "Tyk AI Studio Unified Test Suite"
@echo "=========================================="
@echo "Edition: $(TEST_EDITION)"
@echo "Components: $(TEST_COMPONENTS)"
@echo "Types: $(TEST_TYPES)"
@echo "Timeout: $(TEST_TIMEOUT)"
@echo "=========================================="
@failed=0; \
for component in $(TEST_COMPONENTS); do \
for type in $(TEST_TYPES); do \
target="test-$${component}-$${type}"; \
if $(MAKE) -n $$target > /dev/null 2>&1; then \
echo ""; \
echo ">>> Running: $$target"; \
if ! $(MAKE) $$target TEST_EDITION=$(TEST_EDITION) TEST_VERBOSE=$(TEST_VERBOSE) TEST_COVERAGE=$(TEST_COVERAGE) TEST_TIMEOUT=$(TEST_TIMEOUT); then \
echo "FAILED: $$target"; \
failed=1; \
fi; \
fi; \
done; \
done; \
if [ $$failed -eq 1 ]; then \
echo ""; \
echo "=========================================="; \
echo "SOME TESTS FAILED"; \
echo "=========================================="; \
exit 1; \
fi; \
echo ""; \
echo "=========================================="; \
echo "ALL TESTS PASSED"; \
echo "=========================================="
.PHONY: test-quick
test-quick: ## Run only unit tests (fast feedback)
$(MAKE) test-all TEST_TYPES="unit" TEST_COMPONENTS="studio microgateway frontend"
.PHONY: test-fips
test-fips: ent-link ## Run the Go unit tests in FIPS 140-3 strict mode (GOFIPS140=v1.0.0 GODEBUG=fips140=only; EDITION=ent adds the enterprise module)
@scripts/test-fips.sh $(TEST_EDITION)
.PHONY: test-ci
test-ci: ## Run CI-appropriate tests (unit + integration, with coverage)
$(MAKE) test-all TEST_TYPES="unit integration" TEST_COVERAGE=true TEST_VERBOSE=true
# ============================================================================
# AI Studio Tests
# ============================================================================
.PHONY: test-studio-unit
test-studio-unit: ent-link ## Run AI Studio unit tests
@echo "Running AI Studio unit tests ($(TEST_EDITION))..."
$(call root_gowork,$(TEST_BUILD_TAGS)) go test $(TEST_BUILD_TAGS) $(TEST_VERBOSE_FLAG) $(TEST_COVERAGE_FLAG) \
-timeout $(TEST_TIMEOUT) -race -short ./...
.PHONY: test-studio-integration
test-studio-integration: ent-link ## Run AI Studio integration tests
@echo "Running AI Studio integration tests ($(TEST_EDITION))..."
$(call root_gowork,$(TEST_BUILD_TAGS)) go test $(TEST_BUILD_TAGS) $(TEST_VERBOSE_FLAG) \
-timeout $(TEST_TIMEOUT) -count=1 ./tests/...
# ============================================================================
# Microgateway Tests
# ============================================================================
.PHONY: test-microgateway-unit
test-microgateway-unit: ## Run Microgateway unit tests
@echo "Running Microgateway unit tests ($(TEST_EDITION))..."
cd microgateway && go test $(TEST_BUILD_TAGS) $(TEST_VERBOSE_FLAG) \
-timeout $(TEST_TIMEOUT) -race -short ./...
.PHONY: test-microgateway-integration
test-microgateway-integration: ## Run Microgateway integration tests
@echo "Running Microgateway integration tests ($(TEST_EDITION))..."
cd microgateway && go test $(TEST_BUILD_TAGS) $(TEST_VERBOSE_FLAG) \
-timeout $(TEST_TIMEOUT) -count=1 ./tests/integration/...
# ============================================================================
# Live Vendor Conformance Tests
# ============================================================================
#
# Calls REAL LLM vendors and spends REAL money. Gated twice over -- the
# `vendorlive` build tag AND VENDOR_TESTS_ENABLED=true -- so it can never be
# picked up by `go test ./...`, `make test-all` or CI by accident.
#
# Setup: cp test-secrets/vendors.env.example test-secrets/vendors.env
# $EDITOR test-secrets/vendors.env
# Design: features/VendorConformance.md
#
# Filters (all optional, comma separated):
# VENDORS=openai,anthropic SURFACES=shim,universal SCENARIOS=tools
VENDOR_TEST_TIMEOUT ?= 30m
.PHONY: test-vendors
test-vendors: ## Run live vendor conformance tests (needs test-secrets/vendors.env)
@if [ ! -f test-secrets/vendors.env ]; then \
echo "test-secrets/vendors.env not found."; \
echo " cp test-secrets/vendors.env.example test-secrets/vendors.env"; \
exit 1; \
fi
@echo "Running live vendor conformance tests (gateway surfaces)..."
cd microgateway && VENDOR_TESTS_VENDORS="$(VENDORS)" \
VENDOR_TESTS_SURFACES="$(SURFACES)" \
VENDOR_TESTS_SCENARIOS="$(SCENARIOS)" \
go test -tags vendorlive -v -count=1 \
-timeout $(VENDOR_TEST_TIMEOUT) ./tests/vendorconformance/...
.PHONY: test-vendors-preflight
test-vendors-preflight: ## Verify vendor credentials and model IDs without spending on completions
cd microgateway && VENDOR_TESTS_VENDORS="$(VENDORS)" \
go test -tags vendorlive -v -count=1 \
-timeout 5m -run 'TestPreflight' ./tests/vendorconformance/...
.PHONY: test-vendors-update-golden
test-vendors-update-golden: ## Refresh golden envelope snapshots
cd microgateway && VENDOR_TESTS_UPDATE_GOLDEN=true \
VENDOR_TESTS_VENDORS="$(VENDORS)" \
go test -tags vendorlive -v -count=1 \
-timeout $(VENDOR_TEST_TIMEOUT) ./tests/vendorconformance/...
.PHONY: test-vendors-filters
test-vendors-filters: ## Live check that request filters run on the Bedrock /ai/ and /anthropic/ paths (needs Bedrock credentials; enterprise scripting)
cd microgateway && VENDOR_TESTS_VENDORS=bedrock \
go test -tags "vendorlive enterprise" -v -count=1 \
-timeout 15m -run 'TestBedrockRequestFilters' ./tests/vendorconformance/...
# Decision models (OpenAI /v1/decisions, System One / TypeSafe Jev / llama.cpp)
# through the shim, sdk and universal surfaces: schemas, translation, errors,
# equivalence and analytics. Needs VT_OPENAI_MODEL_DECISION and/or VT_SYSTEMONE_*.
# VENDORS=openai,systemone SURFACES=shim,universal (both optional)
.PHONY: test-vendors-decisions
test-vendors-decisions: ## Live decision-model conformance (needs VT_OPENAI_MODEL_DECISION or VT_SYSTEMONE_* in test-secrets/vendors.env)
cd microgateway && VENDOR_TESTS_VENDORS="$(VENDORS)" \
VENDOR_TESTS_SURFACES="$(SURFACES)" \
go test -tags vendorlive -v -count=1 \
-timeout 15m -run 'TestPreflightDecision|TestDecision' ./tests/vendorconformance/...
.PHONY: test-vendors-harness
test-vendors-harness: ## Run the credential-free unit tests that protect the conformance harness itself
go test -count=1 ./pkg/testinfra/vendorconformance/...
# Guardrail provider conformance: drives every configured guardrail provider
# (Lakera, Azure Content Safety, Azure Language PII, Presidio, Bedrock
# Guardrails, a generic HTTP classifier) against the real service, directly and
# then through the data plane as filters on a real vendor route.
# GUARDRAILS=lakera,azure_cs VENDORS=openai (both optional)
.PHONY: test-guardrails
test-guardrails: ent-link ## Live guardrail provider conformance (needs VT_GUARD_* in test-secrets/vendors.env; enterprise)
@if [ ! -f test-secrets/vendors.env ]; then \
echo "test-secrets/vendors.env not found."; \
echo " cp test-secrets/vendors.env.example test-secrets/vendors.env"; \
exit 1; \
fi
@echo "Running guardrail provider conformance (direct provider calls)..."
VENDOR_TESTS_GUARDRAILS="$(GUARDRAILS)" \
$(ENT_GOWORK) go test -tags "vendorlive enterprise" -v -count=1 \
-timeout 15m ./tests/guardrailconformance/...
@echo "Running guardrail filters through the data plane..."
cd microgateway && VENDOR_TESTS_VENDORS="$(VENDORS)" \
VENDOR_TESTS_GUARDRAILS="$(GUARDRAILS)" \
go test -tags "vendorlive enterprise" -v -count=1 \
-timeout 15m -run 'TestGuardrail' ./tests/vendorconformance/...
.PHONY: test-guardrails-preflight
test-guardrails-preflight: ent-link ## Verify guardrail provider credentials with one benign probe each
VENDOR_TESTS_GUARDRAILS="$(GUARDRAILS)" \
$(ENT_GOWORK) go test -tags "vendorlive enterprise" -v -count=1 \
-timeout 5m -run 'TestGuardrailPreflight' ./tests/guardrailconformance/...
# ============================================================================
# Frontend Tests
# ============================================================================
.PHONY: test-frontend-unit
test-frontend-unit: ## Run frontend Jest tests
@echo "Running frontend unit tests..."
cd ui/admin-frontend && npm test
# ============================================================================
# Plugin Tests
# ============================================================================
.PHONY: test-plugins-unit
test-plugins-unit: ## Run plugin unit tests (all community + enterprise plugin modules)
@echo "Running plugin unit tests ($(TEST_EDITION))..."
@failed=""; \
for mod in $$(find community/plugins -name go.mod 2>/dev/null | sort); do \
dir=$$(dirname $$mod); \
echo ""; echo ">>> $$dir"; \
( cd $$dir && go test $(TEST_VERBOSE_FLAG) -timeout $(TEST_TIMEOUT) ./... ) \
|| failed="$$failed $$dir"; \
done; \
if [ "$(TEST_EDITION)" = "ent" ]; then \
for mod in $$(find enterprise/plugins -name go.mod 2>/dev/null | sort); do \
dir=$$(dirname $$mod); \
echo ""; echo ">>> $$dir (enterprise)"; \
( cd $$dir && go test -tags enterprise $(TEST_VERBOSE_FLAG) -timeout $(TEST_TIMEOUT) ./... ) \
|| failed="$$failed $$dir"; \
done; \
else \
echo "Skipping enterprise plugin unit tests (set EDITION=ent to enable)"; \
fi; \
if [ -n "$$failed" ]; then \
echo ""; echo "FAILED plugin modules:$$failed"; exit 1; \
fi
# ============================================================================
# Enterprise Module Tests
# ============================================================================
.PHONY: test-enterprise-unit
test-enterprise-unit: ## Run enterprise module unit tests (features/, scripting/, ...)
@if [ "$(TEST_EDITION)" != "ent" ] || [ ! -f enterprise/go.mod ]; then \
echo "Skipping enterprise module unit tests (set EDITION=ent to enable)"; \
exit 0; \
fi; \
echo "Running enterprise module unit tests..."; \
cd enterprise && go test -tags enterprise $(TEST_VERBOSE_FLAG) -timeout $(TEST_TIMEOUT) ./...
.PHONY: test-plugins-integration
test-plugins-integration: ## Run plugin integration tests (requires Docker)
@if [ "$(TEST_EDITION)" != "ent" ]; then \
echo "Skipping enterprise plugin integration tests (set EDITION=ent to enable)"; \
exit 0; \
fi
@echo "Running enterprise plugin integration tests..."
@echo ">>> advanced-llm-cache integration tests"
cd enterprise/plugins/advanced-llm-cache && \
go test -v -count=1 -tags="integration,enterprise" \
-timeout $(TEST_TIMEOUT) ./tests/integration/...
@echo ">>> llm-load-balancer integration tests"
cd enterprise/plugins/llm-load-balancer && \
go test -v -count=1 -tags="integration,enterprise" \