Skip to content
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

Add base RemoteSpecsEngine class, add logging for errors in all remote specs #44775

Merged
merged 5 commits into from Feb 21, 2024

Conversation

ilyasfoo
Copy link
Contributor

@ilyasfoo ilyasfoo commented Feb 19, 2024

Changes proposed in this Pull Request:

Closes #44248.

This PR:

  • Adds base RemoteSpecsEngine that's extended by all Remote Specs
  • Adds logging for development environments for all errors from evaluating specs
  • Change evaluate to private to ensure it's not called from outside since it's possible to fatal

How to test the changes in this Pull Request:

Test remote specs still work as expected

  1. Ensure your environment's PHP version is > 8.1
  2. If using an existing site, clear transients by running wp transient delete --all
  3. Ensure WooCommerce > Settings > Advanced > Woo.com > Display suggestions within WooCommerce is checked
  4. Go to Setup Wizard, /wp-admin/admin.php?page=wc-admin&path=/setup-wizard
  5. Click continue
  6. Select I'm already selling and No, I'm selling offline.
  7. Select Australia — Australian Capital Territory and continue
  8. Skip plugin installation
  9. Observe no fatal when loading homescreen
  10. Go to Tools > WCA Test Helper > Tools, Run wc_admin_daily job
  11. Ensure the job is run successfully
  12. Go to /wp-admin/admin.php?page=wc-admin&task=payments
  13. Confirm it displays the gateways (non-JN, JN)

Test logging

  1. In wp-config.php, ensure WP_ENVIRONMENT_TYPE is set to local or development
  2. In your local, modify the file RuleEvaluator.php and add in_array( '', '', true ); to simulate errors in PHP 8+.
  3. Ensure logging is enabled in WooCommerce > Status > Logs > Settings (screenshot)
  4. Go to WooCommerce > Homescreen
  5. Go to Tools > WCA Test Helper > Tools > Run wc_admin_daily job
  6. Go to WooCommerce > Status > Logs and look for logs named remotespecsengine-errors
  7. In the logs, ensure there are errors that came from the following classes:
Automattic\\WooCommerce\\Internal\\Admin\\WCPayPromotion\\Init
Automattic\\WooCommerce\\Internal\\Admin\\RemoteFreeExtensions\\Init
Automattic\\WooCommerce\\Admin\\Features\\PaymentGatewaySuggestions\\Init
Automattic\\WooCommerce\\Internal\\Admin\\WCPayPromotion\\Init
Automattic\\WooCommerce\\Admin\\RemoteInboxNotifications\\RemoteInboxNotificationsEngine

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Comment

@ilyasfoo ilyasfoo requested review from a team, chihsuan and rjchow February 19, 2024 16:11
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Feb 19, 2024
Copy link
Contributor

github-actions bot commented Feb 19, 2024

Hi @chihsuan, @rjchow,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

Copy link
Contributor

github-actions bot commented Feb 19, 2024

Test Results Summary

Commit SHA: 31d6e42

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 37s
E2E Tests3190021034012m 46s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@@ -20,16 +20,13 @@ class EvaluateExtension {
* @param object $extension The extension to evaluate.
* @return object The evaluated extension.
*/
public static function evaluate( $extension ) {
private static function evaluate( $extension ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Set to private since this can now produce fatal errors.

use Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions\EvaluateSuggestion;
use Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions\PaymentGatewaySuggestionsDataSourcePoller as PaymentGatewaySuggestionsDataSourcePoller;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unused imports

Copy link
Member

@chihsuan chihsuan left a comment

Choose a reason for hiding this comment

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

Tested well! 👍 Just left a question about the transient.

Select I'm just starting my business and continue

Sorry, I found that my previous PR test instructions were not accurate. I think to display the Square as shown in the screenshot, we need to select "I'm already selling" and "I'm selling both online and offline." (or I'm selling offline.)

Additionally, if testing via the live branch, the plugin folder name would need to be changed from /srv/htdocs/wp-content/plugins/wc_beta_tester_live_branch_* to /srv/htdocs/wp-content/plugins/woocommerce for WCPay to appear in the set up payment task.

PaymentGatewaySuggestionsDataSourcePoller::get_instance()->set_specs_transient( array( $locale => DefaultPaymentGateways::get_all() ), 3 * HOUR_IN_SECONDS );

return EvaluateSuggestion::evaluate_specs( DefaultPaymentGateways::get_all() )['suggestions'];
$specs_to_return = EvaluateSuggestion::evaluate_specs( DefaultPaymentGateways::get_all() )['suggestions'];
Copy link
Member

Choose a reason for hiding this comment

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

Since we don't return the specs here, when suggestions are empty and errors exist, we will set the transient to $specs in line 53. Is this an intentional change?

Copy link
Contributor Author

@ilyasfoo ilyasfoo Feb 20, 2024

Choose a reason for hiding this comment

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

Thanks for catching it! It's not intentional, the logic went over my head 😵

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chihsuan I've updated the specs logic with c39de1a

@ilyasfoo
Copy link
Contributor Author

Thanks for the review, @chihsuan!

Sorry, I found that my previous PR test instructions were not accurate.
Additionally, if testing via the live branch, the plugin folder name would need to be changed

I've updated the instructions to reflect actual use cases!

Copy link
Member

@chihsuan chihsuan left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM 💯

Copy link
Contributor

@rjchow rjchow left a comment

Choose a reason for hiding this comment

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

Thanks for refactoring!

Optional comment: since it's now extending a base class, I wonder if it would make sense to take it one step further and extract the common logic in get_suggestions?

@ilyasfoo
Copy link
Contributor Author

Thanks, @rjchow!

since it's now extending a base class, I wonder if it would make sense to take it one step further and extract the common logic in get_suggestions?

I've been thinking that too! However, the get_suggestions is not identical for all remote spec engines (only 3 works similarly). I still think there can be a common denominator, but will require a small refactor, and out of the scope of this PR.

@ilyasfoo ilyasfoo merged commit 42aa027 into trunk Feb 21, 2024
40 checks passed
@ilyasfoo ilyasfoo deleted the fix/44248-add-logging-remote-specs branch February 21, 2024 01:33
@github-actions github-actions bot added this to the 8.7.0 milestone Feb 21, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Feb 21, 2024
@nigeljamesstevenson nigeljamesstevenson added needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. needs: internal testing Indicates if the PR requires further testing conducted by Solaris status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. needs: internal testing Indicates if the PR requires further testing conducted by Solaris plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrap remote endpoints with error handling
4 participants