Fix E2E tests on macOS when STUDIO_RUNTIME=native-php#3301
Fix E2E tests on macOS when STUDIO_RUNTIME=native-php#3301fredrikekelund merged 7 commits intotrunkfrom
STUDIO_RUNTIME=native-php#3301Conversation
- When Studio clones a site, explicitly update the site URL. Playground can handle this internally, but the native PHP runtime obviously cannot. - On Posix platforms, spawn process daemon children with `detached: true` to assign them to a new process group. This is so we can pass a negative PID to `process.kill` to terminate the entire process group (the Node.js process and the associated PHP process). This approach isn't bulletproof, but it's alright, and it works for the purpose of the E2E tests. - Favor SIGTERM over SIGKILL when killing child processes to give them a chance to clean up.
STUDIO_RUNTIME=native-php
📊 Performance Test ResultsComparing e82c8a0 vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
bcotrim
left a comment
There was a problem hiding this comment.
I had trouble running the e2e tests locally.
First issue was checksum mismatches — looks like upstream static-php-cli re-publishes archives, so the pinned hashes go stale. Should be moot once #3297 lands and we build binaries ourselves.
Second issue: even with hashes fixed, e2e teardown hung for 3 minutes with one PHP child orphaned per session. Root cause is that php-server-child.ts only handles exit/disconnect, not SIGTERM. When the daemon SIGTERMs the Node fork, it dies without firing exit, so killPhpProcess() never runs and the PHP grandchild leaks. Adding these unblocks teardown for me:
process.on( 'SIGTERM', () => {
killPhpProcess();
process.exit( 0 );
} );
process.on( 'SIGINT', () => {
killPhpProcess();
process.exit( 0 );
} );Could you reproduce + confirm the fix on your end?
|
|
||
| // Playground sets the correct siteurl internally, but for the native-php runtime, we need to | ||
| // explicitly update that option | ||
| await updateSiteUrl( server, `http://localhost:${ details.port }` ); |
There was a problem hiding this comment.
Should we run this only for native-php?
There was a problem hiding this comment.
It's obviously not required for Playground, but that's only because Playground enforces the siteurl internally. I think it makes sense to follow the more standard approach of explicitly updating the siteurl rather than relying on some runtimes to do it for us.
|
Sorry about that, @bcotrim. I did confirm this working previously… It seems you're correct that In any case, I've updated I've also updated the PHP binary checksums for macOS with ARM chips to make the tests pass. |
|
I'm playing around with Windows changes here, too. I could move those commits to a new PR, though. @bcotrim, if you review this again, feel free to ignore the changes explicitly targeting Windows. I'll let you know when those are ready for review. |
bcotrim
left a comment
There was a problem hiding this comment.
Thanks for following up on the changes @fredrikekelund
e2e now run successfully on macOS.
I would suggest moving the Windows to another PR so we can land this one.
Nit: A nice workflow would be to control the STUDIO_RUNTIME via a PR label (for example) so the CI runs native PHP e2e. But we can do it in a follow-up PR, and maybe only after we have the binaries in our own CDN.
0f9ece1 to
e82c8a0
Compare
Good idea 👍 I added this in #3343 |
Related issues
How AI was used in this PR
Primarily to help me debug the problem. I alternated between Claude and Codex.
Proposed Changes
While working on #3271, @bcotrim discovered that the E2E tests were failing when run with
STUDIO_RUNTIME=native-php. This PR fixes that by implementing the following fixes:detached: trueto assign them to a new process group. This is so we can pass a negative PID toprocess.killto terminate the entire process group (the Node.js process and the associated PHP process). This approach isn't bulletproof, but it's alright, and it works for the purpose of the E2E tests.Testing Instructions
Run the E2E tests locally on macOS by following these steps:
npm run packageSTUDIO_RUNTIME=native-php npm run e2ePre-merge Checklist