| 1 | //! Home-directory compatibility adapter, kept as an includable leaf. |
| 2 | //! |
| 3 | //! This is one function that could live in `paths.rs` — and did, until #4757 |
| 4 | //! made it the crate-wide replacement for `dirs::home_dir()`. Two of the new |
| 5 | //! call sites (`network_policy.rs`, `skills/install.rs`) are pulled into the |
| 6 | //! `skill_cli` integration test via `#[path]` includes, where `crate::` means |
| 7 | //! the test binary's root rather than the lib. Anything they reach for has to |
| 8 | //! be includable there too. |
| 9 | //! |
| 10 | //! `paths.rs` is not: its `env_config_path` calls `crate::test_support` under |
| 11 | //! `#[cfg(test)]`, and integration test binaries compile *with* `cfg(test)` |
| 12 | //! set, so including it drags in `test_support` — and then |
| 13 | //! `config_persistence` behind that. Splitting this function out keeps the |
| 14 | //! includable surface to `std` + `codewhale-paths` with no `crate::` references |
| 15 | //! at all, so the test binary picks up production behavior verbatim instead of |
| 16 | //! a divergent shim. |
| 17 | //! |
| 18 | //! `paths.rs` re-exports this so `config::effective_home_dir` and every |
| 19 | //! existing `use paths::{...}` caller resolve unchanged. The implementation |
| 20 | //! delegates to the workspace's leaf path-authority crate, which is also safe |
| 21 | //! to reference from the integration-test binary that includes this file. |
| 22 | |
| 23 | use std::path::PathBuf; |
| 24 | |
| 25 | /// Resolve the user's home directory, preferring the environment over the |
| 26 | /// platform lookup so tests can fake it consistently across OSes (#4757). |
| 27 | /// |
| 28 | /// `HOME` and `USERPROFILE` are checked first (empty values are treated as |
| 29 | /// unset, since an empty home is never a usable path), then the Windows |
| 30 | /// `HOMEDRIVE`/`HOMEPATH` pair, and only then `dirs::home_dir()`. Keeping the |
| 31 | /// OS lookup last is what makes a faked environment win in tests while |
| 32 | /// production still falls back to the real thing. |
| 33 | pub(crate) fn effective_home_dir() -> Option<PathBuf> { |
| 34 | codewhale_paths::user_home() |
| 35 | } |
| 36 |