nixosTests/cosmic: skip testing GUI app if not present

In cases when a given GUI app is absent (encountered when excluding
packages like `cosmic-term`, etc), the test fails because the GUI app
doesn't launch. That, while being a failure, is not connected to the
COSMIC DE itself. So if a binary is missing, skip launch-testing it.
This commit is contained in:
Pratham Patel 2025-04-23 20:53:00 +05:30 committed by Alyssa Ross
parent 0aae134f2f
commit 26a8f74022

View file

@ -112,11 +112,13 @@
gui_apps_to_launch['cosmic-term'] = 'com.system76.CosmicTerm'
for gui_app, app_id in gui_apps_to_launch.items():
machine.succeed(f"su - ${user.name} -c 'WAYLAND_DISPLAY=wayland-1 XDG_RUNTIME_DIR=/run/user/${toString user.uid} ${DISPLAY} {gui_app} >&2 &'", timeout=5)
# Nix builds the following non-commented expression to the following:
# `su - alice -c 'WAYLAND_DISPLAY=wayland-1 XDG_RUNTIME_DIR=/run/user/1000 lswt --json | jq ".toplevels" | grep "^ \\"app-id\\": \\"{app_id}\\"$"' `
machine.wait_until_succeeds(f''''su - ${user.name} -c 'WAYLAND_DISPLAY=wayland-1 XDG_RUNTIME_DIR=/run/user/${toString user.uid} lswt --json | jq ".toplevels" | grep "^ \\"app-id\\": \\"{app_id}\\"$"' '''', timeout=30)
machine.succeed(f"pkill {gui_app}", timeout=5)
# Don't fail the test if binary is absent
if machine.execute(f"su - ${user.name} -c 'command -v {gui_app}'", timeout=5)[0] == 0:
machine.succeed(f"su - ${user.name} -c 'WAYLAND_DISPLAY=wayland-1 XDG_RUNTIME_DIR=/run/user/${toString user.uid} ${DISPLAY} {gui_app} >&2 &'", timeout=5)
# Nix builds the following non-commented expression to the following:
# `su - alice -c 'WAYLAND_DISPLAY=wayland-1 XDG_RUNTIME_DIR=/run/user/1000 lswt --json | jq ".toplevels" | grep "^ \\"app-id\\": \\"{app_id}\\"$"' `
machine.wait_until_succeeds(f''''su - ${user.name} -c 'WAYLAND_DISPLAY=wayland-1 XDG_RUNTIME_DIR=/run/user/${toString user.uid} lswt --json | jq ".toplevels" | grep "^ \\"app-id\\": \\"{app_id}\\"$"' '''', timeout=30)
machine.succeed(f"pkill {gui_app}", timeout=5)
machine.succeed("echo 'test completed succeessfully' > /${testName}", timeout=5)
machine.copy_from_vm('/${testName}')