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

[CMSP-1459] Fixes URL normalization process #138

Merged
merged 40 commits into from
Jul 10, 2024

Conversation

jazzsequence
Copy link
Contributor

@jazzsequence jazzsequence commented Jul 8, 2024

This pull request

  • adds a new helper function that re-parses and normalizes a URL from its parts
  • updates the existing WP URL normalization function to use the new helper function.
  • pre-sets the endpoint option so the updated URL handling does not break existing sites expecting the endpoint to be at /wp/graphql while still allowing that option to be set via the plugin options.
  • adds Playwright tests (adapted from Canaries) that are run on all PRs

This resolves an issue where URLs were being interpreted incorrectly. Most notably, WP core library urls (e.g. to files like /wp-includes/js/dist/interactivity.min.js) were being rendered as https://dev-cxr-wpcm-canary-test.pantheonsite.io/wp-includes/js/dist/interactivity.min.js/?ver=6.5.5.

Additionally, this should resolve the issues with URL structure causing the canary tests to fail.

this is a setting that can be changed, so this way we're setting it to what we think it should be without forcing users to use our path
use dynamic site_url and make the setting conditional based on whether there's already a /wp/ i the siteurl
that's a theme thing. the canary sites are running a different theme
so we haven't cd'd into the local copy when we're looking for the commit message
so it's not just truncated if it's long
@jazzsequence jazzsequence marked this pull request as ready for review July 9, 2024 21:15
@jazzsequence jazzsequence requested review from a team as code owners July 9, 2024 21:15
Copy link
Member

@pwtyler pwtyler left a comment

Choose a reason for hiding this comment

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

None of my feedback is a hard-block.

Comment on lines +67 to +73
if terminus site:info wpcm-playwright-tests; then
echo "Test site already exists, skipping site creation."
# If the site exists already, we should switch it to git mode.
terminus connection:set wpcm-playwright-tests.dev git -y
else
terminus site:create wpcm-playwright-tests 'WordPress (Composer Managed) Playwright Test Site' 'WordPress (Composer Managed)' --org=5ae1fa30-8cc4-4894-8ca9-d50628dcba17
fi
Copy link
Member

Choose a reason for hiding this comment

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

site name and org UUID can/should remain config'd in this file, but can they be abstracted to global variables to ease identification (and replacement)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I was just avoiding it to avoid complexity. We can come back to this to refine it later, I was more concerned that we had tests.

.github/workflows/playwright.yml Outdated Show resolved Hide resolved
web/app/mu-plugins/filters.php Outdated Show resolved Hide resolved
* @param array $parts URL parts from parse_url.
* @return string Re-parsed URL.
*/
function __rebuild_url_from_parts( array $parts ) : string {
Copy link
Member

Choose a reason for hiding this comment

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

feels very dirty that this doesn't exist already 😬

Comment on lines +206 to +213
// Normalize the URL to remove any double slashes.
if ( isset( $parts['path'] ) ) {
$parts['path'] = preg_replace( '#/+#', '/', $parts['path'] );
}

// Normalize the remaining URL to remove any double slashes.
$normalized_url = str_replace( '//', '/', $remaining_url );
// Rebuild and return the full normalized URL.
return __rebuild_url_from_parts( $parts );
}
Copy link
Member

Choose a reason for hiding this comment

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

seems over-engineered with the same result but maybe I'm missing what's changed and how the bugs manifested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not entirely convinced it's necessary but I'm also not convinced that it's not. It was one of the many steps on the path of resolving the bug(s).

Copy link
Member

@pwtyler pwtyler Jul 10, 2024

Choose a reason for hiding this comment

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

we need tests (I know you know this)

