Repository navigation
Commit 0d5c3e4
refactor(config): replace HOME env mutation in TempHome with injected override
CodeRabbit flagged the previous `TempHome` implementation in `config.rs`
and `main.rs` as unsafe under multi-threaded test execution. Both copies
mutated process-global `HOME`/`USERPROFILE` and only serialized themselves
through a shared `test_home_env_lock()` mutex, which does not protect any
other test module that happens to read `$HOME`.
Replace the env mutation with a `pub(crate) test_home::Guard` type in
`config.rs` that:
- Acquires a single serializer mutex so only one test can install an
override at a time.
- Stores the override path in an `RwLock<Option<PathBuf>>` so a wrapper
`home_dir()` can transparently consult it before falling back to
`dirs::home_dir()`.
- Clears the override on `Drop`, so production calls outside test
scopes always see the real home directory.
`Config::config_path` and `Config::themes_dir` now go through the new
`home_dir()` helper, and the per-module `TempHome` structs in `config.rs`
and `main.rs` are thin wrappers around the shared guard. No `env::set_var`
or `env::remove_var` calls remain in the test code.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>1 parent 2f50404 commit 0d5c3e4
2 files changed
Lines changed: 66 additions & 67 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
48 | 56 | | |
49 | | - | |
50 | | - | |
51 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
52 | 101 | | |
53 | 102 | | |
54 | 103 | | |
| |||
181 | 230 | | |
182 | 231 | | |
183 | 232 | | |
184 | | - | |
| 233 | + | |
185 | 234 | | |
186 | 235 | | |
187 | 236 | | |
| |||
198 | 247 | | |
199 | 248 | | |
200 | 249 | | |
201 | | - | |
| 250 | + | |
202 | 251 | | |
203 | 252 | | |
204 | 253 | | |
| |||
219 | 268 | | |
220 | 269 | | |
221 | 270 | | |
222 | | - | |
223 | | - | |
224 | 271 | | |
225 | 272 | | |
226 | | - | |
227 | | - | |
228 | 273 | | |
229 | | - | |
| 274 | + | |
230 | 275 | | |
231 | | - | |
232 | 276 | | |
233 | 277 | | |
234 | 278 | | |
235 | 279 | | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | 280 | | |
240 | 281 | | |
241 | 282 | | |
| |||
244 | 285 | | |
245 | 286 | | |
246 | 287 | | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
| 288 | + | |
| 289 | + | |
262 | 290 | | |
263 | 291 | | |
264 | 292 | | |
265 | 293 | | |
266 | 294 | | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | 295 | | |
275 | 296 | | |
276 | 297 | | |
277 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
278 | 305 | | |
279 | 306 | | |
280 | 307 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
631 | 631 | | |
632 | 632 | | |
633 | 633 | | |
634 | | - | |
635 | 634 | | |
636 | 635 | | |
637 | | - | |
638 | 636 | | |
639 | 637 | | |
640 | | - | |
641 | | - | |
642 | 638 | | |
643 | 639 | | |
644 | 640 | | |
645 | 641 | | |
646 | 642 | | |
647 | 643 | | |
648 | | - | |
| 644 | + | |
649 | 645 | | |
650 | | - | |
651 | 646 | | |
652 | 647 | | |
653 | 648 | | |
| |||
743 | 738 | | |
744 | 739 | | |
745 | 740 | | |
746 | | - | |
747 | | - | |
748 | | - | |
749 | 741 | | |
750 | 742 | | |
751 | 743 | | |
| |||
754 | 746 | | |
755 | 747 | | |
756 | 748 | | |
757 | | - | |
758 | | - | |
759 | | - | |
760 | | - | |
761 | | - | |
762 | | - | |
763 | | - | |
764 | | - | |
765 | | - | |
766 | | - | |
767 | | - | |
768 | | - | |
769 | | - | |
770 | | - | |
771 | | - | |
| 749 | + | |
| 750 | + | |
772 | 751 | | |
773 | 752 | | |
774 | 753 | | |
| |||
780 | 759 | | |
781 | 760 | | |
782 | 761 | | |
783 | | - | |
784 | | - | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | 762 | | |
791 | 763 | | |
792 | 764 | | |
| |||
0 commit comments