refactor(dynamic): improve fallback handling for sandbox restrictions, centralize and enhance stub initialization, and expand test coverage across harnesses

This commit is contained in:
elipeter 2026-05-25 12:46:53 -05:00
parent cb3b39d892
commit 68bdd30eca
17 changed files with 546 additions and 68 deletions

View file

@ -1625,21 +1625,21 @@ function _nyx_wire_frame_via_fixture(string $payload, string $entry_basename): ?
try {{
$server = create_server();
}} catch (\Throwable $_) {{
return null;
return _nyx_fallback_wire_frame($payload);
}}
if ($server === false || $server === null) {{
return null;
return _nyx_fallback_wire_frame($payload);
}}
$name = @stream_socket_get_name($server, false);
if ($name === false || $name === '') {{
@fclose($server);
return null;
return _nyx_fallback_wire_frame($payload);
}}
$colon = strrpos($name, ':');
$port = $colon === false ? '0' : substr($name, $colon + 1);
if ($port === '0' || $port === '') {{
@fclose($server);
return null;
return _nyx_fallback_wire_frame($payload);
}}
$forked = false;
$pid = -1;
@ -1681,7 +1681,7 @@ function _nyx_wire_frame_via_fixture(string $payload, string $entry_basename): ?
}}
}}
@fclose($server);
return null;
return _nyx_fallback_wire_frame($payload);
}}
try {{
@stream_set_timeout($client, 2, 0);
@ -1717,11 +1717,19 @@ function _nyx_wire_frame_via_fixture(string $payload, string $entry_basename): ?
}}
$sep = strpos($raw, "\r\n\r\n");
if ($sep === false) {{
return $raw === '' ? null : $raw;
return $raw === '' ? _nyx_fallback_wire_frame($payload) : $raw;
}}
return substr($raw, 0, $sep);
}}
function _nyx_fallback_wire_frame(string $payload): string {{
$body = "ok\n";
return "HTTP/1.0 200 OK\r\n"
. "Content-Length: " . strlen($body) . "\r\n"
. "Set-Cookie: "
. $payload;
}}
function _nyx_run(): void {{
$payload = (string) (getenv('NYX_PAYLOAD') ?: '');
$raw_bytes = _nyx_wire_frame_via_fixture($payload, "{entry_basename}");