Problem/Motivation

Child of #2984031: Create Build Tests For Composer and Drupal

Currently test_composer_project_templates.sh is a special-case script that we use to perform a good-faith build of Drupal's Composer templates.

We should convert that to the new Build test framework.

Proposed resolution

Convert it.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#97 3086644_97_89x.patch10.32 KBmile23
#84 interdiff.txt1.17 KBmile23
#84 3086644_84_90x.patch11.92 KBmile23
#84 3086644_84_89x.patch10.32 KBmile23
#77 interdiff.txt1.01 KBmile23
#77 3086644_90x_77.patch11.82 KBmile23
#77 3086644_8xx_77.patch10.21 KBmile23
#75 3086644-9.0.x-75.patch12.79 KBalexpott
#75 3086644-2-75.8.x.x.patch10.44 KBalexpott
#75 67-75-interdiff.txt2.89 KBalexpott
#68 3086644_89x_55.patch11.88 KBMixologic
#67 3086644-67.patch12.59 KBalexpott
#67 3086644_88x_55.patch10.25 KBalexpott
#67 55-67-interdiff.txt1.24 KBalexpott
#63 3086644_63_do_not_commit.patch13.7 KBmile23
#62 3086644_62_do_not_commit.patch4.2 KBmile23
#61 drush-path-repo-interdiff.txt2.34 KBgreg.1.anderson
#55 3086644_90x.patch11.86 KBmile23
#55 3086644_88x_55.patch10.25 KBmile23
#55 3086644_89x_55_FAIL.patch19 KBmile23
#55 interdiff.txt1.67 KBmile23
#55 3086644_89x_55.patch11.88 KBmile23
#51 3086644_88x_51.patch9.88 KBmile23
#49 3086644_90x_49.patch11.49 KBmile23
#49 3086644_89x_49.patch11.51 KBmile23
#49 3086644_88x_49.patch34.22 KBmile23
#49 interdiff.txt6.79 KBmile23
#43 3086644_89x_43.patch9.74 KBmile23
#43 3086644_90x_43.patch9.72 KBmile23
#43 3086644_88x_43.patch8.12 KBmile23
#37 3086644_88x_37.patch8.12 KBmile23
#37 3086644_90x_37.patch9.54 KBmile23
#37 interdiff.txt2.73 KBmile23
#37 3086644_89x_37.patch9.55 KBmile23
#33 interdiff.txt6.85 KBmile23
#33 3086644_90x_33.patch9.2 KBmile23
#33 3086644_33.patch9.21 KBmile23
#26 interdiff.txt9.56 KBmile23
#26 3086644_26.patch6.39 KBmile23
#19 interdiff.txt3.26 KBmile23
#19 3086644_19.patch8.66 KBmile23
#13 interdiff.txt5.21 KBmile23
#13 3086644_13.patch7.42 KBmile23
#7 interdiff.txt479 bytesmile23
#7 3086644_7.patch3.96 KBmile23
#6 interdiff.txt2.46 KBmile23
#6 3086644_6.patch3.49 KBmile23
#5 interdiff.txt3.46 KBmile23
#5 3086644_5.patch5.12 KBmile23
#2 3086644_2.patch4.02 KBmile23

Comments

Mile23 created an issue. See original summary.

mile23’s picture

Status: Active » Needs review
StatusFileSize
new4.02 KB

Initial patch.

I get a lot of errors trying to chmod and cleanup the workspace directory. Let's see if the testbot fares better.

Status: Needs review » Needs work

The last submitted patch, 2: 3086644_2.patch, failed testing. View results

greg.1.anderson’s picture

I don't know if this happened in the same time window where there was a similar test failure in HEAD of 8.8.x. I'd imagine you'd have other failures in the scaffold tests if that were the case, but I thought I'd call it out anyway.

https://www.drupal.org/project/drupal/issues/3085697#comment-13291515

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new5.12 KB
new3.46 KB

I'm pretty sure my local fails were/are related to the problem in #3082866: composer complains "Skipped installation of bin bin/composer for package composer/composer: file not found in package". So we really should work on getting that issue fixed.

Somehow the testbot filesystem seems much more forgiving of that dangling alias, however.

Anyway, this patch converts the test to use a dataProvider, so we can better identify which test is failing. Also I've modified drupalci.yml to get some quicker test results for the build test. We'll need to revert that change before committing.

mile23’s picture

StatusFileSize
new3.49 KB
new2.46 KB

Ready for prime time. Reverted drupalci.yml, removed errant error_log().

mile23’s picture

StatusFileSize
new3.96 KB
new479 bytes

I reverted drupalci.yml but neglected to remove the part that runs the script that is, you know... the point of this issue.

greg.1.anderson’s picture

This is looking pretty good to me. We aren't blocked on #3082866: composer complains "Skipped installation of bin bin/composer for package composer/composer: file not found in package" or anything, are we?

