Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions shield-claw/src/shieldclaw/sandbox/docker_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,15 +521,15 @@ def _is_service_healthy(self, service_name: str, project: str, cwd: Path) -> boo

Returns:
``True`` when the container is ``running`` and health is ``healthy``
or ``<no value>`` (no healthcheck configured). ``False`` otherwise.
or ``none`` (no healthcheck configured). ``False`` otherwise.
"""
for sep in ("-", "_"):
container = f"{project}{sep}{service_name}{sep}1"
cmd = [
"docker",
"inspect",
"--format",
"{{.State.Health.Status}}\t{{.State.Status}}",
"{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}\t{{.State.Status}}",
container,
]
_LOG.debug("Running command: %s", cmd)
Expand All @@ -551,8 +551,8 @@ def _is_service_healthy(self, service_name: str, project: str, cwd: Path) -> boo
health, _, status = output.partition("\t")
if status.strip() != "running":
return False
# "<no value>" means no healthcheck is configured — treat as passing.
return health.strip() in ("healthy", "<no value>", "")
# "none" means no healthcheck is configured — treat as passing.
return health.strip() in ("healthy", "none", "")
return False

def _wait_for_compose_ready(
Expand Down
8 changes: 4 additions & 4 deletions shield-claw/tests/test_docker_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def test_is_service_healthy_healthy_with_healthcheck(mocker: MockerFixture) -> N


def test_is_service_healthy_no_healthcheck_counts_as_passing(mocker: MockerFixture) -> None:
"""``<no value>`` health status (no healthcheck) must return ``True`` when running."""
proc = subprocess.CompletedProcess(["docker", "inspect"], 0, "<no value>\trunning", "")
"""``none`` health status (no healthcheck) must return ``True`` when running."""
proc = subprocess.CompletedProcess(["docker", "inspect"], 0, "none\trunning", "")
mocker.patch("shieldclaw.sandbox.docker_orchestrator.subprocess.run", return_value=proc)
assert DockerOrchestrator()._is_service_healthy("web", "proj", Path("/tmp"))

Expand All @@ -188,7 +188,7 @@ def test_is_service_healthy_unhealthy_returns_false(mocker: MockerFixture) -> No

def test_is_service_healthy_not_running_returns_false(mocker: MockerFixture) -> None:
"""Container not yet in ``running`` state must return ``False``."""
proc = subprocess.CompletedProcess(["docker", "inspect"], 0, "<no value>\texited", "")
proc = subprocess.CompletedProcess(["docker", "inspect"], 0, "none\texited", "")
mocker.patch("shieldclaw.sandbox.docker_orchestrator.subprocess.run", return_value=proc)
assert not DockerOrchestrator()._is_service_healthy("web", "proj", Path("/tmp"))

Expand All @@ -205,7 +205,7 @@ def fake_inspect(cmd: list[str], **_kwargs: object) -> subprocess.CompletedProce
if len(calls) == 1:
return subprocess.CompletedProcess(cmd, 1, "", "No such container")
# Second call (legacy underscore form) — success.
return subprocess.CompletedProcess(cmd, 0, "<no value>\trunning", "")
return subprocess.CompletedProcess(cmd, 0, "none\trunning", "")

mocker.patch("shieldclaw.sandbox.docker_orchestrator.subprocess.run", side_effect=fake_inspect)
assert DockerOrchestrator()._is_service_healthy("web", "myproject", Path("/tmp"))
Expand Down