|
10 | 10 | import pytest |
11 | 11 | import yaml |
12 | 12 |
|
| 13 | +from vcspull._internal.private_path import PrivatePath |
13 | 14 | from vcspull.cli import cli |
14 | 15 | from vcspull.cli.fmt import format_config, format_config_file, normalize_repo_config |
15 | 16 | from vcspull.config import ( |
@@ -303,6 +304,10 @@ def test_format_config_file_missing_config( |
303 | 304 | """Formatting without available config should emit an error.""" |
304 | 305 | monkeypatch.chdir(tmp_path) |
305 | 306 |
|
| 307 | + home_config = pathlib.Path("~/.vcspull.yaml").expanduser() |
| 308 | + if home_config.exists(): |
| 309 | + home_config.unlink() |
| 310 | + |
306 | 311 | with caplog.at_level(logging.ERROR): |
307 | 312 | format_config_file(None, write=False, format_all=False) |
308 | 313 |
|
@@ -337,16 +342,40 @@ def test_format_config_file_reports_changes( |
337 | 342 | assert "Run with --write to apply" in text |
338 | 343 |
|
339 | 344 |
|
| 345 | +def test_format_config_file_uses_private_path_in_logs( |
| 346 | + user_path: pathlib.Path, |
| 347 | + caplog: LogCaptureFixture, |
| 348 | +) -> None: |
| 349 | + """CLI logs should redact the home directory via PrivatePath.""" |
| 350 | + config_file = user_path / ".vcspull.yaml" |
| 351 | + config_file.write_text( |
| 352 | + """~/projects/: |
| 353 | + zebra: url1 |
| 354 | + alpha: url2 |
| 355 | +""", |
| 356 | + encoding="utf-8", |
| 357 | + ) |
| 358 | + |
| 359 | + with caplog.at_level(logging.INFO): |
| 360 | + format_config_file(str(config_file), write=True, format_all=False) |
| 361 | + |
| 362 | + expected_path = str(PrivatePath(config_file)) |
| 363 | + text = caplog.text |
| 364 | + assert f"in {expected_path}" in text |
| 365 | + assert f"Successfully formatted {expected_path}" in text |
| 366 | + |
| 367 | + |
340 | 368 | def test_format_all_configs( |
341 | 369 | tmp_path: pathlib.Path, |
342 | 370 | caplog: LogCaptureFixture, |
343 | 371 | monkeypatch: pytest.MonkeyPatch, |
| 372 | + user_path: pathlib.Path, |
344 | 373 | ) -> None: |
345 | 374 | """format_config_file with --all should process discovered configs.""" |
346 | | - config_dir = tmp_path / ".config" / "vcspull" |
347 | | - config_dir.mkdir(parents=True) |
| 375 | + config_dir = user_path / ".config" / "vcspull" |
| 376 | + config_dir.mkdir(parents=True, exist_ok=True) |
348 | 377 |
|
349 | | - home_config = tmp_path / ".vcspull.yaml" |
| 378 | + home_config = user_path / ".vcspull.yaml" |
350 | 379 | home_config.write_text( |
351 | 380 | yaml.dump({"~/projects/": {"repo1": {"repo": "url1"}}}), |
352 | 381 | encoding="utf-8", |
@@ -396,9 +425,9 @@ def fake_find_home_config_files( |
396 | 425 |
|
397 | 426 | text = caplog.text |
398 | 427 | assert "Found 3 configuration files to format" in text |
399 | | - assert str(home_config) in text |
400 | | - assert str(work_config) in text |
401 | | - assert str(local_config) in text |
| 428 | + assert str(PrivatePath(home_config)) in text |
| 429 | + assert str(PrivatePath(work_config)) in text |
| 430 | + assert str(PrivatePath(local_config)) in text |
402 | 431 | assert "already formatted correctly" in text |
403 | 432 | assert "Repositories in ~/work/ will be sorted alphabetically" in text |
404 | 433 | assert "All 3 configuration files processed successfully" in text |
|
0 commit comments