Fix wait command client timeouts and test failures

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Harivansh Rathi 2026-03-25 21:06:42 -04:00
parent f87ac61790
commit 7f12524fbb
4 changed files with 47 additions and 19 deletions

View file

@ -79,8 +79,23 @@ fn spawn_daemon(opts: &GlobalOpts) -> Result<()> {
Ok(())
}
fn request_read_timeout(request: &Request) -> Duration {
let default_timeout = Duration::from_secs(30);
match request.action.as_str() {
"wait-window" | "wait-focus" => {
let wait_timeout = request
.extra
.get("timeout_ms")
.and_then(|value| value.as_u64())
.unwrap_or(10_000);
Duration::from_millis(wait_timeout.saturating_add(5_000))
}
_ => default_timeout,
}
}
fn send_request_over_stream(mut stream: UnixStream, request: &Request) -> Result<Response> {
stream.set_read_timeout(Some(Duration::from_secs(30)))?;
stream.set_read_timeout(Some(request_read_timeout(request)))?;
stream.set_write_timeout(Some(Duration::from_secs(5)))?;
let json = serde_json::to_string(request)?;

View file

@ -245,9 +245,13 @@ pub fn run() -> Result<()> {
// All other commands need a daemon connection
let request = build_request(&app.command)?;
let response = connection::send_command(&app.global, &request)?;
let success = response.success;
if app.global.json {
println!("{}", serde_json::to_string_pretty(&response)?);
if !success {
std::process::exit(1);
}
} else {
print_response(&app.command, &response)?;
}
@ -392,11 +396,7 @@ fn print_response(cmd: &Command, response: &Response) -> Result<()> {
} else {
"visible"
};
let display_title = if title.len() > 30 {
format!("{}...", &title[..27])
} else {
title.to_string()
};
let display_title = truncate_display(title, 30);
println!(
"@{:<4} {:<30} ({:<7}) {},{} {}x{}",
ref_id, display_title, state, x, y, width, height
@ -496,11 +496,7 @@ fn print_window_line(window: &serde_json::Value, stderr: bool) {
let line = format!(
"@{:<4} {:<30} ({:<7}) {},{} {}x{} [{}]",
ref_id,
if title.len() > 30 {
format!("{}...", &title[..27])
} else {
title.to_string()
},
truncate_display(title, 30),
state,
x,
y,
@ -514,3 +510,13 @@ fn print_window_line(window: &serde_json::Value, stderr: bool) {
println!("{line}");
}
}
fn truncate_display(value: &str, max_chars: usize) -> String {
let char_count = value.chars().count();
if char_count <= max_chars {
return value.to_string();
}
let truncated: String = value.chars().take(max_chars.saturating_sub(3)).collect();
format!("{truncated}...")
}