Skip to content

Commit 537dfec

Browse files
schlesseraclaude
andcommitted
Name the command that ended a single process run early
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 2c13df0 commit 537dfec

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎src/Context/FeatureContext.php‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,10 +1705,12 @@ function ( $matches ) use ( $batch_variables ) {
17051705
$rows[] = [ substr( $command, 3 ), $save ];
17061706
}
17071707

1708-
$marker = 'WP_CLI_TEST_SAVED_VARIABLES:';
1709-
$code = '<?php
1708+
$marker = 'WP_CLI_TEST_SAVED_VARIABLES:';
1709+
$started = 'WP_CLI_TEST_STARTED_COMMAND:';
1710+
$code = '<?php
17101711
$wp_cli_test_saved = [];
1711-
foreach ( ' . var_export( $rows, true ) . ' as $wp_cli_test_row ) {
1712+
foreach ( ' . var_export( $rows, true ) . ' as $wp_cli_test_index => $wp_cli_test_row ) {
1713+
echo "\n' . $started . '{$wp_cli_test_index}\n";
17121714
$wp_cli_test_command = strtr( $wp_cli_test_row[0], $wp_cli_test_saved );
17131715
$wp_cli_test_result = WP_CLI::runcommand( $wp_cli_test_command, [ "launch" => false, "return" => "all", "exit_error" => false ] );
17141716
if ( 0 !== $wp_cli_test_result->return_code ) {
@@ -1738,6 +1740,10 @@ function ( $matches ) use ( $batch_variables ) {
17381740
$position = strrpos( $result->stdout, $marker );
17391741
$saved = false !== $position ? json_decode( trim( substr( $result->stdout, $position + strlen( $marker ) ) ), true ) : null;
17401742
if ( ! is_array( $saved ) ) {
1743+
$last = preg_match_all( '/^' . $started . '(\d+)$/m', $result->stdout, $matches ) ? (int) end( $matches[1] ) : null;
1744+
if ( null !== $last ) {
1745+
throw new RuntimeException( "The process ended while running `wp {$rows[ $last ][0]}`. A command that exits on its own cannot share a process with other commands." );
1746+
}
17411747
throw new RuntimeException( "Could not read the saved variables from the output:\n{$result->stdout}" );
17421748
}
17431749

0 commit comments

Comments
 (0)