"""Tests for dotfiles domain models.""" from pathlib import Path from flow.domain.dotfiles.models import ( LinkOp, LinkPlan, LinkTarget, LinkedState, ModuleRef, Package, PlanSummary, ) def test_link_op_str_create(): op = LinkOp(type="create_link", target=Path("/home/x/.zshrc"), source=Path("/dots/zsh/.zshrc"), package="_shared/zsh", needs_sudo=False) assert "LINK:" in str(op) assert ".zshrc" in str(op) def test_link_op_str_sudo(): op = LinkOp(type="create_link", target=Path("/etc/hosts"), source=Path("/dots/dns/hosts"), package="_shared/dns", needs_sudo=True) assert "(sudo)" in str(op) def test_linked_state_roundtrip(): lt = LinkTarget(source=Path("/a"), target=Path("/b"), package="p", from_module=False, needs_sudo=False) state = LinkedState(links={Path("/b"): lt}) data = state.as_dict() restored = LinkedState.from_dict(data) assert Path("/b") in restored.links assert restored.links[Path("/b")].source == Path("/a") assert restored.links[Path("/b")].package == "p" def test_linked_state_empty(): state = LinkedState.from_dict({}) assert state.links == {} def test_package_has_id(): pkg = Package(name="zsh", layer="_shared", package_id="_shared/zsh", source_dir=Path("/dots/_shared/zsh"), module=None, local_files=()) assert pkg.package_id == "_shared/zsh"