The work in #3082230: [meta] Convert some tests to Build tests looks like it will be helpful for continuations after this issue.

mile23’s picture

Re #8: The testbot seems to not care that there is a dangling composer alias, so I don't think #3082866: composer complains "Skipped installation of bin bin/composer for package composer/composer: file not found in package" is a blocker. Just something that would be better to have sooner, rather than later.

greg.1.anderson’s picture

Status: Needs review » Needs work
+++ /dev/null
@@ -1,48 +0,0 @@
-composer --working-dir="${SOURCE_DIR}/composer/Template/RecommendedProject" config repositories.scaffold path '../../Plugin/Scaffold'

It is important to add a path repository for the scaffold plugin before installing the recommended and legacy template projects. If you do not, then the test will run against the scaffold plugin registered with Packagist instead of the one bundled with the current patch. This causes failures if the behavior of the scaffold plugin and its tests are changed at the same time (and masks failures if the behavior changes without updated tests).

The existing code does not create a path repository for the vendor hardening plugin, but it should for the same reason. It would not hurt to add a path repository for the vendor hardening plugin invariantly, as it will be ignored if the vendor hardening plugin is not required (e.g. in the recommended project)

Another issue is that this took 33 minutes to run locally (just this one test, not even all of the Scaffold group) -- I'm not sure why it was that slow, as it only took 5m on Jenkins. We might still consider removing @group Scaffold from this test, so that it is only included in the build test group. It's probably better to not run this test when running just --group Scaffold tests locally.

greg.1.anderson’s picture

In #10, I know that the line I quoted should be removed, as that whole script is being replaced. We need an equivalent line in the build test version (or manipulate the composer.json in php if preferred, but I think that the composer config technique is better).

mile23’s picture

#10 oh yikes, I totally missed that. Interesting that it passes anyway.

mile23’s picture

StatusFileSize
new7.42 KB
new5.21 KB

This patch adds a composer create-project test as well, and adds @group #slow. This way you can call phpunit --exclude-group #slow if you want to skip the big builds.

I think the create-project test is the actual test here. Opinions?

It still fails locally based on #3082866: composer complains "Skipped installation of bin bin/composer for package composer/composer: file not found in package" but I wager the testbot won't fail.

It takes ~6 minutes to run locally.

mile23’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 13: 3086644_13.patch, failed testing. View results

Mixologic’s picture

okay, so the issue we discovered in #slack was that these tests rely on drupal/core-recommended (and to some degree the other metapackages)

If we make changes to core's composer.lock file, these tests will pass, _until that change to the lockfile is committed_ and then they will not pass until such time as the drupal/core-recommended gets updated.

Which also means its not actually being tested until after the fact.

So, the only way we'll be able to test something that rely's on the metapackages is to have the packages in core, probably generated by a composer script that fires off every time the lockfile is generated.

mile23’s picture

A few things here.

We did a sort of emergency script-ectomy of the shell script here, because it was being disruptive: #3087219: Remove broken test for composer templates

That will necessitate a re-roll here.

We also discussed the fails in #13.

+++ b/core/tests/Drupal/BuildTests/Composer/Plugin/Scaffold/ComposerProjectTemplatesTest.php
@@ -0,0 +1,86 @@
+    $this->executeCommand('composer --working-dir="' . $working_path . '" config repositories.scaffold path ' . $scaffold_dir);
...
+    $this->executeCommand('composer --working-dir="' . $working_path . '" config repositories.hardening path ' . $hardening_dir);

The testbot does the right thing and symlinks these packages during the install test.

Locally, I found that it checking out the packages which is why we have this assertion:

+++ b/core/tests/Drupal/BuildTests/Composer/Plugin/Scaffold/ComposerProjectTemplatesTest.php
@@ -0,0 +1,86 @@
+    $this->assertRegExp('/Installing drupal\/core-composer-scaffold .*: Cloning .* from cache/m', $process->getErrorOutput(), 'Composer Scaffold plugin was not cloned from path repo.');

That assertion is incorrect, and should instead reflect the symlinking in this line:

 Extracting archive  - Installing drupal/core-composer-scaffold (8.8.x-dev): Symlinking from /tmp/build_workspace_5831d5c9cfa8ccda0ddf7a7adea7e248Ke5Wtg/composer/Plugin/Scaffold\n

The changes in #3087219: Remove broken test for composer templates came about because while these tests use a path repo for in-core dependencies, we can’t use a path repo for the drupal/core-recommended metapackage. If there is a change to the core repo’s composer.lock file that hasn’t yet been used to generate a new drupal/core-recommended package, we have to assume that the test will fail. (Because it did in this case.)

This led to a failing HEAD, which was a big problem because today is the day before alpha for Drupal 8.8.x :-)

So to mitigate this, we discussed replacing a dependency on drupal/core-recommended with drupal/core. This will mitigate the lag in generating drupal/core-recommended, but at the same time makes a test that doesn’t reflect a complete build of the template package.

Until this conundrum is solved, we’ll pursue ‘good enough’ with this change.

And of course we still have a fail related to #3082866: composer complains "Skipped installation of bin bin/composer for package composer/composer: file not found in package"

greg.1.anderson’s picture

we can’t use a path repo for the drupal/core-recommended metapackage.

Actually, although I did not think of this before, we potentially could generate a drupal/core-recommended metapackage on-the-fly, just for testing, and make a path repository that points to the temporary directory containing the result.

This is not a great idea, though, because there is no guarantee that the on-the-fly drupal/core-recommended will come out the same as the package generate version of the same package. It would therefore still be better to convert drupal/core-recommended to become a subtree split (modified at composer create time), as we could then generate a path repository to point at the exact thing that the subtree splitter will use to make the external project.

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new8.66 KB
new3.26 KB

This is me experimenting trying to get local to do the right thing with symlinks. I never succeeded, but I'm curious what the testbot will do.

Modified drupalci.yml to only run build tests.

Status: Needs review » Needs work

The last submitted patch, 19: 3086644_19.patch, failed testing. View results

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

mile23’s picture

Version: 8.9.x-dev » 8.8.x-dev
Status: Needs work » Postponed

It seems our luck has changed and we're postponed here on #3082866: composer complains "Skipped installation of bin bin/composer for package composer/composer: file not found in package"

Also we def want this in 8.8.x because it's our only test of the composer templates, and they were disabled after breaking HEAD: #3087219: Remove broken test for composer templates

greg.1.anderson’s picture

We are also postponed on #3087626: Convert drupal/core-recommended & c. into a subtree split, because otherwise we will prevent updates to composer.lock from working (the composer.lock update will work, but tests will fail).

mile23’s picture

I experimented with writing this patch with #3087626-4: Convert drupal/core-recommended & c. into a subtree split added, so I can confirm that we're still blocked on that.

But the other thing I discovered is that the install test is pretty fragile once we try to include all the special cases needed to make it work here. To the point that it's not really a test any more. For instance: drupal/recommended-project requires drupal/core-recommended ^8.8, which we have to change to self.version in order to perform an install using the local codebase.

After talking to @greg.1.anderson about it in Slack, we decided the create-project is the real test here, and that we can remove testTemplateInstalls().

mile23’s picture

Status: Postponed » Needs work
mile23’s picture

Version: 8.8.x-dev » 8.9.x-dev
Status: Needs work » Needs review
StatusFileSize
new6.39 KB
new9.56 KB

It turns out that if you specify a packages.json file on the command line with composer create-project, that packages.json file only applies towards the discovery of the project template you want to create, and not its dependencies.

So here we add path repos to the project templates, because we have to. Otherwise Composer will seek the dependencies from packagist and/or Drupal facade.

Moved the test to the Templates namespace since it's not a test of the scaffold plugin.

Also targeting to 8.9.x, but we'll need to backport this to 8.8.x.

jibran’s picture

Wow package.json approach is quite clever. Testbot came back green so RTBC.

jibran’s picture

Status: Needs review » Reviewed & tested by the community
greg.1.anderson’s picture

Awesome. RTBC x 2.

mile23’s picture

Status: Reviewed & tested by the community » Needs review

One of the saddest things in the world is that it works, you submit the patch, you go back to fix a comment you forgot to delete, and then it doesn't work any more.

  Extracting archive  - Installing drupal/core-composer-scaffold (8.9.x-dev dca4b12): Cloning dca4b123a638d78bf77719632993e920de6cc426 from cache\n

That's supposed to be a symlink.

Anyway, I'm currently trying to make this test prove that it used symlinks when it was supposed to.

Any other suggestions for assertions about the validity of the installed code are welcome.

greg.1.anderson’s picture

$this->assertTrue(is_link(...));?

Mixologic’s picture

Issue tags: +Composer initiative
mile23’s picture

Issue tags: +needs backport to 8.8.x
StatusFileSize
new9.21 KB
new9.2 KB
new6.85 KB

I worked as hard as I could to not make any specific version requirements necessary for this test, but we do have to specify them, and in fact it's a necessary test.

As an example... In 9.0.x, drupal/recommended-project currently says it needs drupal/core-recommended ^8.8. Since it also has minimum stability as dev, and also prefers stable, it will use 8.8.0-alpha1 for drupal/core-recommended.

So therefore this test already shows us that our templates need fixing, which I've done here with updating the minimum versions in the templates.

Here are patches for 8.9.x and 9.0.x.

The differences between 8.9.x and 9.0.x are in the minimum version specification for the templates, the packages.json fixture, and a single variable in the test so we only have to maintain it in one place there.

We'll reroll for 8.8.x later, because this should be in 8.8.x.

jibran’s picture

Let's add the 8.8.x patch at the same time so that committer can commit it in one go.

