Files
omarchycn/test/shell.d/idle-test.sh
T
David Heinemeier HanssonandClaude Fable 5 bee9ab476c Bind the Stay Awake indicator to the idle service
The indicator polled omarchy-toggle-idle over a Process and re-ran it on
a timer to toggle, while the CLI called back into the shell over IPC to
apply and refresh the state it had just changed. Now the indicator binds
straight to the idle service's stayAwake property and flips it in
process. The CLI only touches the state file, which the service already
watches, so toggling from keybindings and scripts still reaches the
shell without any reentrant IPC.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-21 15:25:49 -07:00

55 lines
1.9 KiB
Bash

#!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
run_node_test <<'JS'
const idle = requireFromRoot('shell/plugins/services/idle/IdleModel.js')
assertEqual(idle.secondsFromConfig('42.9', 10), 42, 'idle floors configured seconds')
assertEqual(idle.secondsFromConfig('-1', 10), 10, 'idle rejects negative seconds')
assertEqual(idle.secondsFromConfig('nope', 10), 10, 'idle rejects invalid seconds')
assertDeepEqual(idle.eventParts({ data: 'a,b,c' }, 2), ['a', 'b', 'c'], 'idle parses raw event data')
assertDeepEqual(
idle.eventParts({ parse: function(count) { return ['parsed', count] } }, 4),
['parsed', 4],
'idle prefers event parser when available'
)
assertDeepEqual(
idle.screensaverWindowsAfter({ a: true }, 'b', true),
{ windows: { a: true, b: true }, count: 2 },
'idle adds visible screensaver windows'
)
assertDeepEqual(
idle.screensaverWindowsAfter({ a: true, b: true }, 'a', false),
{ windows: { b: true }, count: 1 },
'idle removes closed screensaver windows'
)
assertDeepEqual(
idle.screensaverWindowsAfter({ a: true }, '', false),
{ windows: { a: true }, count: 1 },
'idle leaves screensaver windows unchanged without an address'
)
JS
test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT
test_home="$test_tmp/home"
mkdir -p "$test_home"
HOME="$test_home" "$ROOT/bin/omarchy-toggle-idle" stay-awake >/dev/null
[[ -f $test_home/.local/state/omarchy/indicators/stay-awake ]] || fail "Stay Awake toggle persists enabled state"
HOME="$test_home" "$ROOT/bin/omarchy-toggle-idle" allow-idle >/dev/null
[[ ! -f $test_home/.local/state/omarchy/indicators/stay-awake ]] || fail "Stay Awake toggle persists disabled state"
if rg -q 'omarchy-shell' "$ROOT/bin/omarchy-toggle-idle"; then
fail "Stay Awake toggle avoids reentrant shell IPC"
fi
pass "Stay Awake toggle persists state without reentrant shell IPC"