Agents Manager: Return wp-admin variant for connected CIAB environments#47310
Agents Manager: Return wp-admin variant for connected CIAB environments#47310
Conversation
Previously, get_variant() returned null for CIAB environments when the site was connected (not disconnected), meaning no scripts were loaded. Since there is no dedicated ciab variant, return 'wp-admin' instead so the Agents Manager loads in connected CIAB environments. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
There was a problem hiding this comment.
Pull request overview
This pull request fixes a bug where Agents Manager scripts were not loading for connected CIAB (Commerce in a Box / Next Admin) environments. Previously, connected CIAB environments returned null from get_variant(), preventing scripts from loading. Now they return 'wp-admin' variant, enabling the Agents Manager to work properly in these environments.
Changes:
- Modified
get_variant()logic to return'wp-admin'for CIAB environments when Jetpack is connected, instead of returningnull - Updated the test to verify that connected CIAB environments now return
'wp-admin'variant - Added changelog entry documenting the fix
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
projects/packages/jetpack-mu-wpcom/src/features/agents-manager/class-agents-manager.php |
Updated get_variant() method to return 'wp-admin' for connected CIAB environments instead of null |
projects/packages/jetpack-mu-wpcom/tests/php/features/agents-manager/Agents_Manager_Test.php |
Updated test to verify the new behavior, changing assertion from assertFalse to assertSame('wp-admin') |
projects/packages/jetpack-mu-wpcom/changelog/agents-manager-ciab-wp-admin-variant |
Added changelog entry for the fix |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $this->assertSame( 'wp-admin', $result ); | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
The test verifies that get_variant returns 'wp-admin' for connected CIAB environments, but there's missing integration test coverage. While this unit test checks the variant selection logic, there should be a corresponding integration test similar to test_enqueue_scripts_includes_section_name_ciab_disconnected that verifies the complete enqueue flow with the wp-admin variant actually being used in the inline script data for CIAB connected scenarios. This would ensure that the wp-admin variant scripts can be successfully loaded and that the sectionName is correctly set to "wp-admin" in the agentsManagerData.
| /** | |
| /** | |
| * Tests that enqueue_scripts uses the wp-admin variant in CIAB environment when Jetpack is connected. | |
| * | |
| * This verifies that the complete enqueue flow for a CIAB-connected site | |
| * results in agentsManagerData having sectionName set to "wp-admin". | |
| */ | |
| public function test_enqueue_scripts_includes_section_name_ciab_connected_uses_wp_admin_variant() { | |
| $this->set_admin_context(); | |
| // Save and simulate CIAB environment. | |
| global $wp_actions; | |
| $original_action_count = $wp_actions['next_admin_init'] ?? 0; | |
| do_action( 'next_admin_init' ); | |
| // Enable unified experience but do NOT simulate a Jetpack disconnected site. | |
| // is_jetpack_disconnected() returns false for non-Jetpack sites. | |
| add_filter( 'agents_manager_use_unified_experience', '__return_true', 20 ); | |
| // Capture inline script data added during enqueue_scripts. | |
| $inline_scripts = array(); | |
| Functions::when( 'wp_add_inline_script' )->alias( | |
| function ( $handle, $data, $position = 'after' ) use ( &$inline_scripts ) { | |
| $inline_scripts[] = array( | |
| 'handle' => $handle, | |
| 'data' => $data, | |
| 'position' => $position, | |
| ); | |
| return true; | |
| } | |
| ); | |
| $this->agents_manager->enqueue_scripts(); | |
| remove_filter( 'agents_manager_use_unified_experience', '__return_true', 20 ); | |
| // Restore did_action counter. | |
| if ( $original_action_count === 0 ) { | |
| unset( $wp_actions['next_admin_init'] ); | |
| } else { | |
| $wp_actions['next_admin_init'] = $original_action_count; | |
| } | |
| // Ensure that at least one inline script was enqueued and that it includes sectionName "wp-admin". | |
| $this->assertNotEmpty( $inline_scripts, 'Expected enqueue_scripts to add inline script data.' ); | |
| $found_wp_admin_section = false; | |
| foreach ( $inline_scripts as $script ) { | |
| if ( is_string( $script['data'] ) && strpos( $script['data'], '"sectionName":"wp-admin"' ) !== false ) { | |
| $found_wp_admin_section = true; | |
| break; | |
| } | |
| } | |
| $this->assertTrue( | |
| $found_wp_admin_section, | |
| 'Expected agentsManagerData inline script to have sectionName set to "wp-admin" for CIAB-connected sites.' | |
| ); | |
| } | |
| /** |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
|
Replaced by #47314 |
Proposed changes:
get_variant(), return'wp-admin'for CIAB environments when the site is connected (not disconnected), instead of returningnull(which prevented scripts from loading).ciabvariant, connected CIAB environments should use thewp-adminvariant.assertSame( 'wp-admin' )instead ofassertFalse).Other information:
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
wp-adminvariant (sectionNameshould be"wp-admin"in the inlineagentsManagerData).ciab-disconnectedvariant is still used.Changelog
Changelog entry added to
projects/packages/jetpack-mu-wpcom/changelog/agents-manager-ciab-wp-admin-variant.