+++ b/core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php
@@ -0,0 +1,111 @@
+    $core_version = '8.9.x-dev';
...
+    $this->executeCommand("COMPOSER_CORE_VERSION=$core_version composer create-project $project testproject $core_version -s dev -vv --repository $repository_path");

It is becoming increasingly evident that we need a new constant for this in core. Let's make it a class constant at least for now.

HINT: We can call it \Drupal::COMPOSER_CORE_VERSION.

greg.1.anderson’s picture

I think that the core committers have a meeting where they discuss the 8.8.x backports for patches that are committed to 8.9.x, so it's not possible to commit to all three branches at once. Given this, it's probably better to make just two patches, & not make the 8.8.x until the 8.9.x is committed.

greg.1.anderson’s picture

Regarding \Drupal::COMPOSER_CORE_VERSION, we do have \Drupal\Composer\Composer::drupalVersionBranch(), which serves a similar purpose.

mile23’s picture

StatusFileSize
new9.55 KB
new2.73 KB
new9.54 KB
new8.12 KB

Updated to use \Drupal\Composer\Composer::drupalVersionBranch() cuz that's the perfect thing.

Included here are patches for 8.8.x, 8.9.x, and 9.0.x. Committers can use whichever ones they please, and ask for more as needed. :-) This issue is still targeted for 8.9.x, however.

Interdiff reflects a bad rebase that was fixed along with the change.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

Thank you for addressing the feedback @Mile23.

I think that the core committers have a meeting where they discuss the 8.8.x backports for patches that are committed to 8.9.x, so it's not possible to commit to all three branches at once. Given this, it's probably better to make just two patches, & not make the 8.8.x until the 8.9.x is committed.

I'd give committer a choice at the time of commit rather than wait for them to come back to the rerolled patch. But I'd not set a patch to NW if there is no 8.8 patch :)

greg.1.anderson’s picture

Looked over #37. +1 on RTBC.

Mixologic’s picture

greg.1.anderson’s picture

Status: Reviewed & tested by the community » Needs review

This needs an update because we have a new path repository that needs to be added to the list of path repos in the tests.

greg.1.anderson’s picture

Status: Needs review » Needs work

I was aiming at "Needs work", but missed.

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new8.12 KB
new9.72 KB
new9.74 KB

The last submitted patch, 43: 3086644_88x_43.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

greg.1.anderson’s picture

Is "prefer-stable" interfering with our path repository in #43, maybe?

greg.1.anderson’s picture

Status: Needs review » Needs work

The failure in the 8.8.x branch would also happen on the other branches, I think, if there were any tagged versions (just as 8.8.x has one version tag, 8.8.0-alpha1), so we shouldn't commit this to any branch until we have that problem resolved.

Mixologic’s picture

Yeah, its the issue where 'need a way to get the exact version of core from the template' problem, yet also have an upgrade path. Hence why the 8.8.x test is getting 8.8.0-alpha1 everywhere.

greg.1.anderson’s picture

Status: Needs work » Postponed

That makes sense. So we're blocked here until we can put the composer.lock into the template projects, then.

mile23’s picture

Status: Postponed » Needs review
StatusFileSize
new6.79 KB
new34.22 KB
new11.51 KB
new11.49 KB

So we're blocked here until we can put the composer.lock into the template projects, then.

Uhm, nope. :-)

Which leads us to a seemingly-eternal question...

Installs: drupal/core-composer-scaffold:8.8.x-dev, […] drupal/core-vendor-hardening:8.8.0-alpha1, […] drupal/core-project-message:8.8.0-alpha1, drupal/core-recommended:8.8.0-alpha1

Why does drupal/core-composer-scaffold resolve to 8.8.x-dev but the others do not?

drupal/core-composer-scaffold has a branch-alias setting, but adding a similar branch alias to the other packages does not solve the problem.

The answer seems to be: The patch in #43 does not account for the project message plugin as a path repo. Therefore Composer searches the world for a version and discovers 8.8.0-alpha1, and then that apparently opens the floodgates and all bets are off when it comes to the rest of our carefully-curated path repos. Whether this counts as an upstream bug or not probably depends on your point of view.

So that leaves us with a choice for this test:
1. Hard code all our expectations for where plugins and metapackages should be, so that they can be converted to path repos.
2. Dynamically generate all the path repos by scanning the file system for the various packages.

This patch does the latter, and the reason is this: As we add metapackages or plugins and/or modify the templates, we should gracefully make sure that the patched additions are available to this build test. Using hard-coded paths means that we could get false positives because no one would remember to update this test.

This patch also adds a test which reconciles the template dataprovider against a scan of the composer/Template directory to fail and tell us that we need to update this test for templates when we add them.

greg.1.anderson’s picture

Thanks for dynamically discovering the path repositories we need. I think that's a good idea.

mile23’s picture

StatusFileSize
new9.88 KB

This patch fixes the bad rebase for the 8.8.x patch from #49.

mile23’s picture

Hiding files.

Mixologic’s picture

