From 8b912eb300edcd5cb03e9420c0e842eec7b5c662 Mon Sep 17 00:00:00 2001 From: "Dennis K. Paulsen" Date: Sun, 20 Sep 2026 12:25:50 -0500 Subject: [PATCH] fix: export LibraryNotFoundError from ei, eis and oeffis; correct the docs' stale version, dead links, split roles and per-module claim; run the docstring and markup checks where they were skipped --- CHANGELOG.md | 89 ++++++++++++++++++ README.md | 13 ++- docs/developers/verification.md | 7 +- docs/troubleshooting.md | 8 +- docs/vs-snegg.md | 9 +- pyproject.toml | 8 ++ src/libei/ei.py | 4 + src/libei/eis.py | 4 + src/libei/oeffis.py | 8 +- src/libei/portal.py | 6 +- tests/test_documentation_shape.py | 150 +++++++++++++++++++++++++++--- tests/test_documented_examples.py | 27 ------ tests/test_portal.py | 14 +++ 13 files changed, 289 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a0f7be..5c6c436 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,23 @@ All notable changes to python-libei are recorded here. The format follows ### Added +- **`LibraryNotFoundError` is now part of `libei.ei`'s, `libei.eis`'s and + `libei.oeffis`'s public surface.** It has always been raised from all + three -- `_capi/loader.py` raises it the moment a `dlopen` fails, or an + installed library turns out too old to export a bound function -- and + `docs/troubleshooting.md` had been telling readers to write + `from libei.ei import Error, LibraryNotFoundError` since its exceptions + table went in. It was in no module's `__all__`, alone among the eight + classes that table names: catching `ei.LibraryNotFoundError` worked, but + `from libei.ei import *`, `pydoc`, an IDE's completion, and anything else + reading a module's declared surface did not see it, and the only + obviously public place to import it from was the private + `libei._capi.loader` it is defined in. Two of the three modules come from + the table; `libei.oeffis` was found while fixing those, `Oeffis.create()` + on a machine with no liboeffis being the same failure one module over. + Nothing moved to the package root either way: `libei/__init__.py` still + carries only `__version__`, as that page says. + - **`docs/troubleshooting.md` now names the exceptions, having been the page for everything that *doesn't* raise.** Eight classes are raised from real paths and were named in no user-facing text: `ei.Error` and `eis.Error` (22 @@ -36,6 +53,78 @@ All notable changes to python-libei are recorded here. The format follows connection and lifecycle events, which have no getter and are read through `event_type`. +### Changed + +- **The docstring-completeness check now runs everywhere, and covers + `libei.portal`.** It lived in `tests/test_documented_examples.py`, whose + module-level `integration` mark skips the file where the native libraries + are absent -- so a check that reads source with `ast` and needs nothing + installed was skipping on exactly the machines where it was cheapest to + run. It now sits in `tests/test_documentation_shape.py`, beside the other + checks that need no native library, takes in classes as well as functions, + and includes `libei.portal`, which was never checked. Nothing had to be + written to make it pass: every public definition in all four modules + already carries a docstring, so this is a guard rather than a cleanup. + +- **A new check ties the exceptions table to the modules it names.** + `tests/test_documentation_shape.py` now reads the table in + `docs/troubleshooting.md` and asserts that every class it pairs with a + module is both reachable from that module and listed in its `__all__` -- + and that a class shared between modules is one class in all of them, which + is what makes one `except` clause cover every module that raises it. This + is the check that would have caught `LibraryNotFoundError` when the table + itself was written. + +- **The documentation guards reach the files that were drifting.** + `tests/test_documentation_shape.py` compared the README's version line + against `libei.__version__` but not the developers page's, which is how + 0.5.1 sat there through a release; both pages are compared now. The + module-docstring example check covered the two modules that used `::` and + read nothing at all from the two that did not -- both are covered now, all + four public modules. A new check reads every docstring in those modules + for the two defects below, neither of which is visible anywhere but in the + rendered text: a role split across a line break, and an unpaired backtick. + And `tests/test_portal.py` now asserts what `verification.md` claimed it + covered -- that `CreateSession` carries a `session_handle_token`, whose + absence crashes xdg-desktop-portal 1.22.1 outright. + +### Fixed + +- **`scripts/pre-commit-test.sh` failed its `tests` check on any interpreter + without the package installed.** The script runs `python -m pytest -q -rs` + with no `PYTHONPATH`, deliberately: CI's install step is one of the two + things it leaves to the runner. But `[tool.pytest.ini_options]` here had + only `testpaths`, so nothing put `src` on the path, and `tests/conftest.py`'s + `from libei import ei` died at collection -- reporting an ImportError for + the whole suite where pyguitest and pyguitest-recorder both set + `pythonpath = ["src"]` and just run. The other four checks passed, which is + what made it look like a test failure rather than a path one. Same setting + added here; a bare checkout now runs the suite with nothing installed, which + is also what makes a copied tree testable anywhere. + +- **Four documentation defects, each invisible from the page it is on.** + `docs/developers/verification.md` opened with "the package is beta + (`0.5.1`)" a release after 0.5.2 shipped, and nothing compared that prose + to `pyproject.toml` the way the README's own version line is compared. The + same page and `docs/vs-snegg.md` both pointed a reader at "the README's + Troubleshooting section", which has never existed -- the GNOME 44 + explanation they mean is in `docs/troubleshooting.md`, and both links now + go there. And `InputCaptureSession`'s own docstring broke a role across a + line, so `:meth:`wait_for_activation`` rendered as the literal text + ":meth:" and a name rather than as a link. The README's module table also + promised that *each* module carries an `Error` exception and an + `EventType`/`DeviceCapability` enum, which holds for `ei` and `eis` only: + `oeffis` and `portal` raise their own classes and carry `DeviceType` + instead, so a reader writing `except oeffis.Error` was chasing a class + that does not exist. All four are corrected. + +- **The two module docstrings that carry a usage example now mark it as + one.** `oeffis` and `portal` wrote their examples as plain indented + blocks, where `ei` and `eis` use the `::` a reST literal block needs -- + which is also why the example check had never read either of them, since + the extractor looks for that marker. The blocks themselves were already + valid Python and unaffected. + ## [0.5.2] - 2026-09-12 ### Added diff --git a/README.md b/README.md index bd1c301..646b6ad 100644 --- a/README.md +++ b/README.md @@ -70,11 +70,14 @@ to get permission, then `ei` to inject. | **Get permission**, and not be asked again | `libei.portal` | Same handshake over D-Bus directly, with `persist_mode` / `restore_token`. Needs PyGObject | | **Be the server**, for tests or a compositor | `libei.eis` | Drives your client code with no real compositor and no consent dialog | -Each module has `is_available()`, an `Error` exception, and an `EventType` / -`DeviceCapability` enum. `ei` and `eis` also share the shapes around them: -`Device`, `Seat`, `Region`, `Keymap`, `Touch`, `Ping`, `Event`, and the frozen -dataclasses its accessors return. The package ships `py.typed`, so callers -type-check against real annotations rather than `Any`. +Each module has `is_available()`. `ei` and `eis` share the shapes around them: +an `Error` exception, an `EventType` and `DeviceCapability` enum, and `Device`, +`Seat`, `Region`, `Keymap`, `Touch`, `Ping`, `Event` with the frozen dataclasses +its accessors return. `oeffis` and `portal` are smaller — `DeviceType`, no +`EventType` or `DeviceCapability`, and their own exception classes rather than +an `Error`. [docs/troubleshooting.md](docs/troubleshooting.md) names every class +they raise. The package ships `py.typed`, so callers type-check against real +annotations rather than `Any`. ## What's implemented diff --git a/docs/developers/verification.md b/docs/developers/verification.md index 8386acd..394877d 100644 --- a/docs/developers/verification.md +++ b/docs/developers/verification.md @@ -1,6 +1,6 @@ # What has actually been verified -The package is beta (`0.5.1`) and the API is not frozen — expect renames +The package is beta (`0.5.2`) and the API is not frozen — expect renames before 1.0. This page is what that qualifier covers, concretely: which paths have been driven against real libraries, which have only ever been driven against fakes, and which libei versions the whole thing has met. @@ -27,8 +27,9 @@ a negotiation that fails part-way. By hand: -- **`libei.oeffis`**, 2026-08-25. See the README's troubleshooting section for - what that run established about the GNOME 44 hangs. +- **`libei.oeffis`**, 2026-08-25. See + [troubleshooting.md](../troubleshooting.md#the-portal-dialog-appears-i-approve-it-and-nothing-happens) + for what that run established about the GNOME 44 hangs. - **`libei.portal.RemoteDesktopSession`**, 2026-09-01, against a real GNOME Wayland session (`RemoteDesktop` v2). A first run raised the consent dialog and was approved (5.4s); a second replaying the `restore_token` was granted diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 16b1d0c..370d99c 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -84,7 +84,7 @@ import each from the module that raises it. | `libei.portal` | `PortalVersionError` | The RemoteDesktop portal is too old to offer `ConnectToEIS` | | `libei.portal` | `PortalTimeoutError` | A step was accepted and never answered. Carries `.step` and `.timeout` | | `libei.portal` | `PortalDeniedError` | `CreateSession`, `SelectDevices` or `Start` came back non-zero — an explicit decline, or any other code the spec does not distinguish from one. Carries `.step` and `.message` | -| `libei.ei`, `libei.eis` | `LibraryNotFoundError` | The native library is missing or too old to export the function being called. A `RuntimeError`, and raised at the first *call* — see below | +| `libei.ei`, `libei.eis`, `libei.oeffis` | `LibraryNotFoundError` | The native library is missing or too old to export the function being called. A `RuntimeError`, and raised at the first *call* — see below | Which of those to catch depends on the families, because they do not nest under a single base: @@ -116,9 +116,9 @@ a single base: ## `LibraryNotFoundError` The native library is not installed, or is too old to export a function this -package binds. Check with `ei.is_available()`; the package name for your -distribution, and what to do when it does not match, is in -[install.md](install.md). +package binds. Check with `ei.is_available()`, or `oeffis.is_available()` for +a missing liboeffis; the package name for your distribution, and what to do +when it does not match, is in [install.md](install.md). Because loading is lazy, this is raised at the first *call*, not at import — so an application can import this package, discover the libraries are absent, diff --git a/docs/vs-snegg.md b/docs/vs-snegg.md index 03f1f97..43ccf33 100644 --- a/docs/vs-snegg.md +++ b/docs/vs-snegg.md @@ -99,10 +99,11 @@ project -- it needs an interactive consent dialog, which nothing here drives programmatically. It was manually verified working on 2026-08-25 on GNOME 50.4 (`busctl monitor` trace: `CreateSession -> SelectDevices -> Start -> ConnectToEIS`, 3/3 attempts, a few seconds each), after an earlier attempt on -GNOME 44 saw it hang. See the README's Troubleshooting section for the likely -explanation. Manual verification isn't the same guarantee automated coverage -would be, so treat `oeffis` as the least *automatically* verified part of -this package -- see the note in `tests/test_oeffis.py`. +GNOME 44 saw it hang. See +[troubleshooting.md](troubleshooting.md#the-portal-dialog-appears-i-approve-it-and-nothing-happens) +for the likely explanation. Manual verification isn't the same guarantee +automated coverage would be, so treat `oeffis` as the least *automatically* +verified part of this package -- see the note in `tests/test_oeffis.py`. ## Two things found while building the integration test diff --git a/pyproject.toml b/pyproject.toml index 061e539..97397f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,6 +73,14 @@ libei = ["py.typed"] [tool.pytest.ini_options] testpaths = ["tests"] +# The suite imports `libei` from the checkout rather than requiring an +# install, so `scripts/pre-commit-test.sh` runs on an interpreter with only +# the dev tools in it -- which is what that script's own header asks for, and +# what pyguitest and pyguitest-recorder already do. CI installs the package, +# so the installed path is still covered there. Without this, conftest's +# `from libei import ei` fails at collection and the whole check reports an +# ImportError instead of running anything. +pythonpath = ["src"] markers = [ "integration: requires the real libei/libeis/liboeffis shared libraries to be installed", ] diff --git a/src/libei/ei.py b/src/libei/ei.py index 6e74814..d225a50 100644 --- a/src/libei/ei.py +++ b/src/libei/ei.py @@ -1295,6 +1295,10 @@ def create_for_socket( "KeyEvent", "Keymap", "KeymapType", + # Imported rather than defined here: every call bound through + # _capi.libei can raise it, so a caller importing from this module + # catches it from here too -- see docs/troubleshooting.md. + "LibraryNotFoundError", "Ping", "PointerAbsoluteEvent", "PointerEvent", diff --git a/src/libei/eis.py b/src/libei/eis.py index b1cbd25..68d6311 100644 --- a/src/libei/eis.py +++ b/src/libei/eis.py @@ -1278,6 +1278,10 @@ def create_for_socket(cls, path: Path, flags: Sequence[Flag] = ()) -> Eis: "KeyEvent", "Keymap", "KeymapType", + # Imported rather than defined here: every call bound through + # _capi.libeis can raise it, so a caller importing from this module + # catches it from here too -- see docs/troubleshooting.md. + "LibraryNotFoundError", "Ping", "PointerAbsoluteEvent", "PointerEvent", diff --git a/src/libei/oeffis.py b/src/libei/oeffis.py index 46da3d9..dc839c5 100644 --- a/src/libei/oeffis.py +++ b/src/libei/oeffis.py @@ -6,7 +6,7 @@ This is the path a sandboxed or otherwise non-privileged client uses to get an EI socket: it asks the portal, the user is shown a consent dialog, and on approval this hands back a file descriptor to pass to -:meth:`libei.ei.Sender.create_for_fd`. +:meth:`libei.ei.Sender.create_for_fd`:: oeffis = Oeffis.create(devices=DeviceType.POINTER) while True: @@ -41,6 +41,7 @@ import os from . import _capi +from ._capi.loader import LibraryNotFoundError logger = logging.getLogger("libei.oeffis") @@ -242,6 +243,11 @@ def create( __all__ = [ "DeviceType", "DisconnectedError", + # Imported rather than defined here: every call bound through + # _capi.liboeffis can raise it -- Oeffis.create() on a machine with no + # liboeffis is the ordinary one -- so a caller importing from this + # module catches it from here too. See docs/troubleshooting.md. + "LibraryNotFoundError", "Oeffis", "SessionClosedError", "is_available", diff --git a/src/libei/portal.py b/src/libei/portal.py index a4da350..4cacfc5 100644 --- a/src/libei/portal.py +++ b/src/libei/portal.py @@ -21,7 +21,7 @@ (https://libinput.pages.freedesktop.org/libei/api/group__liboeffis.html). This module is that: the ``CreateSession`` -> ``SelectDevices`` -> ``Start`` -> ``ConnectToEIS`` sequence driven directly, with ``persist_mode`` and -``restore_token`` exposed as real parameters. +``restore_token`` exposed as real parameters:: with RemoteDesktopSession.negotiate( devices=DeviceType.POINTER | DeviceType.KEYBOARD, @@ -1154,8 +1154,8 @@ class InputCaptureSession: direction: instead of injecting synthetic input, this receives real input from the user's own devices once the compositor decides to divert it here. That decision is the whole point of the protocol and is never - this session's to make -- see :meth:`enable` and :meth:` - wait_for_activation`. + this session's to make -- see :meth:`enable` and + :meth:`wait_for_activation`. **Capturing is exclusive.** Once the compositor activates a capture, the events it captures stop reaching the desktop entirely and are sent diff --git a/tests/test_documentation_shape.py b/tests/test_documentation_shape.py index 99fb973..5ec725e 100644 --- a/tests/test_documentation_shape.py +++ b/tests/test_documentation_shape.py @@ -9,6 +9,7 @@ from __future__ import annotations import ast +import importlib import re import textwrap from pathlib import Path @@ -19,6 +20,13 @@ _PROJECT_ROOT = Path(__file__).resolve().parent.parent _README = _PROJECT_ROOT / "README.md" +_TROUBLESHOOTING = _PROJECT_ROOT / "docs" / "troubleshooting.md" + +# The modules a reader can import a public name from -- what the reference +# pages name, and whose docstrings carry the examples worth checking. +_PUBLIC_MODULES = ("libei.ei", "libei.eis", "libei.oeffis", "libei.portal") + +_EXCEPTION_HEADING = "## When it does raise: which name you are catching" def _readme_python_blocks() -> list[str]: @@ -50,14 +58,22 @@ def test_readme_examples_are_valid_python() -> None: pytest.fail(f"README example is not valid Python ({exc}):\n{block}") -@pytest.mark.parametrize("module", [ei, eis]) -def test_module_docstring_examples_are_valid_python(module: object) -> None: +@pytest.mark.parametrize("module_name", _PUBLIC_MODULES) +def test_module_docstring_examples_are_valid_python(module_name: str) -> None: + # Every module with an example has to write it as the ``::`` literal + # block the extractor reads, and the block has to parse. oeffis and + # portal wrote theirs as a plain indented block, so neither example was + # ever extracted here -- or evaluated as reST, where a literal block + # needs the marker. + module = importlib.import_module(module_name) source = _docstring_example(module.__doc__ or "") - assert source.strip(), f"{module.__name__} docstring has no example" # type: ignore[attr-defined] + assert source.strip(), f"{module_name} docstring has no ``::`` example" try: - compile(source, f"<{module.__name__} docstring>", "exec") # type: ignore[attr-defined] + compile(source, f"<{module_name} docstring>", "exec") except SyntaxError as exc: - pytest.fail(f"docstring example is not valid Python ({exc}):\n{source}") + pytest.fail( + f"{module_name} docstring example is not valid Python ({exc}):\n{source}" + ) def _emulating_examples() -> list[str]: @@ -314,12 +330,124 @@ def test_each_pages_own_contents_resolves() -> None: ) -def test_readme_status_names_the_current_version() -> None: - # The Status section states the version in prose; a bump that leaves it - # behind is how a README starts describing a release that no longer - # exists. +@pytest.mark.parametrize("page", ["README.md", "docs/developers/verification.md"]) +def test_status_pages_name_the_current_version(page: str) -> None: + # Both state the version in prose, and nothing keeps them in step with + # pyproject.toml -- so a bump that touches one and not the other ships a + # page describing a release that no longer exists. The developers page + # sat a whole release behind exactly that way: 0.5.1 while + # pyproject.toml, libei.__version__ and the README all said 0.5.2. import libei - assert f"`{libei.__version__}`" in _README.read_text(), ( - f"README does not mention the current version {libei.__version__}" + assert f"`{libei.__version__}`" in (_PROJECT_ROOT / page).read_text(), ( + f"{page} does not mention the current version {libei.__version__}" + ) + + +def _documented_exceptions() -> list[tuple[list[str], list[str]]]: + """The (modules, classes) of each row of the exception table. + + Only the table under :data:`_EXCEPTION_HEADING` is read, so a table + added to that page elsewhere cannot quietly become part of this check. + """ + _, _, after = _TROUBLESHOOTING.read_text().partition(_EXCEPTION_HEADING) + section = after.split("\n## ", 1)[0] + rows: list[tuple[list[str], list[str]]] = [] + for line in section.splitlines(): + if not line.startswith("|"): + continue + cells = [cell.strip() for cell in line.strip("|").split("|")] + if len(cells) < 2 or cells[0] in ("Module", "") or cells[0].strip("- ") == "": + continue + rows.append( + ( + [name.strip(" `") for name in cells[0].split(",")], + [name.strip(" `") for name in cells[1].split(",")], + ) + ) + return rows + + +def test_documented_exceptions_are_part_of_the_public_api() -> None: + # The page says which module to import each exception from, so each has + # to be part of that module's declared surface rather than an attribute + # it happens to carry. LibraryNotFoundError was importable from + # libei.ei and libei.eis but listed in neither __all__ -- which left the + # private libei._capi.loader as the only place it was obviously public. + rows = _documented_exceptions() + assert rows, "no exception table found in docs/troubleshooting.md" + for modules, classes in rows: + for class_name in classes: + found: dict[str, object] = {} + for module_name in modules: + module = importlib.import_module(module_name) + assert hasattr(module, class_name), f"{module_name} has no {class_name}" + assert class_name in module.__all__, ( + f"{module_name}.{class_name} is documented as importable from " + "there, but is missing from that module's __all__" + ) + found[module_name] = getattr(module, class_name) + # A row may name two modules for one class, and Error is a + # separate class on each side -- so a shared row is the only + # thing that has to resolve to one object. + assert len({id(cls) for cls in found.values()}) == 1, ( + f"the row for {class_name} names {modules}, which do not agree " + "on what that class is" + ) + + +@pytest.mark.parametrize("module_name", _PUBLIC_MODULES) +def test_public_api_is_documented(module_name: str) -> None: + # The package ships py.typed and is meant to be consumed as a + # dependency, so every public callable needs at least a one-line + # docstring. This started at 3/64 and 6/74. It reads source text and + # needs nothing installed, so it belongs here rather than in + # test_documented_examples.py, whose module-level `integration` mark + # skipped it on exactly the machines where it was cheapest to run. + module = importlib.import_module(module_name) + source_path = module.__file__ + assert source_path is not None, f"{module_name} has no source file to read" + tree = ast.parse(Path(source_path).read_text()) + undocumented = [ + node.name + for node in ast.walk(tree) + if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)) + and not node.name.startswith("_") + and not ast.get_docstring(node) + ] + assert not undocumented, ( + f"{module_name} has undocumented public definitions: " + f"{sorted(set(undocumented))}" ) + + +# A role whose name starts on the next line renders as literal text wherever +# the docstring is read, and so does everything after an unpaired backtick. +_SPLIT_ROLE = re.compile(r":(class|meth|attr|func|mod|data|exc):`[^`\n]*\n") + + +def _docstrings(module_name: str) -> list[tuple[str, str]]: + """The (where, docstring) of a module and every definition inside it.""" + module = importlib.import_module(module_name) + source_path = module.__file__ + assert source_path is not None, f"{module_name} has no source file to read" + tree = ast.parse(Path(source_path).read_text()) + found = [("", ast.get_docstring(tree) or "")] + for node in ast.walk(tree): + if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)): + found.append((node.name, ast.get_docstring(node) or "")) + return found + + +@pytest.mark.parametrize("module_name", _PUBLIC_MODULES) +def test_docstrings_have_no_broken_markup(module_name: str) -> None: + # Neither defect shows up anywhere except in the rendered text: portal.py + # read ":meth:`enable` and :meth:`" and broke the line before + # "wait_for_activation`", so the second name never became a link, and a + # docstring with an unpaired backtick silently swallows the rest of it. + for where, doc in _docstrings(module_name): + if _SPLIT_ROLE.search(doc) is not None: + pytest.fail(f"{module_name}:{where} breaks a role across a line break") + assert doc.count("`") % 2 == 0, ( + f"{module_name}:{where} has an unpaired backtick" + ) diff --git a/tests/test_documented_examples.py b/tests/test_documented_examples.py index ac962c4..c354e4f 100644 --- a/tests/test_documented_examples.py +++ b/tests/test_documented_examples.py @@ -90,30 +90,3 @@ def dispatch_and_step_server(self: ei.Context) -> None: ei.Context.dispatch = original_dispatch # type: ignore[method-assign] assert namespace["device"] is not None - - -@pytest.mark.parametrize("module", [ei, eis, "oeffis"]) -def test_public_api_is_documented(module: object) -> None: - # The package ships py.typed and is meant to be consumed as a - # dependency, so every public callable needs at least a one-line - # docstring. This started at 3/64 and 6/74. - import ast - import importlib - - if isinstance(module, str): - module = importlib.import_module(f"libei.{module}") - - source = Path(module.__file__).read_text() # type: ignore[attr-defined] - tree = ast.parse(source) - - undocumented = [ - node.name - for node in ast.walk(tree) - if isinstance(node, ast.FunctionDef) - and not node.name.startswith("_") - and not ast.get_docstring(node) - ] - assert not undocumented, ( - f"{module.__name__} has undocumented public callables: " # type: ignore[attr-defined] - f"{sorted(set(undocumented))}" - ) diff --git a/tests/test_portal.py b/tests/test_portal.py index a2ec294..77e42f7 100644 --- a/tests/test_portal.py +++ b/tests/test_portal.py @@ -489,6 +489,20 @@ def test_explicit_all_devices_is_translated_too() -> None: assert select[1][-1]["types"].value != 0 +def test_create_session_carries_a_session_handle_token() -> None: + # Omitting it crashes xdg-desktop-portal 1.22.1 outright -- SIGABRT, + # "assertion failed: (session->token != NULL)" -- and it is a *different* + # token from the handle_token _request() injects on its own, so a + # CreateSession that carries one and not the other still looks right. + connection = FakeConnection() + with install_fake_gi(connection): + portal.RemoteDesktopSession.negotiate(connection=connection) + create = next(c for c in connection.calls if c[0] == "CreateSession") + options = create[1][-1] + assert options["session_handle_token"].value + assert options["handle_token"].value + + def test_restore_token_without_persist_mode_is_refused() -> None: # The portal consumes a restore token on use and only mints a new one # when persistence was asked for, so this combination would spend the