Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ The runner also lists files with skipped checks, including files that ran some c

## Compositor-dependent tests

Some tests launch Quickshell or query Hyprland, but the suite must stay green on headless machines. `require_compositor "description"` handles this: when no compositor answers it calls `skip` with the reason and exits 0, and otherwise returns so the file proceeds. The skip marker lets the runner distinguish unavailable runtime coverage from checks that passed.
Some tests launch Quickshell or query Hyprland, but the suite must stay green on headless machines and must not take over the active screen on a workstation.

When `./test/shell` runs in an active Hyprland session, it automatically starts a private nested Hyprland compositor on a headless `1920x1080` output (`HEADLESS-1`) with no visible window on the host desktop and routes compositor-dependent tests into it. You can run a single compositor test the same way with `./test/headless bash test/shell.d/<area>-test.sh`. Set `OMARCHY_TEST_USE_LIVE_COMPOSITOR=1` (as `test/ci-vm` does inside its disposable VM) to target the live compositor directly.

`require_compositor "description"` handles headless environments: when no compositor answers it calls `skip` with the reason and exits 0, and otherwise returns so the file proceeds. The skip marker lets the runner distinguish unavailable runtime coverage from checks that passed.

The probe is more than an environment check, because `WAYLAND_DISPLAY` only
proves the variable was inherited. Sandboxes pass the environment through
Expand Down
2 changes: 1 addition & 1 deletion test/ci-vm
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fi
# neither the commands nor the files added since.
# The exit status goes to a file of its own, renamed into place whole: the
# tests print lines like "rc=0" themselves, so the log cannot carry it.
command='export OMARCHY_PATH=~/src/omarchy PATH=~/src/omarchy/bin:$PATH; cd ~/src/omarchy && date +%s.%N >~/started && ./test/all >~/run.log 2>&1; echo "$?" >~/rc.next && mv ~/rc.next ~/rc'
command='export OMARCHY_PATH=~/src/omarchy PATH=~/src/omarchy/bin:$PATH OMARCHY_TEST_USE_LIVE_COMPOSITOR=1; cd ~/src/omarchy && date +%s.%N >~/started && ./test/all >~/run.log 2>&1; echo "$?" >~/rc.next && mv ~/rc.next ~/rc'
ssh_vm "systemd-run --user --quiet --collect --same-dir \
-E OMARCHY_PKGS_PATH=\$HOME/src/omarchy-pkgs bash -c $(printf %q "$command")"
last_report="" next_report=0
Expand Down
124 changes: 82 additions & 42 deletions test/cli
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,19 @@ else
fail "commands pads the usage column to at most 48 characters"
fi

"$CLI" commands --json | jq -e '.ok == true and (.commands | length >= 200)' >/dev/null
make_tmpdir CLI_META_DIR
commands_json_file="$CLI_META_DIR/commands.json"
commands_all_json_file="$CLI_META_DIR/commands-all.json"
"$CLI" commands --json >"$commands_json_file"
"$CLI" commands --all --json >"$commands_all_json_file"

jq -e '.ok == true and (.commands | length >= 200)' "$commands_json_file" >/dev/null
pass "commands --json is valid JSON with full bin coverage"

"$CLI" commands --json | jq -e 'all(.commands[]; .summary != "undocumented")' >/dev/null
jq -e 'all(.commands[]; .summary != "undocumented")' "$commands_json_file" >/dev/null
pass "all included commands have summaries"

"$CLI" commands --json | jq -e 'all(.commands[]; has("binary") and has("filename_route") and has("routes") and (has("legacy") | not) and (has("usage") | not) and (has("visibility") | not) and (has("mutates") | not) and (has("interactive") | not))' >/dev/null
jq -e 'all(.commands[]; has("binary") and has("filename_route") and has("routes") and (has("legacy") | not) and (has("usage") | not) and (has("visibility") | not) and (has("mutates") | not) and (has("interactive") | not))' "$commands_json_file" >/dev/null
pass "JSON uses binary/routes and omits legacy/usage/extra metadata"

"$CLI" commands --check >/dev/null
Expand All @@ -90,34 +96,34 @@ pass "commands --check passes"
"$CLI" commands --all >/dev/null
pass "commands --all does not crash"

