aboutsummaryrefslogtreecommitdiff
path: root/tests/detach_reattach.rs
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-09-01 15:48:22 +0300
committerGitHub <noreply@github.com>2026-09-01 15:48:22 +0300
commit207be3c771d281baae6e5fa0fb74be9a056e97a2 (patch)
treed7b037ecdf629224a048c841d11659efdc23507d /tests/detach_reattach.rs
parent8a6d697308162874a236c84aac0b0f8c7ac01f83 (diff)
refactor: render the shell in the client (#3487)
* feat: add opt-in client-rendered shell * feat: add client-owned shell mouse controls * feat: complete client-owned shell chrome * feat: add client-owned shell settings and notifications * feat: run client shell custom commands * feat: render popup terminals in client shell * feat: add client-owned scrollback and copy mode * fix: preserve client worktree trust defaults * feat: render startup diagnostics in client shell * feat: render onboarding in client shell * feat: render product announcements in client shell * feat: render release notes in client shell * feat: render mobile switcher in client shell * feat: render kitty graphics in client shell * fix: preserve client shell lifecycle coherence * refactor: route client shell commands through endpoint connections * refactor: make the client-rendered shell the default * refactor: remove monolithic launch mode * refactor: complete client-rendered shell cutover * perf: retain client pane surface updates * perf: scale retained pane surface updates * perf: remove remote pane input latency * test: make client shell checks platform-independent * fix: prevent client timer starvation * test: fix client shell platform gates * test: accept retained surfaces in cross-area checks * test: make client mode assertions platform-neutral * fix: badge only outdated integrations
Diffstat (limited to 'tests/detach_reattach.rs')
-rw-r--r--tests/detach_reattach.rs210
1 files changed, 43 insertions, 167 deletions
diff --git a/tests/detach_reattach.rs b/tests/detach_reattach.rs
index 4461a17b..f570e979 100644
--- a/tests/detach_reattach.rs
+++ b/tests/detach_reattach.rs
@@ -1,7 +1,7 @@
//! Integration tests for detach/reattach flow.
//!
-mod support;
+pub mod support;
use std::fs;
use std::io::{BufRead, BufReader, Write};
@@ -14,9 +14,9 @@ use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
use portable_pty::{native_pty_system, Child, CommandBuilder, MasterPty, PtySize};
use serde_json::Value;
use support::{
- cleanup_test_base, client_handshake, drain_messages, read_server_message, register_runtime_dir,
- register_spawned_herdr_pid, send_detach, send_input, unregister_spawned_herdr_pid,
- wait_for_disconnect, wait_for_message_variant, wait_for_socket, wait_until, CURRENT_PROTOCOL,
+ cleanup_test_base, client_shell_handshake, drain_messages, register_runtime_dir,
+ register_spawned_herdr_pid, send_detach, unregister_spawned_herdr_pid, wait_for_disconnect,
+ wait_for_socket, wait_until, CURRENT_PROTOCOL,
};
const CUSTOM_HEADLESS_SIZE_CONFIG: &str = r#"onboarding = false
@@ -280,72 +280,6 @@ fn first_pane_id(response: &Value) -> String {
// ---------------------------------------------------------------------------
#[test]
-fn navigate_q_detaches_client_and_server_persists() {
- // In persistence mode, navigate-mode q detaches the client and the server persists.
- // Flow:
- // 1. Start server
- // 2. Connect client, handshake
- // 3. Send prefix key (Ctrl+B) then 'q'
- // 4. Verify server is still alive via API ping
- // 5. Verify the client connection is closed
- let _lock = test_lock();
- let base = unique_test_dir();
- let config_home = base.join("config");
- let runtime_dir = base.join("runtime");
- let api_socket = runtime_dir.join("herdr.sock");
- let client_socket = runtime_dir.join("herdr-client.sock");
-
- let spawned = spawn_server(&config_home, &runtime_dir, &api_socket, &client_socket);
- wait_for_socket(&api_socket, Duration::from_secs(10));
- wait_for_socket(&client_socket, Duration::from_secs(10));
-
- // Connect and handshake.
- let mut stream = UnixStream::connect(&client_socket).expect("should connect to client socket");
- let (version, error) =
- client_handshake(&mut stream, CURRENT_PROTOCOL, 80, 24).expect("handshake should succeed");
- assert_eq!(version, CURRENT_PROTOCOL);
- assert!(error.is_none(), "{:?}", error);
-
- // Drain initial frames.
- drain_messages(&mut stream);
-
- // Send prefix key (Ctrl+B = 0x02) then 'q' (quit/detach in persistence mode).
- send_input(&mut stream, &[0x02]).expect("send prefix");
-
- // Drain any frames generated by entering navigate mode.
- drain_messages(&mut stream);
-
- send_input(&mut stream, b"q").expect("send detach key");
-
- assert!(
- wait_until(Duration::from_secs(2), Duration::from_millis(25), || {
- ping_socket(&api_socket).contains("pong")
- }),
- "server should still respond to ping after client detach"
- );
-
- // Verify server is still alive and responsive.
- let response = ping_socket(&api_socket);
- assert!(
- response.contains("pong"),
- "server should still respond to ping after client detach: {response}"
- );
-
- // The client should receive a ServerShutdown with reason "detached"
- // shortly after the quit/detach key. There may be some frames in
- // between from the mode change, so we read multiple messages.
- let got_shutdown = wait_for_message_variant(&mut stream, Duration::from_secs(2), 2)
- .expect("wait for shutdown message")
- || wait_for_disconnect(&mut stream, Duration::from_secs(1)).expect("wait for disconnect");
- assert!(
- got_shutdown,
- "client should receive ServerShutdown after quit/detach key"
- );
-
- cleanup_spawned_herdr(spawned, base);
-}
-
-#[test]
fn explicit_detach_message_causes_clean_disconnect() {
// Client sends ClientMessage::Detach
// directly (not via keybind), server handles it gracefully.
@@ -363,8 +297,8 @@ fn explicit_detach_message_causes_clean_disconnect() {
// Connect and handshake.
let mut stream = UnixStream::connect(&client_socket).expect("should connect");
- let (version, error) =
- client_handshake(&mut stream, CURRENT_PROTOCOL, 80, 24).expect("handshake should succeed");
+ let (version, error) = client_shell_handshake(&mut stream, CURRENT_PROTOCOL, 80, 24)
+ .expect("handshake should succeed");
assert_eq!(version, CURRENT_PROTOCOL);
assert!(error.is_none(), "{:?}", error);
@@ -422,7 +356,7 @@ fn reattach_after_detach_shows_current_state() {
// --- Client A ---
let mut stream_a = UnixStream::connect(&client_socket).expect("client A should connect");
- let (version, error) = client_handshake(&mut stream_a, CURRENT_PROTOCOL, 80, 24)
+ let (version, error) = client_shell_handshake(&mut stream_a, CURRENT_PROTOCOL, 80, 24)
.expect("handshake should succeed");
assert_eq!(version, CURRENT_PROTOCOL);
assert!(error.is_none(), "{:?}", error);
@@ -461,7 +395,7 @@ fn reattach_after_detach_shows_current_state() {
// --- Client B (reattach) ---
let mut stream_b = UnixStream::connect(&client_socket).expect("client B should connect");
- let (version, error) = client_handshake(&mut stream_b, CURRENT_PROTOCOL, 80, 24)
+ let (version, error) = client_shell_handshake(&mut stream_b, CURRENT_PROTOCOL, 80, 24)
.expect("handshake should succeed");
assert_eq!(version, CURRENT_PROTOCOL);
assert!(
@@ -470,31 +404,10 @@ fn reattach_after_detach_shows_current_state() {
error
);
- // Client B should receive a frame with the current state,
+ // Client B receives the client-owned shell projection.
// including the workspace created while client A was attached.
- stream_b.set_nonblocking(false).unwrap();
- stream_b
- .set_read_timeout(Some(Duration::from_secs(5)))
- .unwrap();
-
- let mut received_frame = false;
- let deadline = Instant::now() + Duration::from_secs(5);
- while Instant::now() < deadline {
- match read_server_message(&mut stream_b) {
- Ok((variant, _payload)) => {
- if variant == 1 {
- // ServerMessage::Frame
- received_frame = true;
- break;
- }
- }
- Err(_) => break,
- }
- }
- assert!(
- received_frame,
- "reattached client should receive a Frame with current state"
- );
+ support::wait_for_client_shell_bootstrap(&mut stream_b, Duration::from_secs(5))
+ .expect("client shell bootstrap");
// Verify the workspace still exists via API.
let mut list_stream = UnixStream::connect(&api_socket).expect("connect to API");
@@ -541,19 +454,29 @@ fn processes_survive_during_and_after_detach() {
// Connect and handshake.
let mut stream = UnixStream::connect(&client_socket).expect("should connect");
- let (version, error) =
- client_handshake(&mut stream, CURRENT_PROTOCOL, 80, 24).expect("handshake should succeed");
+ let (version, error) = client_shell_handshake(&mut stream, CURRENT_PROTOCOL, 80, 24)
+ .expect("handshake should succeed");
assert_eq!(version, CURRENT_PROTOCOL);
assert!(error.is_none(), "{:?}", error);
// Drain initial frames.
drain_messages(&mut stream);
- // Send input to the pane — the fresh server should have at least one
- // pane with a shell running.
- send_input(&mut stream, b"echo SURVIVED_DETACH\n").expect("send echo command");
+ // Drive the pane through the JSON API; the shell transport carries only
+ // client-composed UI state, not legacy raw shell input.
+ let created = workspace_create(&api_socket, "process-survival");
+ let pane_id = created["result"]["root_pane"]["pane_id"]
+ .as_str()
+ .expect("root pane id")
+ .to_string();
+ pane_send_text(&api_socket, &pane_id, "echo SURVIVED_DETACH\n");
+ assert!(wait_until(
+ Duration::from_secs(5),
+ Duration::from_millis(50),
+ || pane_read_recent_text(&api_socket, &pane_id).contains("SURVIVED_DETACH")
+ ));
- // Drain any frames generated by the input.
+ // Drain any shell projection updates.
drain_messages(&mut stream);
// Detach the client via explicit Detach message.
@@ -580,32 +503,14 @@ fn processes_survive_during_and_after_detach() {
// Reattach — verify we can connect and receive a frame.
let mut stream_b = UnixStream::connect(&client_socket).expect("should reattach");
- let (version, error) = client_handshake(&mut stream_b, CURRENT_PROTOCOL, 80, 24)
+ let (version, error) = client_shell_handshake(&mut stream_b, CURRENT_PROTOCOL, 80, 24)
.expect("reattach handshake should succeed");
assert_eq!(version, CURRENT_PROTOCOL);
assert!(error.is_none(), "{:?}", error);
// Verify the reattached client receives a frame.
- stream_b
- .set_read_timeout(Some(Duration::from_secs(5)))
- .unwrap();
- let mut received_frame = false;
- let deadline = Instant::now() + Duration::from_secs(5);
- while Instant::now() < deadline {
- match read_server_message(&mut stream_b) {
- Ok((variant, _)) => {
- if variant == 1 {
- received_frame = true;
- break;
- }
- }
- Err(_) => break,
- }
- }
- assert!(
- received_frame,
- "reattached client should receive a Frame showing current state"
- );
+ support::wait_for_client_shell_bootstrap(&mut stream_b, Duration::from_secs(5))
+ .expect("client shell bootstrap");
cleanup_spawned_herdr(spawned, base);
}
@@ -629,8 +534,8 @@ fn server_persists_after_client_connection_drop() {
// Connect and handshake.
let mut stream = UnixStream::connect(&client_socket).expect("should connect");
- let (version, error) =
- client_handshake(&mut stream, CURRENT_PROTOCOL, 80, 24).expect("handshake should succeed");
+ let (version, error) = client_shell_handshake(&mut stream, CURRENT_PROTOCOL, 80, 24)
+ .expect("handshake should succeed");
assert_eq!(version, CURRENT_PROTOCOL);
assert!(error.is_none(), "{:?}", error);
@@ -656,7 +561,7 @@ fn server_persists_after_client_connection_drop() {
// Reattach — verify we can connect and handshake again.
let mut stream_b = UnixStream::connect(&client_socket).expect("should reattach");
- let (version, error) = client_handshake(&mut stream_b, CURRENT_PROTOCOL, 80, 24)
+ let (version, error) = client_shell_handshake(&mut stream_b, CURRENT_PROTOCOL, 80, 24)
.expect("reattach handshake should succeed");
assert_eq!(version, CURRENT_PROTOCOL);
assert!(error.is_none(), "reattach should succeed: {:?}", error);
@@ -723,11 +628,12 @@ fn pane_created_after_detach_uses_configured_headless_size() {
wait_for_socket(&client_socket, Duration::from_secs(10));
let mut stream = UnixStream::connect(&client_socket).expect("client should connect");
- let (version, error) =
- client_handshake(&mut stream, CURRENT_PROTOCOL, 160, 50).expect("handshake should succeed");
+ let (version, error) = client_shell_handshake(&mut stream, CURRENT_PROTOCOL, 160, 50)
+ .expect("handshake should succeed");
assert_eq!(version, CURRENT_PROTOCOL);
assert!(error.is_none(), "{error:?}");
- drain_messages(&mut stream);
+ support::wait_for_client_shell_bootstrap(&mut stream, Duration::from_secs(5))
+ .expect("client shell bootstrap");
let first = workspace_create(&api_socket, "attached-size");
let first_pane_id = first["result"]["root_pane"]["pane_id"]
@@ -787,8 +693,8 @@ fn detached_output_preserves_last_attached_pty_size() {
wait_for_socket(&client_socket, Duration::from_secs(10));
let mut stream = UnixStream::connect(&client_socket).expect("client should connect");
- let (version, error) =
- client_handshake(&mut stream, CURRENT_PROTOCOL, 120, 40).expect("handshake should succeed");
+ let (version, error) = client_shell_handshake(&mut stream, CURRENT_PROTOCOL, 120, 40)
+ .expect("handshake should succeed");
assert_eq!(version, CURRENT_PROTOCOL);
assert!(error.is_none(), "{:?}", error);
drain_messages(&mut stream);
@@ -856,7 +762,7 @@ fn output_accumulated_while_detached_visible_on_reattach() {
// Connect and handshake client A.
let mut stream_a = UnixStream::connect(&client_socket).expect("client A should connect");
- let (version, error) = client_handshake(&mut stream_a, CURRENT_PROTOCOL, 80, 24)
+ let (version, error) = client_shell_handshake(&mut stream_a, CURRENT_PROTOCOL, 80, 24)
.expect("handshake should succeed");
assert_eq!(version, CURRENT_PROTOCOL);
assert!(error.is_none(), "{:?}", error);
@@ -914,44 +820,14 @@ fn output_accumulated_while_detached_visible_on_reattach() {
// --- Client B (reattach) ---
let mut stream_b = UnixStream::connect(&client_socket).expect("client B should connect");
- let (version, error) = client_handshake(&mut stream_b, CURRENT_PROTOCOL, 80, 24)
+ let (version, error) = client_shell_handshake(&mut stream_b, CURRENT_PROTOCOL, 80, 24)
.expect("reattach handshake should succeed");
assert_eq!(version, CURRENT_PROTOCOL);
assert!(error.is_none(), "{:?}", error);
// Client B should receive a frame with the current state.
- stream_b
- .set_read_timeout(Some(Duration::from_secs(5)))
- .unwrap();
- let mut received_frame = false;
- let deadline = Instant::now() + Duration::from_secs(5);
- while Instant::now() < deadline {
- match read_server_message(&mut stream_b) {
- Ok((variant, _)) => {
- if variant == 1 {
- received_frame = true;
- break;
- }
- }
- Err(_) => break,
- }
- }
- assert!(
- received_frame,
- "reattached client should receive a Frame showing current state"
- );
-
- // Verify the pane content via API includes the output sent while detached.
- let read_response = pane_read_recent(&api_socket, &pane_id);
-
- // The pane output should contain the text sent while detached.
- assert!(
- read_response["result"]["read"]["text"]
- .as_str()
- .unwrap_or_default()
- .contains("DURING_DETACH"),
- "pane should contain output produced while detached: {read_response}"
- );
+ support::wait_for_client_shell_bootstrap(&mut stream_b, Duration::from_secs(5))
+ .expect("client shell bootstrap");
cleanup_spawned_herdr(spawned, base);
}