Skip to content

Commit 73eac9b

Browse files
committed
feat(test): add tests for check_prereqs tool detection in init lifecycle
Covers: all tools present, single tool missing, multiple tools missing, all tools missing, and the (key, name, hint) entry structure.
1 parent 213e6f4 commit 73eac9b

1 file changed

Lines changed: 54 additions & 1 deletion

File tree

packages/deepctl-cmd-init/tests/unit/test_init.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77
from deepctl_cmd_init.command import InitCommand
8-
from deepctl_cmd_init.lifecycle import inject_env
8+
from deepctl_cmd_init.lifecycle import check_prereqs, inject_env
99
from deepctl_cmd_init.models import (
1010
InitResult,
1111
LifecycleStep,
@@ -400,3 +400,56 @@ def test_api_key_injection(
400400

401401
# Clone cancelled because confirm returned False
402402
assert result.status == "cancelled"
403+
404+
405+
class TestCheckPrereqs:
406+
"""Tests for lifecycle.check_prereqs() — prerequisite tool detection."""
407+
408+
def test_all_tools_present_returns_empty_list(self):
409+
with patch("shutil.which", return_value="/usr/bin/tool"):
410+
assert check_prereqs() == []
411+
412+
def test_single_missing_tool_returned(self):
413+
def fake_which(cmd: str) -> str | None:
414+
return None if cmd == "git" else "/usr/bin/tool"
415+
416+
with patch("shutil.which", side_effect=fake_which):
417+
missing = check_prereqs()
418+
419+
assert len(missing) == 1
420+
key, name, hint = missing[0]
421+
assert key == "git"
422+
assert "git" in name.lower()
423+
assert hint # install hint is non-empty
424+
425+
def test_multiple_missing_tools_all_returned(self):
426+
def fake_which(cmd: str) -> str | None:
427+
return None if cmd in ("node", "npm", "curl") else "/usr/bin/tool"
428+
429+
with patch("shutil.which", side_effect=fake_which):
430+
missing = check_prereqs()
431+
432+
keys = [m[0] for m in missing]
433+
assert "node" in keys
434+
assert "npm" in keys
435+
assert "curl" in keys
436+
437+
def test_all_tools_missing_returns_full_list(self):
438+
with patch("shutil.which", return_value=None):
439+
missing = check_prereqs()
440+
441+
from deepctl_cmd_init.lifecycle import PREREQS
442+
443+
assert len(missing) == len(PREREQS)
444+
445+
def test_missing_entry_structure(self):
446+
"""Each entry is a (key, display_name, install_hint) triple."""
447+
with patch("shutil.which", return_value=None):
448+
missing = check_prereqs()
449+
450+
for entry in missing:
451+
assert len(entry) == 3
452+
key, name, hint = entry
453+
assert isinstance(key, str) and key
454+
assert isinstance(name, str) and name
455+
assert isinstance(hint, str) and hint

0 commit comments

Comments
 (0)