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

Dev: Only one WordPress #41057

Draft
wants to merge 13 commits into
base: trunk
Choose a base branch
from
Draft

Conversation

kraftbj
Copy link
Contributor

@kraftbj kraftbj commented Jan 14, 2025

For unit testing, we often use WorDBless, a variant of WordPress that does not require database setup. Except, we include it a lot so there are a lot of copies of WordPress within the repo when fully installed.

Before and after the changes proposed below (conducted in clean directories on my M1 with composer's cache cleared)

Before:
1st run of jetpack install --all: Between 2m 57s and 3m 17s
2nd run: 56s
Size: (du of monorepo with du of .git subtracted): 5.1 GB

After:
1st run: Between 1m 20s and 1m 52s
2nd run: 55s
Size: 2.7 GB

Proposed changes:

  • Remove inclusion of the WorDBless package in packages that did not use it for testing.
  • Add a new test-environment package to serve as the WorDBless loader for monorepo projects.
  • Replaced all inclusion of WorDBless package in individual packages with the new test-environment, updated bootstraps.
  • Added a new tools/php-test-env package that will install WorDBless once in that directory.
  • Updated monorepo root to install/update tools/php-test-env when itself is installed/updated (so jetpack install --all, -r will cover it.

In short, this changes the packages consumed by individual projects to use the internal test-environment. This ensure it is easy to modify all in the future and required little change to each individual package.

The test-environment loads a class that loads the test-php-env autoloader and loads WorDBless.

The test-php-env quasi-package does a singular install of WorDBless.

Other solution investigated was having the test-environment package directly require WorDBless, but that meant it would be re-installed every time test-environment was installed. No gain (at least) to install time, but it would have ended up with only one copy of WP.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

None yet.

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

  • jetpack install -r (at least) and jetpack install a package that uses worDBLess, like packages/admin-ui
  • jetpack test phh packages/admin-ui

Does it still run the test successfully?

@github-actions github-actions bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] mu wpcom jetpack-mu-wpcom plugin [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. Actions GitHub actions used to automate some of the work around releases and repository management labels Jan 14, 2025
Copy link
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

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

Saw this in a list and the title piqued my curiosity 😀

I wonder if the packages/test-environment package is really needed. It seems to do about the same thing as just sticking something like this in each consumer's bootstrap.php would.

require dirname( __DIR__, 5 ) . '/tools/php-test-env/vendor/autoload.php';
\WorDBless\Load::load();

(vary the 5 as needed based on the directory structure). The one added require seems less boilerplate than a whole extra package that in the end does the same thing.

If you still want the additional error handling, make a tools/php-test-env/load.php file to require instead. 🤷

.github/workflows/tests.yml Outdated Show resolved Hide resolved
composer.json Outdated Show resolved Hide resolved
projects/packages/test-environment/.phan/baseline.php Outdated Show resolved Hide resolved
projects/packages/test-environment/package.json Outdated Show resolved Hide resolved
tools/php-test-env/composer.json Outdated Show resolved Hide resolved
tools/php-test-env/composer.json Show resolved Hide resolved
@kraftbj kraftbj force-pushed the try/one-wordpress-to-rule-them-all branch 2 times, most recently from 9609fb1 to 81ed25b Compare January 16, 2025 15:24
@kraftbj kraftbj force-pushed the try/one-wordpress-to-rule-them-all branch from 648c1e0 to f250081 Compare January 22, 2025 20:49
@kraftbj kraftbj force-pushed the try/one-wordpress-to-rule-them-all branch from b38d9dc to 16fdf6f Compare January 23, 2025 14:58
@github-actions github-actions bot added [Plugin] CRM Issues about the Jetpack CRM plugin [Plugin] Debug Helper Debug Tools plugin [Plugin] Super Cache A fast caching plugin for WordPress. [Plugin] VaultPress labels Jan 23, 2025
Comment on lines +120 to +124
# Add WordBless for image-cdn package tests
if [[ "$TEST_SCRIPT" =~ ^test-(php|coverage)$ ]] && jq -e '.name == "automattic/jetpack-image-cdn"' projects/packages/image-cdn/composer.json >/dev/null; then
echo "Adding WordBless for image-cdn tests"
composer require --working-dir=projects/packages/image-cdn automattic/wordbless:^0.4.2 --dev
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this here rather than in projects/packages/image-cdn/composer.json? If someone tries to run image-cdn tests locally, won't it blow up because of missing this?

Ah, I see a comment later mentions concurrent tests, and digging a little more finds that WorDBless has an @after method that clears the uploads dir. I also see a packages/publicize test failed for what looks the same reason in a recent run, and packages/videopress in another.

Probably the thing to do would be to update WorDBless to use wp_upload_dir() to find the upload dir instead of assuming the default, and then have monorepo tests override the default per package so they don't stomp on each other.

@@ -27,6 +27,7 @@
// Ignore stuff in various subdirs too.
'.*/node_modules/',
'tools/docker/',
'tools/php-test-env/wordpress/',
Copy link
Contributor

Choose a reason for hiding this comment

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

Besides this, you'll also need to exclude the tools/php-test-env/vendor from being analyzed by adding something like this into the $options array here.

		'exclude_analysis_directory_list' => array(
			'tools/php-test-env/vendor',
		),

(can't make it a suggestion because it has to go outside of where GH will allow comments, e.g. just after line 36 below).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Actions GitHub actions used to automate some of the work around releases and repository management Docker Docs [Feature] Contact Form [Feature] Google Analytics [Feature] Masterbar WordPress.com Toolbar and Dashboard customizations [Feature] Photon aka "Image CDN". Feature developed in the Image CDN package and shipped in multiple plugins [Feature] Publicize Now Jetpack Social, auto-sharing [Feature] Theme Tools [JS Package] AI Client [JS Package] Analytics [JS Package] Base Styles [JS Package] Boost Score Api [JS Package] Charts [JS Package] Config [JS Package] Critical Css Gen [JS Package] Image Guide [JS Package] Licensing [JS Package] Publicize Components [JS Package] React Data Sync Client [JS Package] Scan [JS Package] Script Data [JS Package] Shared Extension Utils [JS Package] Storybook [JS Package] Svelte Data Sync Client [JS Package] Videopress Core [Package] Admin Ui [Package] Backup Helper Script Manager [Package] Backup [Package] Blaze [Package] Blocks [Package] Boost Core [Package] Boost Speed Score [Package] Chatbot [Package] Classic Theme Helper [Package] Connection [Package] Forms [Package] Google Analytics [Package] Image CDN [Package] Import [Package] Jetpack mu wpcom WordPress.com Features [Package] Licensing [Package] Masterbar [Package] My Jetpack [Package] Password Checker [Package] Plans [Package] Post List [Package] Protect Models [Package] Protect Status [Package] Publicize [Package] Scheduled Updates [Package] Schema [Package] Search Contains core Search functionality for Jetpack and Search plugins [Package] Stats Admin [Package] Stats Data [Package] Sync [Package] Transport Helper [Package] VideoPress [Package] WAF [Package] WP JS Data Sync [Plugin] Automattic For Agencies Client [Plugin] Backup A plugin that allows users to save every change and get back online quickly with one-click restores. [Plugin] Beta For serving live branches and the beta versions. https://github.com/automattic/jetpack-beta [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] Classic Theme Helper Plugin [Plugin] CRM Issues about the Jetpack CRM plugin [Plugin] Debug Helper Debug Tools plugin [Plugin] Inspect [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] mu wpcom jetpack-mu-wpcom plugin [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Plugin] Social Issues about the Jetpack Social plugin [Plugin] Starter Plugin [Plugin] Super Cache A fast caching plugin for WordPress. [Plugin] VaultPress [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. [Plugin] Wpcomsh RNA [Status] In Progress [Tests] Includes Tests [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants