Skip to content

Tests: further Windows compatibility fixes#609

Merged
swissspidy merged 7 commits intomainfrom
fix/windows
Apr 2, 2026
Merged

Tests: further Windows compatibility fixes#609
swissspidy merged 7 commits intomainfrom
fix/windows

Conversation

@swissspidy
Copy link
Copy Markdown
Member

No description provided.

@github-actions github-actions bot added the bug label Mar 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Hello! 👋

Thanks for opening this pull request! Please check out our contributing guidelines. We appreciate you taking the initiative to contribute to this project.

Contributing isn't limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

Here are some useful Composer commands to get you started:

  • composer install: Install dependencies.
  • composer test: Run the full test suite.
  • composer phpcs: Check for code style violations.
  • composer phpcbf: Automatically fix code style violations.
  • composer phpunit: Run unit tests.
  • composer behat: Run behavior-driven tests.

To run a single Behat test, you can use the following command:

# Run all tests in a single file
composer behat features/some-feature.feature

# Run only a specific scenario (where 123 is the line number of the "Scenario:" title)
composer behat features/some-feature.feature:123

You can find a list of all available Behat steps in our handbook.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves the cross-platform compatibility of the test suite by replacing inline wp eval commands with wp eval-file and switching from single to double quotes for command arguments in Behat feature files. These changes help avoid shell escaping issues, particularly on Windows. Feedback indicates that the transition to double quotes in features/post-block.feature was incomplete, as several instances (e.g., lines 1232 and 1248) were missed and should be updated for consistency.

Scenario: Check if a post has blocks
Given a WP install
When I run `wp post create --post_title='Block Post' --post_content='<!-- wp:paragraph --><p>Hello</p><!-- /wp:paragraph -->' --porcelain`
When I run `wp post create --post_title="Block Post" --post_content="<!-- wp:paragraph --><p>Hello</p><!-- /wp:paragraph -->" --porcelain`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While this change to use double quotes for command arguments is correct for Windows compatibility, I've noticed that this fix has not been applied consistently throughout the file. There are other wp post create commands that still use single-quoted arguments containing spaces (e.g., on lines 1232, 1248). For complete Windows compatibility, all such instances should be updated to use double quotes.

@swissspidy swissspidy marked this pull request as ready for review April 2, 2026 11:08
@swissspidy swissspidy requested a review from a team as a code owner April 2, 2026 11:08
Copilot AI review requested due to automatic review settings April 2, 2026 11:08
@swissspidy swissspidy added this to the 2.8.10 milestone Apr 2, 2026
@swissspidy swissspidy merged commit 4792ac2 into main Apr 2, 2026
73 checks passed
@swissspidy swissspidy deleted the fix/windows branch April 2, 2026 11:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR focuses on improving Windows compatibility for WP-CLI entity-command acceptance tests (Behat) and a small path-handling tweak in wp site empty --uploads.

Changes:

  • Normalize upload file paths to forward slashes before checking for multisite /sites/ paths in Site_Command::empty_().
  • Update multiple Behat scenarios to avoid shell-quoting pitfalls by switching to double quotes and using wp eval-file with generated .php files instead of inline wp eval ....
  • Mark several scenarios as @skip-windows where they rely on Unix-specific shell features (e.g., sed, wc, command substitution).

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Site_Command.php Normalizes real paths before /sites/ detection when deleting uploads.
features/user-import-csv.feature Skips a CSV round-trip scenario on Windows.
features/user-application-password.feature Replaces inline wp eval with wp eval-file scripts to avoid quoting issues.
features/term.feature Switches command argument quoting to be more Windows-friendly.
features/term-recount.feature Replaces inline wp eval with wp eval-file script.
features/site.feature Skips several multisite scenarios on Windows due to Unix shell dependencies.
features/post.feature Adjusts quoting (including EDITOR=...) to reduce Windows shell issues.
features/post-meta.feature Skips a scenario on Windows and adjusts quoting for STDIN echo.
features/post-block.feature Broad quoting adjustments and shifts some content into temp files for safer invocation.
features/comment.feature Skips multi-digit ID scenarios on Windows due to shell command substitution usage.
features/comment-recount.feature Replaces inline wp eval with wp eval-file script.
Comments suppressed due to low confidence (1)

features/post-block.feature:1235

  • This step uses --attrs='{not valid json' to keep spaces together. Single quotes aren’t recognized as quoting in Windows shells, so the argument will be split and/or include literal quotes, changing the behavior of the test. Use double quotes for the --attrs value (or move the value into a temp file/STDIN) so the test remains cross-platform.
    When I run `wp post create --post_title="Test" --post_content="<!-- wp:heading --><h2>Title</h2><!-- /wp:heading -->" --porcelain`
    Then save STDOUT as {POST_ID}

    When I try `wp post block update {POST_ID} 0 --attrs='{not valid json'`
    Then STDERR should contain:

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 248 to 252
$realpath = $fileinfo->getRealPath();
// Don't clobber subsites when operating on the main site
if ( $is_main_site && false !== stripos( $realpath, '/sites/' ) ) {
$normalized_realpath = str_replace( '\\', '/', $realpath );
if ( $is_main_site && false !== stripos( $normalized_realpath, '/sites/' ) ) {
continue;
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

SplFileInfo::getRealPath() can return false. Passing that into str_replace() / stripos() will throw a TypeError in PHP 8+ and abort wp site empty --uploads. Add a guard (e.g. if ( false === $realpath ) { continue; }) or fall back to $fileinfo->getPathname() before normalizing/searching.

Copilot uses AI. Check for mistakes.
Comment on lines +1040 to +1044
And a block-content.txt file:
"""
<!-- wp:heading {"level":2} --><h2>Title 1</h2><!-- /wp:heading --><!-- wp:heading {"level":3} --><h3>Title 2</h3><!-- /wp:heading -->
"""
When I run `wp post create block-content.txt --post_title='Block Post' --porcelain`
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

These wp post create ... --post_title='…' commands still rely on single-quote shell quoting, which doesn’t work in Windows shells (the quotes become part of the argument). To keep the intended Windows-compatibility fix consistent, switch these to double quotes (or omit quotes when no spaces) across the file (search for --post_title=').

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants