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
166 lines
5.0 KiB
Bash
Executable File
166 lines
5.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# ============================================================================
|
|
# wake_alarm's default gate for shell and system scripts.
|
|
#
|
|
# Provisions a disposable Arch guest, installs this repo into it exactly the
|
|
# way production does, and runs the cases that cannot safely run on the host:
|
|
# install.sh, the systemd units, the shutdown wrapper, the power-key
|
|
# inhibitor, and the re-fire path after a cut-short alarm.
|
|
#
|
|
# What it deliberately cannot cover -- audio, the phone, real outputs, the
|
|
# bootloader -- is in DOCS-vmbox.md. Read that before trusting a pass.
|
|
#
|
|
# Usage: bash scripts/vmbox/harness.sh [--name <sandbox>] [--keep]
|
|
# ============================================================================
|
|
|
|
set -euo pipefail
|
|
|
|
VM_NAME="wake-alarm-harness"
|
|
KEEP=0
|
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
|
readonly SCRIPT_DIR
|
|
# Absolute and symlink-resolved: `vm share` and `vm repo` both key off the
|
|
# path's basename, so a relative "scripts/vmbox/../.." resolves to the wrong
|
|
# directory in the guest and rsync writes into /home instead of the repo.
|
|
REPO_DIR="$(readlink -f "${SCRIPT_DIR}/../..")"
|
|
readonly REPO_DIR
|
|
SCRIPT_NAME="$(basename "$0")"
|
|
readonly SCRIPT_NAME
|
|
|
|
# Printed by guest_cases.sh only when every case passed. See run_cases().
|
|
readonly GUEST_OK_SENTINEL="ALL-CASES-PASSED"
|
|
|
|
usage() {
|
|
cat <<USAGE
|
|
Usage: $SCRIPT_NAME [OPTIONS]
|
|
|
|
Run wake_alarm's system-level cases in a disposable Arch VM.
|
|
|
|
Options:
|
|
--name <sandbox> Sandbox name (default: $VM_NAME)
|
|
--keep Leave the sandbox running afterwards, for poking at
|
|
-h, --help Show this help
|
|
|
|
Exit codes:
|
|
0 every case passed
|
|
1 a case failed
|
|
2 the harness could not run (vmbox missing, provisioning failed)
|
|
USAGE
|
|
exit 0
|
|
}
|
|
|
|
die() {
|
|
echo "Error: $*" >&2
|
|
exit 2
|
|
}
|
|
|
|
step() {
|
|
echo "==> $*"
|
|
}
|
|
|
|
validate_requirements() {
|
|
command -v vm >/dev/null 2>&1 ||
|
|
die "vmbox is not installed. Run: bash ~/utils/vmbox/install.sh"
|
|
[[ -f "$REPO_DIR/install.sh" ]] ||
|
|
die "cannot find install.sh; run this from the wake-alarm repo"
|
|
}
|
|
|
|
# Bring the sandbox up from scratch. `vm new` on an existing name is an error,
|
|
# so an existing sandbox is reset instead -- that is the sub-second path and
|
|
# it guarantees a pristine starting point either way.
|
|
provision_sandbox() {
|
|
if vm list 2>/dev/null | awk '{print $1}' | grep -qx "$VM_NAME"; then
|
|
step "Resetting existing sandbox '$VM_NAME'"
|
|
vm reset "$VM_NAME" >/dev/null
|
|
else
|
|
step "Creating sandbox '$VM_NAME'"
|
|
vm new "$VM_NAME" >/dev/null
|
|
fi
|
|
|
|
# `vm repo` copies out of the shared mount, so the share must exist first.
|
|
# A bind mount, never a symlink: 9p does not follow one.
|
|
step "Sharing the repo with the guest"
|
|
vm share "$REPO_DIR" >/dev/null
|
|
|
|
# --worktree, not a clone: the point of the gate is to test the edits in
|
|
# front of you, including the ones not committed yet.
|
|
step "Copying the working tree into the guest"
|
|
vm repo "$VM_NAME" "$REPO_DIR" --worktree >/dev/null ||
|
|
die "could not copy the repo into the guest"
|
|
}
|
|
|
|
# The real production install path, not a hand-rolled approximation: this is
|
|
# the same install.sh a machine runs, so a break in it fails the gate.
|
|
run_install() {
|
|
step "Running install.sh in the guest"
|
|
if ! vm run "$VM_NAME" 'cd ~/wake-alarm && bash install.sh' >/tmp/wa-install.log 2>&1; then
|
|
tail -20 /tmp/wa-install.log >&2
|
|
die "install.sh failed in the guest (full log: /tmp/wa-install.log)"
|
|
fi
|
|
}
|
|
|
|
# `vm run` reports the *VM's* verdict (clean/dirty/hung), not the command's
|
|
# exit status -- a guest script exiting 1 still gives rc=0 on the host. That
|
|
# would make this gate fail *open*, which is worse than having no gate, so the
|
|
# verdict is carried in the output as an explicit sentinel and matched here.
|
|
run_cases() {
|
|
step "Running the guest cases"
|
|
local output
|
|
output="$(vm run "$VM_NAME" \
|
|
'bash ~/wake-alarm/scripts/vmbox/guest_cases.sh all' 2>&1)"
|
|
echo "$output"
|
|
grep -q "$GUEST_OK_SENTINEL" <<<"$output"
|
|
}
|
|
|
|
cleanup() {
|
|
if [[ $KEEP -eq 1 ]]; then
|
|
echo "Sandbox '$VM_NAME' left running (--keep). Poke at it with: vm ssh $VM_NAME"
|
|
return
|
|
fi
|
|
vm reset "$VM_NAME" >/dev/null 2>&1 || true
|
|
}
|
|
|
|
main() {
|
|
validate_requirements
|
|
trap cleanup EXIT
|
|
|
|
provision_sandbox
|
|
run_install
|
|
|
|
local status=0
|
|
run_cases || status=1
|
|
|
|
echo "============================================================"
|
|
if [[ $status -eq 0 ]]; then
|
|
echo "vmbox harness: PASSED"
|
|
echo "NOT verified on the host — see DOCS-vmbox.md for what this misses."
|
|
else
|
|
echo "vmbox harness: FAILED"
|
|
fi
|
|
echo "============================================================"
|
|
return $status
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
--name)
|
|
VM_NAME="${2:?--name needs a sandbox name}"
|
|
shift 2
|
|
;;
|
|
--keep)
|
|
KEEP=1
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
usage
|
|
;;
|
|
*)
|
|
echo "Unknown option: $1" >&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
done
|
|
|
|
main "$@"
|