-
Notifications
You must be signed in to change notification settings - Fork 85
next-build tests #23352
base: main
Are you sure you want to change the base?
next-build tests #23352
Changes from all commits
d570bbd
260a5aa
1d6363a
390f95b
d2f87fa
d5e47f5
43887b3
fcc0cbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,225 @@ | ||||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||||||||||||||||||
| # Tests Next Build's use of JSON:API and the Decoupled Router. | ||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||
| # Usage: next-build.sh [env-name] | ||||||||||||||||||||||||||||||||||||||||
| # env-name: Optional environment name (e.g., tugboat, dev, staging, prod) | ||||||||||||||||||||||||||||||||||||||||
| # Maps to next/envs/.env.{env-name} | ||||||||||||||||||||||||||||||||||||||||
| # If not provided, auto-detects from CMS_ENVIRONMENT_TYPE | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| set -eo pipefail | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Number of pages to test per content type during export test | ||||||||||||||||||||||||||||||||||||||||
| EXPORT_TEST_PAGES_PER_CONTENT_TYPE=3 | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Pages that should always be tested (e.g., known edge cases, previously failing pages) | ||||||||||||||||||||||||||||||||||||||||
| ALWAYS_TEST_PAGES=( | ||||||||||||||||||||||||||||||||||||||||
| /salt-lake-city-health-care/news-releases/new-data-shows-veterans-increased-use-of-online-va | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| export NVM_DIR="$HOME/.nvm" | ||||||||||||||||||||||||||||||||||||||||
| [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" | ||||||||||||||||||||||||||||||||||||||||
| [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" | ||||||||||||||||||||||||||||||||||||||||
| source ~/.bashrc | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| repo_root="$(git rev-parse --show-toplevel)" | ||||||||||||||||||||||||||||||||||||||||
| # shellcheck source=/dev/null | ||||||||||||||||||||||||||||||||||||||||
| source "${repo_root}/.env" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Determine APP_ENV: use argument if provided, otherwise auto-detect from CMS_ENVIRONMENT_TYPE | ||||||||||||||||||||||||||||||||||||||||
| if [ -n "${1:-}" ]; then | ||||||||||||||||||||||||||||||||||||||||
| if [ "$1" = "local" ]; then | ||||||||||||||||||||||||||||||||||||||||
| APP_ENV="example" | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| APP_ENV="$1" | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| # Auto-detect based on CMS_ENVIRONMENT_TYPE | ||||||||||||||||||||||||||||||||||||||||
| case "${CMS_ENVIRONMENT_TYPE:-}" in | ||||||||||||||||||||||||||||||||||||||||
| tugboat) APP_ENV="tugboat" ;; | ||||||||||||||||||||||||||||||||||||||||
| prod) APP_ENV="prod" ;; | ||||||||||||||||||||||||||||||||||||||||
| staging) APP_ENV="staging" ;; | ||||||||||||||||||||||||||||||||||||||||
| dev) APP_ENV="dev" ;; | ||||||||||||||||||||||||||||||||||||||||
| *) APP_ENV="" ;; # Fall back to env-loader defaults | ||||||||||||||||||||||||||||||||||||||||
| esac | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if [ -n "${APP_ENV}" ]; then | ||||||||||||||||||||||||||||||||||||||||
| echo "Using APP_ENV: ${APP_ENV}" | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| DRUPAL_ADDRESS="${DRUPAL_ADDRESS:-${DRUSH_OPTIONS_URI:-http://localhost}}" | ||||||||||||||||||||||||||||||||||||||||
| FAILURES=0 | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Generic HTTP test helper - returns body on stdout, exits non-zero on failure | ||||||||||||||||||||||||||||||||||||||||
| http_get() { | ||||||||||||||||||||||||||||||||||||||||
| local url="$1" | ||||||||||||||||||||||||||||||||||||||||
| local response body http_code | ||||||||||||||||||||||||||||||||||||||||
| response=$(curl -gsS -w '\n%{http_code}' "$url" 2>&1) || return 1 | ||||||||||||||||||||||||||||||||||||||||
| http_code="${response##*$'\n'}" | ||||||||||||||||||||||||||||||||||||||||
| body="${response%$'\n'*}" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if [[ "$http_code" != 200 ]]; then | ||||||||||||||||||||||||||||||||||||||||
| echo "HTTP $http_code: $url" >&2 | ||||||||||||||||||||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||
| printf '%s' "$body" | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| run_test() { | ||||||||||||||||||||||||||||||||||||||||
| local name="$1"; shift | ||||||||||||||||||||||||||||||||||||||||
| echo | ||||||||||||||||||||||||||||||||||||||||
| echo "Test: $name starting..." | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| $@ | ||||||||||||||||||||||||||||||||||||||||
| exit_code=$? | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| echo | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if [ "$exit_code" = "0" ]; then | ||||||||||||||||||||||||||||||||||||||||
| echo "[PASSED $name]" | ||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| echo "[FAILED $name]" | ||||||||||||||||||||||||||||||||||||||||
| ((FAILURES++)) | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+73
to
+83
|
||||||||||||||||||||||||||||||||||||||||
| $@ | |
| exit_code=$? | |
| echo | |
| if [ "$exit_code" = "0" ]; then | |
| echo "[PASSED $name]" | |
| return 0 | |
| else | |
| echo "[FAILED $name]" | |
| ((FAILURES++)) | |
| if "$@"; then | |
| echo | |
| echo "[PASSED $name]" | |
| return 0 | |
| else | |
| echo | |
| echo "[FAILED $name]" | |
| FAILURES=$((FAILURES + 1)) |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_sample_paths swallows any HTTP/JSON:API errors (|| return 0 and redirects stderr), which can silently drop an enabled content type from SSG_CHERRY_PICKED_PATHS and let the export test pass without covering that type. Consider returning non-zero (or at least logging a warning and tracking a failure) when the JSON:API request fails.
| body=$(http_get "${DRUPAL_ADDRESS}/jsonapi/node/${content_type}?page[limit]=${limit}&filter[status]=1" 2>/dev/null) || return 0 | |
| jq -r '.data[].attributes.path.alias // empty' <<<"$body" 2>/dev/null | |
| body=$(http_get "${DRUPAL_ADDRESS}/jsonapi/node/${content_type}?page[limit]=${limit}&filter[status]=1") || { | |
| echo "Warning: Failed to fetch sample paths for content type '${content_type}' from JSON:API at ${DRUPAL_ADDRESS}" >&2 | |
| ((FAILURES++)) | |
| return 1 | |
| } | |
| jq -r '.data[].attributes.path.alias // empty' <<<"$body" |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the Next Build env file is missing, the script only emits a warning and continues, which can make the export test run with just ALWAYS_TEST_PAGES and not validate configured content types. Treat a missing env file as a hard failure for this test so it can’t pass in a misconfigured environment.
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function relies on a standalone [[ ... ]] test for success. With set -e enabled, a false condition will terminate the entire script instead of returning non-zero to run_test. Make this check explicitly control flow (e.g., [[ ... ]] || return 1) so failures are reported correctly.
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo $body | jq ... will word-split/glob-expand the JSON and can also be misinterpreted as echo options (e.g., if JSON starts with -n), causing jq parsing failures or incorrect output. Feed jq the variable without echo and with proper quoting (e.g., via a here-string or printf '%s').
| echo $body | jq -rj '.data[0].id' | |
| jq -rj '.data[0].id' <<<"$body" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These script lines add an extra empty argument when composer forwards arguments to the command (because
"$@"expands to empty in this context), which shifts positional parameters fornext-build.sh(e.g.,composer va:test:next-build tugboatwould likely arrive as$1="",$2="tugboat"). This makes the env override unreliable. Prefer omitting"$@"here and rely on Composer’s normal argument forwarding to append args to the command.