Files
hermes-agent/tests/tools/test_docker_find.py
kshitijk4poor e4739c6d2d fix(cli): doctor and terminal setup resolve the container runtime too
`hermes doctor` and `hermes setup terminal` only ever looked for a `docker` binary
(`_safe_which("docker")` / `shutil.which("docker")`) and probed `docker version` by
literal name, so a podman-only machine was told Docker was missing while the docker
terminal backend was already running containers through Podman — the same mis-report
the dashboard probe had.

Both now resolve the CLI through `find_docker()` (HERMES_DOCKER_BINARY → docker →
podman → macOS Docker Desktop paths) and name the runtime they actually found, via
`docker_runtime_name()` and `docker_runtime_start_hint()` next to `find_docker()` —
shared with the dashboard probe instead of a per-module copy. The probe's version call
goes through the backend's `run_capture()`, and a Podman row no longer advises starting
a daemon: Podman is daemonless, so it points at `podman machine start`.

Tests that pinned the old resolution (`_safe_which` / the global `shutil.which`) now pin
`find_docker()`, so they no longer depend on whether the host has Docker Desktop at a
known macOS path.
2026-09-18 21:47:13 +05:30

65 lines
2.3 KiB
Python

"""Tests for tools.environments.docker.find_docker — Docker CLI discovery."""
import os
from unittest.mock import patch
import pytest
from tools.environments import docker as docker_mod
@pytest.fixture(autouse=True)
def _reset_cache():
"""Clear the module-level docker executable cache between tests."""
docker_mod._docker_executable = None
yield
docker_mod._docker_executable = None
class TestFindDocker:
def test_found_via_shutil_which(self):
with patch("tools.environments.docker.shutil.which", return_value="/usr/bin/docker"):
result = docker_mod.find_docker()
assert result == "/usr/bin/docker"
def test_not_in_path_falls_back_to_known_locations(self, tmp_path):
# Create a fake docker binary at a known path
fake_docker = tmp_path / "docker"
fake_docker.write_text("#!/bin/sh\n")
fake_docker.chmod(0o755)
with patch("tools.environments.docker.shutil.which", return_value=None), \
patch("tools.environments.docker._DOCKER_SEARCH_PATHS", [str(fake_docker)]):
result = docker_mod.find_docker()
assert result == str(fake_docker)
def test_docker_preferred_over_podman(self):
"""When both docker and podman are on PATH, docker wins."""
def which_side_effect(name):
if name == "docker":
return "/usr/bin/docker"
if name == "podman":
return "/usr/bin/podman"
return None
with patch("tools.environments.docker.shutil.which", side_effect=which_side_effect):
result = docker_mod.find_docker()
assert result == "/usr/bin/docker"
class TestRuntimeName:
"""The Docker/Podman wording every surface shows must follow the resolved CLI."""
@pytest.mark.parametrize(
("executable", "runtime", "hint"),
[
("/usr/bin/docker", "Docker", "start Docker and retry"),
("/opt/homebrew/bin/podman", "Podman", "run `podman machine start` and retry"),
("/usr/bin/podman-remote", "Podman", "run `podman machine start` and retry"),
],
)
def test_runtime_and_start_hint(self, executable, runtime, hint):
assert docker_mod.docker_runtime_name(executable) == runtime
assert docker_mod.docker_runtime_start_hint(executable) == hint