mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-10 19:27:02 +01:00
The PC no longer wakes anyone -- the phone does. This deletes the alarm window, the audio escalation, the sink/reactivation machinery, the power-key inhibitor, the escape hatch, the curtains, the smart plug, the brightness and DDC/CI control, the hibernate path (shutdown wrapper + rtcwake + sleep hook) and the challenge set: 30 modules, 34 test files, ~5k lines. What stays is the part that still earns its keep: the per-minute trigger reads the alarm the phone published and starts morning-routine.service, so the workout lock still runs at the right time. THE ONE LOAD-BEARING BEHAVIOUR CHANGE. Deleting _alarm.py orphaned the only writer of wake_state.json, and _trigger gated on it via was_alarm_dismissed_today(). With that gone -- and was_workout_logged_today() already permanently False, since WORKOUT_LOG_FILE does not exist -- both gates would have been dead and the routine restarted on every tick for the rest of the 60-minute catch-up window. The unit is Type=simple, so a start while it runs is a no-op, but the moment the workout lock finished the next tick would relaunch it on top of the user. So _trigger now writes its own once-per-day latch (save_trigger_fired / was_trigger_fired_today) and gates on that. Collapsing the catch-up window instead was rejected: that window is the entire reason a suspended or just-booted machine still fires. It also replaces the deleted sleep hook, via Persistent=true. _trigger also imported should_refire from _alarm_session, which was on the delete list. Since start_session lived only in _alarm.py, no session record is ever written again and the branch was unreachable, not merely unused. WAKE_STATE_FILE is now redirected in tests/conftest.py rather than per-file. The trigger tests never redirected it, because until this commit nothing on that path wrote anything -- and a per-file redirect is exactly the kind that gets forgotten when a new writer appears, with a silent failure: a green suite that quietly stamped the live state file. Verified by mtime that it did not. Cross-repo, same change: morning_routine._orchestrator loses its alarm leg and its --with-alarm flag. Leaving an orchestrator pointing at a deleted module caused a month-long silent failure once already. uninstall.sh is new, and matters more than it looks. /usr/local/bin/shutdown is root-owned and shadows /usr/bin/shutdown; deleting this repo would leave it in place, and with the alarm cache gone it falls through to rtcwake + hibernate -- so "shutdown now" would silently stop being a poweroff, every day, forever. /etc/sudoers.d/wake-alarm is deliberately NOT removed: screen-locker's own _wake_alarm.py still needs passwordless rtcwake. 159 tests pass at 100% branch coverage; all 26 pre-commit hooks green. Verified by running it: _sync --show and _trigger --dry-run both resolve. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PcdngP688mW6rJye3LRkSN
90 lines
2.6 KiB
Bash
Executable File
90 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# ============================================================================
|
|
# wake_alarm vmbox harness — the cases that run INSIDE the guest.
|
|
#
|
|
# Kept as its own file rather than inlined into `vm run` for two reasons: the
|
|
# vmbox runner wraps its argument in `sh -c` and chokes on a multi-line
|
|
# command, and a real file gets shellcheck like every other script here.
|
|
#
|
|
# Each case prints "PASS <name>" or "FAIL <name>: <why>" and the script exits
|
|
# non-zero if any failed, so the host adjudicates on an exit code rather than
|
|
# by reading prose.
|
|
# ============================================================================
|
|
|
|
set -uo pipefail
|
|
|
|
readonly PY=/usr/bin/python3
|
|
FAILURES=0
|
|
|
|
pass() {
|
|
echo "PASS $1"
|
|
}
|
|
|
|
fail() {
|
|
echo "FAIL $1: $2"
|
|
FAILURES=$((FAILURES + 1))
|
|
}
|
|
|
|
# --- Case: the package installs and imports from SYSTEM python ---------------
|
|
# The units run /usr/bin/python directly, never a venv, so this is the check
|
|
# that actually matters (CLAUDE.md).
|
|
case_imports() {
|
|
local name="imports-from-system-python"
|
|
if "$PY" -c "import wake_alarm, gatelock" 2>/dev/null; then
|
|
pass "$name"
|
|
else
|
|
fail "$name" "wake_alarm or gatelock missing from /usr/bin/python3"
|
|
fi
|
|
}
|
|
|
|
# --- Case: the trigger timer is actually enabled -----------------------------
|
|
# install.sh writing the unit file is not the same as systemd running it, and
|
|
# a timer that is present but disabled fails silently every morning.
|
|
case_units() {
|
|
local name state
|
|
name="trigger-timer-enabled"
|
|
state="$(systemctl --user is-enabled wake-alarm-trigger.timer 2>&1)"
|
|
if [[ "$state" == "enabled" ]]; then
|
|
pass "$name"
|
|
else
|
|
fail "$name" "expected enabled, got '$state'"
|
|
fi
|
|
}
|
|
|
|
# --- Case: the trigger decides without crashing ------------------------------
|
|
case_trigger_dry_run() {
|
|
local name="trigger-dry-run"
|
|
if "$PY" -m wake_alarm._trigger --dry-run 2>/dev/null | grep -q "firing"; then
|
|
pass "$name"
|
|
else
|
|
fail "$name" "--dry-run produced no decision line"
|
|
fi
|
|
}
|
|
|
|
main() {
|
|
case "${1:-all}" in
|
|
all)
|
|
case_imports
|
|
case_units
|
|
case_trigger_dry_run
|
|
;;
|
|
*)
|
|
echo "usage: $0 [all]" >&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
|
|
echo "---"
|
|
if [[ $FAILURES -gt 0 ]]; then
|
|
echo "$FAILURES case(s) failed"
|
|
exit 1
|
|
fi
|
|
# The host greps for this exact string. `vm run` reports the VM's verdict
|
|
# rather than this script's exit code, so an exit status alone would let
|
|
# the gate fail open.
|
|
echo "ALL-CASES-PASSED"
|
|
}
|
|
|
|
main "$@"
|