Skip to content

Status: add new class used to classify requests on a site. #43843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

jeherve
Copy link
Member

@jeherve jeherve commented Jun 9, 2025

Proposed changes:

jetpack_is_frontend currently lives in the Jetpack plugin only, but would be needed outside of the Jetpack plugin (for example for #43413).

In phase 2, we'll replace usage of the function everywhere where it is used, and deprecate the function.

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)?

Jetpack product discussion

  • N/A

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

  • No

Testing instructions:

  • Is CI happy?

This function currently lives in the Jetpack plugin only, but would be needed outside of the Jetpack plugin (for example for #43413).
@jeherve jeherve requested a review from Copilot June 9, 2025 07:44
@jeherve jeherve self-assigned this Jun 9, 2025
@jeherve jeherve added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] In Progress [Pri] Normal [Package] Status labels Jun 9, 2025
Copy link
Contributor

github-actions bot commented Jun 9, 2025

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 a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ 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

github-actions bot commented Jun 9, 2025

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 (Jetpack or WordPress.com Site Helper), and enable the add/is-frontend-status branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/is-frontend-status
bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/is-frontend-status

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

Copilot

This comment was marked as outdated.

Copy link

jp-launch-control bot commented Jun 9, 2025

Code Coverage Summary

1 file is newly checked for coverage.

File Coverage
projects/packages/status/src/class-request.php 31/31 (100.00%) 💚

Full summary · PHP report · JS report

@jeherve jeherve requested a review from Copilot June 9, 2025 08:05
Copy link
Contributor

@Copilot 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 PR introduces a new Request class to classify site requests outside the Jetpack plugin, and updates the corresponding tests and changelog.

  • Adds Request class with methods to determine if a request is for the frontend and to manage Vary headers.
  • Updates the patchwork.json test configuration to include additional redeclarable header functions.
  • Updates the changelog to reflect the addition.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
projects/packages/status/tests/php/patchwork.json Added new redeclarable header functions to the array.
projects/packages/status/src/class-request.php Introduced a new Request class with methods for frontend detection and Vary header handling.
projects/packages/status/changelog/add-is-frontend-status Changelog entry describing the minor addition of the Request class.
Comments suppressed due to low confidence (1)

projects/packages/status/tests/php/patchwork.json:6

  • Consider adding tests to verify that the additional redeclarable header functions ('headers_sent', 'headers_list', and 'header') behave as expected in various request scenarios.
"headers_sent",

Copy link
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

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

Looks reasonable, and has coverage. The only comment I really care about is line 69, the rest are ok with me to ignore if you disagree.

projects/packages/status/src/class-request.php 31/31 (100.00%) 💚

💚

* Go through headers and get a list of Vary headers to add,
* including a Vary Accept header if necessary.
*
* @since 12.2
Copy link
Contributor

Choose a reason for hiding this comment

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

@since 12.2 doesn't make sense in the context of the Status package.


/**
* Go through headers and get a list of Vary headers to add,
* including a Vary Accept header if necessary.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we update this while we're here?

Suggested change
* including a Vary Accept header if necessary.
* including Vary on Accept and Content-Type if necessary.


return array(
'frontend request' => array(
'scenario_name' => 'frontend request',
Copy link
Contributor

Choose a reason for hiding this comment

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

The scenario_name parameter seems kind of redundant, since it's already the key for the test and will be included in the output

For example,

1) Automattic\Jetpack\Status\Request_Test::test_is_frontend_scenarios with data set "frontend request" ('frontend request', [false, false, false, false, false, false, false], [], false, true)
Failed scenario: frontend request
Failed asserting that true matches expected false.

already says with data set "frontend request".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Status [Pri] Normal [Status] Needs Review This PR is ready for review. [Tests] Includes Tests [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants