Fix false positive in cron-duplicates check for hooks with unique args#210
Fix false positive in cron-duplicates check for hooks with unique args#210swissspidy merged 5 commits intomainfrom
Conversation
…blish_future_post) Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
|
@copilot failing test(s): |
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
... Fixed in 9bafe58. The root cause was that Two changes:
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR adjusts the cron-duplicates doctor check to avoid false positives for WordPress core hooks like publish_future_post, where multiple cron events share the same hook name but legitimately differ by arguments.
Changes:
- Update duplicate detection to group cron events by
(hook, args)instead ofhookalone. - Update cron-event listing to include the
argsfield so the check can differentiate events. - Add a Behat scenario verifying that many
publish_future_post-style events with unique args do not trigger an error.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Check/Cron_Duplicates.php | Changes grouping key to incorporate args to reduce false positives. |
| src/Check/Cron.php | Requests hook,args fields from wp cron event list to support updated grouping. |
| features/check-cron-duplicates.feature | Adds acceptance coverage for “same hook, unique args” cron scheduling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| array( | ||
| 'format' => 'json', | ||
| 'fields' => 'hook,args', | ||
| ) | ||
| ); |
There was a problem hiding this comment.
Cron::get_crons() is shared by Cron_Count and Cron_Duplicates. Requesting args here means the cron-count check now retrieves/serializes args for every event even though it only calls count($crons), which could be a performance/memory regression on sites with large/complex args. Consider keeping get_crons() lightweight and only requesting args for the duplicates check (e.g., accept a $fields parameter and cache per field-set, or add a dedicated method used only by Cron_Duplicates).
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
The
cron-duplicatescheck grouped jobs solely by hook name, causing false positives forpublish_future_post— a WP core hook that schedules one distinct cron job per future post, each with a unique post ID argument.Changes
src/Check/Cron_Duplicates.php: Replace the hook-name-only grouping key with ajson_encode([hook, args])compound key. Jobs are now only counted as duplicates when both the hook name and arguments match.features/check-cron-duplicates.feature: Add scenario registering 15publish_future_post-style jobs (same hook, unique args each) and asserting the check reports success.Original prompt
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.