A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
feat(import): choose the machine to import from and mark imported sessions
RoversXeeb97f7492cc
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftlindex a60cc0fa..146e96cc 100644--- a/thinkterm-i18n/i18n/de-DE.ftl+++ b/thinkterm-i18n/i18n/de-DE.ftl@@ -1095,6 +1095,12 @@ session-import-notes-title = Hinweise zum Importsession-import-location-local = Importziel: dieser Computersession-import-location-remote = Importziel: { $host } · die Prozesse bleiben auf diesem Serversession-import-requirements-remote = Verwenden Sie eine Sitzung des Kontos der Remoteverbindung. Terminals und Arbeitsverzeichnisse bleiben auf diesem Server.+session-import-hosts = Von welchem Rechner importieren+session-import-host-local = Dieser Computer+session-import-host-connected = Verbunden+session-import-host-disconnected = Nicht verbunden · wird bei Auswahl verbunden+session-import-imported = Importiert+session-import-already-imported = Diese Sitzung wurde bereits in { $name } importiert. Ein erneuter Import erstellt einen weiteren Space.session-import-check-result = Importergebnis prüfensession-import-still-running = Der Import läuft noch auf dem Zielrechner. Prüfen Sie das Ergebnis später erneut.diff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftlindex ce2cad5d..cc7ba04e 100644--- a/thinkterm-i18n/i18n/en-US.ftl+++ b/thinkterm-i18n/i18n/en-US.ftl@@ -1095,6 +1095,12 @@ session-import-notes-title = Import notessession-import-location-local = Import location: this computersession-import-location-remote = Import location: { $host } · remote processes stay on this serversession-import-requirements-remote = Use a session owned by the remote connection’s account. Terminals and working directories stay on that server.+session-import-hosts = Which machine to import from+session-import-host-local = This computer+session-import-host-connected = Connected+session-import-host-disconnected = Not connected · connects when chosen+session-import-imported = Imported+session-import-already-imported = This session was already imported into { $name }. Importing it again creates another Space.session-import-check-result = Check import resultsession-import-still-running = The import is still running on the target. Check again to retrieve its result.diff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftlindex 70ec3c34..aa435e01 100644--- a/thinkterm-i18n/i18n/fr-FR.ftl+++ b/thinkterm-i18n/i18n/fr-FR.ftl@@ -1092,6 +1092,12 @@ session-import-notes-title = À savoir avant l’importationsession-import-location-local = Emplacement de l’importation : cet ordinateursession-import-location-remote = Emplacement de l’importation : { $host } · les processus restent sur ce serveursession-import-requirements-remote = Utilisez une session appartenant au compte de la connexion distante. Les terminaux et leurs répertoires de travail restent sur ce serveur.+session-import-hosts = Machine d’où importer+session-import-host-local = Cet ordinateur+session-import-host-connected = Connecté+session-import-host-disconnected = Non connecté · connexion lors du choix+session-import-imported = Importé+session-import-already-imported = Cette session a déjà été importée dans { $name }. L’importer à nouveau crée un autre espace.session-import-check-result = Vérifier le résultatsession-import-still-running = L’importation est toujours en cours sur la machine cible. Vérifiez à nouveau son résultat dans un instant.diff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftlindex a94d4e78..d1db39f2 100644--- a/thinkterm-i18n/i18n/ja-JP.ftl+++ b/thinkterm-i18n/i18n/ja-JP.ftl@@ -1073,6 +1073,12 @@ session-import-notes-title = インポートの注意事項session-import-location-local = インポート先:このコンピュータsession-import-location-remote = インポート先:{ $host } · リモートプロセスはこのサーバーで実行を続けますsession-import-requirements-remote = リモート接続のアカウントが所有するセッションを使用してください。端末プロセスと作業ディレクトリはサーバーに残ります。+session-import-hosts = インポート元のマシン+session-import-host-local = このコンピュータ+session-import-host-connected = 接続済み+session-import-host-disconnected = 未接続 · 選択すると接続します+session-import-imported = インポート済み+session-import-already-imported = このセッションは { $name } にインポート済みです。もう一度インポートすると別の Space が作成されます。session-import-check-result = インポート結果を確認session-import-still-running = 対象のマシンでインポートを実行中です。後でもう一度結果を確認してください。diff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftlindex 288b8e2a..734f2e02 100644--- a/thinkterm-i18n/i18n/zh-CN.ftl+++ b/thinkterm-i18n/i18n/zh-CN.ftl@@ -1073,6 +1073,12 @@ session-import-notes-title = 导入须知session-import-location-local = 导入位置:本机session-import-location-remote = 导入位置:{ $host } · 远程进程仍在这台服务器上运行session-import-requirements-remote = 使用远程连接账号拥有的会话。终端进程和工作目录保留在该服务器上。+session-import-hosts = 从哪台机器导入+session-import-host-local = 本机+session-import-host-connected = 已连接+session-import-host-disconnected = 未连接 · 选中后会先连接+session-import-imported = 已导入+session-import-already-imported = 这个会话已经导入到 { $name }。再导入会另建一个 Space。session-import-check-result = 检查导入结果session-import-still-running = 目标机器仍在导入。稍后再次检查,即可取回本次结果。diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rsindex f132e539..94dce5d2 100644--- a/wezterm-gui/src/settings_window.rs+++ b/wezterm-gui/src/settings_window.rs@@ -1385,6 +1385,8 @@ enum SettingsAction {#[cfg(unix)]SessionImportPreview(u64),#[cfg(unix)]+ SessionImportHost(u64),+ #[cfg(unix)]SessionImportBack,#[cfg(unix)]SessionImportConfirm,@@ -5255,6 +5257,7 @@ impl SettingsWindow {#[cfg(unix)]SettingsAction::SessionImportDetect| SettingsAction::SessionImportPreview(_)+ | SettingsAction::SessionImportHost(_)| SettingsAction::SessionImportBack| SettingsAction::SessionImportRecover| SettingsAction::SessionImportConfirm@@ -15681,8 +15684,7 @@ impl SettingsWindow {/// `title_y`, centred on the title's capitals. Left out when it would/// run past `right_edge`.fn beta_badge_width(&self) -> f32 {- let label = crate::i18n::tr("settings-badge-beta");- (self.measure_text_width(&self.logo_caption_font, &label) + self.ui_px(12.0) * 2.0).round()+ self.badge_width(&crate::i18n::tr("settings-badge-beta"))}fn paint_beta_badge(@@ -15692,10 +15694,28 @@ impl SettingsWindow {title_y: f32,right_edge: f32,) -> anyhow::Result<()> {- let font = Rc::clone(&self.logo_caption_font);let label = crate::i18n::tr("settings-badge-beta");+ let accent = self.chrome_palette.accent;+ self.paint_badge(layers, &label, accent, x, title_y, right_edge)+ }++ fn badge_width(&self, label: &str) -> f32 {+ (self.measure_text_width(&self.logo_caption_font, label) + self.ui_px(12.0) * 2.0).round()+ }++ /// The capsule `paint_beta_badge` draws, with any label and color.+ fn paint_badge(+ &self,+ layers: &mut TripleLayerQuadAllocator<'_>,+ label: &str,+ accent: LinearRgba,+ x: f32,+ title_y: f32,+ right_edge: f32,+ ) -> anyhow::Result<()> {+ let font = Rc::clone(&self.logo_caption_font);let pad = self.ui_px(12.0);- let width = self.beta_badge_width();+ let width = self.badge_width(label);if x + width > right_edge {return Ok(());}@@ -15712,7 +15732,6 @@ impl SettingsWindow {let center_y = title_y + baseline_offset - cap_height(self.ui_font.metrics()) / 2.0;let label_cap = cap_height(font.metrics());let height = (label_cap + self.ui_px(16.0)).round();- let accent = self.chrome_palette.accent;self.draw_rounded_rect(layers,0,@@ -15728,7 +15747,7 @@ impl SettingsWindow {&font,x + pad,(center_y + label_cap / 2.0 - baseline_offset).round(),- &label,+ label,accent,width - pad,)diff --git a/wezterm-gui/src/settings_window/session_import.rs b/wezterm-gui/src/settings_window/session_import.rsindex 313aa7e8..dd486d1e 100644--- a/wezterm-gui/src/settings_window/session_import.rs+++ b/wezterm-gui/src/settings_window/session_import.rs@@ -83,18 +83,28 @@ enum ImportTarget {}impl ImportTarget {+ /// The machine of the Space Settings was opened from.fn current() -> anyhow::Result<Self> {let space_id = OPENED_FROM_SPACE.with(|slot| slot.borrow().clone());let Some(space_id) = space_id else {return Ok(Self::Local);};let store = crate::workspace_threads::workspace_thread_store_snapshot();- let Some(name) = origin_domain(&store, &space_id)? else {+ Self::for_host(origin_domain(&store, &space_id)?)+ }++ /// This machine for `None`, else the connection named `host`. A host+ /// not connected since launch is registered the way its Space would+ /// register it; `owner` connects it.+ fn for_host(host: Option<String>) -> anyhow::Result<Self> {+ let Some(name) = host else {return Ok(Self::Local);};- let domain = mux::Mux::get()- .get_domain_by_name(&name)- .context("The import connection is no longer available")?;+ let domain = match mux::Mux::get().get_domain_by_name(&name) {+ Some(domain) => domain,+ None => crate::connect_domain_from_ssh_host(&name)+ .context("The import connection is no longer available")?,+ };anyhow::ensure!(domain.downcast_ref::<wezterm_client::domain::ClientDomain>()@@ -102,11 +112,18 @@ impl ImportTarget {"Session import requires a ThinkTerm connection");Ok(Self::Remote {- name: name.clone(),+ name,domain_id: domain.domain_id(),})}+ fn host(&self) -> Option<&str> {+ match self {+ Self::Local => None,+ Self::Remote { name, .. } => Some(name),+ }+ }+fn location(&self, source: ImportSource) -> String {match self {Self::Local => source.text("session-import-location-local"),@@ -219,6 +236,53 @@ impl ImportTarget {}}+/// The machines an import can run on: this one, then each host a remote+/// Space comes from.+fn import_hosts() -> Vec<Option<String>> {+ std::iter::once(None)+ .chain(+ crate::workspace_threads::remote_space_domains()+ .into_iter()+ .map(Some),+ )+ .collect()+}++/// Domain names are never empty, so "" can stand for this machine.+fn host_key(host: Option<&str>) -> u64 {+ web_token_key(host.unwrap_or(""))+}++fn host_connected(name: &str) -> bool {+ mux::Mux::get()+ .get_domain_by_name(name)+ .is_some_and(|domain| domain.state() == DomainState::Attached)+}++fn source_id(source: ImportSource) -> Option<&'static str> {+ match source {+ ImportSource::Session(id) => Some(id),+ ImportSource::WezTerm => None,+ }+}++/// Note a finished import where the Import page will find it, whether or+/// not Settings is still open to show the result.+fn remember_import(+ target: &ImportTarget,+ request: &codec::ImportSessionRequest,+ status: &anyhow::Result<codec::ImportSessionStatus>,+) {+ if let Ok(codec::ImportSessionStatus::Completed(result)) = status {+ crate::workspace_threads::note_imported_session(+ &request.request.source,+ &request.request.session,+ target.host(),+ &result.space_id,+ );+ }+}+fn origin_domain(store: &crate::workspace_threads::WorkspaceThreadStore,space_id: &str,@@ -488,6 +552,28 @@ impl SettingsWindow {}).detach();}+ SettingsAction::SessionImportHost(key) => {+ let Some(host) = import_hosts()+ .into_iter()+ .find(|host| host_key(host.as_deref()) == key)+ else {+ return;+ };+ match ImportTarget::for_host(host) {+ Ok(target) => {+ self.ui.session_import.target = Some(target);+ self.perform_session_import_action(SettingsAction::SessionImportDetect);+ }+ Err(err) => {+ self.ui.session_import.failed = true;+ self.ui.session_import.message = localized_error(+ selected_source,+ &format!("{err:#}"),+ "session-import-error-inspect",+ );+ }+ }+ }SettingsAction::SessionImportPreview(key) => {let Some(target) = self.ui.session_import.target.clone() else {return;@@ -592,8 +678,9 @@ impl SettingsWindow {promise::spawn::spawn(async move {let imported = match target.import(request.clone()).await {Ok(result) => Ok(codec::ImportSessionStatus::Completed(result)),- Err(_) => target.recover(request).await,+ Err(_) => target.recover(request.clone()).await,};+ remember_import(&target, &request, &imported);if let Some(settings) = settings_window_for_instance(instance_id) {let mut settings = settings.borrow_mut();if settings.ui.import_source != selected_source {@@ -616,7 +703,8 @@ impl SettingsWindow {};self.ui.session_import.busy = true;promise::spawn::spawn(async move {- let status = target.recover(request).await;+ let status = target.recover(request.clone()).await;+ remember_import(&target, &request, &status);if let Some(settings) = settings_window_for_instance(instance_id) {let mut settings = settings.borrow_mut();settings.apply_import_status(selected_source, status);@@ -693,7 +781,24 @@ impl SettingsWindow {"session-import-select-session"}),)? + self.ui_px(24.0);- if let Some(target) = &state.target {+ // The machine is chosen before a preview; an import in flight keeps+ // the one it was sent to.+ let hosts = if state.preview.is_none() && state.pending.is_none() {+ import_hosts()+ } else {+ Vec::new()+ };+ if hosts.len() > 1 {+ top = self.paint_import_hosts(+ layers,+ left,+ top,+ inner,+ &hosts,+ state.target.as_ref(),+ !state.busy,+ )? + gap;+ } else if let Some(target) = &state.target {top = self.paint_import_copy(layers,left,@@ -703,6 +808,13 @@ impl SettingsWindow {palette.secondary_text,)? + gap;}+ let imported_into = |session: &str| {+ crate::workspace_threads::imported_session_space(+ source_id(selected_source)?,+ session,+ state.target.as_ref()?.host(),+ )+ };if let Some(preview) = &state.preview {let status = selected_source.text(if preview.live {"session-import-status-live"@@ -763,6 +875,17 @@ impl SettingsWindow {}if let Some(preview) = &state.preview {+ if let Some(space) = imported_into(&preview.session) {+ top = self.paint_import_notice(+ layers,+ left,+ top,+ inner,+ &selected_source+ .text_args("session-import-already-imported", &[("name", space)]),+ true,+ )? + gap;+ }let destination = selected_source.text_args("session-import-destination",&[(@@ -945,15 +1068,32 @@ impl SettingsWindow {palette.muted_text,)?;let name_x = left + cell + self.ui_px(12.0);+ let name_y = self.control_text_y(top, height);+ let name_width =+ (inner - (name_x - left) - button_width - self.ui_px(16.0)).max(1.0);self.draw_text(layers,&title,name_x,- self.control_text_y(top, height),+ name_y,&session.name,palette.text,- (inner - (name_x - left) - button_width - self.ui_px(16.0)).max(1.0),+ name_width,)?;+ if imported_into(&session.name).is_some() {+ self.paint_badge(+ layers,+ &selected_source.text("session-import-imported"),+ TileColor::Teal.linear(),+ name_x+ + self+ .measure_text_width(&title, &session.name)+ .min(name_width)+ + self.ui_px(14.0),+ name_y,+ name_x + name_width,+ )?;+ }self.paint_import_actions(layers,left + inner - button_width,@@ -1108,6 +1248,108 @@ impl SettingsWindow {)}+ /// One row per machine an import can run on. Choosing one detects the+ /// sessions there; the imported terminals stay on that machine.+ fn paint_import_hosts(+ &mut self,+ layers: &mut TripleLayerQuadAllocator<'_>,+ x: f32,+ y: f32,+ width: f32,+ hosts: &[Option<String>],+ chosen: Option<&ImportTarget>,+ enabled: bool,+ ) -> anyhow::Result<f32> {+ let selected_source = self.ui.import_source;+ let palette = self.palette();+ let font = Rc::clone(&self.ui_font);+ let cell = self.metrics.cell_size.height as f32;+ let height = self.ui_px(CONTROL_HEIGHT);+ let pad = self.ui_px(14.0);+ let mut top = self.paint_import_copy(+ layers,+ x,+ y,+ width,+ &selected_source.text("session-import-hosts"),+ palette.text,+ )? + self.ui_px(8.0);+ for host in hosts {+ let action = SettingsAction::SessionImportHost(host_key(host.as_deref()));+ let selected = chosen.is_some_and(|target| target.host() == host.as_deref());+ if enabled {+ self.ui_context+ .push(rect(x, top, width, height), WidgetKind::Button, action);+ }+ let bg = if selected {+ Some(palette.nav_selected_bg)+ } else if enabled && self.ui.interaction.pressed == Some(action) {+ Some(palette.control_pressed_bg)+ } else if enabled && self.ui.interaction.hovered == Some(action) {+ Some(palette.control_hover_bg)+ } else {+ None+ };+ if let Some(bg) = bg {+ self.draw_rounded_rect(layers, 0, x, top, width, height, bg, self.ui_px(9.0))?;+ }+ let (text, secondary) = if selected {+ (palette.selected_text, palette.selected_text)+ } else {+ (palette.text, palette.secondary_text)+ };+ let (icon, name, status) = match host {+ None => (+ SvgIcon::Laptop,+ selected_source.text("session-import-host-local"),+ String::new(),+ ),+ Some(name) => (+ SvgIcon::Server,+ name.clone(),+ selected_source.text(if host_connected(name) {+ "session-import-host-connected"+ } else {+ "session-import-host-disconnected"+ }),+ ),+ };+ self.draw_svg_icon(+ layers,+ icon,+ x + pad,+ top + (height - cell) / 2.0,+ cell,+ secondary,+ )?;+ let name_x = x + pad + cell + self.ui_px(12.0);+ let status_width = self.measure_text_width(&font, &status).min(width * 0.5);+ let status_x = x + width - pad - status_width;+ self.draw_text(+ layers,+ &font,+ name_x,+ self.control_text_y(top, height),+ &name,+ text,+ (status_x - name_x - self.ui_px(16.0)).max(1.0),+ )?;+ if !status.is_empty() {+ self.draw_text(+ layers,+ &font,+ status_x,+ self.control_text_y(top, height),+ &status,+ secondary,+ status_width,+ )?;+ }+ top += height + self.ui_px(4.0);+ }+ Ok(top)+ }+fn paint_session_notes(&self,layers: &mut TripleLayerQuadAllocator<'_>,@@ -1287,6 +1529,27 @@ mod tests {assert!(origin_domain(&store, "missing").is_err());}+ #[test]+ fn this_machine_and_each_host_are_told_apart() {+ let keys = [+ host_key(None),+ host_key(Some("server-a")),+ host_key(Some("server-b")),+ ];+ assert_ne!(keys[0], keys[1]);+ assert_ne!(keys[1], keys[2]);+ assert_eq!(host_key(Some("server-a")), keys[1]);+ assert_eq!(ImportTarget::Local.host(), None);+ assert_eq!(+ ImportTarget::Remote {+ name: "server-a".into(),+ domain_id: 7,+ }+ .host(),+ Some("server-a")+ );+ }+#[test]fn generic_errors_are_localized_and_unknown_errors_keep_details() {let source = ImportSource::Session("example");diff --git a/wezterm-gui/src/workspace_threads.rs b/wezterm-gui/src/workspace_threads.rsindex 5ba5f6a4..2fa63153 100644--- a/wezterm-gui/src/workspace_threads.rs+++ b/wezterm-gui/src/workspace_threads.rs@@ -45,9 +45,29 @@ pub struct WorkspaceThreadStore {/// is per-device by nature and never travels to the server.#[serde(default)]pub last_space_per_domain: HashMap<String, SpaceId>,+ /// Sessions imported from other programs, so the Import page can say a+ /// session was brought in already. Per-device, like the field above;+ /// an entry counts only while its Space is here on the same connection.+ #[serde(default, skip_serializing_if = "Vec::is_empty")]+ pub imported_sessions: Vec<ImportedSession>,pub projects: Vec<Project>,}+/// One session the Import page brought in, and the Space it became.+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]+pub struct ImportedSession {+ pub source: String,+ pub session: String,+ /// The connection the import ran on; `None` for this machine.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ pub host: Option<String>,+ pub space_id: SpaceId,+}++/// The most imports remembered; the oldest go first.+#[cfg(unix)]+const MAX_IMPORTED_SESSIONS: usize = 64;+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]pub struct Space {pub id: SpaceId,@@ -1785,6 +1805,30 @@ pub fn remote_space_domains() -> Vec<String> {THREAD_STORE.lock().remote_space_domains()}+/// Remember that `session` of `source`, imported on `host`, became+/// `space_id`.+#[cfg(unix)]+pub fn note_imported_session(source: &str, session: &str, host: Option<&str>, space_id: &str) {+ let mut store = THREAD_STORE.lock();+ store.note_imported_session(ImportedSession {+ source: source.to_string(),+ session: session.to_string(),+ host: host.map(str::to_string),+ space_id: space_id.to_string(),+ });+ schedule_workspace_thread_store_persist();+}++/// The name of the Space `session` of `source` on `host` was imported+/// into, while that Space is still here.+#[cfg(unix)]+pub fn imported_session_space(source: &str, session: &str, host: Option<&str>) -> Option<String> {+ THREAD_STORE+ .lock()+ .imported_session_space(source, session, host)+ .map(|space| space.name.clone())+}+/// The Spaces this device mirrored from a mux server it reaches under any of/// `domain_names`.///@@ -5966,6 +6010,41 @@ impl WorkspaceThreadStore {domains}+ /// The newest import of a session replaces older ones. A local entry+ /// whose Space is gone was deleted with it; a remote one may only be+ /// missing until its host connects again, so it waits for the cap.+ #[cfg(unix)]+ fn note_imported_session(&mut self, imported: ImportedSession) {+ let spaces = &self.spaces;+ self.imported_sessions.retain(|known| {+ !(known.source == imported.source+ && known.session == imported.session+ && known.host == imported.host)+ && (known.host.is_some() || spaces.iter().any(|space| space.id == known.space_id))+ });+ self.imported_sessions.push(imported);+ let excess = self+ .imported_sessions+ .len()+ .saturating_sub(MAX_IMPORTED_SESSIONS);+ self.imported_sessions.drain(..excess);+ }++ #[cfg(unix)]+ fn imported_session_space(+ &self,+ source: &str,+ session: &str,+ host: Option<&str>,+ ) -> Option<&Space> {+ let imported = self.imported_sessions.iter().find(|known| {+ known.source == source && known.session == session && known.host.as_deref() == host+ })?;+ self.spaces+ .iter()+ .find(|space| space.id == imported.space_id && space.client_domain.as_deref() == host)+ }+#[cfg(test)]fn materialized_workspaces_for_space(&self, space_id: &str) -> Vec<String> {self.projects@@ -12960,6 +13039,90 @@ mod tests {store}+ #[cfg(unix)]+ fn imported(source: &str, session: &str, host: Option<&str>, space: &str) -> ImportedSession {+ ImportedSession {+ source: source.to_string(),+ session: session.to_string(),+ host: host.map(str::to_string),+ space_id: space.to_string(),+ }+ }++ #[cfg(unix)]+ #[test]+ fn an_imported_session_is_known_only_while_its_space_is_on_that_connection() {+ let mut store = remote_test_store("server-a");+ let local = store.spaces[0].id.clone();+ store.note_imported_session(imported("example", "default", None, &local));+ store.note_imported_session(imported(+ "example",+ "work",+ Some("server-a"),+ "space-remote",+ ));+ let name = |store: &WorkspaceThreadStore, session, host| {+ store+ .imported_session_space("example", session, host)+ .map(|space| space.name.clone())+ };+ assert_eq!(+ name(&store, "default", None),+ Some(store.spaces[0].name.clone())+ );+ let remote = store+ .spaces+ .iter()+ .find(|space| space.id == "space-remote")+ .map(|space| space.name.clone());+ assert!(remote.is_some());+ assert_eq!(name(&store, "work", Some("server-a")), remote);+ // The same name on another machine, or from another source, is+ // another session.+ assert_eq!(name(&store, "default", Some("server-a")), None);+ assert_eq!(name(&store, "work", None), None);+ assert!(store+ .imported_session_space("other", "default", None)+ .is_none());+ // A Space that is gone takes the mark with it.+ store.spaces.retain(|space| space.id != "space-remote");+ assert_eq!(name(&store, "work", Some("server-a")), None);+ }++ #[cfg(unix)]+ #[test]+ fn imported_sessions_keep_the_newest_and_stay_bounded() {+ let mut store = remote_test_store("server-a");+ let local = store.spaces[0].id.clone();+ store.note_imported_session(imported("example", "default", None, "space-deleted"));+ store.note_imported_session(imported(+ "example",+ "work",+ Some("server-a"),+ "space-offline",+ ));+ store.note_imported_session(imported("example", "default", None, &local));+ // The re-import replaced the first entry; the deleted local Space+ // went with it, while the remote one waits for its host.+ assert_eq!(+ store.imported_sessions,+ vec![+ imported("example", "work", Some("server-a"), "space-offline"),+ imported("example", "default", None, &local),+ ]+ );+ for n in 0..MAX_IMPORTED_SESSIONS {+ store.note_imported_session(imported(+ "example",+ &format!("session-{n}"),+ Some("server-a"),+ "space-remote",+ ));+ }+ assert_eq!(store.imported_sessions.len(), MAX_IMPORTED_SESSIONS);+ assert_eq!(store.imported_sessions[0].session, "session-0");+ }+fn tree_thread(id: &str, project_id: &str, name: &str) -> codec::TtThread {codec::TtThread {id: id.to_string(),