8a304ba19e
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
66 lines
1.8 KiB
Python
66 lines
1.8 KiB
Python
from click.testing import CliRunner
|
|
|
|
from hqt import cli
|
|
from hqt.config import Settings
|
|
|
|
|
|
def test_tool_cmd_opens_tool_window(monkeypatch, tmp_path):
|
|
monkeypatch.setattr(
|
|
"hqt.config.get_settings", lambda: Settings(db_path=tmp_path / "t.db")
|
|
)
|
|
calls = {}
|
|
|
|
async def fake_for_window(self, window, tool):
|
|
calls["tool"] = (window, tool)
|
|
return "@9"
|
|
|
|
monkeypatch.setattr(
|
|
"hqt.sessions.service.SessionService.open_tool_window_for_window",
|
|
fake_for_window,
|
|
)
|
|
|
|
result = CliRunner().invoke(cli.main, ["tool", "lazygit", "hqt-5"])
|
|
|
|
assert result.exit_code == 0, result.output
|
|
assert calls["tool"] == ("hqt-5", "lazygit")
|
|
|
|
|
|
def test_tool_cmd_clone_dispatches_to_clone(monkeypatch, tmp_path):
|
|
monkeypatch.setattr(
|
|
"hqt.config.get_settings", lambda: Settings(db_path=tmp_path / "t.db")
|
|
)
|
|
calls = {}
|
|
|
|
async def fake_clone(self, window):
|
|
calls["clone"] = window
|
|
return "RESULT"
|
|
|
|
monkeypatch.setattr(
|
|
"hqt.sessions.service.SessionService.clone_session_for_window", fake_clone
|
|
)
|
|
|
|
result = CliRunner().invoke(cli.main, ["tool", "clone", "hqt-5"])
|
|
|
|
assert result.exit_code == 0, result.output
|
|
assert calls["clone"] == "hqt-5"
|
|
|
|
|
|
def test_tool_cmd_reports_service_error(monkeypatch, tmp_path):
|
|
from hqt.errors import ServiceError
|
|
|
|
monkeypatch.setattr(
|
|
"hqt.config.get_settings", lambda: Settings(db_path=tmp_path / "t.db")
|
|
)
|
|
|
|
async def boom(self, window, tool):
|
|
raise ServiceError("'hqt-5' is not an hqt session window")
|
|
|
|
monkeypatch.setattr(
|
|
"hqt.sessions.service.SessionService.open_tool_window_for_window", boom
|
|
)
|
|
|
|
result = CliRunner().invoke(cli.main, ["tool", "nvim", "hqt-5"])
|
|
|
|
assert result.exit_code == 1
|
|
assert "not an hqt session window" in result.output
|