"$CLI" commands --all --json | jq -e '.commands[] | select(.route == "omarchy hyprland window gaps toggle" and .summary != "undocumented")' >/dev/null
jq -e '.commands[] | select(.route == "omarchy hyprland window gaps toggle" and .summary != "undocumented")' "$commands_all_json_file" >/dev/null
pass "fallback commands are inferred and documented"

"$CLI" commands --all --json | jq -e '.commands[] | select(.route == "omarchy dev benchmark cli")' >/dev/null
jq -e '.commands[] | select(.route == "omarchy dev benchmark cli")' "$commands_all_json_file" >/dev/null
pass "benchmark command is discoverable in all commands"

"$CLI" commands --json | jq -e '.commands[] | select(.binary == "omarchy-pkg-add" and .route == "omarchy pkg add" and .filename_route == "omarchy pkg add" and (.routes | index("omarchy pkg add")))' >/dev/null
jq -e '.commands[] | select(.binary == "omarchy-pkg-add" and .route == "omarchy pkg add" and .filename_route == "omarchy pkg add" and (.routes | index("omarchy pkg add")))' "$commands_json_file" >/dev/null
pass "JSON exposes direct pkg add route"

"$CLI" commands --json | jq -e '.commands[] | select(.binary == "omarchy-install-gaming-xbox-cloud" and .route == "omarchy install gaming xbox-cloud" and .filename_route == "omarchy install gaming xbox cloud" and (.routes | index("omarchy install gaming xbox cloud")))' >/dev/null
jq -e '.commands[] | select(.binary == "omarchy-install-gaming-xbox-cloud" and .route == "omarchy install gaming xbox-cloud" and .filename_route == "omarchy install gaming xbox cloud" and (.routes | index("omarchy install gaming xbox cloud")))' "$commands_json_file" >/dev/null
pass "Xbox Cloud installer keeps hyphenated canonical route"

"$CLI" commands --json | jq -e '.commands[] | select(.binary == "omarchy-install-gaming-xbox-controllers" and .route == "omarchy install gaming xbox-controllers" and .filename_route == "omarchy install gaming xbox controllers" and (.routes | index("omarchy install gaming xbox controllers")))' >/dev/null
jq -e '.commands[] | select(.binary == "omarchy-install-gaming-xbox-controllers" and .route == "omarchy install gaming xbox-controllers" and .filename_route == "omarchy install gaming xbox controllers" and (.routes | index("omarchy install gaming xbox controllers")))' "$commands_json_file" >/dev/null
pass "Xbox controller installer keeps hyphenated canonical route"

"$CLI" commands --json | jq -e '.commands[] | select(.binary == "omarchy-remove-gaming-xbox-controllers" and .route == "omarchy remove gaming xbox-controllers" and .filename_route == "omarchy remove gaming xbox controllers" and (.routes | index("omarchy remove gaming xbox controllers")))' >/dev/null
jq -e '.commands[] | select(.binary == "omarchy-remove-gaming-xbox-controllers" and .route == "omarchy remove gaming xbox-controllers" and .filename_route == "omarchy remove gaming xbox controllers" and (.routes | index("omarchy remove gaming xbox controllers")))' "$commands_json_file" >/dev/null
pass "Xbox controller remover keeps hyphenated canonical route"

"$CLI" commands --json | jq -e '.commands[] | select(.binary == "omarchy-install-gaming-geforce-now" and .route == "omarchy install gaming geforce-now" and .filename_route == "omarchy install gaming geforce now" and (.routes | index("omarchy install gaming geforce now")))' >/dev/null
jq -e '.commands[] | select(.binary == "omarchy-install-gaming-geforce-now" and .route == "omarchy install gaming geforce-now" and .filename_route == "omarchy install gaming geforce now" and (.routes | index("omarchy install gaming geforce now")))' "$commands_json_file" >/dev/null
pass "GeForce NOW installer keeps hyphenated canonical route"

