fix(hooks): surface continued submit hook stderr

This commit is contained in:
Hunter B
2026-05-31 04:43:54 -07:00
parent 4146ec617e
commit 0d3b81db2e
2 changed files with 47 additions and 1 deletions
+5 -1
View File
@@ -1026,7 +1026,10 @@ fn parse_message_submit_stdout(stdout: &str) -> MessageSubmitStdout {
}
fn message_submit_continue_warning(result: &HookResult) -> Option<String> {
result.error.as_deref().and_then(first_non_empty_line)
message_submit_stdout_reason(&result.stdout)
.or_else(|| first_non_empty_line(&result.stderr))
.or_else(|| first_non_empty_line(&result.stdout))
.or_else(|| result.error.as_deref().and_then(first_non_empty_line))
}
fn message_submit_block_reason(result: &HookResult, fallback: &str) -> String {
@@ -1567,6 +1570,7 @@ printf '%s\n' '{"text":"recovered"}'
assert_eq!(
executor.execute_message_submit_transform(&submit_context(&dir), "original"),
MessageSubmitOutcome::replaced("recovered".to_string())
.with_warning(Some("soft failure".to_string()))
);
}
+42
View File
@@ -2158,6 +2158,48 @@ printf '%s\n' '{"text":"after timeout"}'
}
}
#[cfg(not(windows))]
#[tokio::test]
async fn dispatch_user_message_surfaces_continued_message_submit_stderr() {
let dir = TempDir::new().expect("tempdir");
let failing = write_message_submit_hook(
&dir,
"fail.sh",
r#"#!/bin/sh
printf '%s\n' 'soft failure' >&2
exit 9
"#,
);
let replacing = write_message_submit_hook(
&dir,
"replace.sh",
r#"#!/bin/sh
printf '%s\n' '{"text":"after soft failure"}'
"#,
);
let mut app = create_test_app();
configure_message_submit_hooks(&mut app, &dir, vec![failing, replacing]);
let mut engine = crate::core::engine::mock_engine_handle();
let config = Config::default();
dispatch_user_message(
&mut app,
&config,
&engine.handle,
QueuedMessage::new("hello".to_string(), None),
)
.await
.expect("dispatch user message");
assert_eq!(app.status_message.as_deref(), Some("soft failure"));
match engine.rx_op.recv().await.expect("send message op") {
crate::core::ops::Op::SendMessage { content, .. } => {
assert_eq!(content, "after soft failure");
}
other => panic!("expected SendMessage, got {other:?}"),
}
}
#[cfg(not(windows))]
#[tokio::test]
async fn dispatch_user_message_uses_transformed_message_submit_text() {