Skip to content

De-duplicate packages list on wp package update - #269

Merged
swissspidy merged 2 commits into
wp-cli:mainfrom
manishsongirkar:fix/update-duplicate-package-count
Dec 2, 2026
Merged

swissspidy merged 2 commits into
wp-cli:mainfrom
manishsongirkar:fix/update-duplicate-package-count

Conversation

@manishsongirkar

@manishsongirkar manishsongirkar commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #267

What changed

  • src/Package_Command.php: in update(), the package arguments now go through array_unique() before the validation loop. Before, a package named twice was looked up twice and stayed in $packages_to_update twice.
  • features/package-update.feature: new scenario "Update a package named more than once counts it once".

Why

wp package update A A printed Success: All 2 packages updated successfully. for one package. count( $packages_to_update ) was 2, and array_intersect() also kept the duplicate, so $num_updated was 2 and the plural message was chosen. When the package had no update, the output was the plural "Packages already at latest versions." instead of "Package already at latest version.".

Only exact repeats are removed. Two different spellings of one package (a legacy lowercase name and its pretty name) are not merged. That case is rare and is out of scope here.

About the test

The scenario installs wp-cli-test/updateable-package:v3.0.0, relaxes the constraint to >=3.0.0, and runs wp package update with the same name twice. It expects Success: Package updated successfully. and no All 2 packages. Without the fix the scenario fails with Success: All 2 packages updated successfully.. With the fix it passes.

Out of scope

  • The wording of the other update messages. They are unchanged.
  • The same fix for other commands. Only update builds a package list from arguments.

Test plan

Run locally with WP_CLI_PHP_ARGS cleared. GITHUB_TOKEN was not set, so the @github-api scenarios did not run.

  • New scenario only: passes with the fix, fails with the fix removed.
  • features/package-update.feature (all scenarios that can run without GITHUB_TOKEN): 11 passed, 0 failed.
  • vendor/bin/run-php-unit-tests: 87 tests OK. The 1 PHPUnit deprecation is the same without this change.
  • parallel-lint, phpstan analyse, lint-gherkin: no errors.
  • phpcs: no errors in the changed files.
  • Not tested: the @github-api scenarios, the other feature files, and Windows.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where requesting the same package more than once in a single update command could produce misleading results. Duplicate requests are now handled once, and the update completes successfully.

`wp package update A A` kept the duplicate name in `$packages_to_update`.
`count()` and `array_intersect()` both kept the duplicate, so the two
counts matched and the plural message "All 2 packages updated
successfully." was printed for one package.

Remove duplicate names after the validation loop with `array_unique()`.

Add a Behat scenario that names one package twice and expects
"Package updated successfully.".

Fixes wp-cli#267
@manishsongirkar
manishsongirkar requested a review from a team as a code owner December 2, 2026 13:41
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

wp package update now removes duplicate package names from explicit update requests. A feature scenario checks that requesting the same package twice does not produce the “All 2 packages” message.

Changes: Package update request handling

Layer / File(s) Summary
Deduplicate requests and verify output
src/Package_Command.php, features/package-update.feature
update() validates and adds each distinct requested package name once. The feature scenario requests one package twice and checks for a successful update without the “All 2 packages” message.

Estimated code review effort: 1 (Trivial) | ~4 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: swissspidy, schlessera

Merge Risk: Minimal · up to a341a

wp package update now counts a package once when its name is repeated, so output is singular where appropriate. No merge-blocking risk was identified.

Security architecture risk: Minimal · up to a341a

Repeating a package name no longer inflates the reported update count. WP-CLI still validates each distinct name and uses the same Composer update path.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: duplicate package names in a single wp package update call are now counted once. The raw summary shows Package_Command::update() now removes duplicate requested na…
Linked Issues check Passed [#267] The issue requires that wp package update count a repeated package name once. The expected output is Success: Package updated successfully., and the no-update case must use the singular mes…
Out of Scope Changes check Passed The changes are a deduplication step in Package_Command::update() and one new Behat scenario in features/package-update.feature. The scenario covers the same repeated-name behavior as issue #267. …
Full details: Title check

Explanation

The title names the main change: duplicate package names in a single wp package update call are now counted once. The raw summary shows Package_Command::update() now removes duplicate requested names before validation, and the added feature scenario checks that a package named twice is not reported as 'All 2 packages.' The linked objectives (issue #267, PR #269) describe the same behavior. The title is specific and matches the changeset, so it passes.

Full details: Linked Issues check

Explanation

[#267] The issue requires that wp package update count a repeated package name once. The expected output is Success: Package updated successfully., and the no-update case must use the singular message. The whole-PR summary states that Package_Command::update() removes duplicate requested package names before it validates installed packages and builds the Composer update arguments. The PR description states that the change uses array_unique() on the package arguments before the validation loop. The deduplicated list feeds both count() and array_intersect(), so both counts equal 1 for a repeated name. The new scenario "Update a package named more than once counts it once" in features/package-update.feature checks the singular success message and the absence of All 2 packages. The author reports that the scenario fails without the fix and passes with it. Limitations: the diff and the update() body could not be read at the reviewed head because the changed blobs are missing from the checkout, and the file read was truncated before update(). The verdict therefore relies on the summary and PR description. The whole-PR line count in the summary is +2/-1, while the previous review recorded +2/-0. This difference is not resolved by the available evidence. It does not change the verdict, because the summary describes the same deduplication behavior.

Full details: Out of Scope Changes check

Explanation

The changes are a deduplication step in Package_Command::update() and one new Behat scenario in features/package-update.feature. The scenario covers the same repeated-name behavior as issue #267. The whole-PR summary lists no changes to public declarations. The PR description states that other update-message wording and other commands are not changed, and the summary does not report changes to those areas. Limitations: the source diff could not be read at the reviewed head, so the scope check relies on the summary and PR description. The summary's +2/-1 line count is not reconciled with the earlier +2/-0 count.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 17f80ab0-0d76-438d-bfad-fe1da4b05742
Commits

Reviewing files that changed from the base of the PR and between 9fcac29 and a341aef.

Files selected for processing: 1

  • src/Package_Command.php

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@github-actions github-actions Bot added bug command:package-update Related to 'package update' command labels Dec 2, 2026
@codecov

codecov Bot commented Dec 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread src/Package_Command.php Outdated
Comment on lines +705 to +706
// Report each package once, even if it was named more than once.
$packages_to_update = array_values( array_unique( $packages_to_update ) );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not do array_unique( $args ) before trying to update packages? Otherwise a bit wasteful...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, thanks. Done in a341aef: array_unique( $args ) now runs before the lookup loop, and I removed the second array_unique() after it. Each package is now looked up once. The PR description is updated to match.

Call array_unique() on the arguments before the validation loop, instead of
on the resolved names after it. Each package is now looked up once, so a
repeated name no longer costs extra composer.json reads.

Addresses review feedback on wp-cli#269.
@swissspidy swissspidy changed the title fix(package): count each package once when update names it twice De-duplicate packages list on wp package update Dec 2, 2026
@swissspidy
swissspidy merged commit 286cd47 into wp-cli:main Dec 2, 2026
62 checks passed
@github-actions github-actions Bot added this to the 4.0.1 milestone Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:package-update Related to 'package update' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wp package update reports a wrong count when the same package is named more than once

2 participants