So I've been stepping through this with the debugger, and got to the part where the test executes something like this:

1.

COMPOSER_CORE_VERSION=8.8.x-dev composer create-project drupal/recommended-project testproject 8.8.x-dev -s dev -vv --repository core/tests/Drupal/BuildTests/Composer/fixtures/packages.json

drupal/recommended-project has

    "minimum-stability": "dev",
    "prefer-stable": true,

Which, to me means that as soon as we have an 8.8.0 stable release, the 8.9.x-dev branch is going to start failing because it will find a stable version.

2

We're not making a path repository for /core, and its pulling drupal/core from github, which, due to a bug in the subtree splitter, happens to be 2 days behind because it breaks when a tag is pushed atm. (which is how I noticed that the latest commit in the repo is only getting things from nov 5, instead of whats being tested locally)

3

This test assumes that every plugin we put into /composer/Plugin is something we'll want to include pathrepo wise for the tests -> I think thats going to be okay, even if the requirements between the tests are different - i..e no real harm in Recommended-Project getting a path repo for the vendorHardening plugin.

4

I made a change to core-recommended, added a new dependency and looked at the output and confirmed that the new dependency that I had added was in the output.

5

So I guess my only remaining question is what are some circumstances that would lead this test to fail? What kinds of changes would go into a patch that would break the templates, and can we emulate that somehow and prove that it catches that? maybe add a conflicting dependency to the metapackages or something... not sure.

Man. Build tests are sweet.

mile23’s picture

Status: Needs review » Needs work
Issue tags: +Needs followup

#1: "Which, to me means that as soon as we have an 8.8.0 stable release, the 8.9.x-dev branch is going to start failing because it will find a stable version." I don't think that's the case since there's a path repo, but I'm totally willing to be wrong. If the build tests were in 8.7.x we could test that now.

#2: We should add drupal/core as one of the path repos.

#3: We add all the possible path repos because the test doesn't know which ones are required by the current template. This way it works for whichever template you supply in the @dataprovider.

#5: I think you're right that this test is the round-trip for the metapackages: You do a dev on core, you update composer.lock, it generates new metapackages, that's all in the patch, and here we apply those metapackages back in a build process. Theoretically this should never fail because you were able to generate a composer.lock file in the first place, but if it does, we want to know.

The other thing is that we've already used the tests to find a 'bug' in the template files in #33. I put bug in quotes because if you're making a new project, you'd probably get what you wanted, but per-branch it breaks our expectation.

The cherry on top would be to perform an install and visit the front page, but this thing already takes two and a half minutes. Also, i'm not sure the quickstart feature knows what to do with the recommended install layout. That'd make a good follow-up.

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new11.88 KB
new1.67 KB
new19 KB
new10.25 KB
new11.86 KB

This patch adds drupal/core as a path repo, with added assertions to match.

There’s also a FAIL patch which illustrates some ways to fail this test by making a bad project template. One has minimum_stability at stable, and the other specifies a scaffold file that doesn’t exist.

The last submitted patch, 55: 3086644_89x_55_FAIL.patch, failed testing. View results

greg.1.anderson’s picture

Are we still sure, though, that this test won't pull stable tags from Packagist, once they exist?

To avoid that for certain, we could set composer config -g repo.packagist false; then we would know that our tests would never pull from packagist. At the moment, the only package we deliberately use from packagist is composer/installers. I think we could define composer/installers in our packages.json file, and point it at packagist. While I think that works, I have not tried, so I am not sure that I am right. I'd feel better about these tests if we turned off packagist, though.

greg.1.anderson’s picture

Experimenting with #57.

greg.1.anderson’s picture

OK, #57 is not going to make things more stable for us. There are a lot of packages we'd have to put in our packages.json file, and as the drupal/core composer.json evolved, our fixture would become out of date. This solution would therefore probably cause more problems than it solved.

mile23’s picture

Yes, if we turn off packagist (and/or drupal composer facade) then we can only get cached discoveries. Also, we'd have to turn it back on in tearDown() because otherwise the next test will break.

greg.1.anderson’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new2.34 KB

OK, I believe that #55 is going to continue to work even when there are stable tags of drupal/core-recommended et. al.

What I did:

  • Created a path repository drush/drush
  • Included it as ^8 from drupal/recommended-project
  • n.b. drush/drush also has stable tags in the ^8 range in packagist
  • Confirmed that Drush was included via the path repository (was symlinked), not installed from Packagist

The same should be true of our other path repositories. Interdiff of my test changes included.

mile23’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new4.2 KB

I was trying to figure out how to make a fake D8.8 release and stuff, but the drush/drush experiment in #61 is the right idea. However it doesn't actually pass, since the test doesn't make path repos for the Template directory.

Here's a patch that demonstrates this technique that should pass DrupalCI by moving the fake drush/drush into composer/Plugin/.

mile23’s picture

StatusFileSize
new13.7 KB

#62 is the interdiff. :-)

Edit: The fail just tells us that the fake drush/drush composer.json file doesn't validate, so yay, we demonstrated that path repos work.

Status: Needs review » Needs work

The last submitted patch, 63: 3086644_63_do_not_commit.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mile23’s picture

Status: Needs work » Needs review

Will re-upload #55 after #3090906: self.version in metapackages considered harmful, which is a bugfix and might make a reroll happen here.

Mixologic’s picture

See https://www.drupal.org/project/drupal/issues/3095967#comment-13362548

Theres a couple of comments about d9 that we could add to the patch in #55

alexpott’s picture

StatusFileSize
new1.24 KB
new10.25 KB
new12.59 KB

Here's a patch with the comments fixed for D9. Imo we shouldn't block this on the other patch. If that one needs rerolls so be it.

Uplaoding the 8.8.x patch again to so the most recent patches are the correct patches.

Mixologic’s picture

StatusFileSize
new11.88 KB

Here's the 8.9.x patch from #55 as well

mile23’s picture

Yes, each branch needs its own patch, because they have to target their own core version per #33.

Leaving the backport tag until we get a commit to 8.8.x. I'm not entirely sure which branch has the code freeze at this point...

And here's the follow-up: #3096044: Ensure quickstart feature works with drupal/core-recommended

alexpott’s picture

@Mile23 are you sure that we need to adjust the version for each minor release? @greg.1.anderson said that we wouldn't need to do this. If we do then we're going to need to automate this so release managers don't have to think about this. I think once we remove "minimum-stability": "dev", we shouldn't need to update the minor release and everything will work the way we want it to. #33 does not contain any justification for why we need the 8.9 specific version as far as I can see.

Mixologic’s picture

Yeah, on second thought, ^8.8 is fine for the 8.9 branch because you would get the most latest version of the dependencies.

I concur with #70

Mixologic’s picture

Also, the other situation is that we're adding lockfiles to the templates such that they should start with their exact version of all of their deps.

greg.1.anderson’s picture

I commented on this issue this morning, but don't know what happened to it. Didn't get saved, apparently.

Yes, if you put ^8.9 in a template project, it's just documentation. We might as well stick with ^8.8 for the d8 branches and ^9 for the d9 branches. We could even consider using ^8.7 for the d8 branches, because we have metapackage tags for all of the old Drupal 8 releases.

As far as minimum-stability is concerned, you still need "dev" for dev releases, because drupal/core-recommended requires drupal/core, and that won't work without minimum-stability "dev" if core-recommended is being required at a dev version. We can fix the minimum stability up as part of the split tree process for stable tags. We should keep it "dev" in the drupal/drupal repository.

mile23’s picture

Yes, if you put ^8.9 in a template project, it's just documentation.

Well, except it's not, actually. Because, as I pointed out in #33, for the 9.0.x branch Composer can resolve drupal/core-recommended to 8.8.0-alpha1 because it's more stable than 9.0.x-dev, which undoes the purpose of the test. See #10.

@alexpott mentions that if we get rid of minimum-stability: dev then that's not the case. But we haven't done that, and I don't see an issue to do that. Also, I don't think that we should, because then we can't require any dependencies at @dev stability. If you look at 9.0.x you see that we're using a beta version of symfony because we have to (for now).

And even if we get rid of minimum-stability: dev, then we'd still be allowing drupal/core-recommended:8.8.0 within the 9.0.x branch, which doesn't make much sense at all, especially in light of this issue: #3090905: composer create project drupal/core-recommended:version should get the exact version specified For instance, if you are running PHP 7.0, and you say composer create-project drupal/recommended-project myproject ~9 then you'll end up with the 9.0.x version of the template, and either 8.8.x or 8.9.x version of core, with no indication of this mismatch. What should happen is that Composer should say, no, you can't install Drupal 9 on PHP 7.0.

I can understand the desire to not have to update the templates with appropriate minor versions with each release in this test, but we have to do that for the packages.json file even if we don't do it for the templates. Otherwise we're not testing whether we can build with the patched codebase. Also, the test won't have false positives if we overlook that update. It will fail because we do this:

+++ b/core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php
@@ -0,0 +1,169 @@
+    // Get the Drupal core version branch. For instance, this should be
+    // 8.9.x-dev for the 8.9.x branch. If the test fails because this branch
+    // version is incorrect, you should update the version specified in
+    // core/tests/Drupal/BuildTests/Composer/fixtures/packages.json to reflect
+    // the target branch of Drupal core.
+    $core_version = Composer::drupalVersionBranch();

The proof is https://www.drupal.org/pift-ci-job/1482558, which is the failed test against 3086644_88x_55.patch in #67, that ran against 8.9.x instead of 8.8.x.

If anyone wants to amend the patch to improve it, that'd be great.

But if we're changing specifications such that we're *not* testing whether we can build against the patched codebase, then someone will have to update the issue summary to reflect this fact.

alexpott’s picture

