diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bcb99e29bc..a96b553cf5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -237,16 +237,24 @@ jobs: run: | source ~/.nvm/nvm.sh; nvm install 22; + cd $HOST_PATH RUNNER_TRACKING_ID="" && ( \ - nohup node \ - --experimental-strip-types \ - --experimental-transform-types \ - --import ./packages/meta/src/node-es-module-loader/register.mts \ - ./packages/playground/cli/src/cli.ts server \ - --port=$PORT \ - --mount="$HOST_PATH:/wordpress/$VERSION" \ - --quiet& \ - ) + nohup python3 -c "import http.server + import socketserver + from urllib.parse import unquote + + class PrefixHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): + def do_GET(self): + if self.path.startswith('/${{ env.VERSION }}/'): + self.path = self.path[len('/${{ env.VERSION }}'):] + elif self.path == '/${{ env.VERSION }}': + self.path = '/' + super().do_GET() + + with socketserver.TCPServer(('127.0.0.1', ${{ env.PORT }}), PrefixHTTPRequestHandler) as httpd: + httpd.serve_forever() + "& + ); - name: Wait for the package server to be ready run: | for i in {1..60}; do diff --git a/packages/playground/cli/src/run-cli.ts b/packages/playground/cli/src/run-cli.ts index 65e8decd8f..266bd411fc 100644 --- a/packages/playground/cli/src/run-cli.ts +++ b/packages/playground/cli/src/run-cli.ts @@ -341,6 +341,7 @@ export async function runCLI(args: RunCLIArgs): Promise { const fileLockManager = new FileLockManagerForNode(nativeFlockSync); let wordPressReady = false; + let isFirstRequest = true; logger.log('Starting a PHP server...'); @@ -537,6 +538,28 @@ export async function runCLI(args: RunCLIArgs): Promise { 'WordPress is not ready yet' ); } + // Clear the playground_auto_login_already_happened cookie on the first request. + // Otherwise the first Playground CLI server started on the machine will set it, + // all the subsequent runs will get the stale cookie, and the auto-login will + // assume they don't have to auto-login again. + if (isFirstRequest) { + isFirstRequest = false; + const headers: Record = { + 'Content-Type': ['text/plain'], + 'Content-Length': ['0'], + Location: ['/'], + }; + if ( + request.headers?.['cookie']?.includes( + 'playground_auto_login_already_happened' + ) + ) { + headers['Set-Cookie'] = [ + 'playground_auto_login_already_happened=1; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Path=/', + ]; + } + return new PHPResponse(302, headers, new Uint8Array()); + } return await loadBalancer.handleRequest(request); }, }); diff --git a/packages/playground/cli/tests/test-running-unbuilt-cli.sh b/packages/playground/cli/tests/test-running-unbuilt-cli.sh index bc13af4d5b..19037ced2d 100755 --- a/packages/playground/cli/tests/test-running-unbuilt-cli.sh +++ b/packages/playground/cli/tests/test-running-unbuilt-cli.sh @@ -30,7 +30,7 @@ function test_playground_cli() { echo "Playground CLI started successfully" echo "Checking WordPress home page..." - HOME_PAGE_OUTPUT="$(curl -s http://127.0.0.1:9400 || echo 'No output')" + HOME_PAGE_OUTPUT="$(curl -sL http://127.0.0.1:9400 || echo 'No output')" if [[ $HOME_PAGE_OUTPUT != *"My WordPress Website"* ]]; then echo "Home page output: $HOME_PAGE_OUTPUT" echo "Error: Home page did not contain 'My WordPress Website'" diff --git a/packages/playground/test-built-npm-packages/commonjs-and-jest/tests/wp.spec.ts b/packages/playground/test-built-npm-packages/commonjs-and-jest/tests/wp.spec.ts index 677ec93a6d..d066cd2a43 100644 --- a/packages/playground/test-built-npm-packages/commonjs-and-jest/tests/wp.spec.ts +++ b/packages/playground/test-built-npm-packages/commonjs-and-jest/tests/wp.spec.ts @@ -22,6 +22,6 @@ SupportedPHPVersions.forEach((phpVersion: string) => { } finally { await cli[Symbol.asyncDispose](); } - }, 10000); + }, 22000); }); }); diff --git a/packages/playground/test-built-npm-packages/es-modules-and-vitest/tests/wp.spec.ts b/packages/playground/test-built-npm-packages/es-modules-and-vitest/tests/wp.spec.ts index f8db9886ce..1b6ea9d9f7 100644 --- a/packages/playground/test-built-npm-packages/es-modules-and-vitest/tests/wp.spec.ts +++ b/packages/playground/test-built-npm-packages/es-modules-and-vitest/tests/wp.spec.ts @@ -13,7 +13,7 @@ if (!SupportedPHPVersions.includes(phpVersion)) { } describe(`PHP ${phpVersion}`, () => { - it('Should load WordPress', { timeout: 12000 }, async () => { + it('Should load WordPress', { timeout: 22000 }, async () => { const cli = await runCLI({ command: 'server', php: phpVersion,