"$CLI" commands --json | jq -e '.commands[] | select(.binary == "omarchy-remove-gaming-geforce-now" and .route == "omarchy remove gaming geforce-now" and .filename_route == "omarchy remove gaming geforce now" and (.routes | index("omarchy remove gaming geforce now")))' >/dev/null
jq -e '.commands[] | select(.binary == "omarchy-remove-gaming-geforce-now" and .route == "omarchy remove gaming geforce-now" and .filename_route == "omarchy remove gaming geforce now" and (.routes | index("omarchy remove gaming geforce now")))' "$commands_json_file" >/dev/null
pass "GeForce NOW remover keeps hyphenated canonical route"

"$CLI" commands --json | jq -e '.commands[] | select(.binary == "omarchy-install-gaming-gpu-lib32" and .route == "omarchy install gaming gpu-lib32" and .filename_route == "omarchy install gaming gpu lib32" and (.routes | index("omarchy install gaming gpu lib32")))' >/dev/null
jq -e '.commands[] | select(.binary == "omarchy-install-gaming-gpu-lib32" and .route == "omarchy install gaming gpu-lib32" and .filename_route == "omarchy install gaming gpu lib32" and (.routes | index("omarchy install gaming gpu lib32")))' "$commands_json_file" >/dev/null
pass "GPU lib32 installer keeps hyphenated canonical route"

"$CLI" commands --json | jq -e '.commands[] | select(.binary == "omarchy-refresh-pacman" and .requires_sudo == true)' >/dev/null
jq -e '.commands[] | select(.binary == "omarchy-refresh-pacman" and .requires_sudo == true)' "$commands_json_file" >/dev/null
pass "sudo metadata marks sudo commands"

output=$("$CLI" theme --help)
Expand Down Expand Up @@ -175,14 +181,16 @@ output=$("$CLI" menu share) || status=$?
pass "bare required-arg filename route exits 1"
assert_output_contains "bare required-arg filename route renders CLI help" "$output" "omarchy share <clipboard|file|folder> [path...]"

CLI="$CLI" python3 <<'PY'
CLI="$CLI" COMMANDS_JSON_FILE="$commands_json_file" python3 <<'PY'
from concurrent.futures import ThreadPoolExecutor
import json
import os
import subprocess
import sys

cli = os.environ['CLI']
commands = json.loads(subprocess.check_output([cli, 'commands', '--json'], text=True))['commands']
with open(os.environ['COMMANDS_JSON_FILE']) as fh:
commands = json.load(fh)['commands']
by_group = {}
for command in commands:
binary = command['binary']
Expand All @@ -191,16 +199,22 @@ for command in commands:
filename_route = 'omarchy ' + stem.replace('-', ' ')
by_group.setdefault(group, []).append((binary, filename_route, command['route']))

missing = []
for group, rows in sorted(by_group.items()):
def check_group(item):
group, rows = item
proc = subprocess.run([cli, group, '--help'], text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = proc.stdout + proc.stderr
if proc.returncode != 0:
missing.append((group, '<group-help-failed>', f'exit {proc.returncode}'))
continue
for binary, filename_route, canonical_route in rows:
if filename_route not in output and canonical_route not in output and binary not in output:
missing.append((group, binary, filename_route))
return [(group, '<group-help-failed>', f'exit {proc.returncode}')]
return [
(group, binary, filename_route)
for binary, filename_route, canonical_route in rows
if filename_route not in output and canonical_route not in output and binary not in output
]

missing = []
with ThreadPoolExecutor(max_workers=os.cpu_count() or 8) as pool:
for rows in pool.map(check_group, sorted(by_group.items())):
missing.extend(rows)

if missing:
for row in missing:
Expand Down Expand Up @@ -232,13 +246,11 @@ fi
pass "a group whose commands are all hidden stays out of the top-level listing"

for internal in omarchy-apply-system omarchy-apply-hardware omarchy-apply-lock; do
if "$CLI" commands --json | jq -e --arg binary "$internal" \
'.commands[] | select(.binary == $binary)' >/dev/null; then
if jq -e --arg binary "$internal" '.commands[] | select(.binary == $binary)' "$commands_json_file" >/dev/null; then
fail "$internal stays out of the default command listing"
fi

"$CLI" commands --all --json | jq -e --arg binary "$internal" \
'.commands[] | select(.binary == $binary) | select(.hidden)' >/dev/null ||
jq -e --arg binary "$internal" '.commands[] | select(.binary == $binary) | select(.hidden)' "$commands_all_json_file" >/dev/null ||
fail "$internal is still listed by commands --all"
done
pass "install-time setup plumbing is hidden from the setup wizards"
Expand All @@ -249,7 +261,7 @@ assert_output_contains "hidden setup plumbing still routes" "$output" "omarchy-a
output=$("$CLI" screenshot --help)
assert_output_contains "root alias resolves to command help" "$output" "omarchy-capture-screenshot"

"$CLI" commands --json | jq -e '.commands[] | select(.binary == "omarchy-capture-screenshot") | .aliases | index("omarchy screenshot")' >/dev/null
jq -e '.commands[] | select(.binary == "omarchy-capture-screenshot") | .aliases | index("omarchy screenshot")' "$commands_json_file" >/dev/null
pass "aliases are included in JSON metadata"

output=$("$CLI" pkg add --help)
Expand Down Expand Up @@ -732,20 +744,48 @@ for binary in \
pass "binary is executable: $binary"
done

while IFS= read -r binary_path; do
header=$(awk '
NR == 1 && /^#!/ { next }
/^[[:space:]]*$/ { if (seen) print; next }
/^[[:space:]]*#/ { seen=1; print; next }
{ exit }
' "$binary_path")

grep -q '^# omarchy:summary=' <<<"$header" || fail "metadata summary is present: $binary_path"
! grep -q '^# omarchy:binary=' <<<"$header" || fail "metadata does not repeat inferred binary: $binary_path"
! grep -q '^# omarchy:args=$' <<<"$header" || fail "metadata does not include empty args: $binary_path"
! grep -Eq '^# omarchy:(legacy|usage|visibility|mutates|interactive)=' <<<"$header" || fail "metadata avoids removed fields: $binary_path"
! grep -Eq '^# omarchy:requires-sudo=false$' <<<"$header" || fail "metadata omits false booleans: $binary_path"
done < <(find "$ROOT/bin" -maxdepth 1 -type f -executable -name 'omarchy-*' | sort)
ROOT="$ROOT" python3 - <<'PY' || exit 1
import os, re, sys

bin_dir = os.path.join(os.environ['ROOT'], 'bin')
removed_re = re.compile(r'^# omarchy:(legacy|usage|visibility|mutates|interactive)=')

for name in sorted(os.listdir(bin_dir)):
if not name.startswith('omarchy-'):
continue
path = os.path.join(bin_dir, name)
if not (os.path.isfile(path) and os.access(path, os.X_OK)):
continue
header = []
seen = False
with open(path, 'r', errors='replace') as fh:
for i, line in enumerate(fh, 1):
line = line.rstrip('\r\n')
if i == 1 and line.startswith('#!'):
continue
if not line.strip():
if seen:
header.append(line)
continue
if line.lstrip().startswith('#'):
seen = True
header.append(line)
continue
break
def die(msg):
print(f'not ok - {msg}: {path}', file=sys.stderr)
sys.exit(1)
if not any(l.startswith('# omarchy:summary=') for l in header):
die('metadata summary is present')
if any(l.startswith('# omarchy:binary=') for l in header):
die('metadata does not repeat inferred binary')
if any(l == '# omarchy:args=' for l in header):
die('metadata does not include empty args')
if any(removed_re.match(l) for l in header):
die('metadata avoids removed fields')
if any(l == '# omarchy:requires-sudo=false' for l in header):
die('metadata omits false booleans')
PY
pass "all executable bins have slim self-documenting metadata"

make_tmpdir TMPDIR
Expand Down Expand Up @@ -961,7 +1001,7 @@ cp -a "$ROOT/bin/." "$ROUTER_BIN/"
fastest_ms() {
local best="" start end elapsed

for _ in 1 2 3 4 5; do
for _ in 1 2 3; do
read -r start _ </proc/uptime
"$@" >/dev/null 2>&1
read -r end _ </proc/uptime
Expand Down
Loading