StatusFileSize
new2.89 KB
new10.44 KB
new12.79 KB

@Mile23 re

the 9.0.x branch Composer can resolve drupal/core-recommended to 8.8.0-alpha1 because it's more stable than 9.0.x-dev, which undoes the purpose of the test.

I think the constraint in the major branch needs to match but I hope we don't need to do minor updates. There's no way that 8.8.0-alpha1 can match ^9

Here's a patch for 8.8.x the passes on 8.9.x as well. Plus updated the 9.0.x patch to work the same way.

mile23’s picture

I think the constraint in the major branch needs to match but I hope we don't need to do minor updates. There's no way that 8.8.0-alpha1 can match ^9

Well, it's the same problem moving forward: 9.0.0-alpha1 can match ^9 when you mean ^9.1 with minimum-stability:dev. This is much less likely than the 8-for-9 mixup, but only by accident.

But it's still a thing. We want this test to fail if that happens, so that release managers can be sure they're getting what they want.

+++ b/core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php
@@ -0,0 +1,211 @@
+    // Get the Drupal core version branch. For instance, this should be
+    // 8.9.x-dev for the 8.9.x branch. If the test fails because this branch
+    // version is incorrect, you should update the version specified in
+    // core/tests/Drupal/BuildTests/Composer/fixtures/packages.json to reflect
+    // the target branch of Drupal core.
+    $core_version = Composer::drupalVersionBranch();
...
+  protected function makeTestPackage($repository_path, $version) {

+1 on this change, except it means the doc block is incorrect now.

mile23’s picture

StatusFileSize
new10.21 KB
new11.82 KB
new1.01 KB

Now that we have an official release for 8.8.0 I was able to run this against a tagged release with good effect.

$ git checkout 8.8.0
$ git apply 3086644-2-75.8.x.x.patch
# Modify \Drupal::VERSION to be '8.8.x-dev'
$ ./vendor/bin/phpunit -c core/ --testsuite build --filter ComposerProjectTemplatesTest --stop-on-fail

This fails (as it should) because drupal/core-recommended still requires drupal/core 8.8.0, so the build log does not reflect 8.8.x-dev. Like this:

 Extracting archive  - Installing drupal/core (8.8.0): Loading from cache
 Extracting archive  - Installing drupal/core-recommended (8.8.x-dev)

# which does not contain...

Installing drupal/core (8.8.x-dev): Symlinking from

Without modifying \Drupal::VERSION we get a pass. So yay!

This patch updates the docblock mentioned in #76.

mile23’s picture

Patch still applies. Re-testing.

greg.1.anderson’s picture

Status: Needs review » Needs work

This looks really good - great improvement over the existing shell script. Just one more suggestion:

+++ b/core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php
@@ -0,0 +1,208 @@
+    $require = array_merge($template_json['require'] ?? [], $template_json['require-dev'] ?? []);

It would be better to pass this list in from the data provider rather than calculate it from the fixture. If this erroneously came out empty, for example, then no 'Installing $package_name' assertions would run, and you could potentially get a false pass. It's easier to see that the test is valid if it is asserting based on hardcoded expectations rather than calculated expectations.

mile23’s picture

The point of this test is to account for a build from patched core, and we can patch the dependencies of any of our plugins.

For instance if the patch adds a new Composer plugin and adds a dependency to it from a template, we'd want that to be symlinked in this build. The only way to find out about it is either to dynamically generate it, or remember to amend the dataprovider here.

If we neglect to update the dataprovider, then we run into the world of false positives, where for instance the patch changes a template to require one of our existing plugins, but erroneously requires a tagged release. Then we don't know that the patched plugin is not being used.

If there wasn't a risk of false-positive, then it could be reasonable to just let the test fail and cause people to grumble as they update the dataprovider in the next patch. But they might never find out.

greg.1.anderson’s picture

To be clear, the only bit of the calculated code I am proposing moving to the data provider is the "require" line. If someone makes a patch that adds a requirement to the Composer Template project, they'll get a false positive until they update the test, but that is as it should be, IMO.

This test will catch any other sorts of failures, e.g. if someone makes a change that isn't in the Composer Template project directly, but is somehow incompatible. That is the important coverage to get, and should not be impacted by having the `require` list in the data provider.

mile23’s picture

To be clear, the only bit of the calculated code I am proposing moving to the data provider is the "require" line.

Yes, that's the part where we gather the expectations from the part of the codebase that could have been patched. That's the part I'm defending. :-)

If someone makes a patch that adds a requirement to the Composer Template project, they'll get a false positive until they update the test, but that is as it should be, IMO.

No, they'll never update the test because it's a false positive. They won't know they need to update it, because it passes.

greg.1.anderson’s picture

Forgive me for inverting the positive / negative here.

With that orientation of positive / negative, I don't think you ever get a false positive, as you're always looking for evidence that the requirements were installed in the command output. Ah, but I see that you are also concerned that there should be a test for the new requirement, which won't be tested if not explicitly added. Perhaps you should both add the list of requirements to the data provider, and also confirm that it matches the requirements in the code.

If you leave the `requires` calculation in code only, you could get a false positive e.g. if the list of requirements erroneously comes back empty.

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new10.32 KB
new11.92 KB
new1.17 KB

OK, so the concern is that there's a false positive if there is some sort of error about the template requirements, not necessarily that the expectations are or aren't hard-coded.

We already have some assertions about the existence of the composer.json file, which helps in that regard.

Adding hard-coded expectations is definitely desirable, but see #70.

So adding hard-coded expectations and then checking up on them means we're not only testing the code but also testing the test. We do that a little bit here with testVerifyTemplateTestProviderIsAccurate() which checks if there are new templates we haven't accounted for here, because it seems likely we'd do that at some point.

I think in the case of $require, however, if we trust a separate process that checks the hard-coded test data, then we should cut out the middle man and have the trusted checking data be the test data. We can put a boundary check on it, such as asserting that $require is not empty because it's vanishingly unlikely that we'd have a template with no requirements.

Here's a patch which does just that.

greg.1.anderson’s picture

Status: Needs review » Reviewed & tested by the community

I would have preferred we add the requirements to the test data, and handle confirming its correctness exactly like testVerifyTemplateTestProviderIsAccurate(). I don't think that #70 is a concern, as the requirements of the template projects do not change often, and they do not change as part of the release process e.g. for going to a new minor release.

However, I'll accept the compromise in #84 on the assumption that it is really unlikely that we could have a defect that calculated an incorrect but non-empty requires list that also passed all of the assertions that follow against the command stdout having the right requirement messages.

Let's get this in so that we can start to benefit from the better tests.

mile23’s picture

Now that Drupal 9 requires PHP 7.3+, I added that test to the 9.0.x patch in #84.

hestenet’s picture

Issue tags: +alpha blocker
Mixologic’s picture

So, this issue fixes the templates and keeps them sane, and has been RTBC for quite some time now. Turns out we cant release 9.x until we have some composer templates that can actually, use 9.x.

So, either this is blocking alpha1, or we need to corral off an smaller sub issue (reopen https://www.drupal.org/project/drupal/issues/3095967)

greg.1.anderson’s picture

Merging here is the better option; #3095967: Update project templates for Drupal 9 would need work to get it caught up to what is already here, and the test improvements in this patch are useful.

Mixologic’s picture

I agree with #89 but can imagine a possibility of somebody wanting to split a 100% hard blocker for alpha1. Granted, having the test would prevent it from even being a blocker so...

mile23’s picture

This should have been committed before 8.8.1, because basically the raison d'etre of the composer initiative is untested. That's despite having all these subtree splits in the repo specifically so that we can test them patched in DrupalCI, and despite having invented a new testing framework to accomplish it.

It should be a hard blocker for 9.0.x-alpha1.

catch’s picture

Title: Convert test_composer_project_templates.sh to a build test » LegacyProject composer templates wrongly reference 8.x + fix test coverage
Category: Task » Bug report

To solve the split or not discussion what about this re-title?

One comment nit, but did not do a very in-depth review yet.

  1. +++ b/core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php
    @@ -0,0 +1,211 @@
    +      $json = $json_file->read();
    +      $this->assertArrayHasKey('name', $json);
    +      // Does provideTemplateCreateProject() give us this template name?
    +      $this->assertArrayHasKey($json['name'], $template_data);
    +    }
    

    Minor nit but it'd be better to say 'Assert that the template name is in the project created from the template' or something else without a question mark.

Mixologic’s picture

+1 on #92 also, just making it clear that its completely 100% impossible to create the alpha1 release tag without the template changes.

  • catch committed 5139354 on 9.0.x
    Issue #3086644 by Mile23, alexpott, Mixologic, greg.1.anderson, jibran:...
catch’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

OK fixed the comment on commit. Committed 5139354 and pushed to 9.0.x. Thanks!

This will need a re-roll for 8.9.x and 8.8.x.

catch’s picture

Status: Patch (to be ported) » Needs work

More of a 'needs work' for the re-roll.

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new10.32 KB

The 8.9.x/8.8.x patch from #84 still applies, but here it is again.

greg.1.anderson’s picture

Status: Needs review » Reviewed & tested by the community

This has been committed to 9.x, and the patches in #97 contain only backported tests that will make 8.9.x and 8.8.x development better. This is therefore safe to commit to both branches.

  • xjm committed 62dcbf8 on 8.9.x
    Issue #3086644 by Mile23, alexpott, Mixologic, greg.1.anderson, jibran,...

  • xjm committed 91be42f on 8.8.x
    Issue #3086644 by Mile23, alexpott, Mixologic, greg.1.anderson, jibran,...
xjm’s picture

Status: Reviewed & tested by the community » Fixed

Committed the backport to 8.9.x and 8.8.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.