-
Notifications
You must be signed in to change notification settings - Fork 27
Make the test runners cheaper to run repeatedly and quieter to read back #356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
37faeda
f38e2e6
1d6afbc
203f0ca
e844d35
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,32 @@ | ||
| { | ||
| "file-name": [ | ||
| "on", | ||
| { | ||
| "style": "kebab-case" | ||
| } | ||
| ], | ||
| "indentation": [ | ||
| "on", | ||
| { | ||
| "Feature": 0, | ||
| "Background": 2, | ||
| "Scenario": 2, | ||
| "Examples": 4, | ||
| "Step": 4, | ||
| "given": 4, | ||
| "example": 6, | ||
| "and": 4 | ||
| } | ||
| ], | ||
| "no-dupe-feature-names": "on", | ||
| "no-dupe-scenario-names": "off", | ||
| "no-empty-file": "on", | ||
| "no-files-without-scenarios": "on", | ||
| "no-multiple-empty-lines": "off", | ||
| "no-partially-commented-tag-lines": "on", | ||
| "no-trailing-spaces": "off", | ||
| "no-unnamed-features": "on", | ||
| "no-unnamed-scenarios": "on", | ||
| "no-scenario-outlines-without-examples": "on", | ||
| "use-and": "on" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,22 +97,90 @@ if [ -n "${WP_CLI_TEST_CORE_ZIP-}" ] && [ -z "${WP_VERSION-}" ]; then | |
| export WP_VERSION=trunk | ||
| fi | ||
|
|
||
| # Everything WP_VERSION resolution needs is in one file: the wp-versions artifact | ||
| # maps every WordPress release to its status, with the current one marked | ||
| # "latest". Cache it, so that re-running a single scenario while iterating does | ||
| # not refetch it every time, and so that a run without connectivity can fall back | ||
| # to the last known answer instead of ending up with no version at all. | ||
| # | ||
| # Set WP_CLI_TEST_WP_VERSION_CACHE_TTL to 0 to always refetch. | ||
| WP_VERSIONS_URL="https://raw.githubusercontent.com/wp-cli/wp-cli-tests/artifacts/wp-versions.json" | ||
| WP_VERSIONS_CACHE_FILE="${TMPDIR:-/tmp}/wp-cli-test-wp-version-cache/wp-versions.json" | ||
| WP_VERSIONS_CACHE_TTL="${WP_CLI_TEST_WP_VERSION_CACHE_TTL:-86400}" | ||
|
|
||
| # Print the cached versions file if it is younger than the given number of | ||
| # seconds. A negative TTL accepts it at any age. | ||
| read_versions_cache() { | ||
| local ttl="$1" | ||
| local age | ||
|
|
||
| [ -s "${WP_VERSIONS_CACHE_FILE}" ] || return 1 | ||
|
|
||
| if [ "${ttl}" -ge 0 ]; then | ||
| # PHP rather than `find -newermt`, which is not portable across | ||
| # GNU and BSD userlands. The Behat runner needs PHP anyway. | ||
| age=$(php -r 'echo time() - filemtime( $argv[1] );' "${WP_VERSIONS_CACHE_FILE}" 2>/dev/null) | ||
| case ${age} in | ||
| ''|*[!0-9]*) return 1;; | ||
| esac | ||
| [ "${age}" -lt "${ttl}" ] || return 1 | ||
| fi | ||
|
|
||
| cat "${WP_VERSIONS_CACHE_FILE}" | ||
| } | ||
|
|
||
| # Print the WordPress versions data, from the cache where possible. Warnings go | ||
| # to STDERR so that they cannot end up inside the returned JSON. | ||
| get_wp_versions() { | ||
| local json | ||
|
|
||
| json=$( read_versions_cache "${WP_VERSIONS_CACHE_TTL}" ) | ||
| if [ -n "${json}" ]; then | ||
| printf '%s' "${json}" | ||
| return 0 | ||
| fi | ||
|
|
||
| json=$( curl -s "${WP_VERSIONS_URL}" ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Set connection and total time limits for On a cache miss, this request can wait indefinitely for DNS, connection setup, or a response. The Behat runner then hangs instead of falling back to stale metadata or reporting the unavailable metadata. Use 🤖 Prompt for AI Agents |
||
|
|
||
| # Only cache a well-formed response; an error page is not one. | ||
| if echo "${json}" | jq -e 'type == "object" and length > 0' > /dev/null 2>&1; then | ||
| mkdir -p "$( dirname "${WP_VERSIONS_CACHE_FILE}" )" 2>/dev/null \ | ||
| && printf '%s' "${json}" > "${WP_VERSIONS_CACHE_FILE}" 2>/dev/null || true | ||
|
Comment on lines
+147
to
+148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Write the cache atomically. Concurrent Behat runners can read this file after truncation and before Write to a temporary file in the cache directory, then replace 🤖 Prompt for AI Agents |
||
| printf '%s' "${json}" | ||
| return 0 | ||
| fi | ||
|
|
||
| # Prefer a stale answer over no answer. | ||
| json=$( read_versions_cache -1 ) | ||
| if [ -n "${json}" ]; then | ||
| echo "Warning: Could not fetch the WordPress versions data, falling back to the cached copy." >&2 | ||
| printf '%s' "${json}" | ||
| return 0 | ||
| fi | ||
|
|
||
| return 1 | ||
| } | ||
|
|
||
| # Turn WP_VERSION into an actual number to make sure our tags work correctly. | ||
| if [ "${WP_VERSION-latest}" = "latest" ]; then | ||
| export WP_VERSION=$(curl -s https://api.wordpress.org/core/version-check/1.7/ | jq -r ".offers[0].current") | ||
| fi | ||
| WP_VERSION=$( get_wp_versions | jq -r 'to_entries | map( select( .value == "latest" ) ) | last | .key // empty' ) | ||
|
|
||
| # Normalize WP_VERSION=X.Y.0 to X.Y (WordPress uses X.Y for the initial release, not X.Y.0). | ||
| # If WP_VERSION=X.Y (major.minor only), resolve to the latest available patch release. | ||
| if [[ "${WP_VERSION}" =~ ^([0-9]+\.[0-9]+)\.0$ ]]; then | ||
| if [ -z "${WP_VERSION}" ]; then | ||
| echo "Warning: Could not determine the latest WordPress version. Version-specific tags will not be filtered." | ||
| fi | ||
|
|
||
| export WP_VERSION | ||
| # Normalize WP_VERSION=X.Y.0 to X.Y (WordPress uses X.Y for the initial release, | ||
| # not X.Y.0). This asks for that specific release, so it must not fall through to | ||
| # the patch resolution below. | ||
| elif [[ "${WP_VERSION}" =~ ^([0-9]+\.[0-9]+)\.0$ ]]; then | ||
| export WP_VERSION="${BASH_REMATCH[1]}" | ||
| # If WP_VERSION=X.Y (major.minor only), resolve to the latest available patch release. | ||
| elif [[ "${WP_VERSION}" =~ ^[0-9]+\.[0-9]+$ ]]; then | ||
| WP_VERSIONS_JSON=$(curl -s https://raw.githubusercontent.com/wp-cli/wp-cli-tests/artifacts/wp-versions.json) | ||
| if [ -n "${WP_VERSIONS_JSON}" ]; then | ||
| RESOLVED_VERSION=$(echo "${WP_VERSIONS_JSON}" | jq -r --arg prefix "${WP_VERSION}." 'keys | map(select(startswith($prefix))) | sort_by(split(".") | map(tonumber)) | last // empty') | ||
| if [ -n "${RESOLVED_VERSION}" ]; then | ||
| export WP_VERSION="${RESOLVED_VERSION}" | ||
| fi | ||
| RESOLVED_VERSION=$( get_wp_versions | jq -r --arg prefix "${WP_VERSION}." 'keys | map( select( startswith( $prefix ) ) ) | sort_by( split(".") | map( tonumber ) ) | last // empty' ) | ||
|
|
||
| if [ -n "${RESOLVED_VERSION}" ]; then | ||
| export WP_VERSION="${RESOLVED_VERSION}" | ||
| fi | ||
| fi | ||
|
|
||
|
|
@@ -141,6 +209,11 @@ if [[ "${WP_CLI_TEST_COVERAGE}" == "true" ]] && vendor/bin/behat --help 2>/dev/n | |
| BEHAT_EXTRA_ARGS+=('--xdebug') | ||
| fi | ||
|
|
||
| # Honor the NO_COLOR convention (https://no-color.org/). | ||
| if [ -n "${NO_COLOR}" ]; then | ||
| BEHAT_EXTRA_ARGS+=('--no-colors') | ||
| fi | ||
|
|
||
| # Run the functional tests. | ||
| FORMAT_ARGS=(--format progress) | ||
| for arg in "$@"; do | ||
|
|
||
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Validate
WP_CLI_TEST_WP_VERSION_CACHE_TTLbefore using it.If the value is non-numeric, Line 119 reports an integer-comparison error and then accepts the cache at any age. A typo such as
WP_CLI_TEST_WP_VERSION_CACHE_TTL=foocan therefore prevent version metadata refreshes.Reject invalid values before calling
read_versions_cache, or fall back to86400.🤖 Prompt for AI Agents