Skip to content

Fix plugin install detection when update info unavailable - #541

Open
swissspidy wants to merge 1 commit into
mainfrom
claude/akismet-test-failure-gq0g7i
Open

Fix plugin install detection when update info unavailable#541
swissspidy wants to merge 1 commit into
mainfrom
claude/akismet-test-failure-gq0g7i

Conversation

@swissspidy

@swissspidy swissspidy commented Aug 18, 2026

Copy link
Copy Markdown
Member

What

wp plugin install <slug> could try to install a plugin that is already installed, failing with Warning: Destination folder already exists. instead of reporting Warning: <slug>: Plugin already installed.

Why

Plugin_Command::install_from_repo() relied solely on install_plugin_install_status(). That function only recognizes an installed plugin when it has update data to compare against:

} else {
	// If the above update check failed, then that probably means that the update checker has out-of-date information, force a refresh.
	if ( ! $loop ) {
		delete_site_transient( 'update_plugins' );
		wp_update_plugins();
		return install_plugin_install_status( $api, true );
	}
}

If plugins_api() reports a version newer than the installed one and the refreshed update_plugins transient still holds no entry for that slug, there is no fallback: the status stays install for a plugin that is sitting on disk. WP-CLI then downloads the package and the installation fails on the existing folder.

This broke the Install dependencies with activation scenario in the nightly run of 2026-08-18 (run 32089579364) — in every job, WP latest and trunk, PHP 7.4 through nightly:

Installing Akismet Anti-spam: Spam Protection (5.7.1)
Downloading installation package from https://downloads.wordpress.org/plugin/akismet.5.7.1.zip...
Unpacking the package...
Installing the plugin...
Plugin installation failed.
[...]
Warning: Destination folder already exists. "{WORKING_DIR}/wp-content/plugins/akismet/"
Error: Only installed 1 of 2 plugins.

Nothing changed on our side; the same commit passed the day before. What is certain is that during that run plugins_api() offered Akismet 5.7.1 (and downloads.wordpress.org served the ZIP), while the update_plugins transient held no update entry for the Akismet version bundled with WordPress.

A plausible explanation is the staged distribution of new plugin releases announced in Protect The Shire: Akismet 5.7.1 was released around midnight UTC, and the failing run started at 01:49 UTC. This is not confirmed — the announcement frames the hold in terms of auto-updates, and people have reported seeing such updates offered in wp-admin during the hold — but the timing matches, and re-running the very same workflow later that day passed with no changes.

Either way the fall-through in install_plugin_install_status() is real, and it is not Akismet-specific: any plugin installed from WordPress.org can hit it in the window after a release. The same applies outside WP-CLI, where the Add Plugins screen offers "Install Now" for an already installed plugin and fails the same way on click.

How

Check the file system in addition to the reported status, similar to what Theme_Command::install_from_repo() already does via wp_get_theme( $slug )->exists(). The new is_plugin_installed() helper requires both the directory and a valid plugin file (get_plugins( '/' . $slug )), so the existing Paths aren't backslashed when destination folder already exists scenario — which deletes akismet.php first — keeps working unchanged.

The added scenario reproduces the state deterministically, without depending on WordPress.org timing: an mu-plugin empties site_transient_update_plugins, and a stub debug-bar 0.1 stands in for the outdated install.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NeGydmXhxbx34V4UV6M3L6

Summary by CodeRabbit

  • New Features

    • Plugin installation now recognizes plugins that are already installed, even when update information is unavailable.
    • Added a --force option path to allow installation to proceed when needed.
  • Bug Fixes

    • Prevented unnecessary downloads and destination-folder warnings for already-installed plugins.

`install_plugin_install_status()` returns an `install` status for a plugin
that is already installed whenever the WordPress.org API does not offer any
update information for the installed version. The installation then fails
with a "Destination folder already exists" error instead of the expected
"Plugin already installed" warning.

This is what currently happens for the Akismet plugin bundled with
WordPress, which broke the `Install dependencies with activation` scenario.

Check the file system in addition to the reported status, similar to what
`Theme_Command` already does via `wp_get_theme()`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NeGydmXhxbx34V4UV6M3L6
Copilot AI lite review requested due to automatic review settings August 18, 2026 10:22
@swissspidy
swissspidy requested a review from a team as a code owner August 18, 2026 10:22

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 12d50a66-6bd3-4013-acc8-1c6e05445ac7

📥 Commits

Reviewing files that changed from the base of the PR and between 3d4ea50 and 471b95f.

📒 Files selected for processing (2)
  • features/plugin-install.feature
  • src/Plugin_Command.php

Included review availability: Your plan includes up to 1 review per rolling hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Plugin installation now checks plugin status and filesystem contents before downloading. A feature scenario verifies that an outdated Debug Bar installation is reported as already installed when update data is unavailable.

Changes

Plugin installation detection

Layer / File(s) Summary
Existing plugin detection and validation
src/Plugin_Command.php, features/plugin-install.feature
install_from_repo() detects installed plugins from status data and plugin files, while preserving --force behavior. The feature scenario validates the already_installed result and successful exit status without a destination-folder warning.

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

Merge Risk: ⚪ Minimal · up to 471b9

This is a localized plugin-install detection fix with a regression scenario; no actionable merge-blocking risk remains after the normal validation checks pass.

Suggested reviewers: schlessera, brianhenryie

🚥 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 clearly and concisely describes the main fix for plugin installation detection when update information is unavailable.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/akismet-test-failure-gq0g7i

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions github-actions Bot added bug command:plugin Related to 'plugin' command labels Aug 18, 2026
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy added this to the 3.0.1 milestone Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:plugin Related to 'plugin' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants