Problem/Motivation
This was surfaced by @omkar.podey in #3315834: GitExcluder should not ignore .git directories that belong to packages installed by Composer, where the test infrastructure does not seem to behave as expected. And since VFS lives in memory, it's very painful to debug step-by-step. A helper method would go a long way.
\Drupal\KernelTests\KernelTestBase::vfsDump() is really helpful but does not allow assertions.
The only example in all of Drupal core is in \Drupal\KernelTests\KernelTestBaseTest::testBootEnvironment(). But it does not provide test infrastructure.
Steps to reproduce
Proposed resolution
Add test infrastructure: \Drupal\Tests\package_manager\Kernel\PackageManagerKernelTestBase::assertVfsDump(), which allows you to do:
$this->assertVfsDump('');
to get a baseline. This will then allow you to copy/paste that into something like this (where this is the more complicated part because the site directory name is dynamic):
$site_dir_name = basename($this->siteDirectory);
$this->assertVfsDump(<<<"VFS"
- root
- sites
- simpletest
- $site_dir_name
- files
- config
- sync
VFS);
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #33 | fireworks.gif | 1.73 MB | tedbow |
Issue fork automatic_updates-3328234
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3328234-real-file_system
changes, plain diff MR !649
- 3328234-test-vfs
changes, plain diff MR !629
Comments
Comment #3
wim leersComment #4
wim leersWell that's wild and deeply concerning … it passes locally:
… apparently the sort order is not guaranteed?! 🤯
Well … fortunately we can fix that. Pushed commit that should be green 🤞
Comment #6
tedbowre
Another option would be have an option to not use vfs temporarily while developing to make debugging easier. I think
\Drupal\Tests\package_manager\Kernel\PackageManagerKernelTestBase::createVirtualProjectis the only place where we set that we are using vfs instead of the real file system.\Drupal\BuildTests\Framework\BuildTestBase::$destroyBuildis an example of where core adds a flag that is mainly just used debugging because otherwise the build test projects are destroyed after the test run and it makes things very hard to inspect.I pushed up an branch that tries out this idea.
One advantage of this is you could override
\Drupal\Tests\package_manager\Kernel\PackageManagerKernelTestBase::$useVfsduring debugging and actually inspect your file system at any breakpoint to see what is going onComment #8
tedbowAssigned to @Wim Leers for review of the idea in #6 and in branch 3328234-real-file_system
Comment #9
wim leersI addressed your feedback on my MR.
I am not a fan at all of disabling the use of VFS while debugging because then it's no longer the same test. It's possible a problem is VFS-specific.
If we can run tests without VFS, why don't we just do that always? That would also eliminate an aspect that @phenaproxima raised at https://drupal.slack.com/archives/C7QJNEY3E/p1673357826065869?thread_ts=... to be a reason for #3332256: package_manager_bypass should *minimally* bypass php-tuf/composer-stager, not maximally:
Comment #10
tedbowtagging as core-mvp and added to #3319030: Drupal Core Roadmap for Package Manager and Update Manager
Comment #11
wim leersAll green, ready for final review by @tedbow.
Comment #12
tedbow@Wim Leers I agree that with you points that toggling between vfs and real file system could be a pain. So I do think we should just always use the real file system MR 649 only has 10 test failures that I am sure we could fix
I checked the time and
MR 629 runs the kernel tests in "1 min 11 sec"
and MR 649 also only takes "1 min 11 sec". Even with the fact that 649 would have failed out early on 10 tests the 2 approaches so to be near identical for performance.
Comment #13
wim leersI didn't realize this was so close to working on non-VFS! Just 10 failures, nice!
Let's make the switch to non-VFS then, and also get rid of your MR's
useVFSoption. Per @phenaproxima that will also pave the path for getting rid ofpackage_manager_bypass🤓Yay for peeling away layers of simulation!
Comment #14
wim leersFYI: the only mention of
vfsin all of Project Browser is over at\Drupal\Tests\project_browser\Unit\ProjectBrowserFixtureHelperTest, but that's a unit test unrelated to any of this! 👍That means this won't disrupt PB either 🤩
Comment #16
tedbowNot working on this currently. Needs clean up and getting the testing passing on the open merge request
Comment #17
kunal.sachdev commentedComment #18
wim leersIn Slack, @kunal.sachdev wrote:
That's an interesting difference.
Wow!
So this really did uncover a very significant bug that was being masked by our use of VFS in tests!
\org\bovigo\vfs\vfsStreamWrapper::unlink()indeed returnsFALSE, but not when callingunlink()on the real filesystem.Bumping to critical thanks to this finding!
Currently checking if this is a known problem in
\Drupal\Core\File\FileSystem::unlink()by analyzing https://www.drupal.org/project/issues/drupal?component=file+systemComment #19
wim leerstest.phpfile:👆This is exactly the problem we're seeing today!
E_ALL("all errors") except forE_WARNING, resulting in "all errors except warnings"? Well:Conclusion: we should do
error_reporting(E_ALL & ~E_WARNING);in the::setUp()of this test — because we're simulating what the behavior will be like on production, whereE_ALLought to be disabled (or enabled but then always logged and continue execution as normal).Comment #20
wim leers#19 shows that this should not be critical because it does not impact production sites. Still, it means our testing will be much closer to reality :)
Comment #21
wim leers7 remarks on the MR. Nice progress here :)
Comment #22
wim leersAFAICT
is happening because previously
$stage->destroy()deleted a VFS directory, but now it is deleting one on the real filesystem. On DrupalCI, that directory is owned by a different user, unlike on your local development environment. I think.Just pushed debug output based on https://www.php.net/manual/en/function.chown.php#example-2195.
Comment #23
wim leersFound yet another reason to do this:
👆 This causes
\Drupal\package_manager\Validator\ComposerPatchesValidatorto wrongly conclude someconfig.jsonfile contains the information, even though it'scomposer.json! 🤯Comment #24
wim leersThis blocks #3332256: package_manager_bypass should *minimally* bypass php-tuf/composer-stager, not maximally.
Comment #25
wim leers#23 can and should already be addressed here too, and should result in changes to
\Drupal\Tests\package_manager\Kernel\ComposerPatchesValidatorTest.Comment #26
kunal.sachdev commentedThe test failure in StageTest.php is because we set a staging root '/junk/drawer' in
\Drupal\Tests\package_manager\Kernel\StageTest::testGetStageDirectorywhich doesn't exists and now we use realpath() in \Drupal\package_manager_bypass\PathLocator::setPaths() which returns false because staging_root doesn't exists.Comment #27
wim leersThis likely makes #3156467: [upstream] Updates fail if OS temp directory is a symlink obsolete.
Comment #28
wim leersI know this isn't marked as yet, but because this is the single most important issue right now, I went ahead and alredy did a review. 20 remarks on the MR, most trivial to address (and largely about simplifying the changes), and a bunch of questions.
Comment #29
kunal.sachdev commentedComment #30
wim leers@kunal.sachdev and I just paired to investigate whether we'd be able to remove the
PathLocator::setPaths()call like I said I'd hoped to be able to do in yesterday's review of the MR 🤓Turns out we can't, because in kernel tests,
PathLocator::getVendorDirectory()will always point to the test runner's site, not the system under test's site — because otherwise you'd end up with A) a lot of file copying, B) the impossibility for the same code to be executed for both the test runner and the SUT, because they'd need different class loaders.Conclusion: my idea was idle hope to get rid of
package_manager_bypass'PathLocatoroverride 😅 Well at least we tried!Now doing a deep final review!
Comment #31
wim leers👍 0 remaining strings mentioning- 👎 A lot of the things I asked for wrt simplifying/reducing changes have not been implemented.
- 🥳 Tests are passing!
virtual, 4 remaining forvfsbut they're all necessary.Given point 2 impedes A) blocks many other issues, B) slows down final review + commit by @tedbow, C) reduces likelihood of conflicts, I took that on myself.
I took this from
to
Please land this before your EOD @tedbow 🙏
Comment #33
tedbow🎉Yay! thanks @kunal.sachdev and @Wim Leers!

Comment #34
wim leersThank you for the finishing touches!
Comment #35
wim leersThis unblocked:
And it seems to confirm #3156467-6: [upstream] Updates fail if OS temp directory is a symlink.
Comment #37
tedbowThis issue could still use an issue summary update. Even though this issue is closed it may be still useful for the summary to at least be an accurate summary of what the fix actually was.
I was going to link this issue from #3346707: Add Alpha level Experimental Package Manager module but the realized the summary was not what we actually did so it would just be confusing