From 06bd8d984bf1a08097b4e372482625197651dc33 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 23:00:46 -0600 Subject: [PATCH] =?UTF-8?q?test(id):=20prove=20#796=20item=209-6=20?= =?UTF-8?q?=E2=80=94=20SSH=20window=5Fchange=20refits=20shell=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a_window_change_refits_the_shell_view_to_the_new_size (drafted on #796 from task 6509): a fixed 4x2 screen program served over the SSH test harness shows fully at 80x24, then a window-change to 2x1 refits the view to just the first two cells of row one. The ssh feature compiles on current main (render_ansi_diff visibility fixed by #4681; russh 0.65 auth_publickey signature checks clean), so the #3962 gate for this test is cleared. Test-only; no production code changed. --- pkgs/id/src/world_ssh.rs | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/pkgs/id/src/world_ssh.rs b/pkgs/id/src/world_ssh.rs index c806b160b6..ad22b0094f 100644 --- a/pkgs/id/src/world_ssh.rs +++ b/pkgs/id/src/world_ssh.rs @@ -3255,6 +3255,71 @@ mod tests { server.abort(); } + /// Proving test for tracker #796 item 9-6: an SSH `window-change` + /// request must reach the session as a resize and refit the shell view + /// to the new viewport size (drafted on #796 from task 6509; landed once + /// the ssh feature compiled again after #3962). + /// A program whose view is one fixed 4x2 ASCII screen. + struct FixedScreenSsh; + + impl crate::world::WorldProgram for FixedScreenSsh { + fn view( + &mut self, + _viewer: &crate::world::Participant, + ) -> anyhow::Result> { + Ok(Some( + r#"{"kind":"screen","version":1,"width":4,"height":2,"rows":["abcd","wxyz"]}"# + .to_owned(), + )) + } + } + + #[tokio::test] + async fn a_window_change_refits_the_shell_view_to_the_new_size() { + let world = WorldHandle::spawn_with_program( + WorldCore::new("lobby", WorldLimits::default()).unwrap(), + Box::new(FixedScreenSsh), + ); + let (_, capability) = world + .issue( + "player".to_owned(), + crate::world::WorldScopes::from_names(["join", "input"]).unwrap(), + ) + .await + .unwrap(); + let hub = WorldHub::single(WorldService::new(world, Some("admin".to_owned()))); + let (port, server) = start(hub).await; + let session = connect(port, capability.expose()).await; + let mut channel = shell(&session).await; + let mut terminal = vt100::Parser::new(24, 80, 0); + // The pty opens at 80x24, so the whole 4x2 screen is shown first. + read_until(&mut channel, &mut terminal, "wxyz").await; + assert!(terminal.screen().contents().contains("abcd")); + + // A terminal window change must reach the session as a resize and + // refit the view: 2x1 keeps only the first two cells of row one. + channel.window_change(2, 1, 0, 0).await.unwrap(); + tokio::time::timeout(Duration::from_secs(10), async { + loop { + let contents = terminal.screen().contents(); + if contents.contains("ab") && !contents.contains("wxyz") { + break; + } + match channel.wait().await { + Some(ChannelMsg::Data { data }) => terminal.process(&data), + Some(_) => {} + None => panic!("shell closed before the refitted view"), + } + } + }) + .await + .expect("timed out waiting for the refitted view"); + let contents = terminal.screen().contents(); + assert!(contents.contains("ab"), "{contents:?}"); + assert!(!contents.contains("cd"), "{contents:?}"); + server.abort(); + } + #[cfg(feature = "sandbox")] #[tokio::test] async fn a_shell_plays_the_world_in_command_mode_using_input_command() {