mirror of
https://github.com/l0ng-ai/tty7.git
synced 2026-09-21 16:02:20 +00:00
fix(review): keep pane_procs's doc on pane_procs, round rtt before the unit
The new `link_rtt` landed between `pane_procs`'s doc comment and `pane_procs` itself, so the comment about walking pane process trees documented the latency probe instead. `format_rtt` also compared the unrounded milliseconds against 1000, so a 999.6 ms round trip printed as "1000 ms" — a millisecond reading past the range the millisecond branch exists to cover. Round first, then pick the unit. Claude-Session: https://claude.ai/code/session_01E4EPKzHg1fm9HMmHkUYpER
This commit is contained in:
@@ -253,10 +253,6 @@ impl Host for RemoteHost {
|
||||
})
|
||||
}
|
||||
|
||||
/// The peer owns these panes' PTYs, so it is the one that can walk their
|
||||
/// process trees. A peer that does not announce the feature is not asked:
|
||||
/// it would answer `Err` and the caller cannot tell that apart from a pane
|
||||
/// serving nothing.
|
||||
fn link_rtt(&self) -> Option<std::time::Duration> {
|
||||
// A ping of our own rather than whatever the keepalive last left
|
||||
// behind: that one only fires on an idle link, and a link being polled
|
||||
@@ -273,6 +269,10 @@ impl Host for RemoteHost {
|
||||
self.client.last_rtt()
|
||||
}
|
||||
|
||||
/// The peer owns these panes' PTYs, so it is the one that can walk their
|
||||
/// process trees. A peer that does not announce the feature is not asked:
|
||||
/// it would answer `Err` and the caller cannot tell that apart from a pane
|
||||
/// serving nothing.
|
||||
fn pane_procs(&self, pane_id: u64) -> Option<crate::daemon::protocol::PaneProcs> {
|
||||
if !self
|
||||
.peer()
|
||||
|
||||
@@ -278,8 +278,11 @@ fn format_rtt(rtt: std::time::Duration) -> String {
|
||||
// "0 ms" would read as a failed measurement rather than a fast one.
|
||||
return "<1 ms".to_string();
|
||||
}
|
||||
if ms < 1000. {
|
||||
return format!("{} ms", ms.round() as u64);
|
||||
// Rounded before the comparison, so 999.6 ms is not shown as "1000 ms" —
|
||||
// a millisecond reading that has run past the unit's own range.
|
||||
let rounded = ms.round() as u64;
|
||||
if rounded < 1000 {
|
||||
return format!("{rounded} ms");
|
||||
}
|
||||
format!("{:.1} s", rtt.as_secs_f64())
|
||||
}
|
||||
@@ -2006,6 +2009,9 @@ mod tests {
|
||||
assert_eq!(format_rtt(Duration::from_millis(1)), "1 ms");
|
||||
assert_eq!(format_rtt(Duration::from_micros(23_400)), "23 ms");
|
||||
assert_eq!(format_rtt(Duration::from_millis(999)), "999 ms");
|
||||
// Rounding up out of the millisecond's own range hands the number to
|
||||
// the unit above rather than printing a four-digit millisecond.
|
||||
assert_eq!(format_rtt(Duration::from_micros(999_600)), "1.0 s");
|
||||
// Past a second the millisecond has stopped carrying information, and
|
||||
// the second is the unit anyone would say the number in.
|
||||
assert_eq!(format_rtt(Duration::from_millis(1_450)), "1.4 s");
|
||||
|
||||
Reference in New Issue
Block a user