magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Allow only valid preferences during setup:di:compile

Open fredden opened this issue 4 years ago • 48 comments

Description

The setup:di:compile command has exclude lists to avoid loading / compiling dependency injection for 'test' classes. When preferences exist for these excluded classes, any plugins associated with the original classes are (potentially) rendered useless. This is because the child class (preference) can call the original class in a way which does not use Magento's plugin system (ie, parent::methodName()). And it's impossible to plugin a class that does not go through Magento's compilation process (to have interceptors created, etc). See https://github.com/magento/security-package/issues/296 for a real-world example of this problem in action.

This pull request began as a change to the regular expressions used to exclude classes, and has grown into expanding the exclude list to cover preferences. Changes include:

  • Removal of invalid preferences already within the code-base.
  • Alerting (exception) for preferences that do not exist.
  • Alerting (exception) for preferences that do not exist because of the existing exclude lists.
  • Various bug-fixes for setup:di:compile-related classes.

Related Pull Requests

  • https://github.com/magento/inventory/pull/3315
  • https://github.com/magento-commerce/magento2-page-builder/pull/304

Fixed Issues (if relevant)

  1. Fixes https://github.com/magento/security-package/issues/296

Manual testing scenarios

  1. Create an "around" plugin on Magento\TwoFactorAuth\Observer\ControllerActionPredispatch::execute()
  2. Notice this works in developer mode, but not in production mode

Questions or comments

None

Contribution checklist

  • [x] Pull request has a meaningful description of its purpose
  • [x] All commits are accompanied by meaningful commit messages
  • [x] All new or changed code is covered with unit/integration tests (if applicable)
  • [x] README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • [ ] All automated tests passed successfully (all builds are green)

fredden avatar Jun 07 '21 09:06 fredden

Hi @fredden. Thank you for your contribution Here are some useful tips how you can test your changes using Magento test environment. Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

:exclamation: Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s) For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

:information_source: Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

:warning: According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] avatar Jun 07 '21 09:06 m2-assistant[bot]

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

Hi @fredden, What is a use case for writing plugin on a class that should be used only in tests?

ihor-sviziev avatar Jun 07 '21 11:06 ihor-sviziev

I can't think of a good reason to create a plugin for a class that should only be used in tests. Perhaps the change here should be to exclude Preferences that match these regular expressions as well. I'll investigate further to see if that's something we can include here.

fredden avatar Jun 07 '21 11:06 fredden

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@magento run all tests

ihor-sviziev avatar Jul 05 '21 10:07 ihor-sviziev

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@ihor-sviziev you added the "needs update" label in July 2021 (https://github.com/magento/magento2/pull/33161#event-4977662971). I don't see a corresponding comment saying why. What would you like to see updated / changed here?

fredden avatar Jan 02 '24 18:01 fredden

Hi @fredden, I bet that is due to a vast number of failed tests.

ihor-sviziev avatar Jan 03 '24 07:01 ihor-sviziev

@magento run all tests

ihor-sviziev avatar Jan 03 '24 07:01 ihor-sviziev

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

Hello @fredden Thank you for your contribution I see you updated your repositories I've rerun tests Let's wait it

andrewbess avatar Jan 27 '24 22:01 andrewbess

@magento run all tests

andrewbess avatar Jan 27 '24 22:01 andrewbess

@magento run all tests

andrewbess avatar Jan 28 '24 08:01 andrewbess

@magento run all tests

andrewbess avatar Jan 28 '24 22:01 andrewbess