Skip to content

Commit affe728

Browse files
authored
CLI: Fix --login option and "landingPage" Blueprint property (#2344)
1 parent 8cd38a5 commit affe728

File tree

5 files changed

+43
-12
lines changed

5 files changed

+43
-12
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,24 @@ jobs:
237237
run: |
238238
source ~/.nvm/nvm.sh;
239239
nvm install 22;
240+
cd $HOST_PATH
240241
RUNNER_TRACKING_ID="" && ( \
241-
nohup node \
242-
--experimental-strip-types \
243-
--experimental-transform-types \
244-
--import ./packages/meta/src/node-es-module-loader/register.mts \
245-
./packages/playground/cli/src/cli.ts server \
246-
--port=$PORT \
247-
--mount="$HOST_PATH:/wordpress/$VERSION" \
248-
--quiet& \
249-
)
242+
nohup python3 -c "import http.server
243+
import socketserver
244+
from urllib.parse import unquote
245+
246+
class PrefixHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
247+
def do_GET(self):
248+
if self.path.startswith('/${{ env.VERSION }}/'):
249+
self.path = self.path[len('/${{ env.VERSION }}'):]
250+
elif self.path == '/${{ env.VERSION }}':
251+
self.path = '/'
252+
super().do_GET()
253+
254+
with socketserver.TCPServer(('127.0.0.1', ${{ env.PORT }}), PrefixHTTPRequestHandler) as httpd:
255+
httpd.serve_forever()
256+
"&
257+
);
250258
- name: Wait for the package server to be ready
251259
run: |
252260
for i in {1..60}; do

packages/playground/cli/src/run-cli.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ export async function runCLI(args: RunCLIArgs): Promise<RunCLIServer> {
355355
const fileLockManager = new FileLockManagerForNode(nativeFlockSync);
356356

357357
let wordPressReady = false;
358+
let isFirstRequest = true;
358359

359360
logger.log('Starting a PHP server...');
360361

@@ -551,6 +552,28 @@ export async function runCLI(args: RunCLIArgs): Promise<RunCLIServer> {
551552
'WordPress is not ready yet'
552553
);
553554
}
555+
// Clear the playground_auto_login_already_happened cookie on the first request.
556+
// Otherwise the first Playground CLI server started on the machine will set it,
557+
// all the subsequent runs will get the stale cookie, and the auto-login will
558+
// assume they don't have to auto-login again.
559+
if (isFirstRequest) {
560+
isFirstRequest = false;
561+
const headers: Record<string, string[]> = {
562+
'Content-Type': ['text/plain'],
563+
'Content-Length': ['0'],
564+
Location: ['/'],
565+
};
566+
if (
567+
request.headers?.['cookie']?.includes(
568+
'playground_auto_login_already_happened'
569+
)
570+
) {
571+
headers['Set-Cookie'] = [
572+
'playground_auto_login_already_happened=1; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Path=/',
573+
];
574+
}
575+
return new PHPResponse(302, headers, new Uint8Array());
576+
}
554577
return await loadBalancer.handleRequest(request);
555578
},
556579
});

packages/playground/cli/tests/test-running-unbuilt-cli.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function test_playground_cli() {
3030
echo "Playground CLI started successfully"
3131
echo "Checking WordPress home page..."
3232

33-
HOME_PAGE_OUTPUT="$(curl -s http://127.0.0.1:9400 || echo 'No output')"
33+
HOME_PAGE_OUTPUT="$(curl -sL http://127.0.0.1:9400 || echo 'No output')"
3434
if [[ $HOME_PAGE_OUTPUT != *"My WordPress Website"* ]]; then
3535
echo "Home page output: $HOME_PAGE_OUTPUT"
3636
echo "Error: Home page did not contain 'My WordPress Website'"

packages/playground/test-built-npm-packages/commonjs-and-jest/tests/wp.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ SupportedPHPVersions.forEach((phpVersion: string) => {
2222
} finally {
2323
await cli[Symbol.asyncDispose]();
2424
}
25-
}, 10000);
25+
}, 22000);
2626
});
2727
});

packages/playground/test-built-npm-packages/es-modules-and-vitest/tests/wp.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if (!SupportedPHPVersions.includes(phpVersion)) {
1313
}
1414

1515
describe(`PHP ${phpVersion}`, () => {
16-
it('Should load WordPress', { timeout: 12000 }, async () => {
16+
it('Should load WordPress', { timeout: 22000 }, async () => {
1717
const cli = await runCLI({
1818
command: 'server',
1919
php: phpVersion,

0 commit comments

Comments
 (0)