mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
Application windows opened at the client's default size at the origin, so one as large as the output hid the taskbar with no way back. zweft_shell_window_v1 version 3 adds set_exclusive_zone: a panel reserves a strip along an output edge, and other windows get the new invalid_exclusive_zone error. weft-servo-shell reserves its 48-pixel taskbar at the bottom (TASKBAR_HEIGHT, matching --taskbar-height in the system UI). The compositor computes the work area as the output less the reserved strips and configures every application window to fill it, again when the output or a reservation changes. The desktop harness now uses a 1400x900 X screen so the nested compositor's whole 1280x800 output is captured. check_activation.py requires both applications to fill the work area and end at the reserved strip; check_notes.py finds the Discard button from the window's right edge and check_confinement.py samples its probes from the measured page instead of a fixed 800x600 window.
215 lines
8.2 KiB
Python
215 lines
8.2 KiB
Python
"""Check that the Notes demo stores exactly what the user types.
|
|
|
|
The harness runs weft-appd on a nested desktop with the real runtime and app
|
|
shell, seeds the Notes data with text containing a literal backslash
|
|
sequence, quotes, a tab and non-ASCII characters, launches
|
|
`org.weft.demo.notes` and edits it with real keyboard input:
|
|
|
|
1. Typing at the end and pressing Ctrl+S must store the seeded text plus
|
|
the typed text, byte for byte; a load or save that rewrote `\\n`, quotes
|
|
or tabs fails.
|
|
2. Text typed while a save is in flight (the runtime is paused with SIGSTOP
|
|
between Ctrl+S and the reply) must still be in the editor afterwards: a
|
|
second Ctrl+S stores it too.
|
|
3. After the file is changed on disk (as by another Notes window), a save
|
|
must be refused and the other window's text kept.
|
|
4. Discard reloads the stored text. Keys typed while that reload is in
|
|
flight (runtime paused again) must be ignored, so a following save stores
|
|
the reloaded text plus only what was typed afterwards.
|
|
5. A load that fails (the stored notes are not valid UTF-8) leaves Discard
|
|
usable: after the file is repaired, Discard loads it and it can be edited
|
|
and saved again.
|
|
|
|
Requires Xvfb, xwd, ImageMagick's convert and xdotool.
|
|
"""
|
|
|
|
import argparse
|
|
import os
|
|
import shutil
|
|
import signal
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
from pathlib import Path
|
|
|
|
sys.dont_write_bytecode = True
|
|
from check_counter import AppdClient, free_port, read_endpoint # noqa: E402
|
|
from session import ROOT, Desktop, SessionError, bounding_box, missing_tools, parse_ppm # noqa: E402
|
|
|
|
APP_ID = "org.weft.demo.notes"
|
|
SEED = 'path C:\\new\\table "quoted"\tcaf\u00e9 \u2603'
|
|
|
|
|
|
PAGE = (15, 15, 15) # The Notes page's background, #0f0f0f.
|
|
# The Discard button, right-aligned in the header: its offset from the
|
|
# window's right edge, and its height on the desktop.
|
|
DISCARD_FROM_RIGHT, DISCARD_Y = 137, 68
|
|
|
|
|
|
def runtime_pid():
|
|
"""The process ID of the Notes session's weft-runtime."""
|
|
found = subprocess.run(["pgrep", "-n", "-f", f"weft-runtime {APP_ID}"],
|
|
capture_output=True, text=True)
|
|
if found.returncode != 0:
|
|
raise AssertionError("no weft-runtime process for Notes")
|
|
return int(found.stdout.split()[0])
|
|
|
|
|
|
def wait_for_file(path, expected, timeout=15):
|
|
deadline = time.monotonic() + timeout
|
|
while time.monotonic() < deadline:
|
|
if path.exists() and path.read_text(encoding="utf-8") == expected:
|
|
return
|
|
time.sleep(0.2)
|
|
actual = path.read_text(encoding="utf-8") if path.exists() else None
|
|
raise AssertionError(f"stored notes {actual!r}, expected {expected!r}")
|
|
|
|
|
|
def run(args, desktop, home, xdotool):
|
|
data_home = home / "share"
|
|
notes = data_home / "weft/app-data" / APP_ID / "notes.txt"
|
|
notes.parent.mkdir(parents=True)
|
|
notes.write_text(SEED, encoding="utf-8")
|
|
|
|
t = Path(args.target)
|
|
desktop.launch_client("appd", [t / "weft-appd"], {
|
|
"WEFT_RUNTIME_BIN": str(t / "weft-runtime"),
|
|
"WEFT_APP_SHELL_BIN": str(t / "weft-app-shell"),
|
|
"WEFT_APP_STORE": str(args.store),
|
|
"WEFT_DISABLE_CGROUP": "1",
|
|
"WEFT_APPD_WS_PORT": str(free_port()),
|
|
"HOME": str(home),
|
|
"XDG_DATA_HOME": str(data_home),
|
|
})
|
|
port, token = read_endpoint(desktop.runtime, 30)
|
|
appd = AppdClient(port, token)
|
|
appd.send({"type": "LAUNCH_APP", "app_id": APP_ID, "surface_id": 0})
|
|
reply = appd.wait_for(lambda m: m.get("type") in ("APP_READY", "ERROR"), 120)
|
|
if reply.get("type") != "APP_READY":
|
|
raise AssertionError(f"Notes did not start: {reply}")
|
|
time.sleep(2)
|
|
width, height, pixels = parse_ppm(desktop.capture())
|
|
page = bounding_box(width, height, pixels, PAGE)
|
|
if page is None:
|
|
raise AssertionError("the Notes page is not on screen")
|
|
discard = (str(page[2] + 1 - DISCARD_FROM_RIGHT), str(DISCARD_Y))
|
|
|
|
def act(*arguments):
|
|
subprocess.run([xdotool, *arguments], env={"DISPLAY": desktop.display},
|
|
check=True, timeout=30)
|
|
|
|
act("search", "--class", "weft-compositor", "windowfocus", "--sync")
|
|
# The editor fills the window below the header.
|
|
act("mousemove", "--sync", "100", "300")
|
|
act("click", "1")
|
|
act("key", "ctrl+End")
|
|
|
|
runtime = runtime_pid()
|
|
|
|
act("type", "--delay", "40", ' +\\t "x"')
|
|
expected = SEED + ' +\\t "x"'
|
|
os.kill(runtime, signal.SIGSTOP)
|
|
try:
|
|
act("key", "ctrl+s")
|
|
act("type", "--delay", "40", " more")
|
|
time.sleep(2)
|
|
finally:
|
|
os.kill(runtime, signal.SIGCONT)
|
|
wait_for_file(notes, expected)
|
|
time.sleep(1)
|
|
act("key", "ctrl+s")
|
|
expected += " more"
|
|
wait_for_file(notes, expected)
|
|
|
|
other = "written by another window"
|
|
notes.write_text(other, encoding="utf-8")
|
|
act("type", "--delay", "40", " lost?")
|
|
act("key", "ctrl+s")
|
|
time.sleep(3)
|
|
if notes.read_text(encoding="utf-8") != other:
|
|
raise AssertionError("a save replaced notes changed elsewhere")
|
|
|
|
os.kill(runtime, signal.SIGSTOP)
|
|
try:
|
|
act("mousemove", "--sync", *discard)
|
|
act("click", "1")
|
|
act("mousemove", "--sync", "100", "300")
|
|
act("click", "1")
|
|
act("type", "--delay", "40", "zz")
|
|
# Let the page handle the keys while the reload is still unanswered.
|
|
time.sleep(2)
|
|
finally:
|
|
os.kill(runtime, signal.SIGCONT)
|
|
time.sleep(2)
|
|
act("key", "ctrl+End")
|
|
act("type", "--delay", "40", "!")
|
|
act("key", "ctrl+s")
|
|
wait_for_file(notes, other + "!")
|
|
notes.write_bytes(b"\xff not text")
|
|
act("mousemove", "--sync", *discard)
|
|
act("click", "1")
|
|
time.sleep(2)
|
|
# The editor stays read-only and nothing can be saved over the file.
|
|
act("mousemove", "--sync", "100", "300")
|
|
act("click", "1")
|
|
act("type", "--delay", "40", "x")
|
|
act("key", "ctrl+s")
|
|
time.sleep(2)
|
|
if notes.read_bytes() != b"\xff not text":
|
|
raise AssertionError("a failed load changed the stored notes")
|
|
act("mousemove", "--sync", *discard)
|
|
notes.write_text("repaired", encoding="utf-8")
|
|
act("click", "1")
|
|
time.sleep(2)
|
|
act("mousemove", "--sync", "100", "300")
|
|
act("click", "1")
|
|
act("key", "ctrl+End")
|
|
act("type", "--delay", "40", "?")
|
|
act("key", "ctrl+s")
|
|
wait_for_file(notes, "repaired?")
|
|
|
|
leftovers = [p.name for p in notes.parent.iterdir() if p.name != "notes.txt"]
|
|
if leftovers:
|
|
raise AssertionError(f"files left beside the notes: {leftovers}")
|
|
|
|
|
|
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("--target", type=Path, default=ROOT / "target/debug",
|
|
help="directory with weft-appd, weft-runtime and weft-app-shell")
|
|
parser.add_argument("--store", type=Path, default=ROOT / "examples",
|
|
help="app store containing org.weft.demo.notes")
|
|
parser.add_argument("--output", type=Path, default=ROOT / "target/notes-check")
|
|
args = parser.parse_args(argv)
|
|
|
|
xdotool = shutil.which("xdotool")
|
|
missing = missing_tools() + ([] if xdotool else ["xdotool"])
|
|
missing += [str(p) for p in (args.compositor, args.target / "weft-appd",
|
|
args.target / "weft-runtime", args.target / "weft-app-shell")
|
|
if not p.is_file()]
|
|
if missing:
|
|
print("missing: " + ", ".join(missing), file=sys.stderr)
|
|
return 2
|
|
home = Path(tempfile.mkdtemp(prefix="weft-home-"))
|
|
try:
|
|
with Desktop(args.compositor, args.output, outputs=["appd.log", "notes.ppm"]) as desktop:
|
|
try:
|
|
run(args, desktop, home, xdotool)
|
|
except AssertionError:
|
|
(args.output / "notes.ppm").write_bytes(desktop.capture())
|
|
raise
|
|
except (AssertionError, SessionError, TimeoutError) as failure:
|
|
print(f"notes check failed: {failure}", file=sys.stderr)
|
|
print(f"logs and capture in {args.output}", file=sys.stderr)
|
|
return 1
|
|
finally:
|
|
shutil.rmtree(home, ignore_errors=True)
|
|
print("notes check passed")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|