diff --git a/crates/tui/src/main.rs b/crates/tui/src/main.rs index 206b8bb3..e51a1900 100644 --- a/crates/tui/src/main.rs +++ b/crates/tui/src/main.rs @@ -5006,8 +5006,8 @@ fn workspace_config_path_matches(raw_path: &str, workspace: &Path) -> bool { #[cfg(windows)] fn paths_equal_for_config(left: &Path, right: &Path) -> bool { - left.to_string_lossy() - .eq_ignore_ascii_case(&right.to_string_lossy()) + normalize_windows_config_path_for_compare(left) + == normalize_windows_config_path_for_compare(right) } #[cfg(not(windows))] @@ -5015,6 +5015,25 @@ fn paths_equal_for_config(left: &Path, right: &Path) -> bool { left == right } +#[cfg(windows)] +fn normalize_windows_config_path_for_compare(path: &Path) -> String { + normalize_windows_config_path_str(&path.to_string_lossy()) +} + +#[cfg(any(windows, test))] +fn normalize_windows_config_path_str(path: &str) -> String { + let mut normalized = path.replace('/', "\\"); + if let Some(rest) = normalized.strip_prefix(r"\\?\UNC\") { + normalized = format!("\\\\{rest}"); + } else if let Some(rest) = normalized.strip_prefix(r"\\?\") { + normalized = rest.to_string(); + } + while normalized.len() > 3 && normalized.ends_with('\\') { + normalized.pop(); + } + normalized.to_ascii_lowercase() +} + async fn run_interactive( cli: &Cli, config: &Config, @@ -6961,6 +6980,26 @@ allow_shell = false assert_eq!(config.allow_shell, Some(false)); } + #[test] + fn windows_config_path_compare_normalizes_mixed_separators() { + assert_eq!( + normalize_windows_config_path_str(r"C:\Users\me\repo"), + normalize_windows_config_path_str(r"C:/Users/me/repo/") + ); + } + + #[test] + fn windows_config_path_compare_normalizes_verbatim_and_unc_prefixes() { + assert_eq!( + normalize_windows_config_path_str(r"\\?\C:\Users\me\repo"), + normalize_windows_config_path_str(r"C:/Users/me/repo") + ); + assert_eq!( + normalize_windows_config_path_str(r"\\?\UNC\server\share\repo"), + normalize_windows_config_path_str(r"\\server/share/repo/") + ); + } + #[test] fn project_overlay_clamps_max_subagents_to_safe_range() { let tmp = workspace_with_project_config(