|
13 | 13 | //! names are still read at runtime (via `socket_patch_core::env_compat`) with |
14 | 14 | //! a one-shot deprecation warning; they will be removed in the next major. |
15 | 15 |
|
16 | | -use std::path::PathBuf; |
| 16 | +use std::path::{Path, PathBuf}; |
17 | 17 |
|
18 | 18 | use clap::Args; |
19 | 19 |
|
@@ -305,13 +305,14 @@ pub struct GlobalArgs { |
305 | 305 | } |
306 | 306 |
|
307 | 307 | impl GlobalArgs { |
308 | | - /// Resolve `manifest_path` against `cwd`. See |
309 | | - /// `socket_patch_core::manifest::operations::resolve_manifest_path`. |
| 308 | + /// Resolve `manifest_path` against `cwd`: absolute paths are returned |
| 309 | + /// as-is, relative paths are joined to `cwd`. |
310 | 310 | pub(crate) fn resolved_manifest_path(&self) -> PathBuf { |
311 | | - socket_patch_core::manifest::operations::resolve_manifest_path( |
312 | | - &self.cwd, |
313 | | - &self.manifest_path, |
314 | | - ) |
| 311 | + if Path::new(&self.manifest_path).is_absolute() { |
| 312 | + PathBuf::from(&self.manifest_path) |
| 313 | + } else { |
| 314 | + self.cwd.join(&self.manifest_path) |
| 315 | + } |
315 | 316 | } |
316 | 317 |
|
317 | 318 | /// Build [`ApiClientEnvOverrides`] from the CLI flags. |
@@ -902,14 +903,30 @@ mod tests { |
902 | 903 | /// An absolute `manifest_path` ignores `cwd` and passes through unchanged. |
903 | 904 | #[test] |
904 | 905 | fn resolved_manifest_path_passes_absolute_through() { |
| 906 | + let absolute = if cfg!(windows) { |
| 907 | + r"C:\etc\socket\manifest.json" |
| 908 | + } else { |
| 909 | + "/etc/socket/manifest.json" |
| 910 | + }; |
| 911 | + let args = GlobalArgs { |
| 912 | + cwd: PathBuf::from("/work/project"), |
| 913 | + manifest_path: absolute.to_string(), |
| 914 | + ..GlobalArgs::default() |
| 915 | + }; |
| 916 | + assert_eq!(args.resolved_manifest_path(), PathBuf::from(absolute)); |
| 917 | + } |
| 918 | + |
| 919 | + /// A dotted relative `manifest_path` is joined verbatim, not normalized. |
| 920 | + #[test] |
| 921 | + fn resolved_manifest_path_joins_dotted_relative_verbatim() { |
905 | 922 | let args = GlobalArgs { |
906 | 923 | cwd: PathBuf::from("/work/project"), |
907 | | - manifest_path: "/etc/socket/manifest.json".to_string(), |
| 924 | + manifest_path: "../manifest.json".to_string(), |
908 | 925 | ..GlobalArgs::default() |
909 | 926 | }; |
910 | 927 | assert_eq!( |
911 | 928 | args.resolved_manifest_path(), |
912 | | - PathBuf::from("/etc/socket/manifest.json"), |
| 929 | + PathBuf::from("/work/project/../manifest.json"), |
913 | 930 | ); |
914 | 931 | } |
915 | 932 |
|
|
0 commit comments