Skip to content

Commit 1096f12

Browse files
committed
refactor(envlite): fail loudly on Unix without pcntl; clarify test name
1 parent 3338fb7 commit 1096f12

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

tools/local-env/envlite.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,23 @@ function envlite_pcntl_exec_available(): bool {
288288
}
289289

290290
/**
291-
* Launches the dev server. On Unix with pcntl available, replaces the current
292-
* process via pcntl_exec — same PID, no parent-child relay. On Windows (or
293-
* any environment without pcntl_exec), falls back to envlite_proc_stream
294-
* which inherits stdio so SIGINT still reaches the child. Returns only on
295-
* error or when the fallback child exits.
291+
* Launches the dev server. On Unix, requires pcntl (enforced by Phase 0 at
292+
* init time and re-checked here for safety) and replaces the current process
293+
* via pcntl_exec — same PID, no parent-child relay. On Windows, falls back
294+
* to envlite_proc_stream which inherits stdio so SIGINT still reaches the
295+
* child. Returns only on error or when the Windows-fallback child exits.
296296
*/
297297
function envlite_run_dev_server(string $repoRoot, int $port): int {
298298
$argv = envlite_dev_server_argv($repoRoot, $port);
299299

300-
if (envlite_pcntl_exec_available()) {
300+
if (PHP_OS_FAMILY !== 'Windows') {
301+
if (!function_exists('pcntl_exec')) {
302+
// Phase 0 enforces pcntl on Unix, but `serve` skips Phase 0 — so a
303+
// checkout cached from a different system could land here. The spec
304+
// says Unix uses pcntl_exec; do not silently degrade to proc_open.
305+
envlite_log(null, 'pcntl extension is required on Unix; reinstall PHP with pcntl');
306+
return 1;
307+
}
301308
// pcntl_exec uses the *current* working directory; chdir first so
302309
// `-t src` resolves relative to the repo root, matching the proc_open
303310
// path's $cwd argument.

tools/local-env/tests/test_dev_server.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ function test_dev_server_argv_does_not_include_php_binary_first() {
2222

2323
function test_dev_server_pcntl_replaces_process_on_unix() {
2424
if (!envlite_pcntl_exec_available()) {
25-
// Windows or pcntl-less Unix: the helper takes the proc_open branch.
26-
// Verified separately in test_dev_server_fallback_uses_proc_open.
25+
// Windows or pcntl-less Unix: skip the pcntl_exec replacement check.
26+
// proc_stream behavior is covered by
27+
// test_dev_server_proc_stream_propagates_child_exit_with_dev_server_argv_shape.
2728
return;
2829
}
2930

@@ -45,10 +46,10 @@ function test_dev_server_pcntl_replaces_process_on_unix() {
4546
envlite_assert_eq(7, $exit, 'pcntl_exec must replace process; child exit must be 7');
4647
}
4748

48-
function test_dev_server_fallback_uses_proc_open_when_pcntl_unavailable() {
49-
// We can't disable pcntl in-process. Instead, exercise envlite_proc_stream
50-
// directly with the same argv shape envlite_run_dev_server constructs for
51-
// the Windows fallback, and assert it returns the child's exit code.
49+
function test_dev_server_proc_stream_propagates_child_exit_with_dev_server_argv_shape() {
50+
// pcntl can't be disabled in-process to test the actual fallback selection.
51+
// Instead, verify that envlite_proc_stream propagates the child exit code
52+
// when called with the argv shape envlite_run_dev_server uses on Windows.
5253
$argv = array_merge([PHP_BINARY], ['-r', 'exit(0);']);
5354
$exit = envlite_proc_stream($argv);
5455
envlite_assert_eq(0, $exit, 'proc_open fallback must propagate child exit code');

0 commit comments

Comments
 (0)