Skip to content

Agents Manager: Return wp-admin variant for connected CIAB environments#47310

Closed
aaronfc wants to merge 1 commit intotrunkfrom
fix/agents-manager-ciab-wp-admin-variant
Closed

Agents Manager: Return wp-admin variant for connected CIAB environments#47310
aaronfc wants to merge 1 commit intotrunkfrom
fix/agents-manager-ciab-wp-admin-variant

Conversation

@aaronfc
Copy link
Contributor

@aaronfc aaronfc commented Feb 24, 2026

Proposed changes:

  • In get_variant(), return 'wp-admin' for CIAB environments when the site is connected (not disconnected), instead of returning null (which prevented scripts from loading).
  • Since there is no dedicated ciab variant, connected CIAB environments should use the wp-admin variant.
  • Update the existing test to verify the new behavior (assertSame( 'wp-admin' ) instead of assertFalse).

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

  • In a CIAB/Next Admin environment with Jetpack connected (not disconnected), verify that the Agents Manager scripts load with the wp-admin variant (sectionName should be "wp-admin" in the inline agentsManagerData).
  • In a CIAB/Next Admin environment with Jetpack disconnected, verify that the ciab-disconnected variant is still used.
  • In a non-CIAB wp-admin environment, verify behavior is unchanged.

Changelog

Changelog entry added to projects/packages/jetpack-mu-wpcom/changelog/agents-manager-ciab-wp-admin-variant.

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>
Copilot AI review requested due to automatic review settings February 24, 2026 21:24
@aaronfc aaronfc added the [Status] Needs Review This PR is ready for review. label Feb 24, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (WordPress.com Site Helper), and enable the fix/agents-manager-ciab-wp-admin-variant branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/agents-manager-ciab-wp-admin-variant

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions
Copy link
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 returning null
  • 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 );
}

/**
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
/**
/**
* 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.'
);
}
/**

Copilot uses AI. Check for mistakes.
@jp-launch-control
Copy link

Code Coverage Summary

This 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. 🤷

Full summary · PHP report

@aaronfc aaronfc closed this Feb 25, 2026
@aaronfc aaronfc deleted the fix/agents-manager-ciab-wp-admin-variant branch February 25, 2026 08:45
@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label Feb 25, 2026
@aaronfc
Copy link
Contributor Author

aaronfc commented Feb 25, 2026

Replaced by #47314

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants