Fix agent bundle ability registration for sandbox runs#2629
Merged
Conversation
Contributor
Homeboy Results —
|
WP Codebox sandbox runs (WordPress Playground) execute the smoke via `run-php`, which boots WordPress through wp-load.php — firing init and the one-shot wp_abilities_api_categories_init / wp_abilities_api_init actions — and only THEN require_once's the plugin file. By the time AgentAbilities and AbilityCategories are instantiated, both registration windows have already closed, so the public wp_register_ability()/wp_register_ability_category() helpers no-op. The datamachine-agent category was never registered, and WordPress core then dropped every category-bound agent ability (including datamachine/run-agent-bundle) via _doing_it_wrong() and a null return. Core only enforces the abilities lifecycle in the public helper wrappers; WP_Abilities_Registry::register() and WP_Ability_Categories_Registry::register() have no such guard and are safe to call any time after init. Add a guarded late-registration path to both classes that registers through the registry instance when the init action has already completed, keeping the public-helper path for normal requests. The is_registered() guard makes the late path idempotent. Update the related lifecycle smoke tests to assert the corrected behavior (post-init construction registers via the registry instead of silently no-opping) and faithfully model the registry instances.
The host-smoke-wp backend runs changed smoke tests inside a real WordPress runtime. agent-abilities-late-registration-smoke.php unconditionally declared doing_action(), did_action(), add_action(), and WP_Ability — fataling with "Cannot redeclare" once it ran in real WP. Add a wp_get_ability() real-runtime branch that asserts datamachine/run-agent-bundle is registered (mirroring agent-abilities-registration-smoke.php), and guard every pure-PHP stub behind function_exists()/class_exists() so the file is safe to include in both the standalone pure-PHP harness and the real WordPress runtime.
The wp-codebox host-smoke-wp backend boots a bare WordPress with the plugin
DIRECTORY mounted but NOT activated (recipe blueprint has plugins: []), so
Data Machine's normal plugins_loaded registration never runs. The real-WP
branch of agent-abilities-registration-smoke.php (and the late-registration
smoke) asserted wp_get_ability('datamachine/run-agent-bundle') against this
bare runtime, where no Data Machine ability is ever registered — the test
could not pass.
Load the agent ability registration the same unconditional way data-machine.php
does at file scope (AbilityCategories::ensure_registered() + new AgentAbilities()),
then assert the ability resolves through wp_get_ability(). This exercises the
real registration code on the real registry, covering the hook-before-fire,
register-during-fire, and late-register-after-fire timing states. Also remove
the temporary diagnostic and guard the pure-PHP AbilityCategories stub behind
class_exists() so it never clashes with the required real class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
datamachine/run-agent-bundle.AgentAbilitiesregistered when constructed after the Abilities API lifecycle without actually registering.Testing
php tests/agent-abilities-registration-smoke.phpphp -l inc/Abilities/AgentAbilities.php && php -l data-machine.php && php -l tests/agent-abilities-registration-smoke.phpphp tests/send-email-ability-lazy-definitions-smoke.php && php tests/abilities-categories-load-order-smoke.phpAI assistance