fix(hooks): surface continued submit hook stderr
This commit is contained in:
@@ -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()))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user