jazzsequence and others added 3 commits July 10, 2024 08:37
Co-authored-by: Phil Tyler <[email protected]>
…ntheon-systems/wordpress-composer-managed into bugfix-fix-core-resource-url-handling
@jazzsequence jazzsequence merged commit 7ead49d into default Jul 10, 2024
4 checks passed
@jazzsequence jazzsequence deleted the bugfix-fix-core-resource-url-handling branch July 10, 2024 15:36
jazzsequence added a commit that referenced this pull request Jul 31, 2024
* add new helper function that parses and normalizes a url from parts

* Update URL normalization function to refactor using __rebuild_url_from_parts

* check if endpoint is defined already

* dont' use anonymous function

* add host if exists

* replace graphql endpoint filter with an action hook to prepopulate
this is a setting that can be changed, so this way we're setting it to what we think it should be without forcing users to use our path

* move the prepopulate action and make it more robust
use dynamic site_url and make the setting conditional based on whether there's already a /wp/ i the siteurl

* add exclusions to site_url filter for graphql

* add playwright tests

* change ci to install

* don't create the site if it already exists

* add git config for the user

* wait for the last action to finish before switching to sftp mode

* set pretty permalinks for playwright test site

* switch the existing site to git mode

* force yes

* check the h2 instead of the site title
that's a theme thing. the canary sites are running a different theme

* test that the resource urls have /wp/ in the path

* missing "

* expect the resource url to be truthy on a request

* append the commit message from the PR to the commit to the test site

* use github token so we can use gh

* add package.json to export-ignore

* move the commit msg var up
so we haven't cd'd into the local copy when we're looking for the commit message

* we don't need `page` at all

* this doesn't change anything other than seeing if we're getting the PR number

* fix the commit message

* Include the git commit message body
so it's not just truncated if it's long

* don't fail if there's nothing to commit

* add caching for dependencies

* fix hello world test

* emdash problems

* fix the locator on the welcome message test

* generate lock files so we can use the cache

* pass default values
so the substr check isn't null

* change test to toContainText

* only generate the npm lock
use the composer.json instead of composer.lock
use the conditional to check for cache

* party pooper 💩

Co-authored-by: Phil Tyler <[email protected]>

* bail early

---------

Co-authored-by: Phil Tyler <[email protected]>
jazzsequence added a commit that referenced this pull request Aug 1, 2024
* add new helper function that parses and normalizes a url from parts

* Update URL normalization function to refactor using __rebuild_url_from_parts

* check if endpoint is defined already

* dont' use anonymous function

* add host if exists

* replace graphql endpoint filter with an action hook to prepopulate
this is a setting that can be changed, so this way we're setting it to what we think it should be without forcing users to use our path

* move the prepopulate action and make it more robust
use dynamic site_url and make the setting conditional based on whether there's already a /wp/ i the siteurl

* add exclusions to site_url filter for graphql

* add playwright tests

* change ci to install

* don't create the site if it already exists

* add git config for the user

* wait for the last action to finish before switching to sftp mode

* set pretty permalinks for playwright test site

* switch the existing site to git mode

* force yes

* check the h2 instead of the site title
that's a theme thing. the canary sites are running a different theme

* test that the resource urls have /wp/ in the path

* missing "

* expect the resource url to be truthy on a request

* append the commit message from the PR to the commit to the test site

* use github token so we can use gh

* add package.json to export-ignore

* move the commit msg var up
so we haven't cd'd into the local copy when we're looking for the commit message

* we don't need `page` at all

* this doesn't change anything other than seeing if we're getting the PR number

* fix the commit message

* Include the git commit message body
so it's not just truncated if it's long

* don't fail if there's nothing to commit

* add caching for dependencies

* fix hello world test

* emdash problems

* fix the locator on the welcome message test

* generate lock files so we can use the cache

* pass default values
so the substr check isn't null

* change test to toContainText

* only generate the npm lock
use the composer.json instead of composer.lock
use the conditional to check for cache

* party pooper 💩

Co-authored-by: Phil Tyler <[email protected]>

* bail early

---------

Co-authored-by: Phil Tyler <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants