Repository navigation
649 lines (603 loc) · 30.7 KB
/
Copy pathdeploy-shared.yml
File metadata and controls
649 lines (603 loc) · 30.7 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
name: Deploy Shared
on:
workflow_call:
inputs:
environment:
description: "GitHub environment name (e.g. dev, production)"
required: true
type: string
tofu-directory:
description: "Path to the OpenTofu environment directory"
required: true
type: string
aws-role-session-name:
description: "AWS role session name for this deployment"
required: true
type: string
run-delete-profile-migration:
description: "Whether to run the delete-profile migration workaround"
required: false
type: boolean
default: false
e2e-base-url:
description: "Base URL for post-deploy smoke tests"
required: false
type: string
default: ""
smoke-url-block-pattern:
description: "Shell case pattern for rejected smoke-test URLs"
required: false
type: string
default: ""
smoke-url-block-message:
description: "Error message when a smoke-test URL is rejected"
required: false
type: string
default: ""
smoke-url-block-pattern-2:
description: "Second shell case pattern for rejected smoke-test URLs"
required: false
type: string
default: ""
smoke-url-block-message-2:
description: "Second error message when a smoke-test URL is rejected"
required: false
type: string
default: ""
smoke-role-session-name:
description: "AWS role session name for smoke-test cleanup"
required: false
type: string
default: ""
e2e-base-url-var-suffix:
description: "Suffix for the E2E_BASE_URL variable name (e.g. DEV, PROD)"
required: false
type: string
default: ""
strict-test-account-names:
description: "Require test account emails to contain test/smoke/integration in the local part"
required: false
type: boolean
default: true
allow-non-test-account-emails:
description: "Opt-in to allow smoke tests with non-test email addresses (dev only; use with caution)"
required: false
type: boolean
default: false
secrets:
AWS_ROLE_ARN:
required: true
AWS_REGION:
required: true
TF_VAR_ENCRYPTION_PASSPHRASE:
required: true
TF_VAR_GOOGLE_CLIENT_ID:
required: true
TF_VAR_GOOGLE_CLIENT_SECRET:
required: true
TEST_OWNER_EMAIL:
required: false
TEST_OWNER_PASSWORD:
required: false
TEST_CONTRIBUTOR_EMAIL:
required: false
TEST_CONTRIBUTOR_PASSWORD:
required: false
TEST_READONLY_EMAIL:
required: false
TEST_READONLY_PASSWORD:
required: false
TEST_USER_POOL_ID:
required: false
jobs:
deploy:
name: Plan and deploy to ${{ inputs.environment }}
runs-on: ubuntu-latest
timeout-minutes: 60
outputs:
user_pool_id: ${{ steps.tofu_outputs.outputs.user_pool_id }}
client_id: ${{ steps.tofu_outputs.outputs.client_id }}
appsync_api_key: ${{ steps.tofu_outputs.outputs.appsync_api_key }}
environment:
name: ${{ inputs.environment }}
env:
TF_VAR_github_token: ${{ github.token }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.14"
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Install Python dependencies
run: uv sync --locked
- name: Build Lambda Layer
run: scripts/build-lambda-layer.sh
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".node-version"
cache: npm
cache-dependency-path: |
frontend/package-lock.json
package-lock.json
- name: Install root Node.js dependencies
run: npm ci
# All tofu steps below (resolver-order guard, migration apply, plan/apply)
# evaluate file() against the bundled resolver output, so it must exist first.
- name: Build AppSync resolvers
run: npm run build:resolvers
- name: Set up OpenTofu
uses: opentofu/setup-opentofu@v1
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}
role-session-name: ${{ inputs.aws-role-session-name }}
- name: OpenTofu init
env:
TF_VAR_encryption_passphrase: ${{ secrets.TF_VAR_ENCRYPTION_PASSPHRASE }}
TF_VAR_google_client_id: ${{ secrets.TF_VAR_GOOGLE_CLIENT_ID }}
TF_VAR_google_client_secret: ${{ secrets.TF_VAR_GOOGLE_CLIENT_SECRET }}
TF_VAR_github_token: ${{ github.token }}
TF_IN_AUTOMATION: "true"
working-directory: ${{ inputs.tofu-directory }}
run: tofu init
- name: Check if delete profile migration is needed
id: check_delete_profile_migration
if: ${{ inputs.run-delete-profile-migration }}
env:
TF_VAR_encryption_passphrase: ${{ secrets.TF_VAR_ENCRYPTION_PASSPHRASE }}
TF_VAR_google_client_id: ${{ secrets.TF_VAR_GOOGLE_CLIENT_ID }}
TF_VAR_google_client_secret: ${{ secrets.TF_VAR_GOOGLE_CLIENT_SECRET }}
TF_VAR_github_token: ${{ github.token }}
TF_IN_AUTOMATION: "true"
working-directory: ${{ inputs.tofu-directory }}
run: |
old_functions=$(tofu state list 2>/dev/null | grep -E '^module\.appsync\.aws_appsync_function\.(delete_profile_(campaigns|invites|metadata|orders_cascade_appsync|ownership|shares)|query_profile_(shares|invites|campaigns)_for_delete|verify_profile_owner_for_delete)$' || true)
if [ -n "$old_functions" ]; then
echo "needs_migration=true" >> "$GITHUB_OUTPUT"
echo "Old delete-profile pipeline functions still in state; migration required."
else
echo "needs_migration=false" >> "$GITHUB_OUTPUT"
echo "No old delete-profile pipeline functions in state; skipping migration."
fi
- name: OpenTofu apply - migrate delete profile resolver first
if: ${{ inputs.run-delete-profile-migration && steps.check_delete_profile_migration.outputs.needs_migration == 'true' }}
env:
TF_VAR_encryption_passphrase: ${{ secrets.TF_VAR_ENCRYPTION_PASSPHRASE }}
TF_VAR_google_client_id: ${{ secrets.TF_VAR_GOOGLE_CLIENT_ID }}
TF_VAR_google_client_secret: ${{ secrets.TF_VAR_GOOGLE_CLIENT_SECRET }}
TF_VAR_github_token: ${{ github.token }}
TF_IN_AUTOMATION: "true"
working-directory: ${{ inputs.tofu-directory }}
# One-time migration: the deleteSellerProfile resolver was refactored from
# a multi-function pipeline to a single function. AppSync rejects deleting
# functions still referenced by a resolver, and the AWS provider has a
# long-standing issue ordering resolver updates before function deletions.
# Recreating the resolver first removes the old function references reliably.
# This state-changing step must run BEFORE the saved plan so the plan stays valid.
run: |
tofu apply -replace=module.appsync.aws_appsync_resolver.delete_seller_profile -auto-approve
# One-time migration (#665): the custom CloudFront response headers
# policies `security` and `auth_security` were retired in favour of the
# AWS-managed SecurityHeadersPolicy. CloudFront rejects deleting a
# response headers policy while a cache behaviour still references it
# (ResponseHeadersPolicyInUse), and the apply is what disassociates the
# behaviours, so the plan must not contain the destroy. Removing the
# resources from state first keeps the plan valid; the orphaned policies
# in AWS are deleted by the step that runs after the apply.
- name: Forget retired CloudFront response headers policies
id: forget_response_headers_policies
env:
TF_VAR_encryption_passphrase: ${{ secrets.TF_VAR_ENCRYPTION_PASSPHRASE }}
TF_VAR_google_client_id: ${{ secrets.TF_VAR_GOOGLE_CLIENT_ID }}
TF_VAR_google_client_secret: ${{ secrets.TF_VAR_GOOGLE_CLIENT_SECRET }}
TF_VAR_github_token: ${{ github.token }}
TF_IN_AUTOMATION: "true"
working-directory: ${{ inputs.tofu-directory }}
run: |
# Anchored to the response-headers policy type only: the managed
# cache/origin-request policies the distribution references must
# never be forgotten here.
retired=$(tofu state list 2>/dev/null | grep -E 'aws_cloudfront_response_headers_policy\.' || true)
retired_ids=""
if [ -z "$retired" ]; then
echo "No retired CloudFront response headers policies in state; nothing to forget."
else
for addr in $retired; do
policy_id=$(tofu state show -no-color "$addr" | awk -F'"' '/^[ \t]*id[ \t]*=/ {print $2; exit}')
echo "Forgetting $addr (cloudfront id: $policy_id)"
tofu state rm "$addr"
retired_ids="$retired_ids $policy_id"
done
fi
# Single-line space-separated ids for the post-apply cleanup step.
echo "retired_policy_ids=${retired_ids# }" >> "$GITHUB_OUTPUT"
# Runs after the state-forget migration above and immediately before the
# saved plan is created: the guard itself applies every planned change
# except the deferred AppSync destroys, so any pre-apply state surgery has
# to be finished when it runs, and a guard failure aborts the deploy before
# the saved plan exists.
- name: Ensure AppSync reference-releasing updates precede function/datasource deletes
env:
TF_VAR_encryption_passphrase: ${{ secrets.TF_VAR_ENCRYPTION_PASSPHRASE }}
TF_VAR_google_client_id: ${{ secrets.TF_VAR_GOOGLE_CLIENT_ID }}
TF_VAR_google_client_secret: ${{ secrets.TF_VAR_GOOGLE_CLIENT_SECRET }}
TF_VAR_github_token: ${{ github.token }}
TF_IN_AUTOMATION: "true"
working-directory: ${{ inputs.tofu-directory }}
run: |
# AppSync rejects deleting a pipeline function or data source that a resolver or
# function still references. Removing such a resource from the configuration also
# removes the edge that ordered its destroy after the referencing objects' updates,
# so the apply walks the destroy nodes first and aborts before any reference-
# releasing update runs (#750: 13 consecutive failed deploys, every later merge
# replaying the identical BadRequestException).
#
# The guard derives its own targets: it plans, reads every planned
# aws_appsync_function / aws_appsync_datasource deletion address out of the plan
# JSON, and applies everything else with `-exclude=<addr>`. The reference-releasing
# updates land there, and the saved plan below only destroys objects nothing
# references any more. There is deliberately no hand-maintained target list — the
# derivation covers every future consolidation without a human remembering to
# extend it.
"$GITHUB_WORKSPACE/scripts/appsync-ensure-resolver-order.sh"
- name: OpenTofu plan
env:
TF_VAR_encryption_passphrase: ${{ secrets.TF_VAR_ENCRYPTION_PASSPHRASE }}
TF_VAR_google_client_id: ${{ secrets.TF_VAR_GOOGLE_CLIENT_ID }}
TF_VAR_google_client_secret: ${{ secrets.TF_VAR_GOOGLE_CLIENT_SECRET }}
TF_VAR_github_token: ${{ github.token }}
TF_IN_AUTOMATION: "true"
working-directory: ${{ inputs.tofu-directory }}
run: tofu plan -out=tfplan
# ROLLBACK: To revert this deployment, check out the previous release commit,
# re-run `tofu plan -out=tfplan` against the previous state, and apply it with
# `tofu apply tfplan`. The plan file is not uploaded as an artifact because it
# can contain sensitive values derived from TF_VAR_* secrets.
- name: OpenTofu apply
env:
TF_VAR_encryption_passphrase: ${{ secrets.TF_VAR_ENCRYPTION_PASSPHRASE }}
TF_VAR_google_client_id: ${{ secrets.TF_VAR_GOOGLE_CLIENT_ID }}
TF_VAR_google_client_secret: ${{ secrets.TF_VAR_GOOGLE_CLIENT_SECRET }}
TF_VAR_github_token: ${{ github.token }}
TF_IN_AUTOMATION: "true"
working-directory: ${{ inputs.tofu-directory }}
run: tofu apply -auto-approve tfplan
# One-time migration (#665), continued: the apply above is what
# disassociates the cache behaviours from the retired custom response
# headers policies, so only now can the orphaned AWS policies be deleted
# (CloudFront refuses while a behaviour still references one). Ids were
# captured from state before the removal; empty means a previous deploy
# already cleaned up. The delete API requires the current ETag via
# --if-match (InvalidIfMatchVersion otherwise); already-deleted policies
# are logged, not failures.
- name: Delete orphaned CloudFront response headers policies
if: ${{ success() }}
env:
RETIRED_POLICY_IDS: ${{ steps.forget_response_headers_policies.outputs.retired_policy_ids }}
run: |
if [ -z "$RETIRED_POLICY_IDS" ]; then
echo "No retired response headers policies to delete; nothing to do."
exit 0
fi
for policy_id in $RETIRED_POLICY_IDS; do
etag=$(aws cloudfront get-response-headers-policy --id "$policy_id" --query 'ResponseHeadersPolicy.ETag' --output text 2>aws_err.txt || true)
if [ -z "$etag" ] || grep -q 'NoSuchResponseHeadersPolicy' aws_err.txt; then
echo "Response headers policy $policy_id already deleted; continuing."
continue
fi
if aws cloudfront delete-response-headers-policy --id "$policy_id" --if-match "$etag" 2>aws_err.txt; then
echo "Deleted orphaned CloudFront response headers policy $policy_id"
elif grep -q 'NoSuchResponseHeadersPolicy' aws_err.txt; then
echo "Response headers policy $policy_id already deleted; continuing."
else
echo "::warning::Failed to delete orphaned response headers policy $policy_id; continuing."
cat aws_err.txt
fi
done
rm -f aws_err.txt
- name: Extract OpenTofu outputs for frontend
id: tofu_outputs
env:
TF_VAR_encryption_passphrase: ${{ secrets.TF_VAR_ENCRYPTION_PASSPHRASE }}
TF_VAR_google_client_id: ${{ secrets.TF_VAR_GOOGLE_CLIENT_ID }}
TF_VAR_google_client_secret: ${{ secrets.TF_VAR_GOOGLE_CLIENT_SECRET }}
TF_VAR_github_token: ${{ github.token }}
TF_IN_AUTOMATION: "true"
working-directory: ${{ inputs.tofu-directory }}
run: |
echo "user_pool_id=$(tofu output -raw cognito_user_pool_id)" >> $GITHUB_OUTPUT
echo "client_id=$(tofu output -raw cognito_client_id)" >> $GITHUB_OUTPUT
echo "site_url=$(tofu output -raw site_url)" >> $GITHUB_OUTPUT
echo "static_assets_bucket=$(tofu output -raw static_assets_bucket)" >> $GITHUB_OUTPUT
echo "cloudfront_distribution_id=$(tofu output -raw cloudfront_distribution_id)" >> $GITHUB_OUTPUT
# The public-orders API key is a Terraform output threaded into the
# frontend build environment as VITE_APPSYNC_API_KEY (it grants only
# the @aws_api_key fields; the per-campaign share token in the URL is
# the authorization), so it is not a secret here. The public pages
# read it from the build via their key-only Apollo client, so a build
# MUST pick up this value in the same run: a replaced key with a stale
# bundle fails every public call Unauthorized until the next deploy.
echo "appsync_api_key=$(tofu output -raw appsync_api_key)" >> $GITHUB_OUTPUT
- name: Build and deploy frontend
env:
# Vite build-time variables.
# VITE_APPSYNC_ENDPOINT is intentionally unset: dev/prod serve
# /graphql same-origin through the site's CloudFront distribution.
# VITE_COGNITO_DOMAIN is intentionally unset: auth is proxied
# same-origin at root paths (/login, /logout, /oauth2/*), so the
# frontend derives the OAuth domain from the site URL. Ephemeral
# environments set both to absolute values (no CloudFront there).
VITE_APPSYNC_REGION: ${{ secrets.AWS_REGION }}
VITE_APPSYNC_API_KEY: ${{ steps.tofu_outputs.outputs.appsync_api_key }}
VITE_COGNITO_USER_POOL_ID: ${{ steps.tofu_outputs.outputs.user_pool_id }}
VITE_COGNITO_USER_POOL_CLIENT_ID: ${{ steps.tofu_outputs.outputs.client_id }}
VITE_OAUTH_REDIRECT_SIGNIN: ${{ steps.tofu_outputs.outputs.site_url }}
VITE_OAUTH_REDIRECT_SIGNOUT: ${{ steps.tofu_outputs.outputs.site_url }}
STATIC_ASSETS_BUCKET: ${{ steps.tofu_outputs.outputs.static_assets_bucket }}
AWS_REGION: ${{ secrets.AWS_REGION }}
CLOUDFRONT_DISTRIBUTION_ID: ${{ steps.tofu_outputs.outputs.cloudfront_distribution_id }}
working-directory: frontend
run: |
npm ci
npm run build
# Do not use --delete: hashed JS/CSS chunks from previous deploys may still
# be requested by clients that have an old index.html cached before the
# CloudFront invalidation below completes. Keeping old chunks prevents
# white-screen errors for open sessions during the deploy window.
aws s3 sync dist "s3://${STATIC_ASSETS_BUCKET}" --region "${AWS_REGION}"
aws cloudfront create-invalidation --distribution-id "${CLOUDFRONT_DISTRIBUTION_ID}" --paths "/*"
smoke-tests:
name: Post-deploy smoke tests (${{ inputs.environment }})
runs-on: ubuntu-latest
timeout-minutes: 90
needs: deploy
if: ${{ needs.deploy.result == 'success' && inputs.e2e-base-url != '' }}
environment:
name: ${{ inputs.environment }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.14"
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Install Python dependencies (including dev/test)
run: uv sync --locked --dev
- name: Install Playwright browser dependencies
run: uv run playwright install --with-deps chromium
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".node-version"
cache: npm
cache-dependency-path: tests/integration/package-lock.json
- name: Install Node.js dependencies for integration cleanup
working-directory: tests/integration
run: npm ci
- name: Configure AWS credentials for cleanup
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}
role-session-name: ${{ inputs.smoke-role-session-name }}
- name: Validate smoke target URL
if: ${{ inputs.e2e-base-url != '' }}
env:
E2E_BASE_URL: ${{ inputs.e2e-base-url }}
BLOCK_PATTERN_1: ${{ inputs.smoke-url-block-pattern }}
BLOCK_MESSAGE_1: ${{ inputs.smoke-url-block-message }}
BLOCK_PATTERN_2: ${{ inputs.smoke-url-block-pattern-2 }}
BLOCK_MESSAGE_2: ${{ inputs.smoke-url-block-message-2 }}
URL_SUFFIX: ${{ inputs.e2e-base-url-var-suffix }}
ENV_NAME: ${{ inputs.environment }}
run: |
test -n "$E2E_BASE_URL"
check_block_patterns() {
local url="$1"
local patterns="$2"
local message="$3"
if [ -z "$patterns" ]; then
return 0
fi
local pattern
# Split on '|' so each shell case pattern is evaluated independently.
IFS='|' read -ra pattern_array <<< "$patterns"
for pattern in "${pattern_array[@]}"; do
case "$url" in
$pattern)
echo "Refusing to run $message Set E2E_BASE_URL_${URL_SUFFIX} to your ${ENV_NAME} app URL."
exit 1
;;
esac
done
}
check_block_patterns "$E2E_BASE_URL" "$BLOCK_PATTERN_1" "$BLOCK_MESSAGE_1"
check_block_patterns "$E2E_BASE_URL" "$BLOCK_PATTERN_2" "$BLOCK_MESSAGE_2"
echo "Smoke tests target: $E2E_BASE_URL"
- name: Assert static brand assets are served
if: ${{ inputs.e2e-base-url != '' }}
env:
E2E_BASE_URL: ${{ inputs.e2e-base-url }}
run: |
# Static-object drift assertion. On 2026-10-06 logo.svg and
# logo-rotating.svg broke on BOTH dev and prod after deploys that
# verifiably uploaded them (dev run 37525653122, prod run
# 37178810183). The 2026-10-10 root-cause proof (issue #689): the
# objects were never deleted - the #665 `/l*` ordered cache
# behavior (Cognito auth origin) shadows every root path starting
# with `/l`, so CloudFront sent /logo.svg to Cognito, got a 404,
# and served the SPA index.html fallback (HTTP 200, text/html)
# while every other gate stayed green. The assets were renamed to
# kernelworx-logo*.svg (KW-LOGO-PATHFIX-1) so no auth pattern can
# shadow them; the probes below guard against the object actually
# vanishing at the origin again (no CI path deletes keys - this
# workflow's `s3 sync` omits `--delete` - but a manual
# `frontend/deploy.sh` sync from a partial tree does use `--delete`).
# Every deploy re-uploads all of frontend/public/, so a failure here
# turns silent breakage into a red deploy.
tmpreq="$(mktemp -d)"
trap 'rm -rf "$tmpreq"' EXIT
for path in /kernelworx-logo.svg /kernelworx-logo-rotating.svg /favicon.svg; do
url="$E2E_BASE_URL$path"
if ! code=$(curl -sS --max-time 30 -o "$tmpreq/asset.body" -D "$tmpreq/asset.headers" -w '%{http_code}' "$url"); then
echo "::error::GET $url failed (transport error) - the site is unreachable"
exit 1
fi
if [ "$code" != "200" ]; then
echo "::error::$url returned HTTP $code - the static object is missing at the origin"
exit 1
fi
content_type=$(tr -d '\r' < "$tmpreq/asset.headers" | awk '{ if (tolower($1) == "content-type:") print tolower($2) }')
case "$content_type" in
image/svg+xml*) ;;
*)
echo "::error::$url served content-type '$content_type' instead of image/svg+xml - the SPA index.html fallback means the static object is missing at the origin"
exit 1
;;
esac
if ! grep -qi '<svg' "$tmpreq/asset.body"; then
echo "::error::$url served content-type image/svg+xml but a body with no <svg element"
exit 1
fi
echo "OK: $url ($content_type, $(wc -c < "$tmpreq/asset.body") bytes)"
done
- name: Validate test users
env:
TEST_OWNER_EMAIL: ${{ secrets.TEST_OWNER_EMAIL }}
TEST_CONTRIBUTOR_EMAIL: ${{ secrets.TEST_CONTRIBUTOR_EMAIL }}
TEST_READONLY_EMAIL: ${{ secrets.TEST_READONLY_EMAIL }}
TEST_USER_POOL_ID: ${{ secrets.TEST_USER_POOL_ID }}
STRICT_TEST_ACCOUNT_NAMES: ${{ inputs.strict-test-account-names }}
ALLOW_NON_TEST_ACCOUNT_EMAILS: ${{ inputs.allow-non-test-account-emails }}
ENVIRONMENT: ${{ inputs.environment }}
run: |
test -n "$TEST_OWNER_EMAIL"
test -n "$TEST_CONTRIBUTOR_EMAIL"
test -n "$TEST_READONLY_EMAIL"
test -n "$TEST_USER_POOL_ID"
# Force explicit "test-only" naming so misconfigured real users are rejected.
if [ "${STRICT_TEST_ACCOUNT_NAMES}" = "true" ] && [ "${ALLOW_NON_TEST_ACCOUNT_EMAILS}" != "true" ]; then
for email in "$TEST_OWNER_EMAIL" "$TEST_CONTRIBUTOR_EMAIL" "$TEST_READONLY_EMAIL"; do
local_part="${email%@*}"
if ! echo "$local_part" | grep -Eiq '(test|smoke|integration)'; then
echo "Refusing to run: email '$email' does not look like a test account (must include test/smoke/integration in local-part)."
exit 1
fi
done
fi
if [ "${ALLOW_NON_TEST_ACCOUNT_EMAILS}" = "true" ]; then
if [ "${ENVIRONMENT}" != "dev" ]; then
echo "Refusing to run: allow-non-test-account-emails is only permitted for the dev environment (got '${ENVIRONMENT}')."
exit 1
fi
echo "::warning::allow-non-test-account-emails is enabled. Smoke tests are running with non-test account emails; ensure these are dev-only accounts."
fi
# Verify each configured email exists in the configured user pool.
for email in "$TEST_OWNER_EMAIL" "$TEST_CONTRIBUTOR_EMAIL" "$TEST_READONLY_EMAIL"; do
count=$(aws cognito-idp list-users --user-pool-id "$TEST_USER_POOL_ID" --filter "email = \"$email\"" --query 'length(Users)' --output text)
if [ "$count" != "1" ]; then
echo "Refusing to run: expected exactly one Cognito user for '$email' in pool '$TEST_USER_POOL_ID', got '$count'."
exit 1
fi
done
- name: Ensure owner test user is in ADMIN group
env:
TEST_OWNER_EMAIL: ${{ secrets.TEST_OWNER_EMAIL }}
TEST_USER_POOL_ID: ${{ secrets.TEST_USER_POOL_ID }}
run: |
test -n "$TEST_OWNER_EMAIL"
test -n "$TEST_USER_POOL_ID"
echo "Ensuring owner test user '$TEST_OWNER_EMAIL' is a member of the ADMIN group..."
aws cognito-idp admin-add-user-to-group \
--user-pool-id "$TEST_USER_POOL_ID" \
--username "$TEST_OWNER_EMAIL" \
--group-name ADMIN
echo "Owner test user is in the ADMIN group."
- name: Ensure owner test user has TOTP MFA
env:
TEST_OWNER_EMAIL: ${{ secrets.TEST_OWNER_EMAIL }}
TEST_OWNER_PASSWORD: ${{ secrets.TEST_OWNER_PASSWORD }}
TEST_USER_POOL_ID: ${{ secrets.TEST_USER_POOL_ID }}
AWS_REGION: ${{ secrets.AWS_REGION }}
CLIENT_ID: ${{ needs.deploy.outputs.client_id }}
run: |
test -n "$TEST_OWNER_EMAIL"
test -n "$TEST_OWNER_PASSWORD"
test -n "$TEST_USER_POOL_ID"
# Admin-gated API operations require the mfa claim (#336), so
# the owner test user must authenticate with a TOTP device. A fresh
# device is provisioned on every deploy (the secret cannot be
# recovered from Cognito), and the new secret is exported for the
# smoke tests below. Local runs refresh it via
# scripts/create-test-users.sh.
#
# Must be the tofu-managed KernelWorx-Web app client
# (module.cognito.client_id). Never fall back to
# `list-user-pool-clients --max-results 1`: it returns the first
# client in pool order and breaks provisioning (#567; see AGENTS.md).
# Stop here rather than guessing.
CLIENT_ID="${CLIENT_ID}"
if [ -z "$CLIENT_ID" ] || [ "$CLIENT_ID" = "None" ]; then
CLIENT_ID=$(aws cognito-idp list-user-pool-clients \
--user-pool-id "$TEST_USER_POOL_ID" \
--region "$AWS_REGION" \
--query 'UserPoolClients[?ClientName==`KernelWorx-Web`].ClientId | [0]' --output text)
fi
if [ -z "$CLIENT_ID" ] || [ "$CLIENT_ID" = "None" ]; then
echo "::error::Deploy job exported no client_id and the pool $TEST_USER_POOL_ID has no KernelWorx-Web app client; cannot resolve the app client for TOTP provisioning" >&2
exit 1
fi
# The password goes through the environment, never a positional
# argument: process argv is world-readable (#569).
TOTP_SECRET=$(PROVISION_USER_TOTP_PASSWORD="$TEST_OWNER_PASSWORD" \
scripts/provision-user-totp.sh \
"$TEST_USER_POOL_ID" "$CLIENT_ID" "$TEST_OWNER_EMAIL")
echo "TEST_OWNER_TOTP_SECRET=$TOTP_SECRET" >> "$GITHUB_ENV"
- name: Run E2E smoke tests
if: ${{ inputs.e2e-base-url != '' }}
env:
E2E_BASE_URL: ${{ inputs.e2e-base-url }}
TEST_OWNER_EMAIL: ${{ secrets.TEST_OWNER_EMAIL }}
TEST_OWNER_PASSWORD: ${{ secrets.TEST_OWNER_PASSWORD }}
TEST_CONTRIBUTOR_EMAIL: ${{ secrets.TEST_CONTRIBUTOR_EMAIL }}
TEST_CONTRIBUTOR_PASSWORD: ${{ secrets.TEST_CONTRIBUTOR_PASSWORD }}
TEST_READONLY_EMAIL: ${{ secrets.TEST_READONLY_EMAIL }}
TEST_READONLY_PASSWORD: ${{ secrets.TEST_READONLY_PASSWORD }}
TEST_USER_POOL_ID: ${{ secrets.TEST_USER_POOL_ID }}
TEST_REGION: ${{ secrets.AWS_REGION }}
# Scripted auth-boundary probes (test_smoke_auth_boundary.py) and the
# through-site-origin API-key call (test_smoke_public_orders.py). The
# key is not a secret here: it grants only the @aws_api_key fields.
# The endpoint is the site origin's /graphql, NOT the appsync_api_url
# output: that URL contains the AWS region, which is a configured
# repository secret, and Actions refuses to set any step or job output
# whose value contains a secret (deploy run 39112162724: "Skip output
# 'appsync_api_url' since it may contain secret"), which left the
# variable empty and skipped both probes. Going through the site origin
# is also the stronger assertion - it proves the distribution forwards
# the key-only request and that AppSync still refuses the key on
# Cognito-only fields.
TEST_APPSYNC_ENDPOINT: ${{ inputs.e2e-base-url }}/graphql
TEST_APPSYNC_API_KEY: ${{ needs.deploy.outputs.appsync_api_key }}
# A recipient verified in the sending account's SES sandbox. Unset (the
# default) leaves the emailed-order test on its honest "the email did
# not go out, the order did" branch; set it to exercise the send-
# succeeded branch.
E2E_SES_TEST_RECIPIENT: ${{ vars.E2E_SES_TEST_RECIPIENT }}
TEST_OWNER_TOTP_SECRET: ${{ env.TEST_OWNER_TOTP_SECRET }}
RUN_ACCOUNT_DELETION: "1"
# In CI, fail the job if pre/post cleanup cannot run successfully.
E2E_FAIL_ON_CLEANUP_ERROR: "1"
run: uv run pytest tests/e2e/ -m smoke -v