Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37632a96b7 | ||
|
|
e69be4fdf0 | ||
|
|
fdbd58b628 | ||
|
|
c65aba9d7a | ||
|
|
818b481154 |
Generated
+1
-1
@@ -436,7 +436,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dosh"
|
name = "dosh"
|
||||||
version = "1.0.0-rc32"
|
version = "1.0.0-rc36"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"base64",
|
"base64",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "dosh"
|
name = "dosh"
|
||||||
version = "1.0.0-rc32"
|
version = "1.0.0-rc36"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
|
|||||||
@@ -85,12 +85,14 @@ dosh trace --client-log /tmp/dosh-client.log HOST
|
|||||||
Summarize collected traces with:
|
Summarize collected traces with:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
dosh trace report --client-log /tmp/dosh-client.log
|
dosh trace report HOST --client-log /tmp/dosh-client.log
|
||||||
```
|
```
|
||||||
|
|
||||||
Set `DOSH_TRACE=/tmp/dosh-server.log` on `dosh-server` for matching server
|
When `HOST` is given, Dosh fetches `/tmp/dosh-server.log` over SSH before
|
||||||
events. Trace byte prefixes are enabled for `dosh trace`, so use it only for
|
building the report. Set `DOSH_TRACE=/tmp/dosh-server.log` on `dosh-server` for
|
||||||
short reproductions.
|
matching server events. Reports default to the latest traced client/server
|
||||||
|
process run; add `--all-runs` to include older appended log entries. Trace byte
|
||||||
|
prefixes are enabled for `dosh trace`, so use it only for short reproductions.
|
||||||
|
|
||||||
## VS Code
|
## VS Code
|
||||||
|
|
||||||
|
|||||||
+474
-68
@@ -71,9 +71,10 @@ const MAX_PENDING_USER_INPUT_BYTES: usize = 1024 * 1024;
|
|||||||
const STARTUP_INPUT_HOLD: Duration = Duration::from_millis(750);
|
const STARTUP_INPUT_HOLD: Duration = Duration::from_millis(750);
|
||||||
const POST_SUBMIT_ALL_INPUT_HOLD: Duration = Duration::from_millis(120);
|
const POST_SUBMIT_ALL_INPUT_HOLD: Duration = Duration::from_millis(120);
|
||||||
const STALE_TERMINAL_INPUT_AFTER: Duration = Duration::from_secs(2);
|
const STALE_TERMINAL_INPUT_AFTER: Duration = Duration::from_secs(2);
|
||||||
const POST_RECONNECT_STALE_INPUT_GRACE: Duration = Duration::from_secs(2);
|
const POST_RECONNECT_STALE_INPUT_GRACE: Duration = Duration::from_secs(5);
|
||||||
const FOCUS_REPAINT_COOLDOWN: Duration = Duration::from_secs(1);
|
const FOCUS_REPAINT_COOLDOWN: Duration = Duration::from_secs(1);
|
||||||
const ALT_SCREEN_IDLE_REPAINT_AFTER: Duration = Duration::from_secs(15);
|
const ALT_SCREEN_IDLE_REPAINT_AFTER: Duration = Duration::from_secs(15);
|
||||||
|
const LOCAL_SLEEP_REPAINT_AFTER: Duration = Duration::from_secs(5);
|
||||||
|
|
||||||
/// Sentinel `target_host` the server uses on a server-initiated `StreamOpen` that
|
/// Sentinel `target_host` the server uses on a server-initiated `StreamOpen` that
|
||||||
/// represents an SSH-agent connection (rather than a TCP target). The client
|
/// represents an SSH-agent connection (rather than a TCP target). The client
|
||||||
@@ -245,6 +246,10 @@ enum StartupGateMode {
|
|||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let mut args = Args::parse();
|
let mut args = Args::parse();
|
||||||
|
dosh::trace::event(
|
||||||
|
"client.start",
|
||||||
|
&[("version", dosh::build_info::VERSION.to_string())],
|
||||||
|
);
|
||||||
let config = load_client_config(None).unwrap_or_default();
|
let config = load_client_config(None).unwrap_or_default();
|
||||||
if args.server.as_deref() == Some("cp") {
|
if args.server.as_deref() == Some("cp") {
|
||||||
return run_cp_command(&config, &args);
|
return run_cp_command(&config, &args);
|
||||||
@@ -791,9 +796,11 @@ struct TraceOptions {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
struct TraceReportOptions {
|
struct TraceReportOptions {
|
||||||
|
host: Option<String>,
|
||||||
client_log: Option<PathBuf>,
|
client_log: Option<PathBuf>,
|
||||||
server_log: Option<PathBuf>,
|
server_log: Option<String>,
|
||||||
tail: usize,
|
tail: usize,
|
||||||
|
latest_run: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
||||||
@@ -801,6 +808,8 @@ struct TraceReport {
|
|||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
total_lines: usize,
|
total_lines: usize,
|
||||||
parsed_lines: usize,
|
parsed_lines: usize,
|
||||||
|
skipped_old_run_lines: usize,
|
||||||
|
latest_run_filtered: bool,
|
||||||
first_ts_ms: Option<u128>,
|
first_ts_ms: Option<u128>,
|
||||||
last_ts_ms: Option<u128>,
|
last_ts_ms: Option<u128>,
|
||||||
events: BTreeMap<String, usize>,
|
events: BTreeMap<String, usize>,
|
||||||
@@ -818,6 +827,7 @@ struct TraceReport {
|
|||||||
sent_input_events: usize,
|
sent_input_events: usize,
|
||||||
pty_write_events: usize,
|
pty_write_events: usize,
|
||||||
reconnect_events: usize,
|
reconnect_events: usize,
|
||||||
|
unknown_resume_events: usize,
|
||||||
roam_events: usize,
|
roam_events: usize,
|
||||||
recent_events: VecDeque<String>,
|
recent_events: VecDeque<String>,
|
||||||
}
|
}
|
||||||
@@ -887,15 +897,17 @@ fn parse_trace_options(command: &[String]) -> Result<TraceOptions> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_trace_report_options(command: &[String]) -> Result<TraceReportOptions> {
|
fn parse_trace_report_options(command: &[String]) -> Result<TraceReportOptions> {
|
||||||
|
let mut host: Option<String> = None;
|
||||||
let mut client_log: Option<PathBuf> = None;
|
let mut client_log: Option<PathBuf> = None;
|
||||||
let mut server_log: Option<PathBuf> = Some(PathBuf::from("/tmp/dosh-server.log"));
|
let mut server_log: Option<String> = Some("/tmp/dosh-server.log".to_string());
|
||||||
let mut tail = 20usize;
|
let mut tail = 20usize;
|
||||||
|
let mut latest_run = true;
|
||||||
let mut index = 0usize;
|
let mut index = 0usize;
|
||||||
while index < command.len() {
|
while index < command.len() {
|
||||||
match command[index].as_str() {
|
match command[index].as_str() {
|
||||||
"--client-log" => {
|
"--client-log" => {
|
||||||
let path = command.get(index + 1).ok_or_else(|| {
|
let path = command.get(index + 1).ok_or_else(|| {
|
||||||
anyhow!("usage: dosh trace report [--client-log PATH] [--server-log PATH|none] [--tail N]")
|
anyhow!("usage: dosh trace report [HOST] [--client-log PATH] [--server-log PATH|none] [--latest-run|--all-runs] [--tail N]")
|
||||||
})?;
|
})?;
|
||||||
client_log = Some(expand_tilde(path));
|
client_log = Some(expand_tilde(path));
|
||||||
index += 2;
|
index += 2;
|
||||||
@@ -910,7 +922,7 @@ fn parse_trace_report_options(command: &[String]) -> Result<TraceReportOptions>
|
|||||||
}
|
}
|
||||||
"--server-log" => {
|
"--server-log" => {
|
||||||
let path = command.get(index + 1).ok_or_else(|| {
|
let path = command.get(index + 1).ok_or_else(|| {
|
||||||
anyhow!("usage: dosh trace report [--client-log PATH] [--server-log PATH|none] [--tail N]")
|
anyhow!("usage: dosh trace report [HOST] [--client-log PATH] [--server-log PATH|none] [--latest-run|--all-runs] [--tail N]")
|
||||||
})?;
|
})?;
|
||||||
server_log = parse_optional_trace_path(path);
|
server_log = parse_optional_trace_path(path);
|
||||||
index += 2;
|
index += 2;
|
||||||
@@ -926,9 +938,17 @@ fn parse_trace_report_options(command: &[String]) -> Result<TraceReportOptions>
|
|||||||
server_log = None;
|
server_log = None;
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
|
"--latest-run" => {
|
||||||
|
latest_run = true;
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
"--all-runs" => {
|
||||||
|
latest_run = false;
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
"--tail" => {
|
"--tail" => {
|
||||||
let value = command.get(index + 1).ok_or_else(|| {
|
let value = command.get(index + 1).ok_or_else(|| {
|
||||||
anyhow!("usage: dosh trace report [--client-log PATH] [--server-log PATH|none] [--tail N]")
|
anyhow!("usage: dosh trace report [HOST] [--client-log PATH] [--server-log PATH|none] [--latest-run|--all-runs] [--tail N]")
|
||||||
})?;
|
})?;
|
||||||
tail = parse_trace_tail(value)?;
|
tail = parse_trace_tail(value)?;
|
||||||
index += 2;
|
index += 2;
|
||||||
@@ -940,25 +960,36 @@ fn parse_trace_report_options(command: &[String]) -> Result<TraceReportOptions>
|
|||||||
tail = parse_trace_tail(value)?;
|
tail = parse_trace_tail(value)?;
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
value => {
|
value if value.starts_with('-') => {
|
||||||
return Err(anyhow!(
|
return Err(anyhow!(
|
||||||
"usage: dosh trace report [--client-log PATH] [--server-log PATH|none] [--tail N] (unknown option {value})"
|
"usage: dosh trace report [HOST] [--client-log PATH] [--server-log PATH|none] [--latest-run|--all-runs] [--tail N] (unknown option {value})"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
value => {
|
||||||
|
if host.is_some() {
|
||||||
|
return Err(anyhow!(
|
||||||
|
"usage: dosh trace report [HOST] [--client-log PATH] [--server-log PATH|none] [--latest-run|--all-runs] [--tail N]"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
host = Some(value.to_string());
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(TraceReportOptions {
|
Ok(TraceReportOptions {
|
||||||
|
host,
|
||||||
client_log,
|
client_log,
|
||||||
server_log,
|
server_log,
|
||||||
tail,
|
tail,
|
||||||
|
latest_run,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_optional_trace_path(value: &str) -> Option<PathBuf> {
|
fn parse_optional_trace_path(value: &str) -> Option<String> {
|
||||||
if matches!(value, "" | "none" | "off" | "0") {
|
if matches!(value, "" | "none" | "off" | "0") {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(expand_tilde(value))
|
Some(value.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1005,7 +1036,8 @@ fn sanitize_trace_name(value: &str) -> String {
|
|||||||
|
|
||||||
fn run_trace_command(args: &Args) -> Result<()> {
|
fn run_trace_command(args: &Args) -> Result<()> {
|
||||||
if args.command.first().is_some_and(|value| value == "report") {
|
if args.command.first().is_some_and(|value| value == "report") {
|
||||||
return run_trace_report_command(&args.command[1..]);
|
let config = load_client_config(None).unwrap_or_default();
|
||||||
|
return run_trace_report_command(&config, args, &args.command[1..]);
|
||||||
}
|
}
|
||||||
let options = parse_trace_options(&args.command)?;
|
let options = parse_trace_options(&args.command)?;
|
||||||
if let Some(parent) = options.client_log.parent() {
|
if let Some(parent) = options.client_log.parent() {
|
||||||
@@ -1041,7 +1073,11 @@ fn run_trace_command(args: &Args) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_trace_report_command(command: &[String]) -> Result<()> {
|
fn run_trace_report_command(
|
||||||
|
config: &dosh::config::ClientConfig,
|
||||||
|
args: &Args,
|
||||||
|
command: &[String],
|
||||||
|
) -> Result<()> {
|
||||||
let options = parse_trace_report_options(command)?;
|
let options = parse_trace_report_options(command)?;
|
||||||
let client_log = match options.client_log {
|
let client_log = match options.client_log {
|
||||||
Some(path) => Some(path),
|
Some(path) => Some(path),
|
||||||
@@ -1049,7 +1085,7 @@ fn run_trace_report_command(command: &[String]) -> Result<()> {
|
|||||||
};
|
};
|
||||||
println!("Dosh trace report");
|
println!("Dosh trace report");
|
||||||
if let Some(path) = client_log {
|
if let Some(path) = client_log {
|
||||||
match summarize_trace_file(&path, options.tail) {
|
match summarize_trace_file_for_report(&path, options.tail, options.latest_run) {
|
||||||
Ok(report) => print_trace_report("client", &report),
|
Ok(report) => print_trace_report("client", &report),
|
||||||
Err(err) => println!("[warn] client log {}: {err:#}", path.display()),
|
Err(err) => println!("[warn] client log {}: {err:#}", path.display()),
|
||||||
}
|
}
|
||||||
@@ -1060,7 +1096,21 @@ fn run_trace_report_command(command: &[String]) -> Result<()> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if let Some(path) = options.server_log {
|
if let Some(path) = options.server_log {
|
||||||
match summarize_trace_file(&path, options.tail) {
|
let server_log = if let Some(host) = options.host.as_deref() {
|
||||||
|
match fetch_trace_server_log(config, args, host, &path) {
|
||||||
|
Ok(path) => Some(path),
|
||||||
|
Err(err) => {
|
||||||
|
println!("[warn] server log {host}:{path}: {err:#}");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Some(expand_tilde(&path))
|
||||||
|
};
|
||||||
|
let Some(path) = server_log else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
match summarize_trace_file_for_report(&path, options.tail, options.latest_run) {
|
||||||
Ok(report) => print_trace_report("server", &report),
|
Ok(report) => print_trace_report("server", &report),
|
||||||
Err(err)
|
Err(err)
|
||||||
if err
|
if err
|
||||||
@@ -1075,6 +1125,66 @@ fn run_trace_report_command(command: &[String]) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn fetch_trace_server_log(
|
||||||
|
config: &dosh::config::ClientConfig,
|
||||||
|
args: &Args,
|
||||||
|
requested: &str,
|
||||||
|
remote_log: &str,
|
||||||
|
) -> Result<PathBuf> {
|
||||||
|
let hosts = load_hosts_config(None).unwrap_or_default();
|
||||||
|
let host_config = hosts.hosts.get(requested).cloned().unwrap_or_default();
|
||||||
|
let server = status_ssh_target(requested, &host_config);
|
||||||
|
let ssh_port = args.ssh_port.or(host_config.ssh_port).or(config.ssh_port);
|
||||||
|
if is_local_status_target(&server) {
|
||||||
|
return Ok(expand_tilde(remote_log));
|
||||||
|
}
|
||||||
|
let local_path = fetched_trace_server_log_path(requested);
|
||||||
|
if let Some(parent) = local_path.parent() {
|
||||||
|
fs::create_dir_all(parent)
|
||||||
|
.with_context(|| format!("create trace log directory {}", parent.to_string_lossy()))?;
|
||||||
|
}
|
||||||
|
let mut command = Command::new("ssh");
|
||||||
|
if let Some(ssh_port) = ssh_port {
|
||||||
|
command.arg("-p").arg(ssh_port.to_string());
|
||||||
|
}
|
||||||
|
command.arg("-T");
|
||||||
|
if let Some(key) = args.ssh_key.as_deref() {
|
||||||
|
command.arg("-i").arg(key);
|
||||||
|
}
|
||||||
|
if let Some(known_hosts) = args.ssh_known_hosts.as_deref() {
|
||||||
|
command
|
||||||
|
.arg("-o")
|
||||||
|
.arg(format!("UserKnownHostsFile={}", known_hosts.display()));
|
||||||
|
}
|
||||||
|
let script = format!("test -r {0} && cat {0}", shell_word(remote_log));
|
||||||
|
let output = command
|
||||||
|
.arg(&server)
|
||||||
|
.arg(format!("sh -c {}", shell_word(&script)))
|
||||||
|
.output()
|
||||||
|
.with_context(|| format!("fetch server trace log from {server}"))?;
|
||||||
|
anyhow::ensure!(
|
||||||
|
output.status.success(),
|
||||||
|
"{}",
|
||||||
|
String::from_utf8_lossy(&output.stderr)
|
||||||
|
);
|
||||||
|
fs::write(&local_path, &output.stdout)
|
||||||
|
.with_context(|| format!("write fetched server trace {}", local_path.display()))?;
|
||||||
|
Ok(local_path)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fetched_trace_server_log_path(host: &str) -> PathBuf {
|
||||||
|
let now = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.map(|duration| duration.as_secs())
|
||||||
|
.unwrap_or(0);
|
||||||
|
trace_cache_dir().join(format!(
|
||||||
|
"server-{}-{}-{}.log",
|
||||||
|
sanitize_trace_name(host),
|
||||||
|
now,
|
||||||
|
std::process::id()
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
fn trace_cache_dir() -> PathBuf {
|
fn trace_cache_dir() -> PathBuf {
|
||||||
dirs::cache_dir()
|
dirs::cache_dir()
|
||||||
.unwrap_or_else(|| expand_tilde("~/.cache"))
|
.unwrap_or_else(|| expand_tilde("~/.cache"))
|
||||||
@@ -1119,17 +1229,56 @@ fn newest_client_trace_path() -> Result<Option<PathBuf>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn summarize_trace_file(path: &Path, tail: usize) -> Result<TraceReport> {
|
fn summarize_trace_file(path: &Path, tail: usize) -> Result<TraceReport> {
|
||||||
|
summarize_trace_file_with_mode(path, tail, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn summarize_trace_file_for_report(
|
||||||
|
path: &Path,
|
||||||
|
tail: usize,
|
||||||
|
latest_run: bool,
|
||||||
|
) -> Result<TraceReport> {
|
||||||
|
if latest_run {
|
||||||
|
summarize_trace_file(path, tail)
|
||||||
|
} else {
|
||||||
|
summarize_trace_file_with_mode(path, tail, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn summarize_trace_file_with_mode(
|
||||||
|
path: &Path,
|
||||||
|
tail: usize,
|
||||||
|
latest_run: bool,
|
||||||
|
) -> Result<TraceReport> {
|
||||||
let file = File::open(path).with_context(|| format!("open trace log {}", path.display()))?;
|
let file = File::open(path).with_context(|| format!("open trace log {}", path.display()))?;
|
||||||
let mut report = TraceReport {
|
let mut parsed = Vec::new();
|
||||||
path: path.to_path_buf(),
|
let mut file_lines = 0usize;
|
||||||
..TraceReport::default()
|
|
||||||
};
|
|
||||||
for line in BufReader::new(file).lines() {
|
for line in BufReader::new(file).lines() {
|
||||||
let line = line?;
|
let line = line?;
|
||||||
report.total_lines += 1;
|
file_lines += 1;
|
||||||
let Some(fields) = parse_trace_line(&line) else {
|
if let Some(fields) = parse_trace_line(&line) {
|
||||||
continue;
|
parsed.push(fields);
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
let latest_run_start = if latest_run {
|
||||||
|
parsed.iter().rposition(|fields| {
|
||||||
|
fields
|
||||||
|
.get("event")
|
||||||
|
.is_some_and(|event| trace_run_marker(event))
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
let parsed_len = parsed.len();
|
||||||
|
let skipped_old_run_lines = latest_run_start.unwrap_or(0);
|
||||||
|
let latest_run_filtered = latest_run_start.is_some_and(|index| index > 0);
|
||||||
|
let mut report = TraceReport {
|
||||||
|
path: path.to_path_buf(),
|
||||||
|
total_lines: file_lines.saturating_sub(skipped_old_run_lines),
|
||||||
|
skipped_old_run_lines,
|
||||||
|
latest_run_filtered,
|
||||||
|
..TraceReport::default()
|
||||||
|
};
|
||||||
|
for fields in parsed.into_iter().skip(skipped_old_run_lines) {
|
||||||
report.parsed_lines += 1;
|
report.parsed_lines += 1;
|
||||||
if let Some(ts) = fields
|
if let Some(ts) = fields
|
||||||
.get("ts_ms")
|
.get("ts_ms")
|
||||||
@@ -1192,6 +1341,9 @@ fn summarize_trace_file(path: &Path, tail: usize) -> Result<TraceReport> {
|
|||||||
if event.contains("reconnect") || event.contains("resume") {
|
if event.contains("reconnect") || event.contains("resume") {
|
||||||
report.reconnect_events += 1;
|
report.reconnect_events += 1;
|
||||||
}
|
}
|
||||||
|
if event == "server.resume_unknown_client" {
|
||||||
|
report.unknown_resume_events += 1;
|
||||||
|
}
|
||||||
if event.contains("roam") {
|
if event.contains("roam") {
|
||||||
report.roam_events += 1;
|
report.roam_events += 1;
|
||||||
}
|
}
|
||||||
@@ -1203,12 +1355,21 @@ fn summarize_trace_file(path: &Path, tail: usize) -> Result<TraceReport> {
|
|||||||
report.recent_events.push_back(rendered);
|
report.recent_events.push_back(rendered);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if report.total_lines == 0 && parsed_len > 0 {
|
||||||
|
report.total_lines = parsed_len;
|
||||||
|
}
|
||||||
Ok(report)
|
Ok(report)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_trace_report(label: &str, report: &TraceReport) {
|
fn print_trace_report(label: &str, report: &TraceReport) {
|
||||||
println!();
|
println!();
|
||||||
println!("{label}: {}", report.path.display());
|
println!("{label}: {}", report.path.display());
|
||||||
|
if report.latest_run_filtered {
|
||||||
|
println!(
|
||||||
|
" latest_run=true skipped_old_lines={}",
|
||||||
|
report.skipped_old_run_lines
|
||||||
|
);
|
||||||
|
}
|
||||||
println!(
|
println!(
|
||||||
" lines={} parsed={} span_ms={}",
|
" lines={} parsed={} span_ms={}",
|
||||||
report.total_lines,
|
report.total_lines,
|
||||||
@@ -1239,8 +1400,8 @@ fn print_trace_report(label: &str, report: &TraceReport) {
|
|||||||
report.hex_events
|
report.hex_events
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
" reconnect: events={} roam={}",
|
" reconnect: events={} unknown_resume={} roam={}",
|
||||||
report.reconnect_events, report.roam_events
|
report.reconnect_events, report.unknown_resume_events, report.roam_events
|
||||||
);
|
);
|
||||||
for warning in trace_report_warnings(report) {
|
for warning in trace_report_warnings(report) {
|
||||||
println!(" alert: {warning}");
|
println!(" alert: {warning}");
|
||||||
@@ -1261,6 +1422,12 @@ fn print_trace_report(label: &str, report: &TraceReport) {
|
|||||||
|
|
||||||
fn trace_report_warnings(report: &TraceReport) -> Vec<String> {
|
fn trace_report_warnings(report: &TraceReport) -> Vec<String> {
|
||||||
let mut warnings = Vec::new();
|
let mut warnings = Vec::new();
|
||||||
|
if report.unknown_resume_events > 0 {
|
||||||
|
warnings.push(format!(
|
||||||
|
"{} unknown live resume event(s); ticket reattach should follow after server restart",
|
||||||
|
report.unknown_resume_events
|
||||||
|
));
|
||||||
|
}
|
||||||
if report.server_mouseish_pty_write_events > 0 {
|
if report.server_mouseish_pty_write_events > 0 {
|
||||||
warnings.push(format!(
|
warnings.push(format!(
|
||||||
"{} mouse-like input event(s) reached the server PTY",
|
"{} mouse-like input event(s) reached the server PTY",
|
||||||
@@ -1291,6 +1458,10 @@ fn trace_report_warnings(report: &TraceReport) -> Vec<String> {
|
|||||||
warnings
|
warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn trace_run_marker(event: &str) -> bool {
|
||||||
|
matches!(event, "client.start" | "server.start")
|
||||||
|
}
|
||||||
|
|
||||||
fn top_trace_events(events: &BTreeMap<String, usize>, limit: usize) -> Vec<(String, usize)> {
|
fn top_trace_events(events: &BTreeMap<String, usize>, limit: usize) -> Vec<(String, usize)> {
|
||||||
let mut entries: Vec<_> = events
|
let mut entries: Vec<_> = events
|
||||||
.iter()
|
.iter()
|
||||||
@@ -5506,6 +5677,7 @@ async fn run_terminal(
|
|||||||
let mut last_terminal_frame_at = Instant::now();
|
let mut last_terminal_frame_at = Instant::now();
|
||||||
let mut last_focus_repaint_at = Instant::now() - FOCUS_REPAINT_COOLDOWN;
|
let mut last_focus_repaint_at = Instant::now() - FOCUS_REPAINT_COOLDOWN;
|
||||||
let mut last_idle_repaint_attempt_at = Instant::now() - ALT_SCREEN_IDLE_REPAINT_AFTER;
|
let mut last_idle_repaint_attempt_at = Instant::now() - ALT_SCREEN_IDLE_REPAINT_AFTER;
|
||||||
|
let mut last_status_tick_at = Instant::now();
|
||||||
if let Some(frame) = first_frame {
|
if let Some(frame) = first_frame {
|
||||||
if !forward_only {
|
if !forward_only {
|
||||||
render_frame(&frame)?;
|
render_frame(&frame)?;
|
||||||
@@ -5573,8 +5745,62 @@ async fn run_terminal(
|
|||||||
dosh::trace::event("client.escape", &[]);
|
dosh::trace::event("client.escape", &[]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
let input_status_tick_gap = last_status_tick_at.elapsed();
|
||||||
|
let mut refreshed_before_input = false;
|
||||||
|
if should_reconnect_before_input_for_local_sleep(
|
||||||
|
forward_only,
|
||||||
|
input_status_tick_gap,
|
||||||
|
) {
|
||||||
|
dosh::trace::event(
|
||||||
|
"client.local_sleep_input_reconnect_start",
|
||||||
|
&[(
|
||||||
|
"tick_gap_ms",
|
||||||
|
input_status_tick_gap.as_millis().to_string(),
|
||||||
|
)],
|
||||||
|
);
|
||||||
|
last_status_tick_at = Instant::now();
|
||||||
|
arm_stale_terminal_input_suppression(
|
||||||
|
&mut stale_terminal_input_suppress_until,
|
||||||
|
);
|
||||||
|
if let Some(frame) = reconnect(
|
||||||
|
&socket,
|
||||||
|
&mut cred,
|
||||||
|
&mut send_seq,
|
||||||
|
last_size,
|
||||||
|
&mut frame_buffer,
|
||||||
|
&mut predictor,
|
||||||
|
)
|
||||||
|
.await?
|
||||||
|
{
|
||||||
|
dosh::trace::event(
|
||||||
|
"client.local_sleep_input_reconnect_ok",
|
||||||
|
&[
|
||||||
|
("output_seq", frame.output_seq.to_string()),
|
||||||
|
("bytes", frame.bytes.len().to_string()),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
refresh_live_addr(&mut addr, &cred)?;
|
||||||
|
render_frame(&frame)?;
|
||||||
|
predictor.observe_output(&frame.bytes);
|
||||||
|
last_terminal_frame_at = Instant::now();
|
||||||
|
last_packet_at = Instant::now();
|
||||||
|
last_focus_repaint_at = Instant::now();
|
||||||
|
refreshed_before_input = true;
|
||||||
|
flush_pending_user_input(
|
||||||
|
&socket,
|
||||||
|
addr,
|
||||||
|
&cred,
|
||||||
|
&mut send_seq,
|
||||||
|
&mut predictor,
|
||||||
|
&mut pending_user_input,
|
||||||
|
&mut pending_user_input_bytes,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
let saw_focus_in = input_contains_focus_in(&bytes);
|
let saw_focus_in = input_contains_focus_in(&bytes);
|
||||||
if !forward_only
|
if !forward_only
|
||||||
|
&& !refreshed_before_input
|
||||||
&& saw_focus_in
|
&& saw_focus_in
|
||||||
&& last_focus_repaint_at.elapsed() >= FOCUS_REPAINT_COOLDOWN
|
&& last_focus_repaint_at.elapsed() >= FOCUS_REPAINT_COOLDOWN
|
||||||
{
|
{
|
||||||
@@ -5634,22 +5860,22 @@ async fn run_terminal(
|
|||||||
if bytes.is_empty() {
|
if bytes.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if should_strip_unowned_terminal_reports(
|
let before_mouse_strip = bytes.len();
|
||||||
|
let (stripped_bytes, stripped_unowned_mouse) = strip_unowned_terminal_reports(
|
||||||
|
bytes,
|
||||||
predictor.alternate_screen,
|
predictor.alternate_screen,
|
||||||
predictor.mouse_tracking,
|
predictor.mouse_tracking,
|
||||||
) {
|
);
|
||||||
let before_mouse_strip = bytes.len();
|
bytes = stripped_bytes;
|
||||||
bytes = strip_stale_mouse_reports(&bytes);
|
if stripped_unowned_mouse {
|
||||||
if before_mouse_strip != bytes.len() {
|
dosh::trace::event(
|
||||||
dosh::trace::event(
|
"client.unowned_mouse_stripped",
|
||||||
"client.unowned_mouse_stripped",
|
&[
|
||||||
&[
|
("before", before_mouse_strip.to_string()),
|
||||||
("before", before_mouse_strip.to_string()),
|
("after", bytes.len().to_string()),
|
||||||
("after", bytes.len().to_string()),
|
("summary", dosh::trace::bytes_summary(&bytes)),
|
||||||
("summary", dosh::trace::bytes_summary(&bytes)),
|
],
|
||||||
],
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
if bytes.is_empty() {
|
if bytes.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -6488,6 +6714,10 @@ async fn run_terminal(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = status_tick.tick() => {
|
_ = status_tick.tick() => {
|
||||||
|
let status_tick_at = Instant::now();
|
||||||
|
let status_tick_gap = status_tick_at.duration_since(last_status_tick_at);
|
||||||
|
last_status_tick_at = status_tick_at;
|
||||||
|
let mut repainted_this_tick = false;
|
||||||
let stale = last_packet_at.elapsed();
|
let stale = last_packet_at.elapsed();
|
||||||
if stale >= Duration::from_secs(reconnect_timeout_secs.max(1)) {
|
if stale >= Duration::from_secs(reconnect_timeout_secs.max(1)) {
|
||||||
if let Some(frame) = reconnect(
|
if let Some(frame) = reconnect(
|
||||||
@@ -6508,6 +6738,8 @@ async fn run_terminal(
|
|||||||
render_frame(&frame)?;
|
render_frame(&frame)?;
|
||||||
predictor.observe_output(&frame.bytes);
|
predictor.observe_output(&frame.bytes);
|
||||||
last_terminal_frame_at = Instant::now();
|
last_terminal_frame_at = Instant::now();
|
||||||
|
last_idle_repaint_attempt_at = Instant::now();
|
||||||
|
repainted_this_tick = true;
|
||||||
}
|
}
|
||||||
last_packet_at = Instant::now();
|
last_packet_at = Instant::now();
|
||||||
flush_pending_user_input(
|
flush_pending_user_input(
|
||||||
@@ -6550,13 +6782,22 @@ async fn run_terminal(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
if should_repaint_idle_alternate_screen(
|
if !repainted_this_tick && should_repaint_idle_terminal(
|
||||||
predictor.alternate_screen,
|
predictor.alternate_screen,
|
||||||
last_terminal_frame_at,
|
last_terminal_frame_at,
|
||||||
last_idle_repaint_attempt_at,
|
last_idle_repaint_attempt_at,
|
||||||
|
status_tick_gap,
|
||||||
now,
|
now,
|
||||||
) {
|
) {
|
||||||
last_idle_repaint_attempt_at = now;
|
last_idle_repaint_attempt_at = now;
|
||||||
|
dosh::trace::event(
|
||||||
|
"client.idle_repaint_start",
|
||||||
|
&[
|
||||||
|
("alt", predictor.alternate_screen.to_string()),
|
||||||
|
("tick_gap_ms", status_tick_gap.as_millis().to_string()),
|
||||||
|
("silent_ms", stale.as_millis().to_string()),
|
||||||
|
],
|
||||||
|
);
|
||||||
if let Some(frame) = reconnect(
|
if let Some(frame) = reconnect(
|
||||||
&socket,
|
&socket,
|
||||||
&mut cred,
|
&mut cred,
|
||||||
@@ -6979,10 +7220,31 @@ fn should_strip_stale_terminal_reports(
|
|||||||
|| suppress_until.is_some_and(|deadline| Instant::now() < deadline)
|
|| suppress_until.is_some_and(|deadline| Instant::now() < deadline)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn should_reconnect_before_input_for_local_sleep(
|
||||||
|
forward_only: bool,
|
||||||
|
status_tick_gap: Duration,
|
||||||
|
) -> bool {
|
||||||
|
!forward_only && status_tick_gap >= LOCAL_SLEEP_REPAINT_AFTER
|
||||||
|
}
|
||||||
|
|
||||||
fn should_strip_unowned_terminal_reports(alternate_screen: bool, mouse_tracking: bool) -> bool {
|
fn should_strip_unowned_terminal_reports(alternate_screen: bool, mouse_tracking: bool) -> bool {
|
||||||
!alternate_screen && !mouse_tracking
|
!alternate_screen && !mouse_tracking
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn strip_unowned_terminal_reports(
|
||||||
|
bytes: Vec<u8>,
|
||||||
|
alternate_screen: bool,
|
||||||
|
mouse_tracking: bool,
|
||||||
|
) -> (Vec<u8>, bool) {
|
||||||
|
if !should_strip_unowned_terminal_reports(alternate_screen, mouse_tracking) {
|
||||||
|
return (bytes, false);
|
||||||
|
}
|
||||||
|
let before = bytes.len();
|
||||||
|
let stripped = strip_stale_mouse_reports(&bytes);
|
||||||
|
let changed = stripped.len() != before;
|
||||||
|
(stripped, changed)
|
||||||
|
}
|
||||||
|
|
||||||
fn input_contains_focus_in(bytes: &[u8]) -> bool {
|
fn input_contains_focus_in(bytes: &[u8]) -> bool {
|
||||||
contains_bytes(bytes, b"\x1b[I") || contains_bytes(bytes, b"\x9bI")
|
contains_bytes(bytes, b"\x1b[I") || contains_bytes(bytes, b"\x9bI")
|
||||||
}
|
}
|
||||||
@@ -7007,19 +7269,28 @@ fn strip_terminal_focus_reports(bytes: &[u8]) -> Vec<u8> {
|
|||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_repaint_idle_alternate_screen(
|
fn should_repaint_idle_terminal(
|
||||||
alternate_screen: bool,
|
alternate_screen: bool,
|
||||||
last_terminal_frame_at: Instant,
|
last_terminal_frame_at: Instant,
|
||||||
last_attempt_at: Instant,
|
last_attempt_at: Instant,
|
||||||
|
status_tick_gap: Duration,
|
||||||
now: Instant,
|
now: Instant,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
alternate_screen
|
(alternate_screen
|
||||||
&& now.duration_since(last_terminal_frame_at) >= ALT_SCREEN_IDLE_REPAINT_AFTER
|
&& now.duration_since(last_terminal_frame_at) >= ALT_SCREEN_IDLE_REPAINT_AFTER
|
||||||
|
|| status_tick_gap >= LOCAL_SLEEP_REPAINT_AFTER)
|
||||||
&& now.duration_since(last_attempt_at) >= ALT_SCREEN_IDLE_REPAINT_AFTER
|
&& now.duration_since(last_attempt_at) >= ALT_SCREEN_IDLE_REPAINT_AFTER
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arm_stale_terminal_input_suppression(suppress_until: &mut Option<Instant>) {
|
fn arm_stale_terminal_input_suppression(suppress_until: &mut Option<Instant>) {
|
||||||
*suppress_until = Some(Instant::now() + POST_RECONNECT_STALE_INPUT_GRACE);
|
*suppress_until = Some(Instant::now() + POST_RECONNECT_STALE_INPUT_GRACE);
|
||||||
|
dosh::trace::event(
|
||||||
|
"client.stale_terminal_quarantine_arm",
|
||||||
|
&[(
|
||||||
|
"grace_ms",
|
||||||
|
POST_RECONNECT_STALE_INPUT_GRACE.as_millis().to_string(),
|
||||||
|
)],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn flush_pending_user_input(
|
async fn flush_pending_user_input(
|
||||||
@@ -8958,29 +9229,31 @@ const TERMINAL_CLEANUP: &[u8] = concat!(
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::{
|
use super::{
|
||||||
ALT_SCREEN_IDLE_REPAINT_AFTER, CachedCredential, DisconnectStatus, DynamicForward,
|
ALT_SCREEN_IDLE_REPAINT_AFTER, CachedCredential, DisconnectStatus, DynamicForward,
|
||||||
FRAME_GAP_RESYNC_AFTER_MS, FrameBuffer, LocalForward, MAX_PENDING_USER_INPUT_BYTES,
|
FRAME_GAP_RESYNC_AFTER_MS, FrameBuffer, LOCAL_SLEEP_REPAINT_AFTER, LocalForward,
|
||||||
NativeIdentityContext, POST_SUBMIT_ALL_INPUT_HOLD, PendingStreamOpen, PredictMode,
|
MAX_PENDING_USER_INPUT_BYTES, NativeIdentityContext, POST_RECONNECT_STALE_INPUT_GRACE,
|
||||||
Predictor, RESTART_STATUS_SCRIPT, RemoteForward, STARTUP_INPUT_HOLD, SshConfig,
|
POST_SUBMIT_ALL_INPUT_HOLD, PendingStreamOpen, PredictMode, Predictor,
|
||||||
SshPathTokenContext, StartupGateMode, StatusAction, UpdateOptions, UpdateRole, auth_allows,
|
RESTART_STATUS_SCRIPT, RemoteForward, STARTUP_INPUT_HOLD, SshConfig, SshPathTokenContext,
|
||||||
cache_key, cache_server_prefix, cleanup_stream_state, clear_cached_credentials,
|
StartupGateMode, StatusAction, UpdateOptions, UpdateRole, auth_allows, cache_key,
|
||||||
|
cache_server_prefix, cleanup_stream_state, clear_cached_credentials,
|
||||||
ensure_tui_safe_status_overlay, expand_ssh_path_tokens, input_contains_focus_in,
|
ensure_tui_safe_status_overlay, expand_ssh_path_tokens, input_contains_focus_in,
|
||||||
input_matches_escape, is_local_status_target, is_resume_response_for_client,
|
input_matches_escape, is_local_status_target, is_resume_response_for_client,
|
||||||
latest_release_download_url, load_first_native_identity_with_prompt,
|
latest_release_download_url, load_first_native_identity_with_prompt,
|
||||||
native_proxy_udp_warning, parse_dynamic_forward, parse_escape_key, parse_local_forward,
|
native_proxy_udp_warning, parse_dynamic_forward, parse_escape_key, parse_local_forward,
|
||||||
parse_remote_forward, parse_ssh_config, parse_trace_line, parse_trace_options,
|
parse_remote_forward, parse_ssh_config, parse_trace_line, parse_trace_options,
|
||||||
parse_trace_report_options, parse_trace_summary, parse_update_options,
|
parse_trace_report_options, parse_trace_summary, parse_update_options,
|
||||||
post_submit_hold_duration, queue_pending_user_input, raw_contains_host_table,
|
post_submit_hold_duration, queue_pending_user_input, queue_stale_pending_user_input,
|
||||||
recv_response_until, refresh_live_addr, release_tag_download_url,
|
raw_contains_host_table, recv_response_until, refresh_live_addr, release_tag_download_url,
|
||||||
release_tag_from_effective_url, release_version_from_tag, render_status_clear,
|
release_tag_from_effective_url, release_version_from_tag, render_status_clear,
|
||||||
render_status_overlay, requested_env, resolved_startup_command, retire_stream_state,
|
render_status_overlay, requested_env, resolved_startup_command, retire_stream_state,
|
||||||
retransmit_stream_opens, rewrite_forward_command, sanitize_trace_name,
|
retransmit_stream_opens, rewrite_forward_command, sanitize_trace_name,
|
||||||
selected_predict_mode, selected_udp_host, server_version_mismatch,
|
selected_predict_mode, selected_udp_host, server_version_mismatch,
|
||||||
should_flush_terminal_input_after_contact, should_hold_during_startup_gate,
|
should_flush_terminal_input_after_contact, should_hold_during_startup_gate,
|
||||||
should_hold_post_submit_input, should_repaint_idle_alternate_screen,
|
should_hold_post_submit_input, should_reconnect_before_input_for_local_sleep,
|
||||||
should_strip_unowned_terminal_reports, split_after_command_submit, split_trace_tokens,
|
should_repaint_idle_terminal, should_strip_unowned_terminal_reports,
|
||||||
ssh_command_target, ssh_config_uses_proxy, ssh_destination_host, ssh_username,
|
split_after_command_submit, split_trace_tokens, ssh_command_target, ssh_config_uses_proxy,
|
||||||
ssh_with_user, startup_command, status_ssh_target, strip_stale_mouse_reports,
|
ssh_destination_host, ssh_username, ssh_with_user, startup_command, status_ssh_target,
|
||||||
strip_terminal_focus_reports, summarize_trace_file, terminal_private_mode_transition,
|
strip_stale_mouse_reports, strip_terminal_focus_reports, strip_unowned_terminal_reports,
|
||||||
|
summarize_trace_file, summarize_trace_file_with_mode, terminal_private_mode_transition,
|
||||||
toml_bare_key_or_quoted, top_trace_events, trace_report_warnings, unix_update_script,
|
toml_bare_key_or_quoted, top_trace_events, trace_report_warnings, unix_update_script,
|
||||||
update_installer_url, update_version_status, upsert_managed_block, valid_forward_host,
|
update_installer_url, update_version_status, upsert_managed_block, valid_forward_host,
|
||||||
vscode_safe_alias, windows_update_script,
|
vscode_safe_alias, windows_update_script,
|
||||||
@@ -10290,27 +10563,38 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn trace_report_options_parse_defaults_and_overrides() {
|
fn trace_report_options_parse_defaults_and_overrides() {
|
||||||
let parsed = parse_trace_report_options(&[]).unwrap();
|
let parsed = parse_trace_report_options(&[]).unwrap();
|
||||||
|
assert_eq!(parsed.host, None);
|
||||||
assert_eq!(parsed.client_log, None);
|
assert_eq!(parsed.client_log, None);
|
||||||
assert_eq!(
|
assert_eq!(parsed.server_log, Some("/tmp/dosh-server.log".to_string()));
|
||||||
parsed.server_log,
|
|
||||||
Some(std::path::PathBuf::from("/tmp/dosh-server.log"))
|
|
||||||
);
|
|
||||||
assert_eq!(parsed.tail, 20);
|
assert_eq!(parsed.tail, 20);
|
||||||
|
assert!(parsed.latest_run);
|
||||||
|
|
||||||
let parsed = parse_trace_report_options(&[
|
let parsed = parse_trace_report_options(&[
|
||||||
|
"palav".to_string(),
|
||||||
"--client-log=/tmp/client.log".to_string(),
|
"--client-log=/tmp/client.log".to_string(),
|
||||||
"--server-log".to_string(),
|
"--server-log".to_string(),
|
||||||
"none".to_string(),
|
"/tmp/server.log".to_string(),
|
||||||
|
"--all-runs".to_string(),
|
||||||
"--tail".to_string(),
|
"--tail".to_string(),
|
||||||
"3".to_string(),
|
"3".to_string(),
|
||||||
])
|
])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
assert_eq!(parsed.host.as_deref(), Some("palav"));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parsed.client_log,
|
parsed.client_log,
|
||||||
Some(std::path::PathBuf::from("/tmp/client.log"))
|
Some(std::path::PathBuf::from("/tmp/client.log"))
|
||||||
);
|
);
|
||||||
assert_eq!(parsed.server_log, None);
|
assert_eq!(parsed.server_log.as_deref(), Some("/tmp/server.log"));
|
||||||
assert_eq!(parsed.tail, 3);
|
assert_eq!(parsed.tail, 3);
|
||||||
|
assert!(!parsed.latest_run);
|
||||||
|
|
||||||
|
let parsed = parse_trace_report_options(&[
|
||||||
|
"--server-log=none".to_string(),
|
||||||
|
"--latest-run".to_string(),
|
||||||
|
])
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(parsed.server_log, None);
|
||||||
|
assert!(parsed.latest_run);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -10421,6 +10705,35 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn trace_report_defaults_to_latest_process_run_when_marker_exists() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
let path = dir.path().join("server.log");
|
||||||
|
fs::write(
|
||||||
|
&path,
|
||||||
|
concat!(
|
||||||
|
"ts_ms=10 pid=1 event=server.pty_write session=term seq=1 summary=len=12,esc=false,focus=false,mouseish=true,printable=12\n",
|
||||||
|
"ts_ms=20 pid=2 event=server.start version=1.0.0 bind=0.0.0.0:50000\n",
|
||||||
|
"ts_ms=21 pid=2 event=server.resume_start seq=2 ack=1\n",
|
||||||
|
"ts_ms=22 pid=2 event=server.resume_ok bytes=20\n",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let latest = summarize_trace_file(&path, 10).unwrap();
|
||||||
|
assert!(latest.latest_run_filtered);
|
||||||
|
assert_eq!(latest.skipped_old_run_lines, 1);
|
||||||
|
assert_eq!(latest.total_lines, 3);
|
||||||
|
assert_eq!(latest.server_mouseish_pty_write_events, 0);
|
||||||
|
assert_eq!(latest.reconnect_events, 2);
|
||||||
|
|
||||||
|
let all = summarize_trace_file_with_mode(&path, 10, false).unwrap();
|
||||||
|
assert!(!all.latest_run_filtered);
|
||||||
|
assert_eq!(all.skipped_old_run_lines, 0);
|
||||||
|
assert_eq!(all.total_lines, 4);
|
||||||
|
assert_eq!(all.server_mouseish_pty_write_events, 1);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn update_installer_uses_platform_native_script() {
|
fn update_installer_uses_platform_native_script() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@@ -10817,6 +11130,47 @@ mod tests {
|
|||||||
assert_eq!(pending_bytes, MAX_PENDING_USER_INPUT_BYTES);
|
assert_eq!(pending_bytes, MAX_PENDING_USER_INPUT_BYTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn stale_pending_user_input_is_marked_for_mouse_stripping() {
|
||||||
|
let mut pending = VecDeque::new();
|
||||||
|
let mut pending_bytes = 0usize;
|
||||||
|
|
||||||
|
queue_pending_user_input(&mut pending, &mut pending_bytes, b"\x1b[<35;10;1M".to_vec())
|
||||||
|
.unwrap();
|
||||||
|
queue_stale_pending_user_input(
|
||||||
|
&mut pending,
|
||||||
|
&mut pending_bytes,
|
||||||
|
b"\x1b[<35;11;1M".to_vec(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let normal = pending.pop_front().unwrap();
|
||||||
|
assert!(!normal.strip_mouse_reports);
|
||||||
|
assert_eq!(strip_stale_mouse_reports(&normal.bytes), b"");
|
||||||
|
|
||||||
|
let stale = pending.pop_front().unwrap();
|
||||||
|
assert!(stale.strip_mouse_reports);
|
||||||
|
assert_eq!(strip_stale_mouse_reports(&stale.bytes), b"");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unowned_terminal_mouse_reports_strip_only_without_mouse_owner() {
|
||||||
|
let input = b"\x1b[<35;10;1Mcmd\r".to_vec();
|
||||||
|
|
||||||
|
let (stripped, changed) = strip_unowned_terminal_reports(input.clone(), false, false);
|
||||||
|
assert!(changed);
|
||||||
|
assert_eq!(stripped, b"cmd\r");
|
||||||
|
|
||||||
|
let (preserved, changed) = strip_unowned_terminal_reports(input.clone(), false, true);
|
||||||
|
assert!(!changed);
|
||||||
|
assert_eq!(preserved, input);
|
||||||
|
|
||||||
|
let (preserved, changed) =
|
||||||
|
strip_unowned_terminal_reports(b"\x1b[<35;10;1M".to_vec(), true, false);
|
||||||
|
assert!(!changed);
|
||||||
|
assert_eq!(preserved, b"\x1b[<35;10;1M");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn transient_udp_send_errors_are_not_terminal_fatal() {
|
fn transient_udp_send_errors_are_not_terminal_fatal() {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
@@ -10924,22 +11278,74 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn idle_repaint_only_runs_for_stale_alternate_screen() {
|
fn idle_repaint_runs_for_stale_alternate_screen_or_sleep_gap() {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let stale = now - ALT_SCREEN_IDLE_REPAINT_AFTER - Duration::from_secs(1);
|
let stale = now - ALT_SCREEN_IDLE_REPAINT_AFTER - Duration::from_secs(1);
|
||||||
let recent = now - Duration::from_secs(1);
|
let recent = now - Duration::from_secs(1);
|
||||||
assert!(should_repaint_idle_alternate_screen(
|
assert!(should_repaint_idle_terminal(
|
||||||
true, stale, stale, now
|
true,
|
||||||
|
stale,
|
||||||
|
stale,
|
||||||
|
Duration::from_secs(1),
|
||||||
|
now
|
||||||
));
|
));
|
||||||
assert!(!should_repaint_idle_alternate_screen(
|
assert!(should_repaint_idle_terminal(
|
||||||
false, stale, stale, now
|
false,
|
||||||
|
recent,
|
||||||
|
stale,
|
||||||
|
LOCAL_SLEEP_REPAINT_AFTER + Duration::from_secs(1),
|
||||||
|
now
|
||||||
));
|
));
|
||||||
assert!(!should_repaint_idle_alternate_screen(
|
assert!(!should_repaint_idle_terminal(
|
||||||
true, recent, stale, now
|
false,
|
||||||
|
stale,
|
||||||
|
stale,
|
||||||
|
Duration::from_secs(1),
|
||||||
|
now
|
||||||
));
|
));
|
||||||
assert!(!should_repaint_idle_alternate_screen(
|
assert!(!should_repaint_idle_terminal(
|
||||||
true, stale, recent, now
|
true,
|
||||||
|
recent,
|
||||||
|
stale,
|
||||||
|
Duration::from_secs(1),
|
||||||
|
now
|
||||||
));
|
));
|
||||||
|
assert!(!should_repaint_idle_terminal(
|
||||||
|
true,
|
||||||
|
stale,
|
||||||
|
recent,
|
||||||
|
LOCAL_SLEEP_REPAINT_AFTER + Duration::from_secs(1),
|
||||||
|
now
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn local_sleep_gap_reconnects_before_forwarding_input() {
|
||||||
|
assert!(should_reconnect_before_input_for_local_sleep(
|
||||||
|
false,
|
||||||
|
LOCAL_SLEEP_REPAINT_AFTER
|
||||||
|
));
|
||||||
|
assert!(should_reconnect_before_input_for_local_sleep(
|
||||||
|
false,
|
||||||
|
LOCAL_SLEEP_REPAINT_AFTER + Duration::from_secs(10)
|
||||||
|
));
|
||||||
|
assert!(!should_reconnect_before_input_for_local_sleep(
|
||||||
|
false,
|
||||||
|
LOCAL_SLEEP_REPAINT_AFTER - Duration::from_millis(1)
|
||||||
|
));
|
||||||
|
assert!(!should_reconnect_before_input_for_local_sleep(
|
||||||
|
true,
|
||||||
|
LOCAL_SLEEP_REPAINT_AFTER + Duration::from_secs(10)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn reconnect_mouse_quarantine_is_long_enough_for_sleep_wake_noise() {
|
||||||
|
assert!(POST_RECONNECT_STALE_INPUT_GRACE >= LOCAL_SLEEP_REPAINT_AFTER);
|
||||||
|
assert_eq!(
|
||||||
|
strip_stale_mouse_reports(b"35;152;1M\x1b[A35;149;1M"),
|
||||||
|
b"\x1b[A"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -200,6 +200,13 @@ async fn serve(config_path: Option<std::path::PathBuf>) -> Result<()> {
|
|||||||
.with_context(|| format!("bind {bind}"))?,
|
.with_context(|| format!("bind {bind}"))?,
|
||||||
);
|
);
|
||||||
eprintln!("dosh-server listening on {bind}");
|
eprintln!("dosh-server listening on {bind}");
|
||||||
|
dosh::trace::event(
|
||||||
|
"server.start",
|
||||||
|
&[
|
||||||
|
("version", dosh::build_info::VERSION.to_string()),
|
||||||
|
("bind", bind.clone()),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
let (pty_tx, mut pty_rx) = mpsc::unbounded_channel();
|
let (pty_tx, mut pty_rx) = mpsc::unbounded_channel();
|
||||||
let state = Arc::new(Mutex::new(ServerState::new(
|
let state = Arc::new(Mutex::new(ServerState::new(
|
||||||
|
|||||||
Reference in New Issue
Block a user