1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
from pathlib import Path
from mic_clipper.service import install, render_unit, uninstall
def test_rendered_service_waits_for_audio_services_and_restarts_only_on_failure():
unit = render_unit(Path("/runtime/python"), Path("/project"))
assert "After=pipewire.service wireplumber.service pipewire-pulse.service" in unit
assert "Restart=on-failure" in unit
assert "RestartMaxDelaySec=60s" in unit
assert "ExecStart=/runtime/python -m mic_clipper run" in unit
assert "UMask=0077" in unit
def test_install_and_uninstall_only_manage_the_tool_unit(tmp_path):
unit_path = tmp_path / "systemd" / "mic-clipper.service"
clips = tmp_path / "Mic Clips" / "2026-09-29" / "keep.opus"
clips.parent.mkdir(parents=True)
clips.write_bytes(b"recording")
commands: list[list[str]] = []
install(
unit_path=unit_path,
python=Path("/runtime/python"),
project_root=Path("/project"),
run_command=commands.append,
)
install(
unit_path=unit_path,
python=Path("/runtime/python"),
project_root=Path("/project"),
run_command=commands.append,
)
uninstall(unit_path=unit_path, run_command=commands.append)
assert not unit_path.exists()
assert clips.read_bytes() == b"recording"
assert commands == [
["systemctl", "--user", "daemon-reload"],
["systemctl", "--user", "enable", "--now", "mic-clipper.service"],
["systemctl", "--user", "daemon-reload"],
["systemctl", "--user", "enable", "--now", "mic-clipper.service"],
["systemctl", "--user", "disable", "--now", "mic-clipper.service"],
["systemctl", "--user", "daemon-reload"],
]
def test_dry_run_does_not_write_a_unit(tmp_path):
unit_path = tmp_path / "mic-clipper.service"
commands = install(
unit_path=unit_path,
python=Path("/runtime/python"),
project_root=Path("/project"),
dry_run=True,
)
assert not unit_path.exists()
assert commands[-1] == ["systemctl", "--user", "enable", "--now", "mic-clipper.service"]
|