Skip to content

Commit cf96d61

Browse files
committed
fix: normalize remote recent reopen behavior
1 parent fc12d4f commit cf96d61

1 file changed

Lines changed: 36 additions & 6 deletions

File tree

src/main.rs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@ fn resolve_strategy_for_remote(
100100
}
101101
}
102102

103+
fn normalize_recent_strategy_for_remote(
104+
remote_host: Option<&str>,
105+
cli_strategy: Option<ContainerStrategy>,
106+
stored_strategy: ContainerStrategy,
107+
) -> Result<ContainerStrategy> {
108+
if remote_host.is_none() {
109+
return Ok(cli_strategy.unwrap_or(stored_strategy));
110+
}
111+
112+
match cli_strategy {
113+
Some(strategy) => resolve_strategy_for_remote(remote_host, Some(strategy)),
114+
None => Ok(ContainerStrategy::ForceClassic),
115+
}
116+
}
117+
103118
fn ensure_remote_has_no_config(remote_host: Option<&str>, config: Option<&Path>) -> Result<()> {
104119
if remote_host.is_some() && config.is_some() {
105120
bail!(
@@ -182,15 +197,16 @@ fn reopen_recent(
182197
if let Some(cmd) = launch.command {
183198
entry.behavior.command = cmd;
184199
}
185-
if let Some(beh) = launch.behavior {
186-
entry.behavior.strategy = beh;
187-
}
200+
let cli_strategy = launch.behavior;
188201
if !launch.args.is_empty() {
189202
entry.behavior.args = launch.args;
190203
}
191204

192-
entry.behavior.strategy =
193-
resolve_strategy_for_remote(remote_host.as_deref(), Some(entry.behavior.strategy))?;
205+
entry.behavior.strategy = normalize_recent_strategy_for_remote(
206+
remote_host.as_deref(),
207+
cli_strategy,
208+
entry.behavior.strategy,
209+
)?;
194210

195211
let resolved_config = if launch.config.is_some() {
196212
resolve_launch_config(launch.config.as_ref(), config_store)?
@@ -308,7 +324,10 @@ fn log_format(
308324

309325
#[cfg(test)]
310326
mod tests {
311-
use super::{resolve_strategy_for_remote, workspace_root_from_config};
327+
use super::{
328+
normalize_recent_strategy_for_remote, resolve_strategy_for_remote,
329+
workspace_root_from_config,
330+
};
312331
use crate::launch::ContainerStrategy;
313332
use std::path::{Path, PathBuf};
314333

@@ -384,4 +403,15 @@ mod tests {
384403
.unwrap_err();
385404
assert!(err.to_string().contains("not supported with --remote-host"));
386405
}
406+
407+
#[test]
408+
fn recent_remote_reopen_coerces_stored_detect_to_force_classic() {
409+
let strategy = normalize_recent_strategy_for_remote(
410+
Some("remote-test"),
411+
None,
412+
ContainerStrategy::Detect,
413+
)
414+
.unwrap();
415+
assert_eq!(strategy, ContainerStrategy::ForceClassic);
416+
}
387417
}

0 commit comments

Comments
 (0)