fix(tui): do not freeze the UI on chat send
Some checks failed
ci / test (pull_request) Failing after 1s

Enter used block_on(Node::send), which retries for 180s on the TUI
thread so event::read never ran. Spawn send on the runtime, poll keys
at 100ms, show sending/sent/send failed on the footer.
This commit is contained in:
Sirius DevOps 2026-09-11 22:33:55 -04:00
commit 7d8363a761
No known key found for this signature in database
3 changed files with 75 additions and 7 deletions

View file

@ -1,6 +1,10 @@
//! Composer Enter must send chat to the selected friend, not only slash commands.
use onionwire::tui::{composer_enter, ComposerAction, SlashCmd, WipeKind};
use onionwire::tui::{
composer_enter, take_job_result, ComposerAction, SlashCmd, WipeKind, TUI_POLL,
};
use std::sync::mpsc;
use std::time::{Duration, Instant};
#[test]
fn enter_plain_text_is_send() {
@ -43,3 +47,28 @@ fn enter_unknown_slash_is_not_chat() {
Some(ComposerAction::UnknownSlash("/nope".into()))
);
}
#[test]
fn take_job_result_is_nonblocking_when_empty() {
let (tx, rx) = mpsc::channel::<String>();
let start = Instant::now();
assert_eq!(take_job_result(&rx), None);
assert!(
start.elapsed() < Duration::from_millis(50),
"empty job rx must not wait on the 180s send retry"
);
drop(tx);
}
#[test]
fn take_job_result_reads_status_without_blocking() {
let (tx, rx) = mpsc::channel();
tx.send("sent".into()).unwrap();
assert_eq!(take_job_result(&rx).as_deref(), Some("sent"));
}
#[test]
fn tui_poll_is_short_so_keys_keep_working() {
assert!(TUI_POLL <= Duration::from_millis(200));
assert!(TUI_POLL > Duration::ZERO);
}