Files
Octop/tests/unit/infra/utils/test_docker_env.py
jubaoliangandjubaoliang 86fa910449 feat: Docker sandbox, browser HITL stream, and gateway preemption (#227)
* feat: Docker sandbox, workspace_dir, default_open, HITL and runtime knobs

WIP against local editable orcakit-harness-agent 0.9.20 (PyPI not published yet).
Includes Admin Docker storage, agent workspace_dir, connector default_open,
chat HITL resume/todos UI, and runtime limit fields.


* feat: browser HITL stream listen, gateway preempt stop/cancel

Wire the browser streaming endpoint to listen for human-in-the-loop
events, add gateway-side preemption (stop/cancel) for running agents,
and integrate chat send with the browser session state.

- Add browser stream "listen" endpoint and harness HITL wiring
- Add gateway preemption: stop/cancel handling for running agents
- Wire chat send to browser session state in the dashboard
- Bump harness-gateway to >=0.9.2 and regenerate uv.lock
- Add unit tests for browser stream listen and gateway preemption

* test: fix workspace_dir assertion on Windows

Compare path components (name == agent_id, parent == "agents") instead
of a hard-coded POSIX "/agents/{id}" string suffix, so the check passes
on Windows where Path uses backslash separators.

---------

Co-authored-by: jubaoliang <jubaoliang@tencent.com>
2026-08-11 11:37:59 +08:00

96 lines
3.6 KiB
Python

"""Tests for Docker environment detect / ensure helpers."""
from __future__ import annotations
import pytest
from octop.infra.utils import docker_env as docker_mod
from octop.infra.utils.docker_env import docker_status, ensure_docker, install_script
def test_install_script_linux() -> None:
script = install_script(plat="linux")
assert "get.docker.com" in script
assert "docker info" in script
def test_install_script_darwin() -> None:
script = install_script(plat="darwin")
assert "brew install --cask docker" in script
def test_status_ready(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(docker_mod, "_platform_key", lambda: "linux")
monkeypatch.setattr(docker_mod, "_cli_present", lambda: True)
monkeypatch.setattr(docker_mod, "_daemon_ok", lambda: True)
result = docker_status(attempt_install=False)
assert result["status"] == "ready"
assert result["cli"] is True
assert result["daemon"] is True
assert "install_script" in result
assert "agent_prompt" in result
def test_status_daemon_down(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(docker_mod, "_platform_key", lambda: "darwin")
monkeypatch.setattr(docker_mod, "_cli_present", lambda: True)
monkeypatch.setattr(docker_mod, "_daemon_ok", lambda: False)
result = docker_status(attempt_install=False)
assert result["status"] == "daemon_down"
assert "未响应" in result["agent_prompt"]
assert "CLI is present" in result["install_script"]
assert "open -a Docker" in result["install_script"]
def test_agent_prompt_missing_vs_daemon_down() -> None:
missing = docker_mod.agent_prompt(plat="darwin", status="missing")
down = docker_mod.agent_prompt(plat="darwin", status="daemon_down")
assert "brew install --cask docker" in missing
assert "已有 docker" in down
assert missing != down
def test_status_missing(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(docker_mod, "_platform_key", lambda: "linux")
monkeypatch.setattr(docker_mod, "_cli_present", lambda: False)
monkeypatch.setattr(docker_mod, "_daemon_ok", lambda: False)
monkeypatch.setattr(docker_mod, "_detect_package_manager", lambda: "apt")
monkeypatch.setattr(docker_mod, "_can_install_without_password", lambda: True)
result = docker_status(attempt_install=False)
assert result["status"] == "missing"
assert result["can_auto_install"] is True
def test_ensure_skips_non_linux(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(docker_mod, "_platform_key", lambda: "darwin")
monkeypatch.setattr(docker_mod, "_cli_present", lambda: False)
monkeypatch.setattr(docker_mod, "_daemon_ok", lambda: False)
result = ensure_docker()
assert result["status"] == "skipped"
assert result["reason"] == "manual_install_required"
def test_ensure_installs_on_linux(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(docker_mod, "_platform_key", lambda: "linux")
calls = {"n": 0}
def cli() -> bool:
return calls["n"] >= 1
def daemon() -> bool:
return calls["n"] >= 1
monkeypatch.setattr(docker_mod, "_cli_present", cli)
monkeypatch.setattr(docker_mod, "_daemon_ok", daemon)
monkeypatch.setattr(docker_mod, "_detect_package_manager", lambda: "apt")
monkeypatch.setattr(docker_mod, "_can_install_without_password", lambda: True)
def install() -> tuple[bool, str]:
calls["n"] += 1
return True, "apt"
monkeypatch.setattr(docker_mod, "_try_auto_install_linux", install)
result = ensure_docker()
assert result["status"] == "installed"
assert result["cli"] is True