mirror of
https://github.com/harivansh-afk/deskctl.git
synced 2026-04-15 06:04:41 +00:00
grouped runtime reads and waits selector modes (#5)
- grouped runtime reads and waits selector modes - Fix wait command client timeouts and test failures
This commit is contained in:
parent
cc8f8e548a
commit
a4cf9e32dd
12 changed files with 1323 additions and 77 deletions
|
|
@ -8,13 +8,13 @@ use deskctl::core::doctor;
|
|||
use deskctl::core::protocol::Request;
|
||||
|
||||
use self::support::{
|
||||
deskctl_tmp_screenshot_count, env_lock, successful_json_response, FixtureWindow,
|
||||
SessionEnvGuard, TestSession,
|
||||
deskctl_tmp_screenshot_count, env_lock_guard, json_response, successful_json_response,
|
||||
FixtureWindow, SessionEnvGuard, TestSession,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn doctor_reports_healthy_x11_environment() -> Result<()> {
|
||||
let _guard = env_lock().lock().unwrap();
|
||||
let _guard = env_lock_guard();
|
||||
let Some(_env) = SessionEnvGuard::prepare() else {
|
||||
eprintln!("Skipping X11 integration test because DISPLAY is not set");
|
||||
return Ok(());
|
||||
|
|
@ -46,7 +46,7 @@ fn doctor_reports_healthy_x11_environment() -> Result<()> {
|
|||
|
||||
#[test]
|
||||
fn list_windows_is_side_effect_free() -> Result<()> {
|
||||
let _guard = env_lock().lock().unwrap();
|
||||
let _guard = env_lock_guard();
|
||||
let Some(_env) = SessionEnvGuard::prepare() else {
|
||||
eprintln!("Skipping X11 integration test because DISPLAY is not set");
|
||||
return Ok(());
|
||||
|
|
@ -84,7 +84,7 @@ fn list_windows_is_side_effect_free() -> Result<()> {
|
|||
|
||||
#[test]
|
||||
fn daemon_start_recovers_from_stale_socket() -> Result<()> {
|
||||
let _guard = env_lock().lock().unwrap();
|
||||
let _guard = env_lock_guard();
|
||||
let Some(_env) = SessionEnvGuard::prepare() else {
|
||||
eprintln!("Skipping X11 integration test because DISPLAY is not set");
|
||||
return Ok(());
|
||||
|
|
@ -113,3 +113,123 @@ fn daemon_start_recovers_from_stale_socket() -> Result<()> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wait_window_returns_matched_window_payload() -> Result<()> {
|
||||
let _guard = env_lock_guard();
|
||||
let Some(_env) = SessionEnvGuard::prepare() else {
|
||||
eprintln!("Skipping X11 integration test because DISPLAY is not set");
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let title = "deskctl wait window test";
|
||||
let _window = FixtureWindow::create(title, "DeskctlWait")?;
|
||||
let session = TestSession::new("wait-window-success")?;
|
||||
let response = successful_json_response(session.run_cli([
|
||||
"--json",
|
||||
"wait",
|
||||
"window",
|
||||
"--selector",
|
||||
&format!("title={title}"),
|
||||
"--timeout",
|
||||
"1",
|
||||
"--poll-ms",
|
||||
"50",
|
||||
])?)?;
|
||||
|
||||
let window = response
|
||||
.get("data")
|
||||
.and_then(|data| data.get("window"))
|
||||
.expect("wait window should return a matched window");
|
||||
assert_eq!(
|
||||
window.get("title").and_then(|value| value.as_str()),
|
||||
Some(title)
|
||||
);
|
||||
assert_eq!(
|
||||
response
|
||||
.get("data")
|
||||
.and_then(|data| data.get("wait"))
|
||||
.and_then(|value| value.as_str()),
|
||||
Some("window")
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ambiguous_fuzzy_selector_returns_candidates() -> Result<()> {
|
||||
let _guard = env_lock_guard();
|
||||
let Some(_env) = SessionEnvGuard::prepare() else {
|
||||
eprintln!("Skipping X11 integration test because DISPLAY is not set");
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let _window_one = FixtureWindow::create("deskctl ambiguity alpha", "DeskctlAmbiguous")?;
|
||||
let _window_two = FixtureWindow::create("deskctl ambiguity beta", "DeskctlAmbiguous")?;
|
||||
let session = TestSession::new("selector-ambiguity")?;
|
||||
let output = session.run_cli(["--json", "focus", "ambiguity"])?;
|
||||
let response = json_response(&output)?;
|
||||
|
||||
assert!(!output.status.success());
|
||||
assert_eq!(
|
||||
response.get("success").and_then(|value| value.as_bool()),
|
||||
Some(false)
|
||||
);
|
||||
assert_eq!(
|
||||
response
|
||||
.get("data")
|
||||
.and_then(|data| data.get("kind"))
|
||||
.and_then(|value| value.as_str()),
|
||||
Some("selector_ambiguous")
|
||||
);
|
||||
assert!(response
|
||||
.get("data")
|
||||
.and_then(|data| data.get("candidates"))
|
||||
.and_then(|value| value.as_array())
|
||||
.map(|candidates| candidates.len() >= 2)
|
||||
.unwrap_or(false));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wait_focus_timeout_is_structured() -> Result<()> {
|
||||
let _guard = env_lock_guard();
|
||||
let Some(_env) = SessionEnvGuard::prepare() else {
|
||||
eprintln!("Skipping X11 integration test because DISPLAY is not set");
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let session = TestSession::new("wait-focus-timeout")?;
|
||||
let output = session.run_cli([
|
||||
"--json",
|
||||
"wait",
|
||||
"focus",
|
||||
"--selector",
|
||||
"title=missing-window-for-wait-focus",
|
||||
"--timeout",
|
||||
"1",
|
||||
"--poll-ms",
|
||||
"50",
|
||||
])?;
|
||||
let response = json_response(&output)?;
|
||||
|
||||
assert!(!output.status.success());
|
||||
assert_eq!(
|
||||
response
|
||||
.get("data")
|
||||
.and_then(|data| data.get("kind"))
|
||||
.and_then(|value| value.as_str()),
|
||||
Some("timeout")
|
||||
);
|
||||
assert_eq!(
|
||||
response
|
||||
.get("data")
|
||||
.and_then(|data| data.get("last_observation"))
|
||||
.and_then(|value| value.get("kind"))
|
||||
.and_then(|value| value.as_str()),
|
||||
Some("selector_not_found")
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue