feat: deliver installable local alpha sessions
Some checks failed
tamq-ci / test (push) Failing after 6s
Some checks failed
tamq-ci / test (push) Failing after 6s
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a03397-4d51-7fd1-8ff2-946eb22ea2bc
This commit is contained in:
parent
d56bd3c79f
commit
5774fbd548
18 changed files with 890 additions and 94 deletions
|
|
@ -1,11 +1,17 @@
|
|||
from tamq import tmux
|
||||
import pytest
|
||||
|
||||
|
||||
def test_tmux_manager_builds_tap_windows(monkeypatch):
|
||||
def test_tmux_manager_builds_tap_windows(tmp_path, monkeypatch):
|
||||
calls = []
|
||||
manager = tmux.TmuxManager("tamq-test")
|
||||
repo_a = tmp_path / "a"
|
||||
repo_b = tmp_path / "b"
|
||||
repo_a.mkdir()
|
||||
repo_b.mkdir()
|
||||
monkeypatch.setattr(tmux, "validate_targets", lambda repos: None)
|
||||
monkeypatch.setattr(tmux, "repository_paths", lambda: {"a": "/tmp/a", "b": "/tmp/b"})
|
||||
monkeypatch.setattr(tmux, "repository_paths", lambda: {"a": str(repo_a), "b": str(repo_b)})
|
||||
monkeypatch.setattr(tmux.shutil, "which", lambda command: f"/bin/{command}")
|
||||
def run(*args, check=True):
|
||||
calls.append(args)
|
||||
if args[:2] == ("list-windows", "-t"):
|
||||
|
|
@ -15,6 +21,95 @@ def test_tmux_manager_builds_tap_windows(monkeypatch):
|
|||
return ""
|
||||
monkeypatch.setattr(manager, "_run", run)
|
||||
monkeypatch.setattr(tmux.subprocess, "run", lambda *args, **kwargs: type("R", (), {"returncode": 1})())
|
||||
endpoint = manager.ensure(["a", "b"], "codex")
|
||||
endpoint = manager.ensure(["a", "b"], "codex --quiet")
|
||||
assert endpoint.endpoint_id == "tmux-amq-42"
|
||||
assert any("tamq tap" in " ".join(call) for call in calls if call and call[0] == "send-keys")
|
||||
assert endpoint.instance_id.startswith("tmux-amq-42-")
|
||||
assert endpoint.repos == ["a", "b"]
|
||||
new_session = next(call for call in calls if call and call[0] == "new-session")
|
||||
assert new_session[-2:] == ("-c", str(repo_a))
|
||||
assert "sleep" not in new_session
|
||||
new_window = next(call for call in calls if call and call[0] == "new-window")
|
||||
assert new_window[-2:] == ("-c", str(repo_b))
|
||||
tap_calls = [call for call in calls if call and call[0] == "send-keys"]
|
||||
assert len(tap_calls) == 2
|
||||
assert all("tamq tap" in " ".join(call) for call in tap_calls)
|
||||
assert all("codex --quiet" in " ".join(call) for call in tap_calls)
|
||||
assert ("select-window", "-t", "tamq-test:a") in calls
|
||||
assert any(call and call[0] == "set-option" for call in calls)
|
||||
|
||||
|
||||
def test_tmux_manager_reuses_session_instance_id(tmp_path, monkeypatch):
|
||||
repo = tmp_path / "a"
|
||||
repo.mkdir()
|
||||
manager = tmux.TmuxManager("tamq-test")
|
||||
options = {"@tamq_managed": "1"}
|
||||
monkeypatch.setattr(tmux, "validate_targets", lambda repos: None)
|
||||
monkeypatch.setattr(tmux, "repository_paths", lambda: {"a": str(repo)})
|
||||
monkeypatch.setattr(tmux.shutil, "which", lambda command: f"/bin/{command}")
|
||||
|
||||
def run(*args, check=True):
|
||||
if args[:2] == ("display-message", "-p"):
|
||||
return "42"
|
||||
if args and args[0] == "show-options":
|
||||
return options.get(args[-1], "")
|
||||
if args and args[0] == "set-option":
|
||||
options[args[-2]] = args[-1]
|
||||
if args[:2] == ("list-windows", "-t"):
|
||||
return "a"
|
||||
return ""
|
||||
|
||||
monkeypatch.setattr(manager, "_run", run)
|
||||
monkeypatch.setattr(
|
||||
tmux.subprocess,
|
||||
"run",
|
||||
lambda *args, **kwargs: type("R", (), {"returncode": 0})(),
|
||||
)
|
||||
|
||||
first = manager.ensure(["a"])
|
||||
second = manager.ensure(["a"])
|
||||
assert first.instance_id == second.instance_id
|
||||
|
||||
|
||||
def test_preflight_rejects_foreign_session(tmp_path, monkeypatch):
|
||||
repo = tmp_path / "a"
|
||||
repo.mkdir()
|
||||
manager = tmux.TmuxManager("tamq-test")
|
||||
monkeypatch.setattr(tmux, "validate_targets", lambda repos: None)
|
||||
monkeypatch.setattr(tmux, "repository_paths", lambda: {"a": str(repo)})
|
||||
monkeypatch.setattr(tmux.shutil, "which", lambda command: f"/bin/{command}")
|
||||
monkeypatch.setattr(
|
||||
tmux.subprocess,
|
||||
"run",
|
||||
lambda *args, **kwargs: type("R", (), {"returncode": 0})(),
|
||||
)
|
||||
|
||||
def run(*args, check=True):
|
||||
if args[:2] == ("display-message", "-p"):
|
||||
return "42"
|
||||
return ""
|
||||
|
||||
monkeypatch.setattr(manager, "_run", run)
|
||||
with pytest.raises(tmux.TmuxError, match="not managed by tamq"):
|
||||
manager.preflight(["a"])
|
||||
|
||||
|
||||
def test_preflight_rejects_missing_agent(tmp_path, monkeypatch):
|
||||
repo = tmp_path / "a"
|
||||
repo.mkdir()
|
||||
manager = tmux.TmuxManager("tamq-test")
|
||||
monkeypatch.setattr(tmux, "validate_targets", lambda repos: None)
|
||||
monkeypatch.setattr(tmux, "repository_paths", lambda: {"a": str(repo)})
|
||||
monkeypatch.setattr(tmux.shutil, "which", lambda command: None if command == "missing-agent" else f"/bin/{command}")
|
||||
with pytest.raises(tmux.TmuxError, match="agent command not found"):
|
||||
manager.preflight(["a"], "missing-agent")
|
||||
|
||||
|
||||
def test_preflight_deduplicates_repositories(tmp_path, monkeypatch):
|
||||
repo = tmp_path / "a"
|
||||
repo.mkdir()
|
||||
manager = tmux.TmuxManager("tamq-test")
|
||||
monkeypatch.setattr(tmux, "validate_targets", lambda repos: None)
|
||||
monkeypatch.setattr(tmux, "repository_paths", lambda: {"a": str(repo)})
|
||||
monkeypatch.setattr(tmux.shutil, "which", lambda command: f"/bin/{command}")
|
||||
plan = manager.preflight(["a", "a"], "codex")
|
||||
assert plan.repos == ("a",)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue