the surface: CLI verbs, the module's options, and three checks the compositor votes in
Everything below the CLI was merged and green against fakes; none of it was
reachable and none of it had ever met a compositor. This wires it up and then
puts the compositor in a position to disagree.
CLI (src/hhstream/cli.py, src/hhstream_session/**)
session container [ID], session reconcile [ID], and the seven pointer verbs
from PLAN §9. `start` still prints the bare session id and nothing else.
`list` gains WS / OUTPUT / POINTER, with the gap marker where a value is
genuinely unknown rather than a blank that reads as zero -- the POINTER
column needs a second, read-only `pointer.state` call because the `list`
reply carries no lease state.
The lease id is cached in `hhstream_session.lease` (under
$XDG_RUNTIME_DIR), because PLAN §9's gesture verbs take no --lease and the
wire requires a lease_id on every one of them; --lease and $HHSTREAM_LEASE
override it, and a `no_lease` refusal drops the stale entry.
Exit codes are the contract's: a gesture with no lease is 9 and never
reaches the broker, and a compositor failure is 10 with a message that says
the session is still running. `kill` now warns about
`session.container_survivors` -- windows the compositor still shows -- and
distinguishes `null` ("could not ask") from `[]`.
`shot`/`record --output NAME` capture one container through `grim -o`; the
frame socket publishes the main output only, so it cannot do it.
Module (nix/module.nix)
sessions.containers.{enable,max,mode,workspaceBase},
sessions.pointer.{enable,leaseTtl,leaseMax}, rendered into the generated
TOML with §10's key names. hhstream-pointer.service: the operator's account,
supplementary group hhstream, After=/BindsTo= the compositor,
Restart=on-failure, KillMode=process, and the command line §3.4 freezes.
tmpfiles for /run/hhstream plus RuntimeDirectoryPreserve on the broker,
without which restarting the broker deletes the driver's socket out from
under it. The runtime-directory length assertion is untouched.
And ExecStartPost on the compositor, opening its IPC directory to its own
group: Hyprland creates <runtime>/hypr with S_IRWXU, so the broker -- a
different account by design -- could not reach the request or event socket
at all, and degraded silently exactly as it is built to.
Checks (checks/**)
vm-ipc: both sockets at their frozen names, measured against sun_path's 108
bytes, and a socket2 subscriber that receives an openwindow for a window the
test creates. The subscriber is the shipped HyprlandIPC, not a second
implementation: this check exists to prove that this client hears this
compositor.
vm-containers: one hh-* output per session at the container mode, the window
on it, a second window of the same application beside it, an unmatched
window quarantined, grim -o isolating one container, teardown removing the
output and freeing the slot. PLAN experiment 3 is answered: `hyprctl output
create headless` works.
vm-pointer: a version-2 virtual pointer, a warp and a click whose
coordinates the *application* reports, BUSY naming the holder, an expired
lease swept with its held button lifted, and a broker restart that leaves
the lock free, the bookmark intact and the driver reachable.
checks/lib gains the guest the three share, their test-script helpers (no
assertions live there), an event-socket subscriber and a Wayland client that
says where it was clicked -- nothing in nixpkgs both honours
$HHSTREAM_APP_ID and reports pointer events.
Reported, not worked around: the broker reads none of the container or
pointer config (policy.py takes [defaults] and [apps] only), `start` has no
no_container field so --no-container is refused rather than silently ignored,
and nix/hyprland-conf.nix sets input:follow_mouse = 0, which sends pointer
events to the focused window only -- measured, with the cursor at the aimed
pixel and no client told. README.dev.md has the evidence for each.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WQy29x9AfHWyzNd1f7XPGK
This commit is contained in:
1 parent
57fdd4f636
commit
de408e4b7f
19 files changed
+4304
-98
No files matched your search
@@ -0,0 +1,695 @@
|
||||
"""The CLI surface added in this milestone: containers, and the pointer lease.
|
||||
|
||||
Same shape as ``test_cli_registration.py`` — a host parser the test builds
|
||||
itself and a stubbed transport — because the point is the same: what the
|
||||
handlers put on the wire, what they print, and what they exit with. Nothing
|
||||
here needs a daemon, so nothing here starts one.
|
||||
|
||||
The lease cache is pointed at a temporary directory for every test. It is real
|
||||
(the same code the CLI runs), because "acquire remembers the lease so move
|
||||
needs no flag" is the whole reason it exists and a stub would prove nothing.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import io
|
||||
import json
|
||||
from contextlib import redirect_stderr, redirect_stdout
|
||||
|
||||
import pytest
|
||||
|
||||
import hhstream_session
|
||||
from hhstream_session import format as fmt
|
||||
from hhstream_session import lease, register
|
||||
from hhstream_session.client import ClientError
|
||||
from hhstreamd.protocol import ExitCode
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def lease_cache(tmp_path, monkeypatch):
|
||||
"""Every test gets its own cache, and none of them touch the real one."""
|
||||
|
||||
monkeypatch.setenv(lease.ENV_LEASE_DIR, str(tmp_path / "leases"))
|
||||
monkeypatch.delenv(lease.ENV_LEASE, raising=False)
|
||||
return tmp_path / "leases"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def host_cli():
|
||||
parser = argparse.ArgumentParser(prog="hhstream")
|
||||
sub = parser.add_subparsers(dest="command")
|
||||
register(sub)
|
||||
return parser
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sent(monkeypatch):
|
||||
"""Captured requests, plus per-op canned replies.
|
||||
|
||||
Keyed by op rather than by call order, because a human ``list`` now makes
|
||||
two requests and a test that counted positions would be asserting about
|
||||
the order of calls rather than about the verb.
|
||||
"""
|
||||
|
||||
class Transport(list):
|
||||
replies: dict[str, dict] = {}
|
||||
|
||||
def of(self, op: str) -> list[dict]:
|
||||
return [call for call in self if call["op"] == op]
|
||||
|
||||
calls = Transport()
|
||||
calls.replies = {}
|
||||
|
||||
def fake_call(op, *, socket_path=None, timeout=None, **fields):
|
||||
wire = {k: v for k, v in fields.items() if v is not None}
|
||||
calls.append({"op": op, "socket_path": socket_path, **wire})
|
||||
reply = calls.replies.get(op)
|
||||
if isinstance(reply, ClientError):
|
||||
raise reply
|
||||
return reply if reply is not None else {"ok": True}
|
||||
|
||||
monkeypatch.setattr(hhstream_session, "call", fake_call)
|
||||
return calls
|
||||
|
||||
|
||||
def run(parser: argparse.ArgumentParser, argv: list[str]) -> tuple[int, str, str]:
|
||||
args = parser.parse_args(argv)
|
||||
out, err = io.StringIO(), io.StringIO()
|
||||
with redirect_stdout(out), redirect_stderr(err):
|
||||
code = hhstream_session.dispatch(args)
|
||||
return code, out.getvalue(), err.getvalue()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# registration
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_every_verb_the_contract_names_is_registered(host_cli):
|
||||
"""PLAN §9's surface, verb by verb, as a caller would type it."""
|
||||
|
||||
surface = [
|
||||
["session", "container", "foo-aaaaaa"],
|
||||
["session", "container"],
|
||||
["session", "reconcile"],
|
||||
["session", "reconcile", "foo-aaaaaa"],
|
||||
["session", "pointer", "acquire", "foo-aaaaaa"],
|
||||
["session", "pointer", "acquire", "foo-aaaaaa", "--ttl", "10s", "--no-restore"],
|
||||
["session", "pointer", "move", "foo-aaaaaa", "--to", "0.5,0.5"],
|
||||
["session", "pointer", "move", "foo-aaaaaa", "--by", "-0.1,0.2"],
|
||||
["session", "pointer", "click", "foo-aaaaaa"],
|
||||
["session", "pointer", "click", "foo-aaaaaa", "--button", "right"],
|
||||
["session", "pointer", "down", "foo-aaaaaa", "--button", "middle"],
|
||||
["session", "pointer", "up", "foo-aaaaaa"],
|
||||
["session", "pointer", "release", "foo-aaaaaa"],
|
||||
["session", "pointer", "state"],
|
||||
["session", "pointer", "state", "--json"],
|
||||
]
|
||||
for argv in surface:
|
||||
args = host_cli.parse_args(argv)
|
||||
assert callable(args.func), argv
|
||||
|
||||
|
||||
def test_a_move_needs_exactly_one_target(host_cli):
|
||||
with pytest.raises(SystemExit):
|
||||
host_cli.parse_args(["session", "pointer", "move", "x"])
|
||||
with pytest.raises(SystemExit):
|
||||
host_cli.parse_args(
|
||||
["session", "pointer", "move", "x", "--to", "0,0", "--by", "0,0"]
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("bad", ["0.5", "0.5,", "a,b", "0.5,0.5,0.5", ""])
|
||||
def test_a_malformed_coordinate_pair_is_a_usage_error(host_cli, bad):
|
||||
"""Rejected by argparse, so nothing reaches the broker and exit 2 is exit 2."""
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
host_cli.parse_args(["session", "pointer", "move", "x", "--to", bad])
|
||||
|
||||
|
||||
def test_an_unknown_button_is_refused_before_the_wire(host_cli):
|
||||
with pytest.raises(SystemExit):
|
||||
host_cli.parse_args(["session", "pointer", "click", "x", "--button", "pinky"])
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# containers
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_container_with_no_id_lists_every_container_and_the_orphans(host_cli, sent):
|
||||
sent.replies["container.list"] = {
|
||||
"ok": True,
|
||||
"containers": [
|
||||
{
|
||||
"id": "foot-aaaaaa",
|
||||
"app": "foot",
|
||||
"output": "hh-foot-aaaaaa",
|
||||
"workspace": 1000,
|
||||
"mode": {"width": 1280, "height": 720},
|
||||
"state": "owned",
|
||||
"window": "0x55f",
|
||||
}
|
||||
],
|
||||
"orphans": ["hh-gone-bbbbbb"],
|
||||
"compositor": "ok",
|
||||
"error": None,
|
||||
"workspaces_in_use": [1000],
|
||||
}
|
||||
code, out, _ = run(host_cli, ["session", "container"])
|
||||
assert code == ExitCode.OK
|
||||
assert sent.of("container.list") and not sent.of("container.reconcile")
|
||||
assert "hh-foot-aaaaaa" in out and "1280x720" in out
|
||||
assert "hh-gone-bbbbbb" in out and "orphans" in out
|
||||
|
||||
|
||||
def test_orphans_that_could_not_be_read_are_not_reported_as_none(host_cli, sent):
|
||||
"""`null` orphans is "I could not look", which is not "nothing is there"."""
|
||||
|
||||
sent.replies["container.list"] = {
|
||||
"ok": True,
|
||||
"containers": [],
|
||||
"orphans": None,
|
||||
"compositor": "absent",
|
||||
"error": "no compositor IPC",
|
||||
"workspaces_in_use": [],
|
||||
}
|
||||
code, out, _ = run(host_cli, ["session", "container"])
|
||||
assert code == ExitCode.OK
|
||||
assert "could not be asked" in out
|
||||
assert "none" not in out.split("orphans:")[1]
|
||||
assert "no compositor IPC" in out
|
||||
|
||||
|
||||
def test_container_with_an_id_reconciles_so_the_answer_is_current(host_cli, sent):
|
||||
sent.replies["container.reconcile"] = {
|
||||
"ok": True,
|
||||
"id": "foot-aaaaaa",
|
||||
"container": {
|
||||
"output": "hh-foot-aaaaaa",
|
||||
"workspace": 1000,
|
||||
"mode": {"width": 1280, "height": 720},
|
||||
"created_by": "broker",
|
||||
"state": "owned",
|
||||
},
|
||||
"diff": [
|
||||
{
|
||||
"id": "foot-aaaaaa",
|
||||
"field": "workspace",
|
||||
"recorded": None,
|
||||
"observed": 1000,
|
||||
}
|
||||
],
|
||||
}
|
||||
code, out, _ = run(host_cli, ["session", "container", "foot-aaaaaa"])
|
||||
assert code == ExitCode.OK
|
||||
assert sent.of("container.reconcile")[0]["id"] == "foot-aaaaaa"
|
||||
assert "hh-foot-aaaaaa" in out
|
||||
# Both values, so a reader can see which way the record moved.
|
||||
assert "recorded None" in out and "compositor says 1000" in out
|
||||
|
||||
|
||||
def test_reconcile_with_no_drift_says_so_rather_than_printing_nothing(host_cli, sent):
|
||||
sent.replies["container.reconcile"] = {
|
||||
"ok": True,
|
||||
"container": None,
|
||||
"diff": [],
|
||||
"scan": {
|
||||
"available": True,
|
||||
"signature": "abc123",
|
||||
"quarantine": "special:quarantine",
|
||||
"adopted": [],
|
||||
"removed": ["hh-stale-cccccc"],
|
||||
"orphaned": [],
|
||||
"failed": [],
|
||||
},
|
||||
}
|
||||
code, out, _ = run(host_cli, ["session", "reconcile"])
|
||||
assert code == ExitCode.OK
|
||||
assert "id" not in sent.of("container.reconcile")[0]
|
||||
assert "matches the compositor" in out
|
||||
assert "hh-stale-cccccc" in out and "removed" in out
|
||||
assert "abc123" in out
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# the lease, across two invocations
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def _acquired(lease_id: str = "lease-1") -> dict:
|
||||
return {
|
||||
"ok": True,
|
||||
"id": "foot-aaaaaa",
|
||||
"lease_id": lease_id,
|
||||
"bookmark": {
|
||||
"x": 0.5,
|
||||
"y": 0.5,
|
||||
"output": "hh-foot-aaaaaa",
|
||||
"at": "2026-10-03T00:00:00Z",
|
||||
},
|
||||
"expires_in_s": 30.0,
|
||||
}
|
||||
|
||||
|
||||
def test_acquire_prints_the_bare_lease_id_on_stdout_and_detail_on_stderr(host_cli, sent):
|
||||
"""Same contract as `start`: stdout is the one token a caller passes back."""
|
||||
|
||||
sent.replies["pointer.acquire"] = _acquired()
|
||||
code, out, err = run(host_cli, ["session", "pointer", "acquire", "foot-aaaaaa"])
|
||||
assert code == ExitCode.OK
|
||||
assert out == "lease-1\n"
|
||||
assert "hh-foot-aaaaaa" in err
|
||||
assert "release foot-aaaaaa" in err
|
||||
|
||||
|
||||
def test_acquire_sends_ttl_and_restore_only_when_asked(host_cli, sent):
|
||||
sent.replies["pointer.acquire"] = _acquired()
|
||||
run(host_cli, ["session", "pointer", "acquire", "foot-aaaaaa"])
|
||||
first = sent.of("pointer.acquire")[0]
|
||||
assert "ttl_s" not in first and "restore" not in first
|
||||
|
||||
run(
|
||||
host_cli,
|
||||
["session", "pointer", "acquire", "foot-aaaaaa", "--ttl", "2m", "--no-restore"],
|
||||
)
|
||||
second = sent.of("pointer.acquire")[1]
|
||||
assert second["ttl_s"] == 120.0
|
||||
assert second["restore"] is False
|
||||
|
||||
|
||||
def test_a_gesture_reuses_the_lease_acquire_cached(host_cli, sent):
|
||||
"""The contract's surface has no --lease, so something has to remember it."""
|
||||
|
||||
sent.replies["pointer.acquire"] = _acquired()
|
||||
sent.replies["pointer.move"] = {
|
||||
"ok": True,
|
||||
"id": "foot-aaaaaa",
|
||||
"bookmark": {
|
||||
"x": 0.25,
|
||||
"y": 0.75,
|
||||
"output": "hh-foot-aaaaaa",
|
||||
"at": "2026-10-03T00:00:01Z",
|
||||
},
|
||||
}
|
||||
run(host_cli, ["session", "pointer", "acquire", "foot-aaaaaa"])
|
||||
code, out, _ = run(
|
||||
host_cli, ["session", "pointer", "move", "foot-aaaaaa", "--to", "0.25,0.75"]
|
||||
)
|
||||
assert code == ExitCode.OK
|
||||
move = sent.of("pointer.move")[0]
|
||||
assert move["lease_id"] == "lease-1"
|
||||
assert (move["x"], move["y"]) == (0.25, 0.75)
|
||||
assert "0.2500,0.7500" in out
|
||||
|
||||
|
||||
def test_a_relative_move_sends_dx_dy_and_never_x_y(host_cli, sent):
|
||||
sent.replies["pointer.acquire"] = _acquired()
|
||||
run(host_cli, ["session", "pointer", "acquire", "foot-aaaaaa"])
|
||||
run(host_cli, ["session", "pointer", "move", "foot-aaaaaa", "--by", "-0.1,0.2"])
|
||||
move = sent.of("pointer.move")[0]
|
||||
assert (move["dx"], move["dy"]) == (-0.1, 0.2)
|
||||
assert "x" not in move and "y" not in move
|
||||
|
||||
|
||||
def test_an_explicit_lease_beats_the_cache(host_cli, sent):
|
||||
sent.replies["pointer.acquire"] = _acquired()
|
||||
run(host_cli, ["session", "pointer", "acquire", "foot-aaaaaa"])
|
||||
run(
|
||||
host_cli,
|
||||
["session", "pointer", "click", "foot-aaaaaa", "--lease", "from-the-caller"],
|
||||
)
|
||||
assert sent.of("pointer.click")[0]["lease_id"] == "from-the-caller"
|
||||
|
||||
|
||||
def test_the_environment_beats_the_cache_too(host_cli, sent, monkeypatch):
|
||||
sent.replies["pointer.acquire"] = _acquired()
|
||||
run(host_cli, ["session", "pointer", "acquire", "foot-aaaaaa"])
|
||||
monkeypatch.setenv(lease.ENV_LEASE, "from-the-environment")
|
||||
run(host_cli, ["session", "pointer", "click", "foot-aaaaaa"])
|
||||
assert sent.of("pointer.click")[0]["lease_id"] == "from-the-environment"
|
||||
|
||||
|
||||
def test_a_lease_cached_for_another_broker_is_not_a_lease_here(host_cli, sent):
|
||||
sent.replies["pointer.acquire"] = _acquired()
|
||||
run(host_cli, ["session", "--socket", "/a.sock", "pointer", "acquire", "foot-aaaaaa"])
|
||||
code, _, err = run(
|
||||
host_cli, ["session", "--socket", "/b.sock", "pointer", "click", "foot-aaaaaa"]
|
||||
)
|
||||
assert code == ExitCode.NO_LEASE
|
||||
assert not sent.of("pointer.click")
|
||||
assert "no pointer lease" in err
|
||||
|
||||
|
||||
def test_a_gesture_with_no_lease_is_nine_and_never_reaches_the_broker(host_cli, sent):
|
||||
"""Exit 9, not 2: the command line is fine, the lease is what is missing."""
|
||||
|
||||
for argv in (
|
||||
["session", "pointer", "move", "foot-aaaaaa", "--to", "0.5,0.5"],
|
||||
["session", "pointer", "click", "foot-aaaaaa"],
|
||||
["session", "pointer", "down", "foot-aaaaaa"],
|
||||
["session", "pointer", "up", "foot-aaaaaa"],
|
||||
["session", "pointer", "release", "foot-aaaaaa"],
|
||||
):
|
||||
code, out, err = run(host_cli, argv)
|
||||
assert code == ExitCode.NO_LEASE, argv
|
||||
assert "acquire" in err
|
||||
assert sent == []
|
||||
|
||||
|
||||
def test_a_no_lease_refusal_drops_the_stale_cache_entry(host_cli, sent):
|
||||
"""Otherwise every later verb fails the same way and `acquire` looks pointless."""
|
||||
|
||||
sent.replies["pointer.acquire"] = _acquired()
|
||||
sent.replies["pointer.move"] = {
|
||||
"ok": False,
|
||||
"error": "no_lease",
|
||||
"reason": "foot-aaaaaa does not hold the pointer: lease expired",
|
||||
"holder": None,
|
||||
}
|
||||
run(host_cli, ["session", "pointer", "acquire", "foot-aaaaaa"])
|
||||
code, _, err = run(
|
||||
host_cli, ["session", "pointer", "move", "foot-aaaaaa", "--to", "0.5,0.5"]
|
||||
)
|
||||
assert code == ExitCode.NO_LEASE
|
||||
assert "exit 9" in err
|
||||
assert lease.recall("foot-aaaaaa", socket=None) is None
|
||||
|
||||
|
||||
def test_release_gives_the_lease_back_and_forgets_it(host_cli, sent):
|
||||
sent.replies["pointer.acquire"] = _acquired()
|
||||
sent.replies["pointer.release"] = {
|
||||
"ok": True,
|
||||
"id": "foot-aaaaaa",
|
||||
"bookmark": {
|
||||
"x": 0.5,
|
||||
"y": 0.5,
|
||||
"output": "hh-foot-aaaaaa",
|
||||
"at": "2026-10-03T00:00:02Z",
|
||||
},
|
||||
"released_by": "lease",
|
||||
"released_at": "2026-10-03T00:00:02Z",
|
||||
"buttons_lifted": ["left"],
|
||||
}
|
||||
run(host_cli, ["session", "pointer", "acquire", "foot-aaaaaa"])
|
||||
code, out, _ = run(host_cli, ["session", "pointer", "release", "foot-aaaaaa"])
|
||||
assert code == ExitCode.OK
|
||||
# The loud part: a button that was down came back up.
|
||||
assert "lifted left" in out
|
||||
assert lease.recall("foot-aaaaaa", socket=None) is None
|
||||
|
||||
|
||||
def test_a_held_button_is_reported_with_everything_still_down(host_cli, sent):
|
||||
sent.replies["pointer.acquire"] = _acquired()
|
||||
sent.replies["pointer.button"] = {
|
||||
"ok": True,
|
||||
"id": "foot-aaaaaa",
|
||||
"buttons": ["left"],
|
||||
}
|
||||
run(host_cli, ["session", "pointer", "acquire", "foot-aaaaaa"])
|
||||
code, out, _ = run(host_cli, ["session", "pointer", "down", "foot-aaaaaa"])
|
||||
assert code == ExitCode.OK
|
||||
request = sent.of("pointer.button")[0]
|
||||
assert request["button"] == "left" and request["state"] == "down"
|
||||
assert "held: left" in out
|
||||
|
||||
|
||||
def test_up_sends_the_other_state_through_the_same_verb(host_cli, sent):
|
||||
sent.replies["pointer.acquire"] = _acquired()
|
||||
sent.replies["pointer.button"] = {"ok": True, "id": "foot-aaaaaa", "buttons": []}
|
||||
run(host_cli, ["session", "pointer", "acquire", "foot-aaaaaa"])
|
||||
run(host_cli, ["session", "pointer", "up", "foot-aaaaaa", "--button", "right"])
|
||||
request = sent.of("pointer.button")[0]
|
||||
assert (request["button"], request["state"]) == ("right", "up")
|
||||
|
||||
|
||||
def test_pointer_state_needs_no_lease_and_no_session(host_cli, sent):
|
||||
sent.replies["pointer.state"] = {
|
||||
"ok": True,
|
||||
"holder": "foot-aaaaaa",
|
||||
"since": 123.0,
|
||||
"lease_id": "lease-1",
|
||||
"expires_at": 153.0,
|
||||
"buttons": ["left"],
|
||||
"bookmark": None,
|
||||
"driver": "/run/hhstream/pointer.sock",
|
||||
}
|
||||
code, out, _ = run(host_cli, ["session", "pointer", "state"])
|
||||
assert code == ExitCode.OK
|
||||
assert "foot-aaaaaa" in out and "left" in out
|
||||
|
||||
|
||||
def test_a_busy_pointer_exits_eight_naming_the_holder(host_cli, sent):
|
||||
sent.replies["pointer.acquire"] = {
|
||||
"ok": False,
|
||||
"error": "pointer_busy",
|
||||
"reason": "the pointer is held by chromium-bbbbbb",
|
||||
"holder": "chromium-bbbbbb",
|
||||
}
|
||||
code, out, err = run(host_cli, ["session", "pointer", "acquire", "foot-aaaaaa"])
|
||||
assert code == ExitCode.BUSY
|
||||
assert out == ""
|
||||
assert "chromium-bbbbbb" in err
|
||||
# Nothing was cached: there is no lease to remember.
|
||||
assert lease.recall("foot-aaaaaa", socket=None) is None
|
||||
|
||||
|
||||
def test_a_compositor_failure_says_the_session_is_still_running(host_cli, sent):
|
||||
"""Exit 10 is not exit 4, and the message has to carry that difference."""
|
||||
|
||||
sent.replies["pointer.acquire"] = {
|
||||
"ok": False,
|
||||
"error": "no_container",
|
||||
"reason": "session foot-aaaaaa has no container output to aim at",
|
||||
"hint": "the compositor was unreachable when this session started",
|
||||
}
|
||||
code, _, err = run(host_cli, ["session", "pointer", "acquire", "foot-aaaaaa"])
|
||||
assert code == ExitCode.COMPOSITOR
|
||||
assert "compositor error" in err
|
||||
assert "the session itself is unaffected" in err
|
||||
|
||||
|
||||
def test_json_mode_puts_the_protocol_object_on_stdout(host_cli, sent):
|
||||
sent.replies["pointer.acquire"] = _acquired()
|
||||
code, out, err = run(
|
||||
host_cli, ["session", "pointer", "acquire", "--json", "foot-aaaaaa"]
|
||||
)
|
||||
assert code == ExitCode.OK
|
||||
assert json.loads(out)["lease_id"] == "lease-1"
|
||||
assert err == ""
|
||||
# Still cached: --json changes the rendering, not the behaviour.
|
||||
assert lease.recall("foot-aaaaaa", socket=None) == "lease-1"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# list: the three new columns
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def _listed(**overrides) -> dict:
|
||||
session = {
|
||||
"id": "foot-aaaaaa",
|
||||
"app": "foot",
|
||||
"state": "ready",
|
||||
"pid": 4242,
|
||||
"live": True,
|
||||
"idle_s": 12.0,
|
||||
"expires_in_s": 600.0,
|
||||
"workspace": 1000,
|
||||
"container": {"output": "hh-foot-aaaaaa", "workspace": 1000, "state": "owned"},
|
||||
}
|
||||
session.update(overrides)
|
||||
return {"ok": True, "sessions": [session]}
|
||||
|
||||
|
||||
def test_list_gains_the_workspace_output_and_pointer_columns(host_cli, sent):
|
||||
sent.replies["list"] = _listed()
|
||||
sent.replies["pointer.state"] = {"ok": True, "holder": None}
|
||||
code, out, _ = run(host_cli, ["session", "list"])
|
||||
assert code == ExitCode.OK
|
||||
header = out.splitlines()[0].split()
|
||||
assert header[:9] == [
|
||||
"ID",
|
||||
"APP",
|
||||
"STATE",
|
||||
"PID",
|
||||
"WS",
|
||||
"OUTPUT",
|
||||
"POINTER",
|
||||
"IDLE",
|
||||
"EXPIRES",
|
||||
]
|
||||
row = out.splitlines()[1].split()
|
||||
# PID stays in column four: callers (and vm-sessions) already read it there.
|
||||
assert row[3] == "4242"
|
||||
assert row[4] == "1000" and row[5] == "hh-foot-aaaaaa" and row[6] == "free"
|
||||
|
||||
|
||||
def test_the_row_that_holds_the_cursor_says_held_and_the_others_say_who(host_cli, sent):
|
||||
sent.replies["list"] = {
|
||||
"ok": True,
|
||||
"sessions": _listed()["sessions"]
|
||||
+ [
|
||||
{
|
||||
"id": "chromium-bbbbbb",
|
||||
"app": "chromium",
|
||||
"state": "ready",
|
||||
"pid": 4343,
|
||||
"live": True,
|
||||
"idle_s": 3.0,
|
||||
"expires_in_s": 600.0,
|
||||
"workspace": 1001,
|
||||
"container": {"output": "hh-chromium-bbbbbb"},
|
||||
}
|
||||
],
|
||||
}
|
||||
sent.replies["pointer.state"] = {"ok": True, "holder": "foot-aaaaaa"}
|
||||
code, out, _ = run(host_cli, ["session", "list"])
|
||||
assert code == ExitCode.OK
|
||||
rows = {line.split()[0]: line.split() for line in out.splitlines()[1:]}
|
||||
assert rows["foot-aaaaaa"][6] == "held"
|
||||
assert rows["chromium-bbbbbb"][6] == "held:foot-aaaaaa"
|
||||
|
||||
|
||||
def test_a_degraded_session_shows_the_gap_marker_not_a_blank(host_cli, sent):
|
||||
"""A blank reads as zero, or as "no". Neither is what `null` means."""
|
||||
|
||||
sent.replies["list"] = _listed(
|
||||
workspace=None,
|
||||
container={"output": None, "workspace": None, "state": "degraded"},
|
||||
)
|
||||
sent.replies["pointer.state"] = {"ok": True, "holder": None}
|
||||
code, out, _ = run(host_cli, ["session", "list"])
|
||||
row = out.splitlines()[1].split()
|
||||
assert row[4] == fmt.DASH and row[5] == fmt.DASH
|
||||
|
||||
|
||||
def test_an_unreachable_pointer_state_leaves_the_column_unknown_not_free(host_cli, sent):
|
||||
"""The sessions were listed; only the lease could not be read."""
|
||||
|
||||
sent.replies["list"] = _listed()
|
||||
sent.replies["pointer.state"] = ClientError("daemon_unreachable", "socket went away")
|
||||
code, out, _ = run(host_cli, ["session", "list"])
|
||||
assert code == ExitCode.OK
|
||||
assert out.splitlines()[1].split()[6] == fmt.DASH
|
||||
|
||||
|
||||
def test_json_list_makes_no_second_request_and_is_the_protocol_object(host_cli, sent):
|
||||
sent.replies["list"] = _listed()
|
||||
code, out, _ = run(host_cli, ["session", "list", "--json"])
|
||||
assert code == ExitCode.OK
|
||||
assert not sent.of("pointer.state")
|
||||
assert json.loads(out)["sessions"][0]["id"] == "foot-aaaaaa"
|
||||
|
||||
|
||||
def test_a_failed_list_does_not_go_on_to_ask_about_the_pointer(host_cli, sent):
|
||||
sent.replies["list"] = {"ok": False, "error": "bad_request", "reason": "nope"}
|
||||
code, _, err = run(host_cli, ["session", "list"])
|
||||
assert code == ExitCode.USAGE
|
||||
assert not sent.of("pointer.state")
|
||||
assert "nope" in err
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# teardown: the survivors the CLI used to be silent about
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_kill_warns_about_windows_that_survived_the_teardown(host_cli, sent):
|
||||
sent.replies["kill"] = {
|
||||
"ok": True,
|
||||
"id": "foot-aaaaaa",
|
||||
"session": {
|
||||
"id": "foot-aaaaaa",
|
||||
"state": "killed",
|
||||
"signal_sent": "TERM",
|
||||
"pgid": 4242,
|
||||
"survivors": [],
|
||||
"container_removed": True,
|
||||
"container_survivors": [
|
||||
{
|
||||
"address": "0x55f",
|
||||
"pid": 4243,
|
||||
"class": "hh-foot-aaaaaa",
|
||||
"initial_class": "hh-foot-aaaaaa",
|
||||
"workspace": 1000,
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
code, out, _ = run(host_cli, ["session", "kill", "foot-aaaaaa"])
|
||||
assert code == ExitCode.OK
|
||||
assert "WARNING" in out
|
||||
assert "still shows 1 window" in out
|
||||
assert "0x55f" in out
|
||||
|
||||
|
||||
def test_kill_says_when_the_compositor_could_not_be_asked_about_survivors(host_cli, sent):
|
||||
"""`null` is "I could not check", which must not print as "nothing survived"."""
|
||||
|
||||
sent.replies["kill"] = {
|
||||
"ok": True,
|
||||
"session": {
|
||||
"id": "foot-aaaaaa",
|
||||
"state": "killed",
|
||||
"survivors": [],
|
||||
"container_removed": False,
|
||||
"container_survivors": None,
|
||||
"container_error": "no compositor IPC",
|
||||
},
|
||||
}
|
||||
code, out, _ = run(host_cli, ["session", "kill", "foot-aaaaaa"])
|
||||
assert code == ExitCode.OK
|
||||
assert "could not be asked" in out
|
||||
assert "no compositor IPC" in out
|
||||
|
||||
|
||||
def test_a_clean_teardown_says_the_container_went_away(host_cli, sent):
|
||||
sent.replies["kill"] = {
|
||||
"ok": True,
|
||||
"session": {
|
||||
"id": "foot-aaaaaa",
|
||||
"state": "killed",
|
||||
"survivors": [],
|
||||
"container_removed": True,
|
||||
"container_survivors": [],
|
||||
},
|
||||
}
|
||||
code, out, _ = run(host_cli, ["session", "kill", "foot-aaaaaa"])
|
||||
assert code == ExitCode.OK
|
||||
assert "container removed" in out
|
||||
assert "WARNING" not in out
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# the gap this slice could not close
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_no_container_is_refused_rather_than_sent_and_ignored(host_cli, sent):
|
||||
"""The broker's `start` has no such field, so sending it would be a lie.
|
||||
|
||||
PLAN §9 lists the flag; CONTRACT-sessions.md §4 leaves `start` unchanged and
|
||||
`SessionManager.start` takes no `no_container`. A request carrying it would
|
||||
be accepted, ignored, and the session would get a container anyway — so the
|
||||
CLI refuses and says which document disagrees with which.
|
||||
"""
|
||||
|
||||
code, out, err = run(host_cli, ["session", "start", "foot", "--no-container"])
|
||||
assert code == ExitCode.USAGE
|
||||
assert sent == []
|
||||
assert "not implemented" in err
|
||||
assert out == ""
|
||||
|
||||
|
||||
def test_start_without_the_flag_is_untouched(host_cli, sent):
|
||||
sent.replies["start"] = {
|
||||
"ok": True,
|
||||
"id": "foot-aaaaaa",
|
||||
"session": {"id": "foot-aaaaaa", "app": "foot", "pid": 1, "state": "ready"},
|
||||
}
|
||||
code, out, _ = run(host_cli, ["session", "start", "foot"])
|
||||
assert code == ExitCode.OK
|
||||
assert out == "foot-aaaaaa\n"
|
||||
assert "no_container" not in sent.of("start")[0]
|
||||
Reference in new issue
Block a user