Skip to content

Commit aa12999

Browse files
Fix missing exit code check for streaming prepare command
The streaming version of run_stream() did not return exit code information, so the prepare command in DefaultProvider would proceed even if the command failed with non-zero exit code. Changes: - Add ExitCode(i32) variant to OutputLine enum - Modify ShellConnector::run_stream() to yield exit code after stdout/stderr complete - Check exit code in DefaultProvider::from_config() and return ProviderError::ExecFailed if prepare command fails - Handle new ExitCode variant in output callbacks 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0fe3dd6 commit aa12999

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

src/connector.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,16 @@ impl Connector for ShellConnector {
420420

421421
let combined = futures::stream::select(stdout_stream, stderr_stream);
422422

423-
Ok(Box::pin(combined))
423+
// After stdout/stderr close, wait for child and yield exit code
424+
let exit_stream = futures::stream::once(async move {
425+
let exit_code = match child.wait().await {
426+
Ok(status) => status.code().unwrap_or(-1),
427+
Err(_) => -1,
428+
};
429+
OutputLine::ExitCode(exit_code)
430+
});
431+
432+
Ok(Box::pin(combined.chain(exit_stream)))
424433
}
425434
}
426435

src/orchestrator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ where
424424
let callback: OutputCallback = Arc::new(|test_id, line| match line {
425425
OutputLine::Stdout(s) => println!("[{}] {}", test_id, s),
426426
OutputLine::Stderr(s) => eprintln!("[{}] {}", test_id, s),
427+
OutputLine::ExitCode(_) => {}
427428
});
428429
runner = runner.with_output_callback(callback);
429430
}

src/orchestrator/runner.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ impl<'a, S: Sandbox, D: TestFramework> TestRunner<'a, S, D> {
228228
stderr.push_str(s);
229229
stderr.push('\n');
230230
}
231+
OutputLine::ExitCode(_) => {}
231232
}
232233
}
233234
None => break, // Stream ended
@@ -253,6 +254,7 @@ impl<'a, S: Sandbox, D: TestFramework> TestRunner<'a, S, D> {
253254
stderr.push_str(s);
254255
stderr.push('\n');
255256
}
257+
OutputLine::ExitCode(_) => {}
256258
}
257259
}
258260
}

src/provider.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,16 @@ impl ExecResult {
397397
/// A single line of output from a streaming command.
398398
///
399399
/// Used with [`Sandbox::exec_stream`] to process output in real-time.
400-
/// Each line is tagged with its source (stdout or stderr).
400+
/// Each line is tagged with its source (stdout or stderr), or indicates
401+
/// the final exit code of the command.
401402
#[derive(Debug, Clone)]
402403
pub enum OutputLine {
403404
/// A line from standard output.
404405
Stdout(String),
405406
/// A line from standard error.
406407
Stderr(String),
408+
/// The exit code of the command (yielded last, after all output).
409+
ExitCode(i32),
407410
}
408411

409412
/// A stream of output lines from a command.

src/provider/default.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ impl DefaultProvider {
119119

120120
let mut stream = connector.run_stream(&full_prepare_cmd).await?;
121121
let mut last_stdout_line = String::new();
122+
let mut exit_code = 0;
122123

123124
while let Some(line) = stream.next().await {
124125
match line {
@@ -129,9 +130,19 @@ impl DefaultProvider {
129130
OutputLine::Stderr(s) => {
130131
eprintln!(" {}", s);
131132
}
133+
OutputLine::ExitCode(code) => {
134+
exit_code = code;
135+
}
132136
}
133137
}
134138

139+
if exit_code != 0 {
140+
return Err(ProviderError::ExecFailed(format!(
141+
"Prepare command failed with exit code {}",
142+
exit_code
143+
)));
144+
}
145+
135146
// Image id is the last line of stdout
136147
let image_id = last_stdout_line.trim().to_string();
137148

0 commit comments

Comments
 (0)