Jetpack AI: gate the AI Answers toggle on the Jetpack AI master switch (Search) - #50884
Jetpack AI: gate the AI Answers toggle on the Jetpack AI master switch (Search)#50884ariskataoka wants to merge 9 commits into
Conversation
|
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! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 11 files. Only the first 5 are listed here.
|
76e3373 to
c7d7064
Compare
There was a problem hiding this comment.
Pull request overview
This PR ensures Jetpack Search’s AI Answers setting is correctly gated by the site-wide Jetpack AI master switch, preventing UI and API paths from enabling AI Answers when Jetpack AI is off while still preserving the user’s saved choice.
Changes:
- Add a master-switch check (
AI_Answers::is_master_enabled()) and apply it as a hard gate after filters when computing “enabled”. - Close write paths when the master is off (REST endpoint validation +
sanitize_callbackon the registered setting for/wp/v2/settingswrites). - Update both dashboard and Customberg UIs to disable the toggle with explanatory copy while still showing the saved choice; expand test coverage accordingly.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| projects/packages/search/tests/php/trait-toggles-ai-master.php | Adds test helpers to simulate the presence and state of the Jetpack AI “master” module in package tests. |
| projects/packages/search/tests/php/Settings_Test.php | Adds unit tests for the setting sanitize behavior under master-on/master-off scenarios. |
| projects/packages/search/tests/php/REST_Controller_Test.php | Extends REST controller tests to cover master gating and new response fields (ai_master_enabled, ai_answers_saved). |
| projects/packages/search/tests/php/Initial_Javascript_State_Test.php | Adds tests for reporting the master state in the initial JS payload. |
| projects/packages/search/tests/php/bootstrap.php | Loads the new test trait in the package PHP test bootstrap. |
| projects/packages/search/tests/php/AI_Answers_Test.php | Adds coverage for is_master_enabled(), saved vs effective enabled state, and the “cannot filter past master gate” behavior. |
| projects/packages/search/src/dashboard/store/selectors/jetpack-settings.js | Adds selectors for ai_answers_saved and ai_master_enabled with backward-compatible defaults. |
| projects/packages/search/src/dashboard/hooks/use-search-settings.js | Exposes the new selectors via the useSearchSettings() hook. |
| projects/packages/search/src/dashboard/components/test/ai-answers-tab.test.jsx | Adds UI tests for disabled state, saved-choice display, and explanatory notice when master is off. |
| projects/packages/search/src/dashboard/components/ai-answers-tab/index.jsx | Disables/annotates the toggle and keeps saved choice visible when the master is off; disables related controls. |
| projects/packages/search/src/customberg/components/sidebar/sidebar-options.jsx | Disables the Customberg toggle and updates help text when the master is off using the initial state payload. |
| projects/packages/search/src/class-settings.php | Adds optional sanitize_callback support and wires it for the AI Answers setting. |
| projects/packages/search/src/class-rest-controller.php | Rejects enabling AI Answers via POST /jetpack/v4/search/settings when master is off; reports master + saved choice in get_settings(). |
| projects/packages/search/src/class-helper.php | Includes aiMasterEnabled in the initial JS state. |
| projects/packages/search/src/class-ai-answers.php | Implements master-gate logic, saved-choice accessor, setting sanitizer, and applies the master gate after filters. |
| projects/packages/search/changelog/add-search-ai-answers-master-gate | Adds a changelog entry for the gating change. |
c7d7064 to
a74e29c
Compare
74ee3d3 to
b982196
Compare
a707b4b to
0fdf7d1
Compare
45d81f7 to
d4b2f0e
Compare
d4b2f0e to
9dcaefc
Compare
Fixes #FORNO-427
Proposed changes
This PR gates the AI Answers toggle on the Jetpack AI master switch, behind the internal testing flag. Master off = toggle disabled in both UIs, endpoint rejects enabling, overlay and block render nothing — the saved choice persists for when the master returns.
Screenshots
Details
Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Needs a paid Jetpack Search plan and the Jetpack plugin.
wp jetpack module deactivate ai, reload. The toggle is disabled but still checked, with "Jetpack AI is turned off for this site."; Personality and Save are disabled.POST jetpack/v4/search/settings{"ai_answers_enabled": true}→ 400.POST /wp/v2/settings{"jetpack_search_ai_answers_enabled": true}→ the option is stored (the choice persists, like the other AI feature options), but AI Answers stays off everywhere while the master is off.wp jetpack module activate ai→ enabled again, saved value restored.