Skip to content

Fix beta versions, apply fixes for shellcheck hints - #389

Open
nextgenthemes wants to merge 1 commit into
wp-cli:mainfrom
nextgenthemes:patch-3
Open

Fix beta versions, apply fixes for shellcheck hints#389
nextgenthemes wants to merge 1 commit into
wp-cli:mainfrom
nextgenthemes:patch-3

Conversation

@nextgenthemes

@nextgenthemes nextgenthemes commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

The script failed with -betaX as the version.

While at it, I fixed all the things shellcheck was complaining about. If you do not want them, this is the part that is needed:

if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then
	# Beta/RC versions — the stable branch (e.g. 7.1) does not exist yet on
	# GitHub, so fall back to trunk for the test suite. WordPress core itself
	# is still downloaded from wordpress.org which hosts beta archives.
	WP_TESTS_TAG="trunk"

Summary by CodeRabbit

  • Bug Fixes
    • Improved WordPress test environment installation reliability.
    • Corrected handling of beta and release candidate versions.
    • Improved support for temporary directories, database hosts, ports, and socket connections.
    • Added safer handling for paths containing spaces or special characters.
    • Improved reinstall prompts and cleanup of existing WordPress and test-suite files.
    • Enhanced database connection handling and credential processing.

instal-wp-tests-fail.txt

The script failed with -betaX as the version
@nextgenthemes
nextgenthemes requested a review from a team as a code owner July 29, 2026 06:32
@github-actions github-actions Bot added bug scope:testing Related to testing labels Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The installation template updates WordPress version selection, shell path handling, test-suite configuration, database host parsing, database administration commands, and reinstall confirmation input.

Changes

WordPress test installation

Layer / File(s) Summary
Core version and installation flow
templates/install-wp-tests.sh
Temporary directories, beta/RC tags, core paths, downloads, extraction commands, and version lookups now use updated handling and quoting.
Test-suite installation and configuration
templates/install-wp-tests.sh
Test-suite paths are quoted, core directory values are normalized and escaped, and sed replacements use consistent quoting.
Database parsing and administration
templates/install-wp-tests.sh
Database credentials and options are quoted, host parsing distinguishes ports from sockets, and reinstall input is read and passed quoted.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: brianhenryie, ernilambar, janw-me

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main changes: beta/RC version handling and ShellCheck-driven shell script fixes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@templates/install-wp-tests.sh`:
- Around line 239-242: Update the sed substitutions in the install configuration
flow to escape DB_NAME, DB_USER, DB_PASS, and DB_HOST for replacement syntax,
following the existing WP_CORE_DIR_ESCAPED pattern. Use one consistent sed
delimiter across all substitutions so values containing &, the delimiter, or
backslashes are inserted literally.
- Around line 288-296: Replace the EXTRA option string in
templates/install-wp-tests.sh:288-296 with a Bash array and append each host,
port, protocol, or socket option as separate elements. Update the command
invocations at templates/install-wp-tests.sh:256-258, 270-272, and 306-306 to
pass "${EXTRA[@]}" after --password="$DB_PASS", preserving correct argument
boundaries at every site.
- Around line 283-295: Update the DB_HOST parsing logic before the existing
PARTS-based hostname/port handling to recognize bracketed IPv6 values such as
[::1]:3306, preserving the full IPv6 hostname and extracting only the trailing
port or socket. Keep the current hostname-and-port/socket behavior unchanged for
non-bracketed DB_HOST values, using DB_HOSTNAME and DB_SOCK_OR_PORT for the
subsequent EXTRA construction.
- Line 145: Update the VERSION_ESCAPED assignment to use shell parameter
expansion on WP_VERSION for replacing dots with escaped dots, removing the echo
and sed pipeline that triggers ShellCheck SC2001. Preserve the existing escaped
VERSION_ESCAPED value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ab8f5e13-2d94-4020-b55c-0bf235637bf2

📥 Commits

Reviewing files that changed from the base of the PR and between 18a6706 and 8476cd0.

📒 Files selected for processing (1)
  • templates/install-wp-tests.sh

local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'`
LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1)
local VERSION_ESCAPED
VERSION_ESCAPED=$(echo "$WP_VERSION" | sed 's/\./\\\\./g')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove the remaining ShellCheck SC2001 warning.

Use parameter expansion for this fixed substitution instead of spawning echo and sed.

Proposed fix
-				VERSION_ESCAPED=$(echo "$WP_VERSION" | sed 's/\./\\\\./g')
+				VERSION_ESCAPED=${WP_VERSION//./\\.}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
VERSION_ESCAPED=$(echo "$WP_VERSION" | sed 's/\./\\\\./g')
VERSION_ESCAPED=${WP_VERSION//./\\.}
🧰 Tools
🪛 Shellcheck (0.11.0)

[style] 145-145: See if you can use ${variable//search/replace} instead.

(SC2001)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@templates/install-wp-tests.sh` at line 145, Update the VERSION_ESCAPED
assignment to use shell parameter expansion on WP_VERSION for replacing dots
with escaped dots, removing the echo and sed pipeline that triggers ShellCheck
SC2001. Preserve the existing escaped VERSION_ESCAPED value.

Source: Linters/SAST tools

Comment on lines +239 to +242
sed "$ioption" "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
sed "$ioption" "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
sed "$ioption" "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
sed "$ioption" "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Escape database values for sed replacement syntax.

Quoted expansions only protect the shell; DB_NAME, DB_USER, DB_PASS, and DB_HOST can still alter the sed replacement when they contain &, a delimiter, or \. Escape these values like WP_CORE_DIR_ESCAPED and use one delimiter consistently.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@templates/install-wp-tests.sh` around lines 239 - 242, Update the sed
substitutions in the install configuration flow to escape DB_NAME, DB_USER,
DB_PASS, and DB_HOST for replacement syntax, following the existing
WP_CORE_DIR_ESCAPED pattern. Use one consistent sed delimiter across all
substitutions so values containing &, the delimiter, or backslashes are inserted
literally.

Comment on lines 283 to +295
# parse DB_HOST for port or socket references
local PARTS=(${DB_HOST//\:/ })
local PARTS
read -ra PARTS <<< "${DB_HOST//:/ }"
local DB_HOSTNAME=${PARTS[0]};
local DB_SOCK_OR_PORT=${PARTS[1]};
local EXTRA=""

if ! [ -z $DB_HOSTNAME ] ; then
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
if [ -n "$DB_HOSTNAME" ] ; then
if [[ "$DB_SOCK_OR_PORT" =~ ^[0-9]+$ ]]; then
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
elif [ -n "$DB_SOCK_OR_PORT" ] ; then
EXTRA=" --socket=$DB_SOCK_OR_PORT"
elif ! [ -z $DB_HOSTNAME ] ; then
elif [ -n "$DB_HOSTNAME" ] ; then

Copy link
Copy Markdown

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

Preserve bracketed IPv6 database hosts.

Replacing every colon breaks valid values such as [::1]:3306: DB_HOSTNAME becomes [ and the next fragment is incorrectly used as a socket. Parse bracketed IPv6 hosts before handling the hostname-and-port/socket form.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@templates/install-wp-tests.sh` around lines 283 - 295, Update the DB_HOST
parsing logic before the existing PARTS-based hostname/port handling to
recognize bracketed IPv6 values such as [::1]:3306, preserving the full IPv6
hostname and extracting only the trailing port or socket. Keep the current
hostname-and-port/socket behavior unchanged for non-bracketed DB_HOST values,
using DB_HOSTNAME and DB_SOCK_OR_PORT for the subsequent EXTRA construction.

Comment on lines 288 to 296
local EXTRA=""

if ! [ -z $DB_HOSTNAME ] ; then
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
if [ -n "$DB_HOSTNAME" ] ; then
if [[ "$DB_SOCK_OR_PORT" =~ ^[0-9]+$ ]]; then
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
elif [ -n "$DB_SOCK_OR_PORT" ] ; then
EXTRA=" --socket=$DB_SOCK_OR_PORT"
elif ! [ -z $DB_HOSTNAME ] ; then
elif [ -n "$DB_HOSTNAME" ] ; then
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Pass database connection options as an argument array.

Quoting "$EXTRA" while adjoining it to --password="$DB_PASS" creates one argument, e.g. --password=secret --host=localhost; authentication fails whenever EXTRA is populated. Use a Bash array instead of an option string.

  • templates/install-wp-tests.sh#L288-L296: build EXTRA with local -a EXTRA=() and append each option separately.
  • templates/install-wp-tests.sh#L256-L258: pass "${EXTRA[@]}" after --password="$DB_PASS".
  • templates/install-wp-tests.sh#L270-L272: pass "${EXTRA[@]}" after --password="$DB_PASS".
  • templates/install-wp-tests.sh#L306-L306: pass "${EXTRA[@]}" after --password="$DB_PASS".
📍 Affects 1 file
  • templates/install-wp-tests.sh#L288-L296 (this comment)
  • templates/install-wp-tests.sh#L256-L258
  • templates/install-wp-tests.sh#L270-L272
  • templates/install-wp-tests.sh#L306-L306
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@templates/install-wp-tests.sh` around lines 288 - 296, Replace the EXTRA
option string in templates/install-wp-tests.sh:288-296 with a Bash array and
append each host, port, protocol, or socket option as separate elements. Update
the command invocations at templates/install-wp-tests.sh:256-258, 270-272, and
306-306 to pass "${EXTRA[@]}" after --password="$DB_PASS", preserving correct
argument boundaries at every site.

@swissspidy

Copy link
Copy Markdown
Member

Thanks for opening this!

Would you mind addressing the review comments & the failing tests?

Some tests for the changed behavior for beta versions would be nice too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants