Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
1460 lines (1333 loc) · 76.8 KB
/
Copy pathMakefile
File metadata and controls
1460 lines (1333 loc) · 76.8 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
# Scion Makefile
# Run 'make help' to see available targets.
BINARY := scion
BUILD_DIR := ./build
CONTAINER_DIR := ./.build/container
PREFIX ?= /usr/local
DESTDIR ?=
INSTALL_DIR := $(PREFIX)/bin
MAIN_PKG := ./cmd/scion
LDFLAGS := $(shell ./hack/version.sh)
SCIONTOOL_LDFLAGS := $(shell ./hack/version.sh github.com/GoogleCloudPlatform/scion/cmd/sciontool/commands)
CONTAINER_OS := linux
CONTAINER_ARCH := $(shell if [ "$$(uname -m)" = "x86_64" ]; then echo amd64; else echo arm64; fi)
# golangci-lint built from source with the go-tools#1839 patch, the same
# binary CI runs (cr-ci/runner/golangci-lint/README.md). Override with
# GOLANGCI_LINT=/path/to/golangci-lint to use another binary.
GOLANGCI_LINT_PATCHED := $(BUILD_DIR)/tools/golangci-lint
GOLANGCI_LINT ?= $(GOLANGCI_LINT_PATCHED)
.DEFAULT_GOAL := help
.PHONY: all build build-a2a-bridge test-a2a-integration install test test-fast test-hub-sqlite test-sqlite-nonhub test-cmd-sqlite test-fast-ci test-fast-ci-shard build-fast-ci-shard fastshard-parity fastshard-selftest test-launch-store-postgres test-store-postgres test-store-postgres-others test-store-postgres-env-check test-store-postgres-integrationtest test-store-postgres-entadapter test-store-postgres-tail testpart-selftest hangwatch-selftest hubshard-skip-summary-selftest hubshard-shard-run-selftest test-hub-postgres test-hub-postgres-env-check test-hub-postgres-default test-hub-postgres-integration hub-postgres-integration-shards test-webchat-postgres test-webchat-pkg-postgres test-conduit-authz-postgres test-artifacts-postgres test-fixture-coverage hubshard-parity hub-dupcheck build-hub-shard test-hub-shard test-hub-shards vet-hub-shard vet lint lint-ci vet-integration vet-integration-ci vet-integration-extras compat-literals check-annotation-prefix check-authz-guards check-conversation-upsert-guard check-hub-store-embeds check-hub-store-reassign check-store-delete-callers check-root-open check-scan-coverage check-areadag check-winsec-guard check-security-marker-gates check-agent-mutators check-trigger-reattribution check-trigger-flip check-dispatch-role cli-time-zones time-literals check-raw-sql-predicates check-setenv-guard check-harness-coverage check-atif-schema test-image-scripts check-image-go-dirs check-authorization-catalog check-route-authz-manifest check-method-not-allowed check-debug-defaults check-sqlite-coverage sqlite-ci-pkgs check-extras-go-images check-downgrade-floor-selftest check-docs-links check-pi-harness-version check-custom golangci-lint golangci-lint-build golangci-lint-split-selftest web web-budget web-typecheck web-lint web-test fmt fmt-check tidy-extras ci ci-full clean help container-sciontool container-scion container-binaries proto proto-check ent-check tidy-check check-entsql-driver-assert
## all: Build the web frontend and compile the Go binary (run 'make install' separately to install)
all: web build
## build: Compile the scion binary into ./build/
build:
@echo "Building $(BINARY)..."
@mkdir -p $(BUILD_DIR)
@go build -buildvcs=false -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY) $(MAIN_PKG)
@echo "Binary: $(BUILD_DIR)/$(BINARY)"
## build-a2a-bridge: Build the A2A bridge binary into ./bin/
build-a2a-bridge:
@echo "Building scion-a2a-bridge..."
@mkdir -p bin
@go build -o bin/scion-a2a-bridge ./extras/scion-a2a-bridge/cmd/scion-a2a-bridge/
@echo "Binary: bin/scion-a2a-bridge"
## test-a2a-integration: Run the A2A bridge deterministic integration suite with fail-closed PostgreSQL
test-a2a-integration:
@./extras/scion-a2a-bridge/scripts/run-integration-ci.sh
## install: Install a pre-built binary (default: /usr/local/bin, override with PREFIX=~/.local). Run 'make build' first.
install:
@if [ ! -f $(BUILD_DIR)/$(BINARY) ]; then \
echo "Error: $(BUILD_DIR)/$(BINARY) not found. Run 'make build' (or 'make all') first."; \
exit 1; \
fi
@echo "Installing $(BINARY) to $(DESTDIR)$(INSTALL_DIR)..."
@mkdir -p $(DESTDIR)$(INSTALL_DIR)
@install $(BUILD_DIR)/$(BINARY) $(DESTDIR)$(INSTALL_DIR)/$(BINARY)
@echo ""
@echo "✔ Installed $(BINARY) to $(DESTDIR)$(INSTALL_DIR)/$(BINARY)"
@echo ""
@echo " Run 'scion version' to verify."
@echo ""
@case ":$$PATH:" in \
*":$(INSTALL_DIR):"* | *":$(INSTALL_DIR)/:"*) ;; \
*) echo " ⚠ WARNING: $(INSTALL_DIR) is not in your PATH."; \
echo " Add it with:"; \
echo ""; \
echo " export PATH=\"$(INSTALL_DIR):\$$PATH\""; \
echo "" ;; \
esac
## test: Run all tests
test:
@echo "Running tests..."
@go test ./...
## test-fast: Run tests without SQLite (lower memory usage)
test-fast:
@echo "Running tests (no SQLite)..."
@go test -tags no_sqlite ./...
## test-fast-ci: test-fast without the pkg/hub package itself (CI runs it as no_sqlite shards: test-hub-shard NOSQLITE=1)
test-fast-ci:
@echo "Running tests (no SQLite, pkg/hub itself excluded)..."
@pkgs=$$($(call non_hub_pkgs,no_sqlite)) || exit 1; \
go test -tags no_sqlite $$pkgs
## test-fast-ci-shard: Run one fast CI test shard (SHARD=<id> from hack/fastshard/shards.txt; see hack/fastshard/README.md)
test-fast-ci-shard:
@echo "Running fast CI test shard '$(SHARD)' (no SQLite, pkg/hub itself excluded)..."
@pkgs=$$($(call non_hub_pkgs,no_sqlite)) || exit 1; \
printf '%s\n' "$$pkgs" | ./hack/fastshard/fastshard.sh parity || exit 1; \
parts_spec=$$(./hack/fastshard/fastshard.sh parts '$(SHARD)') || exit 1; \
part=$${parts_spec%% *}; parts=$${parts_spec#* }; \
shard_pkgs=$$(printf '%s\n' "$$pkgs" | ./hack/fastshard/fastshard.sh packages '$(SHARD)') || exit 1; \
if [ "$$parts" = 1 ]; then \
go test -tags no_sqlite $$shard_pkgs; \
else \
./hack/testpart-run.sh --part "$$part" --parts "$$parts" --tags no_sqlite -- $$shard_pkgs; \
fi
## build-fast-ci-shard: Compile test binaries for fast CI test shard SHARD=<id> into GOCACHE without executing tests
build-fast-ci-shard:
@echo "Prebuilding fast CI test shard '$(SHARD)' (no SQLite, pkg/hub itself excluded)..."
@pkgs=$$($(call non_hub_pkgs,no_sqlite)) || exit 1; \
printf '%s\n' "$$pkgs" | ./hack/fastshard/fastshard.sh parity || exit 1; \
shard_pkgs=$$(printf '%s\n' "$$pkgs" | ./hack/fastshard/fastshard.sh packages '$(SHARD)') || exit 1; \
go test -tags no_sqlite -count=1 -exec true $$shard_pkgs
## fastshard-parity: Verify hack/fastshard/shards.txt covers every test-fast-ci package in exactly one shard
fastshard-parity:
@pkgs=$$($(call non_hub_pkgs,no_sqlite)) || exit 1; \
printf '%s\n' "$$pkgs" | ./hack/fastshard/fastshard.sh parity
## fastshard-selftest: Test hack/fastshard/fastshard.sh and report.sh against fixtures (bash only)
fastshard-selftest:
@./hack/fastshard/fastshard.sh --selftest
@./hack/fastshard/report.sh --selftest
# HUB_TEST_GOGC is prefixed to go test commands that compile large test
# packages: the test-sqlite-nonhub prebuild (go test -c, build only) and the
# cmd run in test-store-postgres (there the go test command also runs the
# tests, so GOGC=25 applies to them too; they are short). The pkg/hub
# package itself compiles only in shards, through hack/hubshard/shard.sh,
# which applies the same default (GOGC=25 for its compiles, unless GOGC is
# set). History: with the default GOGC the whole pkg/hub test-package
# compile peaked at about 15 GB RSS (15.4 GB with -tags integration) on a
# 16 GB GitHub-hosted runner, filled its 3 GB swap, and the runner was shut
# down mid-step (exit 143, ptone/scion#4083); GOGC=25 cut that to about
# 12 GB for about 5% more compile time. A non-empty GOGC in the environment
# wins.
HUB_TEST_GOGC = GOGC=$${GOGC:-25}
# HUB_PKG is the pkg/hub package itself. Its tests are split into build-tag
# shards (hack/hubshard/README.md), so a shard's test binary compiles with
# about half the memory of the whole package's; CI never compiles the whole
# pkg/hub test package. Its subpackages are ordinary packages.
HUB_PKG := github.com/GoogleCloudPlatform/scion/pkg/hub
# non_hub_pkgs is a shell command that lists every package except HUB_PKG
# under build tags $(1), as ./... would match them for go test or go vet
# with those tags. It runs in the recipe, so other make invocations do not
# run go list.
non_hub_pkgs = go list -tags '$(1)' ./... | grep -vx '$(HUB_PKG)'
# SHARD selects the pkg/hub test shard (1..N, N from
# hack/hubshard/hubshard.sh -shards) for test-hub-shard, build-hub-shard,
# vet-hub-shard and test-hub-postgres.
SHARD ?= 1
## test-hub-sqlite: Run pkg/hub (every shard) and the non-hub SQLite packages (SQLITE_NONHUB_PKGS) with SQLite
# enabled (no build tag). This is the ~67% of pkg/hub's test files that
# "make test-fast" never compiles (see ptone/scion#1118), plus the
# non-hub SQLite packages (test-sqlite-nonhub). pkg/hub runs shard by
# shard (test-hub-shard), never as one test binary. CI runs the same
# pieces in parallel jobs: SQLite Tests (non-hub) and pkg/hub shard K/N.
test-hub-sqlite: test-sqlite-nonhub test-hub-shards
## test-sqlite-nonhub: Run the pkg/hub subpackages and the other non-hub SQLite packages (SQLITE_NONHUB_PKGS) with SQLite
# perf/bench/seed's and pkg/store/entadapter's own SQLite-backed tests carry
# a `//go:build !no_sqlite` constraint (ptone/scion#2393,
# ptone/scion#2851), pkg/conduit's relay/router tests run against the
# SQLite-backed conduit registry store, and pkg/artifacts' store and
# service tests run on SQLite. pkg/brokerownership, pkg/brokerregistration,
# pkg/ent/entc, pkg/secret, pkg/store/storetest and pkg/testinfra also have
# `//go:build !no_sqlite` test files; before ptone/scion#1088 they ran only
# in the non-blocking Full Test Suite. The pkg/hub package itself is left
# out: it runs in shards (test-hub-shard).
#
# The test binaries are first compiled with HUB_TEST_GOGC (go test -c into a
# scratch directory, then deleted). The go test run that follows reuses the
# cached compiled packages, so only the build runs with the lower GOGC; the
# tests themselves run with the default GOGC. go test -c with several
# packages fails if two of the test packages share a package name (Go
# 1.21+). There are no duplicates among the test packages today; if one
# appears, prebuild with $(HUB_TEST_GOGC) go test -count=1 -run '^$'
# instead, which compiles every package and runs no test functions.
#
# check-sqlite-coverage fails if a package with a `//go:build !no_sqlite`
# test file is in none of SQLITE_CI_PKGS, so add new SQLite packages here.
SQLITE_NONHUB_PKGS := ./pkg/hub/... ./perf/bench/seed/... ./pkg/conduit/... \
./pkg/store/entadapter/... ./pkg/artifacts/... ./pkg/brokerownership/... \
./pkg/brokerregistration/... ./pkg/ent/entc/... ./pkg/secret/... \
./pkg/store/storetest/... ./pkg/store/enttest ./pkg/store/relaydb ./pkg/testinfra/... \
./pkg/observability/txdiag ./pkg/agent/tmuxdeliver ./pkg/durablequeue/... \
./pkg/trajectory/e2e ./pkg/mcpserver/... ./pkg/servermigrate/...
SQLITE_NONHUB_PKGS_CMD = go list $(SQLITE_NONHUB_PKGS) | grep -vx '$(HUB_PKG)'
# SQLITE_CI_PKGS are the package patterns that blocking CI jobs test with
# SQLite enabled (no no_sqlite tag): SQLITE_NONHUB_PKGS (SQLite Tests
# (non-hub), test-sqlite-nonhub; ./pkg/hub/... there also matches the
# pkg/hub package itself, which the pkg/hub shard jobs run instead),
# SQLITE_CMD_PKGS (test-cmd-sqlite) and FIXTURE_PKGS
# (test-fixture-coverage). Those targets test exactly these variables, so
# the list check-sqlite-coverage checks is the list CI runs.
SQLITE_CMD_PKGS := ./cmd
FIXTURE_PKGS := ./internal/fixturegen/...
SQLITE_CI_PKGS = $(SQLITE_NONHUB_PKGS) $(SQLITE_CMD_PKGS) $(FIXTURE_PKGS)
## sqlite-ci-pkgs: Print SQLITE_CI_PKGS, one pattern per line (read by hack/check-sqlite-coverage.sh)
sqlite-ci-pkgs:
@printf '%s\n' $(SQLITE_CI_PKGS)
test-sqlite-nonhub:
@echo "Running pkg/hub subpackages + the other SQLITE_NONHUB_PKGS tests (SQLite-enabled)..."
@pkgs=$$($(SQLITE_NONHUB_PKGS_CMD)) || exit 1; \
dir=$$(mktemp -d) || exit 1; \
$(HUB_TEST_GOGC) go test -c -o "$$dir/" $$pkgs; \
status=$$?; \
if [ -n "$$dir" ]; then rm -rf "$$dir"; fi; \
if [ $$status -ne 0 ]; then exit $$status; fi; \
go test -count=1 -timeout 60m $$pkgs
## test-cmd-sqlite: Run the cmd package tests with SQLite enabled (no build tag)
# 41 cmd test files carry `//go:build !no_sqlite`, so "make test-fast"
# (-tags no_sqlite) never compiles them (ptone/scion#1088). This runs the
# whole cmd package untagged: those files plus the untagged ones, which
# test-fast also runs (about 30s). CI runs it in the SQLite Tests
# (non-hub) job.
test-cmd-sqlite:
@echo "Running cmd tests (SQLite-enabled)..."
@go test -count=1 -timeout 20m $(SQLITE_CMD_PKGS)
## hubshard-parity: Check the pkg/hub test shards: every test runs in exactly one shard, every shard compiles (parse only)
# Also fails if a hubshard tag or a generated imports file is committed:
# the tags exist only in the overlay hack/hubshard writes on every run.
# hubshard prints the shard sizes; -untag strips tags an older generator
# committed. hack/hubshard/hubshard.sh builds the tool into a temp dir and
# runs it (as go run would). See hack/hubshard/README.md.
hubshard-parity:
@./hack/hubshard/hubshard.sh -parity
## hub-dupcheck: Fail on a duplicate top-level declaration in pkg/hub plus its test files under any CI tag set (parse only)
# The shards compile apart, so two test files in different shards can each
# declare the same helper: every shard builds, and every whole-package build
# (go vet ./pkg/hub/) fails. HUB_DUPCHECK_TAGS are the tag sets CI compiles
# pkg/hub with: shard tests (default, no_sqlite; race-detection adds race),
# shard vets and the integration Postgres jobs. See hack/dupdecl/main.go.
HUB_DUPCHECK_TAGS := "" no_sqlite no_sqlite,race integration integration,tzcontract
hub-dupcheck:
@go run ./hack/dupdecl $(foreach t,$(HUB_DUPCHECK_TAGS),-tags $(t)) ./pkg/hub
## testpart-selftest: Test hack/testpart.sh, which splits the T1 entadapter Postgres tests over CI jobs (bash only)
testpart-selftest:
@./hack/test-testpart.sh
## hangwatch-selftest: Test hack/ci/hangwatch.sh, the CI hang watchdog (bash only)
hangwatch-selftest:
@./hack/ci/hangwatch.sh --selftest
## hubshard-skip-summary-selftest: Test the skipped-tests summary of make test-hub-shard (bash only, a fake test binary; no go)
hubshard-skip-summary-selftest:
@./hack/hubshard/test-skip-summary.sh
## hubshard-shard-run-selftest: Test shard.sh -run zero-test detection and shard hints
hubshard-shard-run-selftest:
@./hack/hubshard/test-shard-run.sh
## test-hub-shard: Run pkg/hub test shard SHARD=K (NOSQLITE=1: with -tags no_sqlite; RACE=1: with -race; VERBOSE=1: with -v; RUN=pattern: -run pattern)
# Generates the shard overlay in a temp dir (the tree is not modified),
# compiles the shard, checks its test list against hubshard -list, then
# runs it. The common files' tests run only in shard 1.
test-hub-shard:
@./hack/hubshard/shard.sh test $(SHARD) $(if $(NOSQLITE),--nosqlite) $(if $(RACE),--race) $(if $(VERBOSE),-v) $(if $(value RUN),-run '$(subst ','\'',$(value RUN))')
## test-hub-shards: Run every pkg/hub test shard in turn (NOSQLITE=1, RACE=1, VERBOSE=1 as for test-hub-shard)
# The shard list comes from hack/hubshard/hubshard.sh -shards. Every shard
# runs even when an earlier one fails; the target fails if any did.
test-hub-shards:
@shards=$$(./hack/hubshard/hubshard.sh -shards) || exit 1; \
failed=; \
for k in $$shards; do \
./hack/hubshard/shard.sh test $$k $(if $(NOSQLITE),--nosqlite) $(if $(RACE),--race) $(if $(VERBOSE),-v) || failed="$$failed $$k"; \
done; \
if [ -n "$$failed" ]; then echo "ERROR: pkg/hub shard(s) failed:$$failed" >&2; exit 1; fi
## build-hub-shard: Compile (go test -c, discarded) pkg/hub test shard SHARD=K (NOSQLITE=1: with -tags no_sqlite)
build-hub-shard:
@./hack/hubshard/shard.sh build $(SHARD) $(if $(NOSQLITE),--nosqlite)
## vet-hub-shard: go vet pkg/hub test shard SHARD=K with -tags no_sqlite and -tags 'integration tzcontract'
# The shards' vets together cover every pkg/hub file that make lint and
# make vet-integration cover (hubshard-parity checks it). CI vets pkg/hub
# this way (lint-ci and vet-integration-ci leave the package out).
vet-hub-shard:
@./hack/hubshard/shard.sh vet $(SHARD)
## test-fixture-coverage: Run the hub fixture coverage gate (TestFixtureCoverage) with SQLite
# internal/fixturegen's tests carry `//go:build !no_sqlite`, so
# "make test-fast" never compiles them and a schema change that skips the
# fixture went red only in the non-blocking full suite (ptone/scion#625,
# ptone/scion#1931). CI runs this in the SQLite Tests (non-hub) job.
test-fixture-coverage:
@echo "Running fixture coverage gate (SQLite-enabled)..."
@go test -count=1 $(FIXTURE_PKGS)
# TEST_IDENTITY_POSTGRES_TESTS are the pkg/hub test identity concurrency
# tests (ptone/scion#4240: the Phase 3b purge, and the X4 parallel admin-kind
# mints across workload delegations) run by test-launch-store-postgres
# (pkg/hub shard Postgres (integration) jobs in CI).
TEST_IDENTITY_POSTGRES_TESTS := TestFixturePurge_ConcurrentCoOwner_Postgres \
TestWorkloadAdminDelegation_ParallelMintsHoldCaps_Postgres
# MEMBERSHIP_LOSS_POSTGRES_TESTS are the pkg/hub membership loss
# concurrency tests (ptone/scion#3433) run by test-launch-store-postgres.
MEMBERSHIP_LOSS_POSTGRES_TESTS := TestMembershipLossProcessor_vs_ProjectDelete_Postgres \
TestMembershipLossProcessor_vs_AgentHardDelete_Postgres \
TestMembershipLossProcessor_vs_ReAdd_Postgres \
TestMembershipLossProcessor_vs_CredentialMint_Postgres \
TestMembershipLossProcessor_vs_ChildCreate_Postgres \
TestMembershipLossProcessor_TwoInstances_Postgres \
TestMembershipLossProcessor_vs_UserDelete_Postgres \
TestMembershipReconciler_LocksCoexist_Postgres
## test-store-postgres: Run the T1 async-create launch store/reaper
# suite against a real Postgres server (design t1-async-create-v11.md §6,
# "Postgres in CI"). Requires -tags integration and SCION_TEST_POSTGRES_URL;
# see pkg/store/enttest's package doc for the connection string format.
#
# pkg/store/integrationtest runs in full (its own self-contained Postgres-only
# harness). pkg/store/entadapter is scoped with -run to just the new launch
# store/reaper/report tests, per the design's literal wording ("runs
# pkg/store/integrationtest ... plus the new store and report-handler
# tests") -- NOT the whole existing entadapter suite. That distinction
# matters: this is the first CI job ever to run entadapter's existing tests
# against real Postgres (they otherwise only run against SQLite, or against
# Postgres in a developer's local -tags integration run), and running the
# full package here surfaced multiple pre-existing failures unrelated to T1
# (a backfill migration's raw SQL is invalid on Postgres; a conversation
# upsert test asserts timestamp equality at a precision Postgres does not
# preserve). Fixing those is out of scope for this design; -run keeps this
# job to what it was scoped to test.
#
# The -run regex also includes the broker-settings compare-and-set and
# row-lock tests (TestPutBrokerSettings*, TestDeleteBrokerSettings*,
# TestUsesRowLocks_ReflectsBackend, ptone/scion#2327): they assert
# dialect-dependent behavior (usesRowLocks/FOR UPDATE) the same way the T1
# tests do, so they belong in this job's Postgres coverage rather than running
# only against SQLite.
#
# It also includes the secret-value compare-and-swap tests
# (TestUpdateSecretValueIfVersion*): the Conduit grant key ring rotation relies
# on this conditional UPDATE, and HA hubs run it on Postgres.
#
# It also includes the ListSchedules keyset-cursor tests (TestListSchedules_*,
# ptone/scion#2502): the keyset compares and binds `created` timestamps, whose
# storage and precision differ between SQLite and Postgres. It also includes
# TestListActiveZonePrefixedSchedules: its prefix match compiles to LIKE, whose
# case sensitivity differs between the two backends.
#
# It also includes the utc-timestamp-normalize JSON tests
# (TestUTCTimestampNormalizeJSON_*, ptone/scion#2499): the JSON-embedded
# timestamp rewrite is the part of that operation that runs on Postgres, with
# its own SQL (jsonb casts, id keyset).
# It also includes the agent run intent tests (TestRunIntent_*): they take
# a FOR UPDATE row lock on Postgres, read the store clock with now(), and
# compare run_intent_at values whose stored precision differs between the
# two backends.
#
# It also includes the Conduit registry suite (TestConduitRegistry_*,
# ptone/scion#2778): design conduit v2.1 §3.4 requires relay_instances,
# conduit_sessions and conduit_principal_epochs to behave identically on
# Postgres and SQLite (generation/epoch upsert ... RETURNING, generation-CAS
# deletes, concurrent epoch allocation), so the same suite runs on both.
#
# It also includes the project owner_id store-contract tests
# (TestProjectOwnerID_*, ptone/scion#2597): UpdateProject must not write
# owner_id on either backend, so SetProjectOwnerID stays its only writer.
#
# It also includes the child-group edge removal tests
# (TestRemoveChildGroupEdge_*, ptone/scion#2723): on Postgres a second
# transaction deleting the same edge waits on the first one's row lock and
# must then report ErrNotFound, so only one caller writes an audit record.
# It also includes the orphaned group-membership tests and the composite
# purge tests (ptone/scion#2769): PurgeDeletedAgents re-reads its batch with
# FOR UPDATE on Postgres only, and the restore-during-purge cases exercise
# that path. A third run covers the storetest group/MembershipCleanup
# conformance (pkg/store/storetest), selected by name so only that subtest
# of the CRUD-parity suite runs here. The TestCompositeDeleteAgent_ and
# TestCompositeDeleteProject_ prefixes also select the PostgreSQL-only
# *_LockOrderNoDeadlock tests, which check that both deletes lock agent rows
# before deleting their memberships (the purge/finalize order).
# TestCompositeDeleteProject_LocksAgentsInIDOrder pins the ascending order of
# that lock, and the TestPurgeDeletedAgents_ prefix selects
# TestPurgeDeletedAgents_CrossBatchLockOrderNoDeadlock (purge batches in ID
# order). A fourth run covers the production project-delete path in pkg/hub
# (TestProjectDeletionService_LockOrderNoDeadlock: ProjectDeletionService
# locks the project's agents before its project-group cascade deletes agent
# memberships), selected by name so only that test runs here. In the second
# run (the full entadapter suite), the TestDeleteGroupMembershipsForUser_
# prefix also selects
# TestDeleteGroupMembershipsForUser_LockOrderVsProjectGroupCascade (a user
# delete locks the groups it owns before its memberships, so it cannot
# deadlock against a project delete's group cascade) and
# TestDeleteGroupMembershipsForUser_OwnedGroupLockAllowsMemberInsert (that
# lock is FOR NO KEY UPDATE, so it does not block the FK check of a
# membership inserted into an owned group, which would deadlock).
#
# Since ptone/scion#2207 the job runs the FULL pkg/store/entadapter suite on
# Postgres (no -run filter); the lists above document why particular groups
# matter here, not what is selected. Every entadapter test now has to pass on
# both backends.
#
# Fail loudly, not green, if a Postgres-only case in this job's own suite
# skips instead of running. SCION_TEST_POSTGRES_URL is checked explicitly
# first; on -v test output, any "--- SKIP" line (including an indented
# subtest skip) also fails the target, since in this job every test that
# self-skips on a missing Postgres backend (enttest.Active() == false)
# indicates the job is misconfigured, not that skipping is an acceptable
# outcome here.
#
# pkg/store/integrationtest is exempt from that skip check: its Category 7
# (multi-process) tests always self-skip TestWorker_AdvisoryLock and
# TestWorker_NotifyPublisher when run normally -- those are child-process
# entrypoints a parent test in the same file launches as a subprocess with
# SCION_TEST_WORKER_DSN set (see multiprocess_test.go's package comment),
# not Postgres-availability skips. They are excluded by name so a genuine
# new skip in that package still fails the target.
#
# The pkg/ent/entc run covers skill creation against a pre-existing
# `visibility` column
# (TestSkillStore_CreateAgainstOldSchemaWithVisibilityColumn_Postgres,
# ptone/scion#4370), the core-to-global skill scope startup migration
# (TestMigrateSkillCoreScope_Postgres, ptone/scion#1713), and the message_mode
# rename migration (TestMigrateMessageModeRename_Postgres). The
# SQLite-to-Postgres `scion server migrate` path runs in ./pkg/servermigrate/.
# Each works in its own throwaway schema, so none disturbs the shared database.
# Any skip fails the target first, then each test must print its own PASS line.
#
# The cmd run covers the PostgreSQL search_path shadow guard in every
# standalone command that migrates the hub database (server migrate,
# server backfill, server migrate-dm-keys, server recover-authz,
# server test-infra mark, hub secret migrate-names; ptone/scion#4432):
# TestMaintenanceCommandsSchemaShadowGuard_Postgres. Each case uses its own
# throwaway schemas. Any skip fails the target, and the test must print its
# own PASS line.
#
# In the entadapter run, a test that is SQLite-only by design skips through
# enttest.SkipOnPostgres, whose skip message is
# "enttest-sqlite-only: <test name> <reason>". A skipped test is allowed only
# if its own skip message carries that marker, so there is no name list here
# and any other skip still fails the target.
#
# The entadapter run has a 60m go test timeout. On green main runs it took
# ~774s and ~1259s, but GoogleCloudPlatform/scion#2855 hit the old 40m
# (2400s) limit on a runner 2-3x slower than usual, with no failing or hung
# test (ptone/scion#3945). A timeout there also stops the storetest and
# later runs below, so the headroom is kept generous.
#
# test-store-postgres is the part without the pkg/hub package itself
# (CI's T1 job runs it); test-launch-store-postgres adds the pkg/hub
# Postgres tests, which CI runs in the pkg/hub shard Postgres jobs.
#
# CI splits this target over several T1 jobs (see the T1 jobs in
# .github/workflows/ci.yml): test-store-postgres-entadapter with
# ENTADAPTER_PART=K ENTADAPTER_PARTS=N runs part K of the entadapter tests,
# and test-store-postgres-others runs the rest. Locally,
# make test-store-postgres runs it all, in the order below. The umbrella
# targets run their parts one after another through sub-makes (not as
# prerequisites), so make -j never runs them at once: they share one
# Postgres server, and the cmd run is a large compile.
test-store-postgres:
@$(MAKE) --no-print-directory test-store-postgres-integrationtest
@$(MAKE) --no-print-directory test-store-postgres-entadapter
@$(MAKE) --no-print-directory test-store-postgres-tail
## test-store-postgres-others: test-store-postgres without pkg/store/entadapter (CI runs entadapter in its own jobs)
test-store-postgres-others:
@$(MAKE) --no-print-directory test-store-postgres-integrationtest
@$(MAKE) --no-print-directory test-store-postgres-tail
# test-store-postgres-env-check fails if SCION_TEST_POSTGRES_URL is unset.
test-store-postgres-env-check:
@if [ -z "$$SCION_TEST_POSTGRES_URL" ]; then \
echo "ERROR: SCION_TEST_POSTGRES_URL is not set -- the Postgres-only cases would silently skip instead of running." >&2; \
exit 1; \
fi
test-store-postgres-integrationtest: test-store-postgres-env-check
@echo "Running launch store tests against Postgres..."
@go test -tags integration -count=1 -timeout 20m -v \
./pkg/store/integrationtest/... > /tmp/test-launch-store-postgres-integrationtest.log 2>&1; \
status=$$?; \
cat /tmp/test-launch-store-postgres-integrationtest.log; \
if [ $$status -ne 0 ]; then exit $$status; fi; \
if grep -E '^[[:space:]]*--- SKIP' /tmp/test-launch-store-postgres-integrationtest.log \
| grep -qvE 'TestWorker_(AdvisoryLock|NotifyPublisher)'; then \
echo "ERROR: one or more Postgres-only integration tests were skipped -- see '--- SKIP' lines above." >&2; \
exit 1; \
fi
# ENTADAPTER_PARTS splits the pkg/store/entadapter Postgres tests into that
# many parts and ENTADAPTER_PART (1..ENTADAPTER_PARTS) selects the one
# test-store-postgres-entadapter runs. The default, 1 of 1, runs the whole
# package without -run, as before the split. CI runs every part in its own
# job (the T1 entadapter jobs in .github/workflows/ci.yml).
ENTADAPTER_PART ?= 1
ENTADAPTER_PARTS ?= 1
## test-store-postgres-entadapter: The pkg/store/entadapter part of test-store-postgres (ENTADAPTER_PART=K ENTADAPTER_PARTS=N: part K of N)
# With ENTADAPTER_PARTS > 1 the target lists the package's top-level tests
# (go test -list, which runs TestMain and so needs the Postgres server),
# checks with hack/testpart.sh parity that the N parts together hold every
# listed test exactly once, and runs part K with -run '^(A|B|...)$'
# (round-robin over the sorted names; subtests of a selected test run with
# it). After the usual checks, every test of the part must print its own
# top-level PASS or SKIP line, so a test that the pattern misses fails the
# target instead of silently not running.
test-store-postgres-entadapter: test-store-postgres-env-check
@part='$(ENTADAPTER_PART)'; parts='$(ENTADAPTER_PARTS)'; \
set --; \
if [ "$$parts" = 1 ] && [ "$$part" != 1 ]; then \
echo "ERROR: ENTADAPTER_PART must be 1 when ENTADAPTER_PARTS is 1 (got $$part)." >&2; \
exit 1; \
fi; \
if [ "$$parts" != 1 ]; then \
if ! go test -tags integration -count=1 -list '.*' \
./pkg/store/entadapter/... > /tmp/test-launch-store-postgres.list 2>&1; then \
cat /tmp/test-launch-store-postgres.list; \
echo "ERROR: could not list the entadapter tests." >&2; \
exit 1; \
fi; \
./hack/testpart.sh parity "$$parts" < /tmp/test-launch-store-postgres.list || exit 1; \
./hack/testpart.sh list "$$part" "$$parts" < /tmp/test-launch-store-postgres.list \
> /tmp/test-launch-store-postgres.part || exit 1; \
regex=$$(./hack/testpart.sh regex "$$part" "$$parts" < /tmp/test-launch-store-postgres.list) || exit 1; \
echo "Running part $$part of $$parts of the entadapter Postgres tests ($$(wc -l < /tmp/test-launch-store-postgres.part | tr -d ' ') top-level tests)..."; \
set -- -run "$$regex"; \
fi; \
go test -tags integration -count=1 -timeout 60m -v "$$@" \
./pkg/store/entadapter/... > /tmp/test-launch-store-postgres.log 2>&1; \
status=$$?; \
cat /tmp/test-launch-store-postgres.log; \
if [ $$status -ne 0 ]; then exit $$status; fi; \
sed -nE 's/^[[:space:]]*--- SKIP: ([^ ]+).*/\1/p' /tmp/test-launch-store-postgres.log | sort -u \
> /tmp/test-launch-store-postgres.skipped; \
grep -oE 'enttest-sqlite-only: [^ ]+' /tmp/test-launch-store-postgres.log | awk '{print $$2}' | sort -u \
> /tmp/test-launch-store-postgres.sqlite-only; \
unexpected=$$(grep -vxF -f /tmp/test-launch-store-postgres.sqlite-only /tmp/test-launch-store-postgres.skipped); \
if [ -n "$$unexpected" ]; then \
echo "ERROR: these entadapter tests were skipped on Postgres without enttest.SkipOnPostgres:" >&2; \
echo "$$unexpected" >&2; \
exit 1; \
fi; \
if [ "$$parts" != 1 ]; then \
sed -nE 's/^--- (PASS|SKIP): ([^ ]+).*/\2/p' /tmp/test-launch-store-postgres.log | LC_ALL=C sort -u \
> /tmp/test-launch-store-postgres.ran; \
missing=$$(LC_ALL=C comm -23 /tmp/test-launch-store-postgres.part /tmp/test-launch-store-postgres.ran); \
if [ -n "$$missing" ]; then \
echo "ERROR: these entadapter tests of part $$part of $$parts printed no top-level PASS or SKIP line:" >&2; \
echo "$$missing" >&2; \
exit 1; \
fi; \
fi
# test-store-postgres-tail: the storetest, pkg/store/enttest, pkg/durablequeue,
# pkg/ent/entc, pkg/testinfra and cmd runs of test-store-postgres (after
# entadapter). The enttest run includes TestSchemaSnapshot_MatchesAutoMigrate,
# which checks that the schema snapshot the harness provisions test schemas
# from matches entc.AutoMigrate.
test-store-postgres-tail: test-store-postgres-env-check
@go test -tags integration -count=1 -timeout 10m -v \
./pkg/durablequeue/... > /tmp/test-launch-store-postgres-durablequeue.log 2>&1; \
status=$$?; \
cat /tmp/test-launch-store-postgres-durablequeue.log; \
if [ $$status -ne 0 ]; then exit $$status; fi; \
if grep -qE '^[[:space:]]*--- SKIP' /tmp/test-launch-store-postgres-durablequeue.log; then \
echo "ERROR: one or more pkg/durablequeue Postgres tests were skipped -- see '--- SKIP' lines above." >&2; \
exit 1; \
fi; \
if ! grep -qE '^--- PASS: TestEchoConsumer_TwoConcurrentDrainers ' /tmp/test-launch-store-postgres-durablequeue.log; then \
echo "ERROR: the pkg/durablequeue two-drainer Postgres test did not run." >&2; \
exit 1; \
fi
@go test -tags integration -count=1 -timeout 10m -v \
./pkg/hub/trigger/... > /tmp/test-launch-store-postgres-trigger.log 2>&1; \
status=$$?; \
cat /tmp/test-launch-store-postgres-trigger.log; \
if [ $$status -ne 0 ]; then exit $$status; fi; \
if grep -qE '^[[:space:]]*--- SKIP' /tmp/test-launch-store-postgres-trigger.log; then \
echo "ERROR: one or more pkg/hub/trigger Postgres tests were skipped -- see '--- SKIP' lines above." >&2; \
exit 1; \
fi; \
if ! grep -qE '^--- PASS: TestDispatcher_TwoConcurrentDrainers_UniqueTriggerFire ' /tmp/test-launch-store-postgres-trigger.log; then \
echo "ERROR: the pkg/hub/trigger two-drainer uniqueness Postgres test did not run." >&2; \
exit 1; \
fi
@go test -tags integration -count=1 -timeout 10m -v \
-run '^TestCompositeStore_CRUDParity$$/^group$$/^MembershipCleanup$$' \
./pkg/store/storetest/... > /tmp/test-launch-store-postgres-storetest.log 2>&1; \
status=$$?; \
cat /tmp/test-launch-store-postgres-storetest.log; \
if [ $$status -ne 0 ]; then exit $$status; fi; \
if ! grep -qE '^[[:space:]]*--- PASS: TestCompositeStore_CRUDParity/group/MembershipCleanup' /tmp/test-launch-store-postgres-storetest.log; then \
echo "ERROR: the storetest group/MembershipCleanup conformance did not run." >&2; \
exit 1; \
fi; \
if grep -qE '^[[:space:]]*--- SKIP' /tmp/test-launch-store-postgres-storetest.log; then \
echo "ERROR: one or more storetest group/MembershipCleanup cases were skipped -- see '--- SKIP' lines above." >&2; \
exit 1; \
fi
@go test -tags integration -count=1 -timeout 10m -v \
./pkg/store/enttest/ > /tmp/test-launch-store-postgres-enttest.log 2>&1; \
status=$$?; \
cat /tmp/test-launch-store-postgres-enttest.log; \
if [ $$status -ne 0 ]; then exit $$status; fi; \
if grep -qE '^[[:space:]]*--- SKIP' /tmp/test-launch-store-postgres-enttest.log; then \
echo "ERROR: one or more pkg/store/enttest Postgres tests were skipped -- see '--- SKIP' lines above." >&2; \
exit 1; \
fi; \
if ! grep -qE '^--- PASS: TestSchemaSnapshot_MatchesAutoMigrate ' /tmp/test-launch-store-postgres-enttest.log; then \
echo "ERROR: the schema snapshot equivalence test did not run." >&2; \
exit 1; \
fi
@go test -tags integration -count=1 -timeout 10m -v \
-run '^(TestSkillStore_CreateAgainstOldSchemaWithVisibilityColumn_Postgres|TestMigrateSkillCoreScope_Postgres|TestMigrateMessageModeRename_Postgres|TestAutoMigrateNoOp_Postgres|TestMessagesLegacyColumnsDrop_Postgres|TestEnsureChatSearchTrigramIndex_Postgres|TestEnsureChatSearchTrigramIndex_RestrictedRole_Postgres)$$' \
./pkg/ent/entc/ > /tmp/test-launch-store-postgres-entc.log 2>&1; \
status=$$?; \
cat /tmp/test-launch-store-postgres-entc.log; \
if [ $$status -ne 0 ]; then exit $$status; fi; \
if grep -qE '^[[:space:]]*--- SKIP' /tmp/test-launch-store-postgres-entc.log; then \
echo "ERROR: one or more pkg/ent/entc Postgres tests were skipped -- see '--- SKIP' lines above." >&2; \
exit 1; \
fi; \
if ! grep -qE '^--- PASS: TestSkillStore_CreateAgainstOldSchemaWithVisibilityColumn_Postgres ' /tmp/test-launch-store-postgres-entc.log; then \
echo "ERROR: the skill-visibility old-schema Postgres test did not run." >&2; \
exit 1; \
fi; \
if ! grep -qE '^--- PASS: TestMigrateSkillCoreScope_Postgres ' /tmp/test-launch-store-postgres-entc.log; then \
echo "ERROR: the core-to-global skill scope Postgres migration test did not run." >&2; \
exit 1; \
fi; \
if ! grep -qE '^--- PASS: TestMigrateMessageModeRename_Postgres ' /tmp/test-launch-store-postgres-entc.log; then \
echo "ERROR: the message_mode rename Postgres migration test did not run." >&2; \
exit 1; \
fi; \
if ! grep -qE '^--- PASS: TestAutoMigrateNoOp_Postgres ' /tmp/test-launch-store-postgres-entc.log; then \
echo "ERROR: the AutoMigrate no-op Postgres test did not run." >&2; \
exit 1; \
fi; \
if ! grep -qE '^--- PASS: TestEnsureChatSearchTrigramIndex_Postgres ' /tmp/test-launch-store-postgres-entc.log; then \
echo "ERROR: the chat search trigram index Postgres test did not run." >&2; \
exit 1; \
fi; \
if ! grep -qE '^--- PASS: TestEnsureChatSearchTrigramIndex_RestrictedRole_Postgres ' /tmp/test-launch-store-postgres-entc.log; then \
echo "ERROR: the chat search trigram index restricted-role Postgres test did not run." >&2; \
exit 1; \
fi
@go test -tags integration -count=1 -timeout 10m -v \
-run '^TestServerMigrate_AllTables_Postgres$$' \
./pkg/servermigrate/ > /tmp/test-launch-store-postgres-servermigrate.log 2>&1; \
status=$$?; \
cat /tmp/test-launch-store-postgres-servermigrate.log; \
if [ $$status -ne 0 ]; then exit $$status; fi; \
if grep -qE '^[[:space:]]*--- SKIP' /tmp/test-launch-store-postgres-servermigrate.log; then \
echo "ERROR: one or more pkg/servermigrate Postgres tests were skipped -- see '--- SKIP' lines above." >&2; \
exit 1; \
fi; \
if ! grep -qE '^--- PASS: TestServerMigrate_AllTables_Postgres ' /tmp/test-launch-store-postgres-servermigrate.log; then \
echo "ERROR: the servermigrate Postgres integration test did not run." >&2; \
exit 1; \
fi
@go test -tags integration -count=1 -timeout 10m -v \
-run '^TestDelegate_ConcurrentLiveCapHolds_Postgres$$' \
./pkg/testinfra/ > /tmp/test-launch-store-postgres-testinfra.log 2>&1; \
status=$$?; \
cat /tmp/test-launch-store-postgres-testinfra.log; \
if [ $$status -ne 0 ]; then exit $$status; fi; \
if grep -qE '^[[:space:]]*--- SKIP' /tmp/test-launch-store-postgres-testinfra.log; then \
echo "ERROR: the pkg/testinfra Postgres test was skipped -- see '--- SKIP' lines above." >&2; \
exit 1; \
fi; \
if ! grep -qE '^--- PASS: TestDelegate_ConcurrentLiveCapHolds_Postgres ' /tmp/test-launch-store-postgres-testinfra.log; then \
echo "ERROR: the offline delegation live-cap Postgres test did not run." >&2; \
exit 1; \
fi
@st=$$(mktemp) || exit 1; \
{ $(HUB_TEST_GOGC) go test -tags integration -count=1 -timeout 20m -v \
-run '^(TestMaintenanceCommandsSchemaShadowGuard_Postgres|TestServerPreflight_Postgres)$$' \
./cmd/ 2>&1; echo $$? > "$$st"; } \
| tee /tmp/test-launch-store-postgres-cmd.log; \
status=$$(cat "$$st" 2>/dev/null); \
rm -f "$$st"; \
case "$$status" in ''|*[!0-9]*) status=1;; esac; \
if [ $$status -ne 0 ]; then exit $$status; fi; \
if grep -qE '^[[:space:]]*--- SKIP' /tmp/test-launch-store-postgres-cmd.log; then \
echo "ERROR: one or more cmd maintenance-command Postgres cases were skipped -- see '--- SKIP' lines above." >&2; \
exit 1; \
fi; \
if ! grep -qE '^--- PASS: TestMaintenanceCommandsSchemaShadowGuard_Postgres ' /tmp/test-launch-store-postgres-cmd.log; then \
echo "ERROR: the maintenance-command search_path guard Postgres test did not run." >&2; \
exit 1; \
fi; \
if ! grep -qE '^--- PASS: TestServerPreflight_Postgres ' /tmp/test-launch-store-postgres-cmd.log; then \
echo "ERROR: the server preflight Postgres test did not run." >&2; \
exit 1; \
fi
## test-launch-store-postgres: test-store-postgres plus the pkg/hub Postgres tests in HUB_INTEGRATION_POSTGRES_TESTS (every shard holding one)
# CI runs the two halves in different jobs: test-store-postgres in the T1
# Launch Store PostgreSQL Tests jobs, and the pkg/hub tests in the pkg/hub
# shard Postgres (integration) jobs (test-hub-postgres-integration
# SHARD=K).
test-launch-store-postgres: test-store-postgres
@./hack/hubshard/shard.sh postgres all integration $(HUB_INTEGRATION_POSTGRES_TESTS)
# BROKER_RESERVATION_TRANSFER_POSTGRES_TESTS are the Postgres variants of
# the atomic broker reservation transfer (ptone/scion#5951): the forward
# move at the source cap, the cap on the target, the target lock held across
# the transaction (two replicas) and the concurrent soak.
BROKER_RESERVATION_TRANSFER_POSTGRES_TESTS := TestMoveBrokerQuota_SourceAtCapTargetFull_Postgres \
TestTransferBroker_TargetAtCapRefused_Postgres \
TestTransferBroker_TargetLockHeldAcrossTransaction_Postgres \
TestTransferBroker_ConcurrentReserveSoak_Postgres
# USER_DELETION_POSTGRES_TESTS are the forced user delete concurrency tests
# (ptone/scion#2143): a restore racing the delete request, a restore racing
# the completion, two hub processes completing one deletion, and a finalize
# racing the completion's reopen of a blocking agent; and a token's user
# delete refused in its transaction for a system-scope binding the
# pre-check did not see.
USER_DELETION_POSTGRES_TESTS := TestForceDeleteUser_RestoreRacesRequest_Postgres \
TestForceDeleteUser_RestoreRacesCompletion_Postgres \
TestForceDeleteUser_TwoReconcilersOneCompletion_Postgres \
TestForceDeleteUser_FinalizeRacesCompletionReopen_Postgres \
TestUserDeleteToken_InTransactionBindingRefused_Postgres
# INTEGRATIONS_HA_POSTGRES_TESTS are the pkg/hub integrations HA tests
# (ptone/scion#6947) that require a Postgres backend via enttest.Active().
# TestUpdateConfig_NoStoredConfigStoresNewKeys is listed by its top-level
# name so its postgres_null_config_row subtest runs under -tags integration.
INTEGRATIONS_HA_POSTGRES_TESTS := TestUpdateIntegration_HA_Accepted \
TestGetUpdateStatus_ByID \
TestGetUpdateStatus_Latest \
TestGetUpdateStatus_NotFound \
TestGetUpdateStatus_InvalidID \
TestGetUpdateStatus_CrossIntegrationRejected \
TestUpdateConfig_HA_Integration \
TestUpdateConfig_HA_SetsUpdatedBy \
TestUpdateConfig_HA_SkipsReconfigure \
TestGetIntegration_HA_ReadsFromPostgres \
TestUpdateConfig_NoStoredConfigStoresNewKeys
# HUB_SETTINGS_HA_POSTGRES_TESTS are the pkg/hub settings HA e2e tests
# (pkg/hub/ha_e2e_test.go) that exercise two hub instances sharing Postgres
# (settings propagation, concurrent seeding advisory lock, maintenance
# persistence across restart, env overrides, concurrent CAS, poll backstop
# on LISTEN disruption, and rollback safety).
HUB_SETTINGS_HA_POSTGRES_TESTS := TestHA_AC1_SettingsPropagation \
TestHA_AC2_ConcurrentSeedingAdvisoryLock \
TestHA_AC3_MaintenanceSurvivesRestart \
TestHA_AC5_EnvOverrideOneHub \
TestHA_AC7_ConcurrentCAS \
TestHA_AC9_PollBackstopOnListenDisruption \
TestHA_AC10_RollbackSafety
# HUB_INTEGRATION_POSTGRES_TESTS are the pkg/hub Postgres tests that need
# -tags integration (the integration TestMain sets up the ent test
# database): the project-delete lock-order test, the two-replica scheduled
# send test, the membership loss and test identity concurrency tests, and
# the broker presence registry test (its conduit registry runs on the ent
# test database), the agent delegation issuance vs reincarnation claim
# race, the broker reservation transfer tests
# (BROKER_RESERVATION_TRANSFER_POSTGRES_TESTS), the forced user delete
# tests (USER_DELETION_POSTGRES_TESTS), the integrations HA tests
# (INTEGRATIONS_HA_POSTGRES_TESTS), the hub settings HA e2e tests
# (HUB_SETTINGS_HA_POSTGRES_TESTS), the chat retention cascade and
# replica race and deleted-conversation tests, the two-replica project
# quota admission test, the encryption scan, audit and verify tests
# (TestEncryptionScan_*, TestEncryptionAudit_*, TestVerifyEncryption_*),
# and the 2-node Postgres conduit HA harness tests
# (TestConduitHA_DeliverCrossNode, TestConduitHA_FaultHooks,
# TestConduitHA_MessageForward_RoundRobinLB,
# TestConduitHA_MessageForward_TimeoutAndTypedError,
# TestConduitHA_MessageForward_ConcurrencyAndBrokerIsolation).
# Each must print a PASS line, and any skip fails (shard.sh postgres).
HUB_INTEGRATION_POSTGRES_TESTS := TestProjectDeletionService_LockOrderNoDeadlock \
TestScheduledSend_TwoHubReplicasPostgres_OneDelivery \
TestBrokerPresence_LiveRegistrySession \
TestAgentDelegationIssuanceVsReincarnateClaim_Postgres \
$(MEMBERSHIP_LOSS_POSTGRES_TESTS) \
$(TEST_IDENTITY_POSTGRES_TESTS) \
$(BROKER_RESERVATION_TRANSFER_POSTGRES_TESTS) \
$(USER_DELETION_POSTGRES_TESTS) \
$(INTEGRATIONS_HA_POSTGRES_TESTS) \
$(HUB_SETTINGS_HA_POSTGRES_TESTS) \
TestHubInternal_ReplayAcrossHubReplicas \
TestChatRetention_Postgres_CascadeAndReplicaRace \
TestChatRetention_Postgres_DeletedConversationsAndAttachments \
TestChatRetention_Postgres_DeleteTopicSweep \
TestProjectQuota_TwoHubReplicasPostgres_OneAdmission \
TestEncryptionScan_ClassifiesByAuthenticatingKey \
TestEncryptionScan_PagesCoverEveryRow \
TestEncryptionAudit_CountsAuthenticatedKeysOnly \
TestVerifyEncryption_PolicyAllowedSet \
TestVerifyEncryption_AllV2Passes \
TestInvitedUser_HubRoleGuard_ConcurrentGroupBindAndAdd_Postgres \
TestCustomDefaultUserRole_ConcurrentFirstSignIn_Postgres \
TestTriggers_ConcurrentCaps_Postgres \
TestWebhookIngress_ConcurrentPendingCap_Postgres \
TestNeverSuspend_QuotaConcurrencyAndIsolation_Postgres \
TestUpdateProject_ConcurrentLabelPatches_Postgres \
TestConduitHA_DeliverCrossNode \
TestConduitHA_FaultHooks \
TestConduitHA_2801_C2_BrokerPathCrossNode \
TestConduitHA_2801_C20_AmbiguousAndRetrySemantics \
TestConduitHA_2801_BrokerDrainAfterGoAwayCrossNode \
TestConduitHA_2801_C17_BrokerIncarnation \
TestConduitHA_2796_C2_AgentPTYCrossNode \
TestConduitHA_2796_C4_LifetimeHandoffCrossNode \
TestConduitHA_2796_C10_CapabilityTruthCrossNode \
TestConduitHA_2796_C16b_ActiveAuthzCrossNode \
TestConduitHA_2796_C5_SlowReaderIsolationCrossNode \
TestConduitHA_C19_FunctionalSmoke \
TestConduitHA_MessageForward_RoundRobinLB \
TestConduitHA_MessageForward_TimeoutAndTypedError \
TestConduitHA_MessageForward_ConcurrencyAndBrokerIsolation
## test-hub-postgres: Run the pkg/hub Postgres tests of shard SHARD=K (SHARD=all: every shard holding one)
# Requires SCION_TEST_POSTGRES_URL (integration tests) and
# SCION_TEST_POSTGRES_DSN (web chat and conduit tests). Runs
# WEBCHAT_POSTGRES_TESTS and CONDUIT_AUTHZ_POSTGRES_TESTS (default tags)
# and HUB_INTEGRATION_POSTGRES_TESTS (-tags integration) that live in the
# shard; hack/hubshard -locate fails if a listed test no longer exists.
# CI runs the two halves in different jobs. test-hub-postgres-default runs
# in each pkg/hub shard job, after the shard's SQLite run, so the
# default-tag build comes from the cache. test-hub-postgres-integration
# needs its own pkg/hub compile (-tags integration: a different TestMain
# and extra test files), so it runs in its own job, in parallel with the
# shard jobs, for each shard hub-postgres-integration-shards prints.
# The two halves run one after another through sub-makes (not as
# prerequisites), so make -j never runs two pkg/hub compiles at once.
test-hub-postgres:
@$(MAKE) --no-print-directory test-hub-postgres-default
@$(MAKE) --no-print-directory test-hub-postgres-integration
# test-hub-postgres-env-check fails unless both Postgres variables are set.
test-hub-postgres-env-check:
@if [ -z "$$SCION_TEST_POSTGRES_URL" ] || [ -z "$$SCION_TEST_POSTGRES_DSN" ]; then \
echo "ERROR: SCION_TEST_POSTGRES_URL and SCION_TEST_POSTGRES_DSN must be set -- the Postgres tests would silently skip instead of running." >&2; \
exit 1; \
fi
## test-hub-postgres-default: The default-tag half of test-hub-postgres (HUB_WEBCHAT_POSTGRES_TESTS, CONDUIT_AUTHZ_POSTGRES_TESTS) for SHARD=K
test-hub-postgres-default: test-hub-postgres-env-check
@./hack/hubshard/shard.sh postgres $(SHARD) "" $(HUB_WEBCHAT_POSTGRES_TESTS) $(CONDUIT_AUTHZ_POSTGRES_TESTS)
## test-hub-postgres-integration: The -tags integration half of test-hub-postgres (HUB_INTEGRATION_POSTGRES_TESTS) for SHARD=K
test-hub-postgres-integration: test-hub-postgres-env-check
@./hack/hubshard/shard.sh postgres $(SHARD) integration $(HUB_INTEGRATION_POSTGRES_TESTS)
## hub-postgres-integration-shards: Print the pkg/hub shards that hold a HUB_INTEGRATION_POSTGRES_TESTS test, one per line (CI's shard plan)
# Fails if a listed test is in no test file (hubshard -locate).
hub-postgres-integration-shards:
@located=$$(./hack/hubshard/hubshard.sh -tags integration -locate $(HUB_INTEGRATION_POSTGRES_TESTS)) || exit 1; \
echo "$$located" | awk '{print $$2}' | sort -nu
## test-webchat-postgres: Run the web chat store Postgres tests (pkg/hub/webchat and pkg/hub) against a real server
# Requires SCION_TEST_POSTGRES_DSN (a pgx connection string). The selected
# tests self-skip without it, so the target fails if the variable is unset,
# if any selected test skips, or if any listed test reports no PASS line.
# The tests drop and recreate the webchat_* tables, so point the DSN at a
# scratch database.
HUB_WEBCHAT_POSTGRES_TESTS := TestScheduledStore_Postgres \
TestChatSearchLiteralWildcards_Postgres \
TestChatSearchDeletedAndEdited_Postgres \
TestChatSearchDifferential_Postgres \
TestChatSearchStatementTimeout_Postgres \
TestChatSearchVisibility_Postgres \
TestChatSearchStoreTimeoutStopsStatement_Postgres \
TestChatSearchTrigramIndex_Postgres \
TestPromoteDM_ReallocatesConversationSeqWithoutCollision_Postgres \
TestChatSearchConversationIDWithoutThreadID_Postgres \
TestBackfillNativeMessageConversations_Idempotent_Postgres
WEBCHAT_PKG_POSTGRES_TESTS := TestListTopicsByProjects_Postgres \
TestC4Fix_Postgres_FreshDB \
TestC4Fix_Postgres_PreExistingDB \
TestC4Fix_Postgres_Idempotent \
TestC4Fix_Postgres_PreExistingDB_Idempotent \
TestUnreadMentionKeys_Postgres \
TestMessageStarStore_Postgres \
TestWebChatStore_Postgres_MessagesInOtherSchema \
TestWebChatStore_Postgres_ThreadMigrationsWaitForMessagesTable \
TestWebChatStore_Postgres_ThreadMigrationsRunOnce \
TestUserPrefsThreadGroupsMarker_Postgres \
TestUserPrefsThreadGroupsMigratedAt_Postgres_PreExistingDB \
TestTopicIdentityOwnership_Postgres \
TestTopicReconcile_Postgres \
TestUpdateTopic_ConcurrentLockOrder_Postgres \
TestTopicReads_MalformedConversationID_Postgres \
TestPromoteDM_DoesNotWriteThreadID_Postgres \
TestTopicActiveCount_UppercaseArchivedSibling_Postgres \
TestTopicConversationLookupInProject_OtherProjectNotFound \
TestSoftDeleteDM_Postgres \
TestTopicArchiveAndDelete_Postgres \
TestListMessageIDsForAttachment_Postgres \
TestListTopicsIncludingDeletedForProjects_Postgres \
TestMessageReactionStore_Postgres
test-webchat-pkg-postgres:
@if [ -z "$$SCION_TEST_POSTGRES_DSN" ]; then \
echo "ERROR: SCION_TEST_POSTGRES_DSN is not set -- the Postgres tests would silently skip instead of running." >&2; \
exit 1; \
fi
@pattern=$$(printf '%s\n' $(WEBCHAT_PKG_POSTGRES_TESTS) | paste -sd '|' -); \
go test -buildvcs=false -count=1 -timeout 10m -v -run "^($$pattern)$$" ./pkg/hub/webchat > /tmp/test-webchat-pkg-postgres.log 2>&1; \
rc=$$?; \
cat /tmp/test-webchat-pkg-postgres.log; \
if [ $$rc -ne 0 ]; then exit $$rc; fi; \
if grep -qE '^[[:space:]]*--- SKIP' /tmp/test-webchat-pkg-postgres.log; then \
echo "ERROR: one or more pkg/hub/webchat Postgres tests were skipped -- see '--- SKIP' lines above." >&2; \
exit 1; \
fi; \
for t in $(WEBCHAT_PKG_POSTGRES_TESTS); do \
if ! grep -qE "^--- PASS: $$t " /tmp/test-webchat-pkg-postgres.log; then \
echo "ERROR: pkg/hub/webchat Postgres test $$t did not report PASS." >&2; \
exit 1; \
fi; \
done
test-webchat-postgres: test-webchat-pkg-postgres
@if [ -z "$$SCION_TEST_POSTGRES_DSN" ]; then \
echo "ERROR: SCION_TEST_POSTGRES_DSN is not set -- the Postgres tests would silently skip instead of running." >&2; \
exit 1; \
fi
@./hack/hubshard/shard.sh postgres all "" $(HUB_WEBCHAT_POSTGRES_TESTS)
## test-conduit-authz-postgres: Run the conduit user-stream re-check tests (criterion 16b, P tier) against a real Postgres server
# Requires SCION_TEST_POSTGRES_DSN (a pgx connection string). Two hub nodes
# share one database through their own stores and LISTEN/NOTIFY event
# publishers; each test creates and drops its own schema. The tests
# self-skip without the DSN, so the target fails if the variable is unset,
# if any selected test skips, or if any listed test reports no PASS line.
CONDUIT_AUTHZ_POSTGRES_TESTS := TestConduitAuthzPostgres_NotifyAcrossNodes \
TestConduitAuthzPostgres_UserSuspendDeleteAndTokenRevoke \
TestConduitAuthzPostgres_ListenGapResync \
TestConduitAuthzPostgres_BulkRevocation \
TestSeparateRelayListenerReceivesHubEvents
test-conduit-authz-postgres:
@if [ -z "$$SCION_TEST_POSTGRES_DSN" ]; then \
echo "ERROR: SCION_TEST_POSTGRES_DSN is not set -- the Postgres tests would silently skip instead of running." >&2; \
exit 1; \
fi
@./hack/hubshard/shard.sh postgres all "" $(CONDUIT_AUTHZ_POSTGRES_TESTS)
## test-artifacts-postgres: Run the pkg/artifacts tests: store tests on SQLite and a real Postgres (service tests on SQLite)
# Requires SCION_TEST_POSTGRES_DSN (a pgx connection string). The artifact
# store is not an Ent store (design D3: own tables, created by Init), so like
# the web chat store it has its own Postgres SQL and its own Postgres tests.
# Every store test runs once per dialect as a /sqlite and a /postgres
# subtest; the Postgres subtests are added only when the DSN is set, so the
# target fails if the variable is unset, if any test skips, or if no
# /postgres subtest passed. Each test works in its own throwaway schema.
# CI runs this in the T1 Launch Store PostgreSQL Tests (other packages) job.
test-artifacts-postgres:
@echo "Running pkg/artifacts tests (store tests on SQLite and Postgres)..."
@if [ -z "$$SCION_TEST_POSTGRES_DSN" ]; then \
echo "ERROR: SCION_TEST_POSTGRES_DSN is not set -- the Postgres tests would silently be left out." >&2; \
exit 1; \
fi
@go test -count=1 -timeout 10m -v ./pkg/artifacts/... > /tmp/test-artifacts-postgres.log 2>&1; \
status=$$?; \
cat /tmp/test-artifacts-postgres.log; \
if [ $$status -ne 0 ]; then exit $$status; fi; \
if grep -qE '^[[:space:]]*--- SKIP' /tmp/test-artifacts-postgres.log; then \
echo "ERROR: an artifact test was skipped -- see '--- SKIP' lines above." >&2; \
exit 1; \
fi; \
if ! grep -qE '^[[:space:]]*--- PASS: [^ ]+/postgres ' /tmp/test-artifacts-postgres.log; then \
echo "ERROR: no Postgres subtest passed." >&2; \
exit 1; \
fi
## test-tz-contract: Run the real-binary timestamp contract test (SQLite; Postgres too when SCION_TEST_POSTGRES_URL is set)
# It builds cmd/scion, starts `scion server start --foreground` under non-UTC TZ values
# and checks every timestamp on the wire is the written instant in UTC ("Z").
# SQLite always runs; Postgres runs when SCION_TEST_POSTGRES_URL is set, and
# the target then fails if the Postgres cases did not pass.
test-tz-contract:
@echo "Running the timestamp contract test..."
@go test -tags tzcontract -count=1 -timeout 15m -v \
./pkg/hub/tzcontract/... > /tmp/test-tz-contract.log 2>&1; \
status=$$?; \
cat /tmp/test-tz-contract.log; \
if [ $$status -ne 0 ]; then exit $$status; fi; \
if [ -n "$$SCION_TEST_POSTGRES_URL" ] && \
! grep -qE '^[[:space:]]*--- PASS: TestTimestampContract/postgres ' /tmp/test-tz-contract.log; then \
echo "ERROR: SCION_TEST_POSTGRES_URL is set but the Postgres contract cases did not run." >&2; \
exit 1; \
fi
## vet: Run go vet
vet:
@go vet ./...
## lint: Run go vet (no SQLite, memory-safe)
lint:
@go vet -tags no_sqlite ./...
## vet-integration: Compile-check integration-tagged code (go vet -tags 'integration tzcontract')
# Catches build breaks in integration-tagged files that other vet/lint