|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 | 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 |
9 | 9 | from deepctl_cmd_init.models import ( |
10 | 10 | InitResult, |
11 | 11 | LifecycleStep, |
@@ -400,3 +400,56 @@ def test_api_key_injection( |
400 | 400 |
|
401 | 401 | # Clone cancelled because confirm returned False |
402 | 402 | 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