diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index aa4e398c..d6630385 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -30,8 +30,38 @@ steps: tar -xzf dist.tar.gz echo "--- :docker: Starting wp-env" make wp-env-start - echo "--- :performing_arts: Running E2E tests" - make test-e2e + WP_CONTAINER=$(docker ps -qf "publish=8888" | head -1) + echo "--- :performing_arts: Running E2E tests in Playwright container" + E2E_EXIT=0 + docker run --rm \ + --userns=host \ + --network host \ + -v "$(pwd):/work" \ + -w /work \ + -e CI=true \ + mcr.microsoft.com/playwright:v1.58.2-noble \ + bash -c "npm ci && npx playwright install chromium && npx playwright test" \ + || E2E_EXIT=$? + echo "--- :broom: Fixing ownership of root-owned files" + docker run --rm \ + --userns=host \ + -v "$(pwd):/work" \ + -w /work \ + mcr.microsoft.com/playwright:v1.58.2-noble \ + chown -R "$(id -u):$(id -g)" /work + echo "--- :wordpress: WordPress debug log" + if [ -n "$WP_CONTAINER" ]; then + docker exec "$WP_CONTAINER" cat /var/www/html/wp-content/debug.log 2>/dev/null || echo "(no debug.log found)" + echo "--- :file_folder: Uploads directory permissions" + docker exec "$WP_CONTAINER" ls -la /var/www/html/wp-content/uploads/ 2>/dev/null || echo "(no uploads directory)" + echo "--- :whale: WordPress container status" + docker inspect --format='{{.State.Status}}' "$WP_CONTAINER" 2>/dev/null || echo "(container gone)" + else + echo "(WordPress container not found before tests)" + fi + exit $E2E_EXIT + agents: + queue: default plugins: *plugins - label: ':android: Publish Android Library' diff --git a/bin/wp-env-setup.sh b/bin/wp-env-setup.sh index f7464810..4eaf3945 100755 --- a/bin/wp-env-setup.sh +++ b/bin/wp-env-setup.sh @@ -65,7 +65,31 @@ done # --------------------------------------------------------------------------- echo "Flushing rewrite rules..." -npm run --silent wp-env run cli -- wp rewrite structure '/%postname%/' --hard 2>/dev/null +npm run --silent wp-env run cli -- wp rewrite structure '/%postname%/' 2>/dev/null + +echo "Writing .htaccess for pretty permalinks..." +WP_CONTAINER=$(docker ps -qf "publish=8888" | head -1) +if [ -z "$WP_CONTAINER" ]; then + echo "Error: Could not find WordPress container on port 8888." + echo "Running containers:" + docker ps --format "{{.ID}} {{.Image}} {{.Ports}} {{.Names}}" + exit 1 +fi +echo "Found WordPress container: $WP_CONTAINER" +docker exec -u 0 "$WP_CONTAINER" sh -c 'cat > /var/www/html/.htaccess << "HTACCESS" +# BEGIN WordPress + +RewriteEngine On +RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] +RewriteBase / +RewriteRule ^index\.php$ - [L] +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule . /index.php [L] + +# END WordPress +HTACCESS +' # --------------------------------------------------------------------------- # Enable Jetpack blocks module diff --git a/e2e/image-upload.spec.js b/e2e/image-upload.spec.js index 8e1c4635..18c5a43b 100644 --- a/e2e/image-upload.spec.js +++ b/e2e/image-upload.spec.js @@ -13,6 +13,59 @@ const TEST_IMAGE = path.resolve( import.meta.dirname, 'assets/test-image.png' ); test.describe( 'Image Upload', () => { test( 'should upload an image via the Image block', async ( { page } ) => { + // Log all network requests to wp-env for debugging upload issues in CI. + page.on( 'request', ( request ) => { + const url = request.url(); + if ( url.includes( 'localhost:8888' ) ) { + // eslint-disable-next-line no-console + console.log( + `[REQ] ${ request.method() } ${ url } headers=${ JSON.stringify( + Object.fromEntries( + Object.entries( request.headers() ).filter( + ( [ k ] ) => + [ + 'content-type', + 'authorization', + 'origin', + ].includes( k ) + ) + ) + ) }` + ); + } + } ); + page.on( 'response', ( response ) => { + const url = response.url(); + if ( url.includes( 'localhost:8888' ) ) { + // eslint-disable-next-line no-console + console.log( + `[RES] ${ response.status() } ${ url } headers=${ JSON.stringify( + Object.fromEntries( + Object.entries( response.headers() ).filter( + ( [ k ] ) => + [ + 'access-control-allow-origin', + 'access-control-allow-headers', + 'access-control-allow-methods', + ].includes( k ) + ) + ) + ) }` + ); + } + } ); + page.on( 'requestfailed', ( request ) => { + const url = request.url(); + if ( url.includes( 'localhost:8888' ) ) { + // eslint-disable-next-line no-console + console.log( + `[FAIL] ${ request.method() } ${ url } failure=${ + request.failure()?.errorText + }` + ); + } + } ); + const editor = new EditorPage( page ); await editor.setup();