from pathlib import Path

from osx_backup.context import Context
from osx_backup.modules.base import NullProgress, get_module
from osx_backup.modules.dotfiles import DotfilesModule


def test_registered() -> None:
    assert isinstance(get_module("dotfiles"), DotfilesModule)


def test_dotfiles_ignores_secret_entries(ctx: Context, map_path: Path) -> None:
    ctx.map_path = map_path
    (ctx.home / ".zshrc").write_text("z")
    (ctx.home / ".ssh").mkdir()
    (ctx.home / ".ssh" / "id").write_text("k")
    m = DotfilesModule()
    inv = m.inventory(ctx)
    assert inv.items == 1 and inv.available
    m.backup(ctx, NullProgress())
    assert (ctx.dest / "dotfiles" / ".zshrc").exists()
    assert not (ctx.dest / "dotfiles" / ".ssh").exists()
