mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-22 17:22:18 +01:00
Fourth app onto freedays (~/utils/freedays), the shared pool of pre-declared days when every gate app stands down. _skip_reason is the right seam: it already exists to say why the alarm must not fire, and the free-day check joins the day gate and the once-per-day latch as another clock-independent reason. It goes first because it is the cheapest and the most absolute. "free day" means the alarm does not ring -- not that it rings later. The orchestrator is never started, so neither the alarm nor the workout lock behind it appears. That is the one app in this fleet where standing down is a physical event rather than an absent dialog, so it is worth being explicit: nothing happens that morning. Fail closed, as everywhere else: an unreadable pool reads as "not free" and the alarm rings normally. Silence is never the failure mode -- there is a test that a corrupt pool still wakes you up. The pool is one local file read, so the per-minute tick stays a millisecond-scale process with no network in it. The pylint hook's gatelock pin had drifted all the way back to v0.4.1; it moves to v0.7.3 alongside crdt-sync and freedays. pip refuses two different direct URLs for one distribution, so that stale pin would have made the hook environment unresolvable rather than merely old. requirements.txt also takes pytest-randomly 5.0.0 and ruff 0.16.6, which the freshness gate flagged once the file was touched. 171 tests, 100% coverage. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
"""Shared fixtures keeping the wake_alarm suite off the real machine.
|
|
|
|
Two hazards are left now that the PC no longer owns a lock screen, audio or
|
|
an inhibitor:
|
|
|
|
* ``_state`` signs its records with gatelock's HMAC key, and the real key is
|
|
root-owned but *world-readable*. An unpatched run would sign test entries
|
|
with the **production** key on this machine and with none at all anywhere
|
|
else, so the suite would pass here and behave differently in CI.
|
|
* ``WAKE_STATE_FILE`` is a real path inside the repo, and ``_trigger`` now
|
|
*writes* it. The trigger tests never redirected it, because until the
|
|
once-per-day latch moved into the trigger nothing on that path wrote
|
|
anything. Redirecting it here rather than per-file is deliberate: a
|
|
per-file redirect is exactly the kind that gets forgotten when a new writer
|
|
appears, and the failure is silent -- a green suite that quietly stamped
|
|
the live state file.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
from unittest.mock import patch
|
|
|
|
import freedays
|
|
import pytest
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Generator
|
|
from pathlib import Path
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _hermetic(tmp_path: Path) -> Generator[None]:
|
|
"""Keep signing keys and state writes inside ``tmp_path``."""
|
|
key_file = tmp_path / "hmac.key"
|
|
key_file.write_bytes(b"0" * 32)
|
|
with (
|
|
patch("gatelock.log_integrity.DEFAULT_HMAC_KEY_FILE", key_file),
|
|
patch("wake_alarm._state.WAKE_STATE_FILE", tmp_path / "wake_state.json"),
|
|
# The shared free-day pool lives under ~/.local/share, outside every
|
|
# path above. Without this, a real free day on the developer's
|
|
# machine would silence the alarm in every trigger test here.
|
|
patch(
|
|
"freedays._api.resolve_paths",
|
|
lambda paths: paths or freedays.Paths.under(tmp_path / "freedays"),
|
|
),
|
|
):
|
|
yield
|