diff --git a/app/nullius/standard/kits/agent-computer-v1/fixture.py b/app/nullius/standard/kits/agent-computer-v1/fixture.py index 96920d4a..42c226aa 100644 --- a/app/nullius/standard/kits/agent-computer-v1/fixture.py +++ b/app/nullius/standard/kits/agent-computer-v1/fixture.py @@ -17,6 +17,8 @@ Words and labels are drawn as bitmaps from the glyphs below: no widget holds their text, and Tk's ``send`` is removed, so no other program can read them but from the screen. The window fills the screen, so every press lands on it. +Like an application's window, it names its machine and its process +(``WM_CLIENT_MACHINE`` and ``_NET_WM_PID``). Each press, release, scroll and key goes to ``events.jsonl`` in the fixture's home, a folder only ``fixture`` reads, one JSON object a line: ``kind``, the @@ -35,6 +37,7 @@ """ import json import os +import socket import struct import sys import time @@ -207,6 +210,7 @@ def __init__(self, values, log): self.root = tk.Tk() self.root.tk.call("rename", "send", "") # no other X client may run Tcl in this one self.root.title(TITLE) + self.root.wm_client(socket.gethostname()) # with it Tk sets _NET_WM_PID as the window maps self.root.configure(background=BACKGROUND) self.root.attributes("-fullscreen", True) self.images, self.names, self.field, self.texts = [], {}, None, [] diff --git a/app/tests/test_computer_kit.py b/app/tests/test_computer_kit.py index e7807fe2..1d77415e 100644 --- a/app/tests/test_computer_kit.py +++ b/app/tests/test_computer_kit.py @@ -588,6 +588,25 @@ def _from_corner(cells): return sorted((c - c0, r - r0) for c, r in cells) +# What the desktop's Python reads of the active window: the process and the machine it names, the command line of +# that process, and the desktop's host name. +_WINDOW_OWNER = r""" +import json, socket +from Xlib import X, Xatom, display +d = display.Display(":0") +root = d.screen().root +active = root.get_full_property(d.intern_atom("_NET_ACTIVE_WINDOW"), X.AnyPropertyType).value[0] +w = d.create_resource_object("window", active) +pid = w.get_full_property(d.intern_atom("_NET_WM_PID"), Xatom.CARDINAL) +machine = w.get_full_property(Xatom.WM_CLIENT_MACHINE, X.AnyPropertyType) +pid = int(pid.value[0]) if pid else None +machine = machine.value if machine else None +command = open(f"/proc/{pid}/cmdline", "rb").read().decode().split("\0") if pid else [] +print(json.dumps({"pid": pid, "machine": machine.decode() if isinstance(machine, bytes) else machine, + "command": command, "host": socket.gethostname()})) +""" + + _PREFIX = os.environ.get("NULLIUS_TEST_CONTAINER_PREFIX", "nullius-test") @@ -678,6 +697,14 @@ def test_a_click_by_an_action_passes_and_the_same_click_by_python_fails(self): self.assertFalse(v["passed"]) self.assertIn("outside every action", v["why"]) + def test_the_fixture_window_names_its_process_and_its_machine(self): + self.d.start_fixture(checks.draw("type")[0]) + said = self.d.python(_WINDOW_OWNER) + self.assertEqual(said["returncode"], 0, said["error"]) + owner = json.loads(said["output"]) + self.assertEqual(owner["machine"], owner["host"]) + self.assertIn("/opt/desktop/fixture.py", owner["command"]) + def test_a_word_typed_by_an_action_passes(self): values, exp = checks.draw("type") self.d.start_fixture(values) diff --git a/docs/ports/agent-computer-v1.md b/docs/ports/agent-computer-v1.md index b1b6bdc0..a14b1fda 100644 --- a/docs/ports/agent-computer-v1.md +++ b/docs/ports/agent-computer-v1.md @@ -115,7 +115,7 @@ Every check also fails when a pointer or key event came outside an acting call: | Piece | Where | | --- | --- | -| The desktop | A container of the kit's image, `desktop.Dockerfile` on Debian slim, built the first time a unit needs it, with a display at 1920 by 1080. The agent's actions run as its user; the kit's fixture runs as another, its log out of that user's reach | +| The desktop | A container of the kit's image, `desktop.Dockerfile` on Debian slim, built the first time a unit needs it, with a display at 1920 by 1080. The agent's actions run as its user; the kit's fixture runs as another, its log out of that user's reach. The fixture's window names its process and its machine (`_NET_WM_PID`, `WM_CLIENT_MACHINE`), as an application's window does | | The controls | The null control passes no check; the reference passes all nine | A machine that runs the kit needs Docker, or Podman 4.7 or later, as the container backend does. The first unit builds the image.