Reliably support cweagans/composer-patches in Package Manager & Automatic Updates: validate stage

Created on 2 December 2021, over 2 years ago
Updated 21 February 2023, over 1 year ago

Problem/Motivation

https://github.com/cweagans/composer-patches is widely used but we probably can't offer full support.

Proposed resolution

Possible solutions:

  1. Do nothing in code but have handbook page to describe possible problems
  2. Make a validator that doesn't allow updates if the this library is installed. In this case more complex use cases could remove this validator if they want to support it.
  3. Check for composer-exit-on-patch-failure to make sure it will error out and warn or error if not set
  4. check to see if core in patched and warn or error
  5. check the patches applied in stage and make sure they are applied the same as active


โ†’ this problem has been addressed by ๐Ÿ“Œ Limit trusted Composer plugins to a known list, allow user to add more Fixed and will be fully addressed once ๐Ÿ“Œ Tighten ComposerPluginsValidator: support only specified version constraint Fixed is done.


โ†’ Automatic Updates will never modify the extra section of composer.json, so that is a non-concern โ€” combined with composer-exit-on-patch-failure, plus the protection against installing/uninstalling cweagans/composer-patches means this is all addressed.

We should not check that the same set of patches is applied. Because package_manager is a very general module; there very well may be a patch_manager module at some point in the future which will allow adding/removing patches listed in extra ๐Ÿค“

To be clear: we only need to address this problem thoroughly enough to be included in core. That means we don't need to solve the problem from every angle; we just need to make this "good enough" for the majority of sites. Even a simple warning about composer-exit-on-patch-failure might be enough for core's purposes. We can leave very robust solutions to contrib.

At this point, we've done much more than this โ€” we're validating that::

  1. composer-exit-on-patch-failure is enabled
  2. cweagans/composer-patches is required in the root composer.json โ€” i.e. not indirectly
  3. cweagans/composer-patches cannot be installed nor removed through Package Manager โ€” it can only be enabled manually

โ€ฆ which combined with ๐Ÿ“Œ Limit trusted Composer plugins to a known list, allow user to add more Fixed and ๐Ÿ“Œ Tighten ComposerPluginsValidator: support only specified version constraint Fixed does guarantee that the use of cweagans/composer-patches cannot result in a site getting broken through either Automatic Updates or Project Browser.

Remaining tasks

๐Ÿ“Œ Task
Status

Fixed

Version

2.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States tedbow Ithaca, NY, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Assigned to kunal.sachdev
  • @kunalsachdev opened merge request.
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Paired with @kunal.sachdev on a way forward to do #17 โ€” realized that we cannot test that in a Kernel test, so helped him get the outline in place for testing that in a Build test! ๐Ÿ‘ Good luck, @kunal.sachdev ๐Ÿ˜„

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tedbow Ithaca, NY, USA

    The summary currently still has "Possible solutions:" so it should updated describing what the current merge request is meant to do. Also we specify which merge request is the chosen fix, and close the other if that is appropriate

  • Assigned to kunal.sachdev
  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    @tedbow identified an extra thing we need to protect against. I posted a proposal on how to do that.

    I identified a few clarity nits โ€ฆ but also just spotted one more thing we need to test: https://github.com/cweagans/composer-patches#allowing-patches-to-be-appl... โ€” we should expand our test so that the drupal/alpha project specifies a drupal/core patch, which will be installed if and only if config.extra.enable-patching === true.

    GREAT job on getting this test to work! ๐Ÿคฉ It looks excellent! With just these few additions (from @tedbow and the one I just asked for), we'll be able to be highly confident in our support for https://github.com/cweagans/composer-patches ๐Ÿ˜Š

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia kunal.sachdev

    So, for the build test failure
    Failed to copy "/tmp/.package_manager1138399f-efbb-4de5-9615-4d8919835d23/cYjbXr4SVceHzcM14tPFfA2Jnk3JCLZvpjYgEVtk-Xo/vendor/drupal/coder/.git/objects/pack/pack-4a9af0fe0580e9f82296d111933506654039d16a.idx" to "/tmp/build_workspace_1f164ac4a984a2ad22cbee436c59452bfdpZqI/project/vendor/drupal/coder/.git/objects/pack/pack-4a9af0fe0580e9f82296d111933506654039d16a.idx". in Drupal\package_manager\Stage->apply() (line 495 of modules/contrib/automatic_updates/package_manager/src/Stage.php) which is currently not there as we have a temp fix in GitExcluder , I tried to update drupal/core with Automatic Updates in a real drupal project:

    1. Created drupal project using composer create-project drupal/recommended-project:10.0.0 ten_zero --no-install --no-interaction
    2. Ran following commands :
      composer config allow-plugins.composer/installers true                                          
      composer config allow-plugins.drupal/core-project-message true
      composer config allow-plugins.drupal/core-composer-scaffold true
    3. Ran composer require drupal/core-dev as drupal/core-dev has a dependency on drupal/coder
    4. Confirmed presence of the .git folder in vendor/drupal/coder
    5. Updated drupal/core from 10.0.0 to 10.0.2 without any problem with Automatic Updates

    This points out that we may not have this problem in real time.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Discussed in detail with @tedbow & @kunal.sachdev.

    Conclusions:

    1. doing a build test for composer-patches is something that would be good to have, but it's post-MVP
    2. instead, we do want for MVP a build test that proves there is a reasonable UX whenever composer has a hard failure โ€” no matter whether that is due to a patch failing to apply from composer-patches or whether that is from a networking error, wrong requirement, whatever โ†’ this needs a separate issue
    3. in fact, @tedbow spotted one more thing we should validate: composer-patches should never be installed nor removed โ€” it should stay exactly as it is: so if it's absent in the active, it should be in stage, and vice versa
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Executing #27:

    1. doing a build test for composer-patches is something that would be good to have, but it's post-MVP
    2. instead, we do want for MVP a build test that proves there is a reasonable UX whenever composer has a hard failure โ€” no matter whether that is due to a patch failing to apply from composer-patches or whether that is from a networking error, wrong requirement, whatever โ†’ this needs a separate issue

    Done:

    1. ๐Ÿ“Œ Add functional test that proves there is reasonable UX whenever a stage event subscriber has an exception Fixed
    2. ๐Ÿ“Œ Add build test to test cweagans/composer-patches end-to-end Closed: won't fix

    The third point is up to @kunal.sachdev ๐Ÿ˜Š

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Extracted the build test work Kunal did to ๐Ÿ“Œ Add build test to test cweagans/composer-patches end-to-end Closed: won't fix 's MR, while preserving Kunal's commits ๐Ÿ‘

    Just pushed a commit that now reverts those changes from this MR.

  • Assigned to Wim Leers
  • Status changed to Needs review over 1 year ago
  • Assigned to kunal.sachdev
  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Note that this still uses ::getStageComposer() and ::getActiveComposer(), but that was already the case in HEAD, so let's not delay it over that.

    This merge request is looking great, but is still in need of a range of finishing touches before this is RTBC. I'm confident you can get that done by the next time we meet, @kunal.sachdev! ๐Ÿ˜„

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Excellent work here, @kunal.sachdev! ๐Ÿ‘

    Docs: โœ…
    Tests: โœ…

    Issue summary update: just did that.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States phenaproxima Massachusetts

    Found a few small things that aren't blocking, and then one thing that looks like a genuine mistake that I'm surprised is not breaking tests.

  • Assigned to kunal.sachdev
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • Status changed to Needs work over 1 year ago
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Assigned to phenaproxima
  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tedbow Ithaca, NY, USA

    Test failing on 7.4 ,core 9.5

  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tedbow Ithaca, NY, USA

    RTBC again. I haven't reviewed this more, just fixed the php 7.4 error(pretty sure tests will pass now)

    Leaving assigned to @phenaproxima

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tedbow Ithaca, NY, USA

    Sorry I know this issue has been long slog. See MR comments

  • Assigned to kunal.sachdev
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tedbow Ithaca, NY, USA
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tedbow Ithaca, NY, USA

    Looks great!

  • Status changed to Fixed over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States tedbow Ithaca, NY, USA

    ๐ŸŽ‰ Thanks @kunal.sachdev, @Wim Leers, and @phenaproxima

    And @cweagans for making a plugin that is so useful to so many people in Drupal that we can't just ignore it๐Ÿ˜œ

    โ˜๏ธ gif reserved for critical, core-mvp issues

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    YAY!

    Unpostponed ๐Ÿ“Œ Add build test to test cweagans/composer-patches end-to-end Closed: won't fix .

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    A regression was introduced shortly before commit, spotted by @kunal.sachdev: ๐Ÿ› Fix language nit in package_manager_help() Fixed .

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States mark_fullmer Tucson

    I saw this recent comment from the maintainer of composer-patches: https://github.com/cweagans/composer-patches/issues/411#issuecomment-142...

    main doesn't resolve patches from dependencies anymore.

    I take that to mean that a future release of cweagans/composer-patches simply won't allow patches from this module to apply to a site: the patches *must* be defined in the site's composer.json file.

    Testing on dev-main of Composer Patches (#f88fd4) seems to confirm this. Can someone corroborate this? Does this mean this approach for automatic_updates simply won't work?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States cweagans Boise, ID, USA

    I can corroborate that :) probably donโ€™t take action on that right away though. Currently traveling, but Iโ€™ve gotten a lot of feedback on that and Iโ€™m thinking it through a bit more.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    @mark_fullmer Thanks for bringing that to our attention! But โ€ฆ

    1. We need to ensure the existing version of composer-patches also works reliably!
    2. In ๐Ÿ“Œ Tighten ComposerPluginsValidator: support only specified version constraint Fixed , we're tightening support for composer plugins further: only the known to be supported version range will be allowed. That means we'll be forced to revisit the validation strategy when a new major version of composer-patches is released โ€ฆ and this very upstream change proves that that is a valuable and essential requirement ๐Ÿ˜Š๐Ÿ‘
Production build 0.69.0 2024