From ef7d10511864125ee5468a90eba1beaabfdcc6ee Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Fri, 9 Oct 2026 00:43:35 +0000 Subject: [PATCH 1/5] fix(appd): drop --wait from the systemd-run scope launch When a systemd user manager was detected, weft-appd launched the runtime with `systemd-run --user --scope --wait ...`. systemd rejects that combination while parsing options ("--wait may not be combined with --scope"), so every app launch on such a host exited immediately and the session stopped without the runtime ever starting. A scope already runs the command in the foreground: systemd-run registers the scope and then executes the command in its own process, so stdout and the exit status still reach appd without --wait. The options now live in one constant. A Linux test runs the installed systemd-run with them against an empty runtime directory and bus address and requires it to reach the manager connection; option and combination errors stop it earlier. The test does not validate the -p property values or start a scope. It requires systemd-run to be installed. This keeps the existing ownership scope for the runtime only; placing the app shell and helpers under the same owner is separate lifecycle work. Validation: - systemd-run 255: the test passes with the new options and fails with the old --wait (and with --pty) using systemd's own message - cargo test -p weft-appd (38 passed), clippy -D warnings, fmt --check --- crates/weft-appd/src/runtime.rs | 68 ++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 13 deletions(-) diff --git a/crates/weft-appd/src/runtime.rs b/crates/weft-appd/src/runtime.rs index 77e4686..6541f65 100644 --- a/crates/weft-appd/src/runtime.rs +++ b/crates/weft-appd/src/runtime.rs @@ -70,6 +70,22 @@ pub(crate) async fn spawn_ipc_relay( const READY_TIMEOUT: Duration = Duration::from_secs(30); +/// `systemd-run` options that place the runtime in a transient user scope. +/// +/// A scope runs the command in the foreground as systemd-run's own process, +/// so its stdout and exit status reach appd directly. `--wait` only applies +/// to service units; systemd rejects it together with `--scope`. +const SYSTEMD_SCOPE_ARGS: &[&str] = &[ + "--user", + "--scope", + "--collect", + "--slice=weft-apps.slice", + "-p", + "CPUQuota=200%", + "-p", + "MemoryMax=512M", +]; + fn systemd_cgroup_available() -> bool { if std::env::var("WEFT_DISABLE_CGROUP").is_ok() { return false; @@ -240,19 +256,7 @@ pub(crate) async fn supervise( let mut cmd = if systemd_cgroup_available() { let mut c = tokio::process::Command::new("systemd-run"); - c.args([ - "--user", - "--scope", - "--wait", - "--collect", - "--slice=weft-apps.slice", - "-p", - "CPUQuota=200%", - "-p", - "MemoryMax=512M", - "--", - &bin, - ]); + c.args(SYSTEMD_SCOPE_ARGS).arg("--").arg(&bin); c } else { tokio::process::Command::new(&bin) @@ -437,3 +441,41 @@ async fn drain_stderr(stderr: tokio::process::ChildStderr, session_id: u64) { tracing::warn!(session_id, stderr = %line, "app stderr"); } } + +#[cfg(all(test, target_os = "linux"))] +mod tests { + use super::SYSTEMD_SCOPE_ARGS; + + /// systemd-run checks its options and their combinations before it + /// connects to the service manager. Run against an empty runtime + /// directory and bus address, it must get as far as the connection + /// attempt; any option error ends earlier with a different message. This + /// does not validate the `-p` property values, which only the manager + /// checks, and never starts a real scope. + #[test] + fn systemd_run_accepts_scope_options() { + let empty = std::env::temp_dir().join(format!("weft-scope-test-{}", std::process::id())); + std::fs::create_dir_all(&empty).unwrap(); + let output = std::process::Command::new("systemd-run") + .args(SYSTEMD_SCOPE_ARGS) + .args(["--", "true"]) + .env_clear() + .env("PATH", std::env::var_os("PATH").unwrap_or_default()) + .env("LC_ALL", "C") + .env("XDG_RUNTIME_DIR", &empty) + .env( + "DBUS_SESSION_BUS_ADDRESS", + format!("unix:path={}/bus", empty.display()), + ) + .output(); + std::fs::remove_dir_all(&empty).unwrap(); + let output = output.expect("systemd-run is required to check the scope options"); + let stderr = String::from_utf8_lossy(&output.stderr); + // systemd 255 says "Failed to connect to bus"; later releases name the + // transport, e.g. "Failed to connect to user scope bus via local transport". + assert!( + stderr.starts_with("Failed to connect to"), + "systemd-run did not reach the manager connection: {stderr}" + ); + } +} From ae176aae93895c74c176e93df63f560d0e75cfdf Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Fri, 9 Oct 2026 01:18:53 +0000 Subject: [PATCH 2/5] test: verify native pointer and keyboard input through weft-compositor Nothing checked that input reaches a page through the compositor; the Servo hosts' input forwarding had only been compiled. tests/frame/check_input.py runs weft-servo-shell with tests/frame/input.html on the nested desktop and injects real X input with xdotool into weft-compositor's window. The compositor's winit backend routes it through its seat to the Wayland client, which has no X display. The page must react in its presented pixels: clicks 6 px either side of the boundary between its halves change only the half under the pointer, and the a and Shift+a key presses arrive with the right key value and modifier. The harness gives the compositor's X window input focus, as a window manager would; the client's keyboard focus comes from the compositor's click-to-focus. The nested desktop setup shared with check_frame.py moves to tests/frame/session.py. Xvfb now reports the display it picked through -displayfd, so concurrent runs cannot share an X server, and a run clears only the logs and capture it writes. Validation: - check_input.py: 3 of 3 runs pass; two concurrent runs pass - negative pages fail: no script; left click handled by the right half; an element extending the left half 20 px across the boundary; a key handler ignoring Shift - check_frame.py --host system, --host app, --host app --slow-style 3 pass after the refactor - unverified: key release and repeat, pointer motion and button release events, wheel, focus loss, non-US layouts, non-ASCII text, scale changes, weft-app-shell input --- crates/weft-servo-shell/SERVO_PIN.md | 13 +- docs/building.md | 10 + tests/frame/check_frame.py | 269 ++++++--------------------- tests/frame/check_input.py | 140 ++++++++++++++ tests/frame/input.html | 31 +++ tests/frame/session.py | 209 +++++++++++++++++++++ 6 files changed, 460 insertions(+), 212 deletions(-) create mode 100644 tests/frame/check_input.py create mode 100644 tests/frame/input.html create mode 100644 tests/frame/session.py diff --git a/crates/weft-servo-shell/SERVO_PIN.md b/crates/weft-servo-shell/SERVO_PIN.md index 928d56f..3b1ebfd 100644 --- a/crates/weft-servo-shell/SERVO_PIN.md +++ b/crates/weft-servo-shell/SERVO_PIN.md @@ -116,9 +116,16 @@ exercised is listed as unverified. the software path (Ubuntu 24.04, x86_64; `check_frame.py --host system`, `--host app` and `--host app --slow-style 3`, five runs each). The EGL path, DRM sessions, resize, output scale and idle wakeup are unverified. -- **Input:** keyboard and pointer events are forwarded through - `WebView::notify_input_event`; delivery through the compositor is - unverified. +- **Input:** `tests/frame/check_input.py` verifies, on the same nested + setup, that left clicks 6 px either side of a boundary reach the element + under the pointer, and that `a` and `Shift+a` key presses reach the page with + the right key value and modifier, using real X input that `weft-compositor` + routes to `weft-servo-shell` (three runs). The harness gives the compositor's + X window input focus, as a window manager would; the client's keyboard focus + comes from the compositor's click-to-focus. Unverified: key release and + repeat, pointer motion, enter/leave and button release events, other buttons, + wheel, focus loss, non-US layouts, non-ASCII text, scale changes and + `weft-app-shell` input. - **`backdrop-filter`**: the parsing (Stylo `f1ba496`) and rendering (Servo `8e7dc40`, `f0bb1aa`) patches are selected by the lockfile; rendering is unverified. diff --git a/docs/building.md b/docs/building.md index a6b8af0..ec8fab1 100644 --- a/docs/building.md +++ b/docs/building.md @@ -67,6 +67,16 @@ reveals the page so premature readiness becomes visible. Logs and the last capture are written to `target/frame-check`. +`tests/frame/check_input.py` uses the same nested desktop to send real X +pointer and keyboard input (with `xdotool`) through `weft-compositor` to +`weft-servo-shell` showing `tests/frame/input.html`, and checks that the +page reacts to clicks on either side of a boundary and to the `a` and +`Shift+a` keys. Logs and the last capture are written to `target/input-check`. + +```sh +python3 tests/frame/check_input.py +``` + ## Demo apps (wasm32-wasip2) Each demo is a standalone crate in `examples/`. Pre-built `app.wasm` binaries are committed. To rebuild: diff --git a/tests/frame/check_frame.py b/tests/frame/check_frame.py index eacce3f..8fd89a0 100644 --- a/tests/frame/check_frame.py +++ b/tests/frame/check_frame.py @@ -17,27 +17,22 @@ early readiness observable: the page stays hidden until a stylesheet that a local HTTP server delivers after the delay reveals it, so a host that reports READY before the document has loaded shows no page within the grace period. -Requires Xvfb, xwd and ImageMagick's convert. Processes are started from -argument arrays and are always terminated before the harness exits. +Requires Xvfb, xwd and ImageMagick's convert; see session.py. """ import argparse import http.server -import os -import re import shutil -import signal -import subprocess import sys -import tempfile import threading import time from pathlib import Path +sys.dont_write_bytecode = True +from session import ROOT, Desktop, SessionError, bounding_box, missing_tools, parse_ppm # noqa: E402 + HERE = Path(__file__).resolve().parent -ROOT = HERE.parents[1] -SCREEN = (1024, 768) COLORS = { "red": (255, 0, 0), "green": (0, 255, 0), @@ -46,52 +41,6 @@ COLORS = { } MIN_SIDE = 40 MIN_TEXT_PIXELS = 30 -ANSI_ESCAPE = re.compile(r"\x1b\[[0-9;]*m") - - -def parse_ppm(data): - """Decode a binary P6 PPM into (width, height, bytes).""" - tokens = [] - index = 0 - while len(tokens) < 4: - while data[index:index + 1].isspace(): - index += 1 - if data[index:index + 1] == b"#": - index = data.index(b"\n", index) + 1 - continue - end = index - while not data[end:end + 1].isspace(): - end += 1 - tokens.append(data[index:end]) - index = end - magic, width, height, maxval = tokens - if magic != b"P6" or int(maxval) != 255: - raise ValueError("expected an 8-bit P6 image") - width, height = int(width), int(height) - pixels = data[index + 1:index + 1 + width * height * 3] - if len(pixels) != width * height * 3: - raise ValueError("truncated image") - return width, height, pixels - - -def bounding_box(width, height, pixels, color): - """Return (x0, y0, x1, y1) of pixels exactly matching color, or None.""" - target = bytes(color) - xs, ys = [], [] - for y in range(0, height, 2): - row = pixels[y * width * 3:(y + 1) * width * 3] - start = row.find(target) - while start != -1: - if start % 3 == 0: - xs.append(start // 3) - ys.append(y) - start = row.find(target, start + 3) - else: - # A match spanning two pixels; realign on the next byte. - start = row.find(target, start + 1) - if not xs: - return None - return min(xs), min(ys), max(xs), max(ys) def dark_pixels(width, pixels, box): @@ -183,57 +132,6 @@ def hidden_until_styled(page, destination, port): return destination -def capture(display): - xwd = subprocess.run(["xwd", "-root", "-silent", "-display", display], - capture_output=True, check=True, timeout=20) - ppm = subprocess.run(["convert", "xwd:-", "ppm:-"], input=xwd.stdout, - capture_output=True, check=True, timeout=20) - return ppm.stdout - - -def free_display(): - for number in range(90, 140): - if not Path(f"/tmp/.X11-unix/X{number}").exists() and \ - not Path(f"/tmp/.X{number}-lock").exists(): - return f":{number}" - raise RuntimeError("no free X display number") - - -def start(command, log, env): - return subprocess.Popen(command, stdout=log, stderr=subprocess.STDOUT, env=env, - start_new_session=True) - - -def signal_group(process, signum): - try: - os.killpg(process.pid, signum) - except ProcessLookupError: - pass - - -def stop(process): - """Terminate the process and everything left in its process group.""" - if process is None: - return - signal_group(process, signal.SIGTERM) - try: - process.wait(timeout=10) - except subprocess.TimeoutExpired: - signal_group(process, signal.SIGKILL) - process.wait(timeout=10) - signal_group(process, signal.SIGKILL) - - -def wait_for(predicate, timeout, interval=0.5): - deadline = time.monotonic() + timeout - while time.monotonic() < deadline: - result = predicate() - if result: - return result - time.sleep(interval) - return None - - def main(argv=None): parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) @@ -255,115 +153,68 @@ def main(argv=None): name = "weft-servo-shell" if args.host == "system" else "weft-app-shell" args.shell = ROOT / "target/debug" / name - for tool in ("Xvfb", "xwd", "convert"): - if shutil.which(tool) is None: - print(f"missing required tool: {tool}", file=sys.stderr) - return 2 - for binary in (args.compositor, args.shell): - if not binary.is_file(): - print(f"missing binary: {binary}", file=sys.stderr) - return 2 + missing = missing_tools() + [str(b) for b in (args.compositor, args.shell) if not b.is_file()] + if missing: + print("missing: " + ", ".join(missing), file=sys.stderr) + return 2 - args.output.mkdir(parents=True, exist_ok=True) - runtime = Path(tempfile.mkdtemp(prefix="weft-frame-")) - runtime.chmod(0o700) - display = free_display() - base_env = {key: value for key, value in os.environ.items() - if key not in ("DISPLAY", "WAYLAND_DISPLAY", "WAYLAND_SOCKET")} - base_env["XDG_RUNTIME_DIR"] = str(runtime) - base_env.setdefault("RUST_LOG", "info") - - page = args.page style_server = None - if args.slow_style: - style_server = slow_style_server(args.slow_style) - page = hidden_until_styled(args.page, runtime / "page.html", - style_server.server_address[1]) - - processes = [] - logs = {name: open(args.output / f"{name}.log", "w", encoding="utf-8") - for name in ("xvfb", "compositor", "shell")} try: - xvfb = start(["Xvfb", display, "-screen", "0", f"{SCREEN[0]}x{SCREEN[1]}x24", - "-nolisten", "tcp"], logs["xvfb"], base_env) - processes.append(xvfb) - if not wait_for(lambda: Path(f"/tmp/.X11-unix/X{display[1:]}").exists(), 15): - print("Xvfb did not start", file=sys.stderr) - return 1 - - compositor_env = dict(base_env, DISPLAY=display) - compositor = start([str(args.compositor), "--winit"], logs["compositor"], - compositor_env) - processes.append(compositor) - compositor_log = args.output / "compositor.log" - - def socket_name(): - if compositor.poll() is not None: - return "exited" - text = ANSI_ESCAPE.sub("", compositor_log.read_text(encoding="utf-8", - errors="replace")) - match = re.search(r'socket_name="([^"]+)"', text) - return match and match.group(1) - - socket = wait_for(socket_name, 30) - if socket in (None, "exited"): - print(f"compositor did not open a Wayland socket; see {compositor_log}", - file=sys.stderr) - return 1 - - shell_env = dict(base_env, WAYLAND_DISPLAY=socket) - if args.host == "system": - shell_env["WEFT_SYSTEM_UI_HTML"] = str(page.resolve()) - command = [str(args.shell)] - else: - shell_env["WEFT_APP_STORE"] = str(install_app(runtime / "store", page)) - command = [str(args.shell), APP_ID, "1"] - shell = start(command, logs["shell"], shell_env) - processes.append(shell) - shell_log = args.output / "shell.log" - - def ready_printed(): - text = shell_log.read_text(encoding="utf-8", errors="replace") - return any(line.strip() == "READY" for line in text.splitlines()) - - problems = ["no frame captured"] - screenshot = None - ready_at = None - deadline = time.monotonic() + args.timeout - while time.monotonic() < deadline: - if shell.poll() is not None: - problems = [f"shell exited with status {shell.returncode}"] - break - if args.host == "app" and ready_at is None and ready_printed(): - ready_at = time.monotonic() - ready = ready_at is not None - screenshot = capture(display) - problems = evaluate(*parse_ppm(screenshot)) - if ready and problems and time.monotonic() - ready_at > COMPOSITE_GRACE: - problems = [f"page not on screen {COMPOSITE_GRACE:g} s after READY"] + problems - break - if not problems and (args.host == "system" or ready): - break - if not problems: - problems = ["frame presented but READY not printed"] - time.sleep(1) - - if screenshot is not None: - (args.output / "frame.ppm").write_bytes(screenshot) - if problems: - print("frame check failed: " + "; ".join(problems), file=sys.stderr) - print(f"logs and last capture in {args.output}", file=sys.stderr) - return 1 - print(f"frame check passed; capture in {args.output / 'frame.ppm'}") - return 0 + with Desktop(args.compositor, args.output, outputs=["frame.ppm"]) as desktop: + page = args.page + if args.slow_style: + style_server = slow_style_server(args.slow_style) + page = hidden_until_styled(args.page, desktop.runtime / "page.html", + style_server.server_address[1]) + if args.host == "system": + shell = desktop.launch_client( + "shell", [args.shell], {"WEFT_SYSTEM_UI_HTML": str(page.resolve())}) + else: + store = install_app(desktop.runtime / "store", page) + shell = desktop.launch_client( + "shell", [args.shell, APP_ID, "1"], {"WEFT_APP_STORE": str(store)}) + problems, screenshot = watch(desktop, shell, args) + except SessionError as error: + print(error, file=sys.stderr) + return 1 finally: - for process in reversed(processes): - stop(process) if style_server is not None: style_server.shutdown() - for log in logs.values(): - log.close() - shutil.rmtree(runtime, ignore_errors=True) + + if screenshot is not None: + (args.output / "frame.ppm").write_bytes(screenshot) + if problems: + print("frame check failed: " + "; ".join(problems), file=sys.stderr) + print(f"logs and last capture in {args.output}", file=sys.stderr) + return 1 + print(f"frame check passed; capture in {args.output / 'frame.ppm'}") + return 0 + + +def watch(desktop, shell, args): + """Capture until the frame matches, the host exits or the time runs out.""" + def ready_printed(): + return any(line.strip() == "READY" for line in desktop.log_text("shell").splitlines()) + + problems = ["no frame captured"] + screenshot = None + ready_at = None + deadline = time.monotonic() + args.timeout + while time.monotonic() < deadline: + if shell.poll() is not None: + return [f"shell exited with status {shell.returncode}"], screenshot + if args.host == "app" and ready_at is None and ready_printed(): + ready_at = time.monotonic() + screenshot = desktop.capture() + problems = evaluate(*parse_ppm(screenshot)) + if ready_at is not None and problems and time.monotonic() - ready_at > COMPOSITE_GRACE: + return [f"page not on screen {COMPOSITE_GRACE:g} s after READY"] + problems, screenshot + if not problems and (args.host == "system" or ready_at is not None): + return [], screenshot + if not problems: + problems = ["frame presented but READY not printed"] + time.sleep(1) + return problems, screenshot if __name__ == "__main__": diff --git a/tests/frame/check_input.py b/tests/frame/check_input.py new file mode 100644 index 0000000..950d989 --- /dev/null +++ b/tests/frame/check_input.py @@ -0,0 +1,140 @@ +"""Check that native pointer and keyboard input reaches a page through weft-compositor. + +The harness runs weft-servo-shell with `input.html` on a nested desktop (see +session.py) and injects real X input into the compositor's window with +xdotool (after giving that window X input focus, since Xvfb runs without a +window manager), which weft-compositor's winit backend receives and routes to +the focused Wayland client. Each step must change the page as the page's script +defines, as seen in the presented pixels: + +1. A click 6 px inside the left half's right edge turns only the left half + green; the right half must stay blue. +2. Typing `a` turns the right half yellow. +3. Typing `Shift+a` turns the right half magenta, which checks the modifier. +4. A click 6 px inside the right half's left edge turns the right half white. + +The two clicks straddle the boundary between the halves, so a pointer +position that is scaled or offset by more than a few pixels fails. + +Requires Xvfb, xwd, ImageMagick's convert and xdotool. +""" + +import argparse +import shutil +import subprocess +import sys +import time +from pathlib import Path + +sys.dont_write_bytecode = True +from session import ROOT, Desktop, SessionError, bounding_box, missing_tools, parse_ppm # noqa: E402 + + +HERE = Path(__file__).resolve().parent +RED, GREEN, BLUE = (255, 0, 0), (0, 255, 0), (0, 0, 255) +WHITE, YELLOW, MAGENTA = (255, 255, 255), (255, 255, 0), (255, 0, 255) +MIN_SIDE = 40 + + +def region(screenshot, color): + """Bounding box of `color` if it covers a page half, else None.""" + box = bounding_box(*parse_ppm(screenshot), color) + if box and box[2] - box[0] >= MIN_SIDE and box[3] - box[1] >= MIN_SIDE: + return box + return None + + +STARTUP_TIMEOUT = 120.0 +EDGE_INSET = 6 + + +class Steps: + def __init__(self, desktop, shell, timeout): + self.desktop = desktop + self.shell = shell + self.timeout = timeout + self.screenshot = None + self.xdotool_path = shutil.which("xdotool") + + def expect(self, description, present, absent=(), timeout=None): + """Wait until every colour in `present` and none in `absent` is shown.""" + deadline = time.monotonic() + (self.timeout if timeout is None else timeout) + while time.monotonic() < deadline: + if self.shell.poll() is not None: + raise AssertionError(f"shell exited with status {self.shell.returncode}") + self.screenshot = self.desktop.capture() + boxes = {color: region(self.screenshot, color) for color in present} + if all(boxes.values()) and not any(region(self.screenshot, c) for c in absent): + return boxes + time.sleep(0.5) + raise AssertionError(f"{description}: expected page state not shown") + + def xdotool(self, *arguments): + subprocess.run([self.xdotool_path, *arguments], env={"DISPLAY": self.desktop.display}, + check=True, timeout=20) + + def click(self, x, y): + self.xdotool("mousemove", "--sync", str(x), str(y)) + self.xdotool("click", "1") + + +def run(steps): + boxes = steps.expect("initial page", [RED, BLUE], timeout=STARTUP_TIMEOUT) + # Xvfb runs without a window manager, so give the compositor's window the + # X input focus that a real session's window manager would. + steps.xdotool("search", "--class", "weft-compositor", "windowfocus", "--sync") + left, right = boxes[RED], boxes[BLUE] + middle = (left[1] + left[3]) // 2 + steps.click(left[2] - EDGE_INSET, middle) + steps.expect("click near the right edge of the left half", [GREEN, BLUE], + absent=[RED, WHITE]) + steps.xdotool("key", "a") + steps.expect("key a", [GREEN, YELLOW], absent=[BLUE]) + steps.xdotool("key", "shift+a") + steps.expect("key Shift+a", [GREEN, MAGENTA], absent=[YELLOW]) + steps.click(right[0] + EDGE_INSET, middle) + steps.expect("click near the left edge of the right half", [GREEN, WHITE], + absent=[MAGENTA, RED]) + + +def main(argv=None): + parser = argparse.ArgumentParser(description=__doc__, + formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument("--compositor", type=Path, default=ROOT / "target/debug/weft-compositor") + parser.add_argument("--shell", type=Path, default=ROOT / "target/debug/weft-servo-shell") + parser.add_argument("--page", type=Path, default=HERE / "input.html") + parser.add_argument("--timeout", type=float, default=30.0, + help="seconds to wait for each expected page state") + parser.add_argument("--output", type=Path, default=ROOT / "target/input-check", + help="directory for logs and the last capture") + args = parser.parse_args(argv) + + missing = missing_tools() + [tool for tool in ("xdotool",) if shutil.which(tool) is None] + missing += [str(b) for b in (args.compositor, args.shell) if not b.is_file()] + if missing: + print("missing: " + ", ".join(missing), file=sys.stderr) + return 2 + + try: + with Desktop(args.compositor, args.output, outputs=["input.ppm"]) as desktop: + shell = desktop.launch_client("shell", [args.shell], + {"WEFT_SYSTEM_UI_HTML": str(args.page.resolve())}) + steps = Steps(desktop, shell, args.timeout) + try: + run(steps) + except AssertionError as failure: + print(f"input check failed: {failure}", file=sys.stderr) + print(f"logs and last capture in {args.output}", file=sys.stderr) + return 1 + finally: + if steps.screenshot is not None: + (args.output / "input.ppm").write_bytes(steps.screenshot) + except SessionError as error: + print(error, file=sys.stderr) + return 1 + print("input check passed") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tests/frame/input.html b/tests/frame/input.html new file mode 100644 index 0000000..b0bf76c --- /dev/null +++ b/tests/frame/input.html @@ -0,0 +1,31 @@ + + + + +WEFT input reference + + + +
+ + + + diff --git a/tests/frame/session.py b/tests/frame/session.py new file mode 100644 index 0000000..0b45837 --- /dev/null +++ b/tests/frame/session.py @@ -0,0 +1,209 @@ +"""Nested WEFT desktop for graphical tests: Xvfb, weft-compositor and Wayland clients. + +`Desktop` starts Xvfb and weft-compositor with its winit backend, launches +clients on the compositor's Wayland socket, captures the X screen and +terminates every process it started when the `with` block ends. Processes are +started from argument arrays in their own process groups. +""" + +import os +import re +import shutil +import signal +import subprocess +import tempfile +import time +from pathlib import Path + + +ROOT = Path(__file__).resolve().parents[2] +SCREEN = (1024, 768) +ANSI_ESCAPE = re.compile(r"\x1b\[[0-9;]*m") +REQUIRED_TOOLS = ("Xvfb", "xwd", "convert") + + +class SessionError(Exception): + """The nested desktop could not be started.""" + + +def parse_ppm(data): + """Decode a binary P6 PPM into (width, height, bytes).""" + tokens = [] + index = 0 + while len(tokens) < 4: + while data[index:index + 1].isspace(): + index += 1 + if data[index:index + 1] == b"#": + index = data.index(b"\n", index) + 1 + continue + end = index + while not data[end:end + 1].isspace(): + end += 1 + tokens.append(data[index:end]) + index = end + magic, width, height, maxval = tokens + if magic != b"P6" or int(maxval) != 255: + raise ValueError("expected an 8-bit P6 image") + width, height = int(width), int(height) + pixels = data[index + 1:index + 1 + width * height * 3] + if len(pixels) != width * height * 3: + raise ValueError("truncated image") + return width, height, pixels + + +def bounding_box(width, height, pixels, color): + """Return (x0, y0, x1, y1) of pixels exactly matching color, or None.""" + target = bytes(color) + xs, ys = [], [] + for y in range(0, height, 2): + row = pixels[y * width * 3:(y + 1) * width * 3] + start = row.find(target) + while start != -1: + if start % 3 == 0: + xs.append(start // 3) + ys.append(y) + start = row.find(target, start + 3) + else: + # A match spanning two pixels; realign on the next byte. + start = row.find(target, start + 1) + if not xs: + return None + return min(xs), min(ys), max(xs), max(ys) + + +def pixel(width, pixels, x, y): + offset = (y * width + x) * 3 + return tuple(pixels[offset:offset + 3]) + + +def missing_tools(): + return [tool for tool in REQUIRED_TOOLS if shutil.which(tool) is None] + + +def wait_for(predicate, timeout, interval=0.5): + deadline = time.monotonic() + timeout + while time.monotonic() < deadline: + result = predicate() + if result: + return result + time.sleep(interval) + return None + + +def _signal_group(process, signum): + try: + os.killpg(process.pid, signum) + except ProcessLookupError: + pass + + +def _stop(process): + """Terminate the process and everything left in its process group.""" + _signal_group(process, signal.SIGTERM) + try: + process.wait(timeout=10) + except subprocess.TimeoutExpired: + _signal_group(process, signal.SIGKILL) + process.wait(timeout=10) + _signal_group(process, signal.SIGKILL) + + +class Desktop: + """Xvfb plus weft-compositor; logs are written to `output/.log`.""" + + def __init__(self, compositor, output, outputs=()): + """`outputs` names further files in `output` that this run will write.""" + self.compositor = Path(compositor) + self.output = Path(output) + self.own_outputs = ["xvfb.log", "compositor.log", "shell.log", *outputs] + self.processes = [] + self.logs = {} + + def __enter__(self): + self.output.mkdir(parents=True, exist_ok=True) + for name in self.own_outputs: + (self.output / name).unlink(missing_ok=True) + self.runtime = Path(tempfile.mkdtemp(prefix="weft-desktop-")) + self.runtime.chmod(0o700) + self.env = {key: value for key, value in os.environ.items() + if key not in ("DISPLAY", "WAYLAND_DISPLAY", "WAYLAND_SOCKET")} + self.env["XDG_RUNTIME_DIR"] = str(self.runtime) + self.env.setdefault("RUST_LOG", "info") + try: + self._start_display() + self._start_compositor() + except BaseException: + self.__exit__(None, None, None) + raise + return self + + def __exit__(self, *exc): + for process in reversed(self.processes): + _stop(process) + for log in self.logs.values(): + log.close() + shutil.rmtree(self.runtime, ignore_errors=True) + return False + + def launch(self, name, command, env=None): + """Start a process with its output in `.log`.""" + log = open(self.output / f"{name}.log", "w", encoding="utf-8") + self.logs[name] = log + process = subprocess.Popen([str(part) for part in command], stdout=log, + stderr=subprocess.STDOUT, env=dict(self.env, **(env or {})), + start_new_session=True) + self.processes.append(process) + return process + + def launch_client(self, name, command, env=None): + """Start a Wayland client of the compositor.""" + return self.launch(name, command, dict(env or {}, WAYLAND_DISPLAY=self.socket)) + + def log_text(self, name): + text = (self.output / f"{name}.log").read_text(encoding="utf-8", errors="replace") + return ANSI_ESCAPE.sub("", text) + + def capture(self): + """Return the X screen as a P6 PPM.""" + xwd = subprocess.run(["xwd", "-root", "-silent", "-display", self.display], + capture_output=True, check=True, timeout=20) + ppm = subprocess.run(["convert", "xwd:-", "ppm:-"], input=xwd.stdout, + capture_output=True, check=True, timeout=20) + return ppm.stdout + + def _start_display(self): + # Xvfb picks a free display itself and writes its number to the pipe + # once it accepts connections, so concurrent runs cannot share one. + read_end, write_end = os.pipe() + log = open(self.output / "xvfb.log", "w", encoding="utf-8") + self.logs["xvfb"] = log + try: + xvfb = subprocess.Popen( + ["Xvfb", "-displayfd", str(write_end), "-screen", "0", + f"{SCREEN[0]}x{SCREEN[1]}x24", "-nolisten", "tcp"], + stdout=log, stderr=subprocess.STDOUT, env=self.env, + start_new_session=True, pass_fds=(write_end,)) + finally: + os.close(write_end) + self.processes.append(xvfb) + with os.fdopen(read_end) as reported: + number = reported.readline().strip() + if not number.isdigit() or xvfb.poll() is not None: + raise SessionError("Xvfb did not start") + self.display = f":{number}" + + def _start_compositor(self): + compositor = self.launch("compositor", [self.compositor, "--winit"], + {"DISPLAY": self.display}) + + def socket_name(): + if compositor.poll() is not None: + return "exited" + match = re.search(r'socket_name="([^"]+)"', self.log_text("compositor")) + return match and match.group(1) + + socket = wait_for(socket_name, 30) + if socket in (None, "exited"): + raise SessionError("compositor did not open a Wayland socket; see " + f"{self.output / 'compositor.log'}") + self.socket = socket From 1e19326d3953440a231ea8b08cbd3ff6e2ea7b5f Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Thu, 8 Oct 2026 22:58:47 +0000 Subject: [PATCH 3/5] fix(compositor): collapse nested submit condition in winit backend The nested if around backend.submit failed clippy::collapsible_if under -D warnings, breaking the linux-only clippy job. Use a let chain instead. --- crates/weft-compositor/src/backend/winit.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/weft-compositor/src/backend/winit.rs b/crates/weft-compositor/src/backend/winit.rs index 087b04c..7575211 100644 --- a/crates/weft-compositor/src/backend/winit.rs +++ b/crates/weft-compositor/src/backend/winit.rs @@ -157,10 +157,8 @@ pub fn run() -> anyhow::Result<()> { false } }; - if render_ok { - if let Err(e) = backend.submit(Some(&[full_damage])) { - tracing::warn!(?e, "backend submit failed"); - } + if render_ok && let Err(e) = backend.submit(Some(&[full_damage])) { + tracing::warn!(?e, "backend submit failed"); } state.space.elements().for_each(|window| { From 29a7f6f50845f2a137e3702950c60a67542644f6 Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Fri, 9 Oct 2026 08:16:59 +0000 Subject: [PATCH 4/5] ci: build and test on Linux only WEFT OS targets Linux and systemd. The Windows runner only compiled and tested the crates without Linux system libraries, which says nothing about a supported configuration, and was the slowest job in every run. The job is now `portable` on Ubuntu, matching the verification profile of the same name. The building guide, README and development environment notes now state that builds are validated on Linux only. --- .github/workflows/ci.yml | 16 +++++----------- README.md | 2 +- docs/building.md | 4 ++-- infra/vm/linux-dev-environment.md | 2 +- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c131fe..ab8c084 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,15 +7,9 @@ on: pull_request: jobs: - # Crates that must compile on every supported host platform. - cross-platform: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: - - ubuntu-latest - - windows-latest + # Crates that build without Wayland or other Linux system libraries. + portable: + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable @@ -24,14 +18,14 @@ jobs: components: rustfmt, clippy - name: cargo fmt run: cargo fmt --all --check - - name: cargo clippy (cross-platform crates) + - name: cargo clippy (portable crates) run: > cargo clippy --workspace --exclude weft-compositor --exclude weft-servo-shell --exclude weft-app-shell --all-targets -- -D warnings - - name: cargo test (cross-platform crates) + - name: cargo test (portable crates) run: > cargo test --workspace --exclude weft-compositor diff --git a/README.md b/README.md index ae036f9..8bd1cbb 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ See `docs/building.md` for full instructions including Wasm component builds, Ni Three jobs on every push and pull request: -- `cross-platform` — fmt, clippy, tests on Ubuntu and Windows +- `portable` — fmt, clippy and tests for the crates that need no Linux system libraries - `linux-only` — clippy and tests for compositor and shell crates - `servo-embed-linux` — `cargo check --features servo-embed` for both servo crates diff --git a/docs/building.md b/docs/building.md index 96f1359..91eca21 100644 --- a/docs/building.md +++ b/docs/building.md @@ -2,7 +2,7 @@ ## Prerequisites -Linux (x86_64 or aarch64). Building on Windows is supported for workspace validation only; runtime components require Linux kernel interfaces. +Linux (x86_64 or aarch64). WEFT OS is built and validated on Linux only; runtime components require Linux kernel interfaces. System packages (openSUSE): @@ -92,6 +92,6 @@ See `infra/nixos/weft-packages.nix` for the package derivations. The `outputHash Three jobs run on every push to `main` and on pull requests: -- `cross-platform` — fmt, clippy, tests on Ubuntu and Windows (excludes Wayland crates) +- `portable` — fmt, clippy, tests for the crates that need no Linux system libraries (excludes Wayland crates) - `linux-only` — clippy and tests for `weft-compositor`, `weft-servo-shell`, `weft-app-shell` - `servo-embed-linux` — `cargo check --features servo-embed` for servo-shell and app-shell diff --git a/infra/vm/linux-dev-environment.md b/infra/vm/linux-dev-environment.md index 22784b5..877ef94 100644 --- a/infra/vm/linux-dev-environment.md +++ b/infra/vm/linux-dev-environment.md @@ -22,7 +22,7 @@ The guest is the validation target for: ## Host versus target boundary -The Windows host is acceptable for editing, documentation, and workspace validation. +The Windows host is acceptable for editing and documentation. Builds and tests are validated on Linux only; CI does not build on Windows. The Linux guest is authoritative for: From b0bd763e704aac3609d4a542b4780be08e2cbe4c Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Thu, 8 Oct 2026 22:58:47 +0000 Subject: [PATCH 5/5] fix(compositor): collapse nested submit condition in winit backend The nested if around backend.submit failed clippy::collapsible_if under -D warnings, breaking the linux-only clippy job. Use a let chain instead. --- crates/weft-compositor/src/backend/winit.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/weft-compositor/src/backend/winit.rs b/crates/weft-compositor/src/backend/winit.rs index 087b04c..7575211 100644 --- a/crates/weft-compositor/src/backend/winit.rs +++ b/crates/weft-compositor/src/backend/winit.rs @@ -157,10 +157,8 @@ pub fn run() -> anyhow::Result<()> { false } }; - if render_ok { - if let Err(e) = backend.submit(Some(&[full_damage])) { - tracing::warn!(?e, "backend submit failed"); - } + if render_ok && let Err(e) = backend.submit(Some(&[full_damage])) { + tracing::warn!(?e, "backend submit failed"); } state.space.elements().for_each(|window| {