Skip to content

Commit f909904

Browse files
committed
tests/fmt(test[path-redaction]): assert sanitized fmt logs
why: new PrivatePath output needs regression coverage, and integration tests previously looked for absolute tmp paths. what: - import PrivatePath and assert fmt logs collapse home dir - add dedicated test ensuring successful write logs use PrivatePath - adjust fmt --all fixture to run within the fake home directory and expect redacted paths
1 parent 893d6ed commit f909904

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

tests/cli/test_fmt.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111
import yaml
1212

13+
from vcspull._internal.private_path import PrivatePath
1314
from vcspull.cli import cli
1415
from vcspull.cli.fmt import format_config, format_config_file, normalize_repo_config
1516
from vcspull.config import (
@@ -303,6 +304,10 @@ def test_format_config_file_missing_config(
303304
"""Formatting without available config should emit an error."""
304305
monkeypatch.chdir(tmp_path)
305306

307+
home_config = pathlib.Path("~/.vcspull.yaml").expanduser()
308+
if home_config.exists():
309+
home_config.unlink()
310+
306311
with caplog.at_level(logging.ERROR):
307312
format_config_file(None, write=False, format_all=False)
308313

@@ -337,16 +342,40 @@ def test_format_config_file_reports_changes(
337342
assert "Run with --write to apply" in text
338343

339344

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+
340368
def test_format_all_configs(
341369
tmp_path: pathlib.Path,
342370
caplog: LogCaptureFixture,
343371
monkeypatch: pytest.MonkeyPatch,
372+
user_path: pathlib.Path,
344373
) -> None:
345374
"""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)
348377

349-
home_config = tmp_path / ".vcspull.yaml"
378+
home_config = user_path / ".vcspull.yaml"
350379
home_config.write_text(
351380
yaml.dump({"~/projects/": {"repo1": {"repo": "url1"}}}),
352381
encoding="utf-8",
@@ -396,9 +425,9 @@ def fake_find_home_config_files(
396425

397426
text = caplog.text
398427
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
402431
assert "already formatted correctly" in text
403432
assert "Repositories in ~/work/ will be sorted alphabetically" in text
404433
assert "All 3 configuration files processed successfully" in text

0 commit comments

Comments
 (0)