From d4fc5ba635280f01173dbae7ef7f8cc5feb1d45a Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 21:00:26 -0700 Subject: [PATCH] refactor(mac): converge core/pathext.rs to the shared version The macOS copy gains the module docs, the ~ special case is enabled on every unix (it was target_os = "macos" only, which is a subset) and the test is split by platform. ResolvedPathBuf's schema description is selected by cfg(target_os = "windows"), so macOS keeps its text and schema.json is unchanged. Verified: fast-check macOS (fake CC) cargo check --workspace --all-targets: PASS, 0 errors. macOS unit tests cannot run on Linux (not verified). --- komorebi-for-mac/komorebi/src/core/pathext.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/komorebi-for-mac/komorebi/src/core/pathext.rs b/komorebi-for-mac/komorebi/src/core/pathext.rs index dfb7c635..81f61ea7 100644 --- a/komorebi-for-mac/komorebi/src/core/pathext.rs +++ b/komorebi-for-mac/komorebi/src/core/pathext.rs @@ -1,3 +1,5 @@ +//! Resolving environment variables in the paths of the configuration. + use std::collections::HashMap; use std::ffi::OsStr; use std::path::Component; @@ -33,8 +35,8 @@ impl> PathExt for P { c = OsStr::new("$Env:USERPROFILE"); } - #[cfg(target_os = "macos")] - // Special case for ~, replace with $HOME + #[cfg(unix)] + // Special case for ~, replace with $HOME (macOS and Linux) if c == OsStr::new("~") { c = OsStr::new("$HOME"); } @@ -135,9 +137,15 @@ impl serde_with::schemars_1::JsonSchemaAs for ResolvedPathBuf { } fn json_schema(_generator: &mut schemars::SchemaGenerator) -> schemars::Schema { + // the description is part of the checked-in schemas, which differ per platform + #[cfg(target_os = "windows")] + let description = "A file system path. Environment variables like %VAR%, $Env:VAR, or $VAR are automatically resolved."; + #[cfg(not(target_os = "windows"))] + let description = "A file system path. Environment variables like $VAR are automatically resolved."; + schemars::json_schema!({ "type": "string", - "description": "A file system path. Environment variables like $VAR are automatically resolved." + "description": description }) } } @@ -206,7 +214,7 @@ mod tests { assert_eq!(resolve("$HOME"), expected("C:\\Users\\user")); } - #[cfg(target_os = "macos")] + #[cfg(unix)] { // Set a $env:USERPROFILE variable for testing unsafe {