The four slices existed and nothing called them. Now the broker builds a
spatial container per session, reads back what the compositor actually did,
and aims the cursor into one container under a broker-wide lease.
Record schema 3 (registry.py): `container` {output, workspace, mode,
created_by, state}, `pointer` {bookmark, last_released_at, released_by} and
the compositor's `signature`. A v2 record is migrated on load, not refused —
its application is still running. Every field that could not be verified is
null; `container: null` means "no container", never "probably something".
Containers (new container_host.py, manager.py, launcher.py): `start`
allocates a slot from `WorkspaceAllocator`, runs `container_plan()`'s argv,
launches the app with the container stamp in its environment, then reads the
workspace, output and window back out of `clients -j`. Teardown removes the
output, releases the slot and reports survivors rather than claiming success
— and runs for an unprompted exit and for `gc` too, so no container is ever
left unattended. Broker start-up reconciles: adopt `hh-*` outputs a live
session claims, remove the rest, `contains_output()` being the only filter.
No IPC means `container: degraded` and lifecycle verbs unchanged.
The plans' argv are dispatched over the compositor's request socket rather
than by executing `hyprctl`, which is what hyprctl does with the same words;
the reply is checked, so a refused command is not recorded as a container.
Pointer (new driver.py, manager.py): a client for the driver's private
socket, and `pointer.acquire|move|button|click|release|state` on top of
`PointerLease`. The broker owns the lease, the driver executes. The bookmark
is marked on every move and before release and stored in the record, so it
survives a restart. On expiry `pressed()` is read before `expire()` and
`release_all` goes to the driver, because the lease cannot lift a button
itself; a sweep runs unprompted so the TTL is a promise.
containers.py to v2: `quarantine_plan()` -> `quarantine_argv()`, with the
before-any-per-session-rule ordering stated where the caller could get it
wrong. protocol.py: 9 NO_LEASE, 10 COMPOSITOR, the verb table, and the
`request_id` cache moved out of the server so the CLI agrees with it.
Tests: real AF_UNIX everywhere — a stateful fake compositor and the shipped
pointer driver behind a recording sink. No mocked sockets, no compositor, no
VM. 551 -> 693.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017mUq7QvQ9EZb2Wi35xj4cs
84 lines
2.3 KiB
Python
84 lines
2.3 KiB
Python
"""Shared fixtures.
|
|
|
|
Two things are worth knowing:
|
|
|
|
* **Nothing here sleeps for real time** except where the brief requires it: the
|
|
one integration test that proves a real three-second idle reap. Everything
|
|
else either injects a clock or polls with a deadline.
|
|
* **Unix socket paths are short by force.** ``AF_UNIX`` caps a path at 108
|
|
bytes and ``pytest``'s ``tmp_path`` can exceed that on a deep ``TMPDIR``, so
|
|
sockets live in a shallow ``mkdtemp`` of their own rather than under
|
|
``tmp_path``.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import shutil
|
|
import socket
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
# `tests/` for the shared helpers, and this directory for `fakes`, which the
|
|
# unit tests and the integration tests both import.
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
|
|
#: Linux's sun_path is 108 bytes including the NUL.
|
|
SUN_PATH_MAX = 107
|
|
|
|
|
|
@pytest.fixture
|
|
def short_tmpdir() -> Path:
|
|
"""A temp directory shallow enough to hold a unix socket path."""
|
|
|
|
path = Path(tempfile.mkdtemp(prefix="hh"))
|
|
try:
|
|
yield path
|
|
finally:
|
|
shutil.rmtree(path, ignore_errors=True)
|
|
|
|
|
|
def socket_path(directory: Path, name: str = "c.sock") -> str:
|
|
path = str(directory / name)
|
|
if len(path.encode()) > SUN_PATH_MAX:
|
|
pytest.skip(f"socket path too long for AF_UNIX ({len(path)} bytes): {path}")
|
|
return path
|
|
|
|
|
|
def wait_until(predicate, timeout: float, interval: float = 0.02, what: str = "condition"):
|
|
"""Poll ``predicate`` until it is truthy. Returns its value, or fails.
|
|
|
|
This is how the integration tests wait: a deadline and a tight poll, never
|
|
a fixed sleep sized by guesswork.
|
|
"""
|
|
|
|
deadline = time.monotonic() + timeout
|
|
while True:
|
|
value = predicate()
|
|
if value:
|
|
return value
|
|
if time.monotonic() > deadline:
|
|
pytest.fail(f"timed out after {timeout}s waiting for {what}")
|
|
time.sleep(interval)
|
|
|
|
|
|
def pid_alive(pid: int) -> bool:
|
|
return os.path.isdir(f"/proc/{pid}")
|
|
|
|
|
|
def socket_is_live(path: str) -> bool:
|
|
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
try:
|
|
sock.settimeout(0.5)
|
|
sock.connect(path)
|
|
return True
|
|
except OSError:
|
|
return False
|
|
finally:
|
|
sock.close()
|