mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-19 02:34:24 +01:00
Report errors and stalls to the shared board
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (flutter, flutter-analyze, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,flutter-analyze) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / lock-popup-safety (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (0) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (1) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (2) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (3) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (4) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (5) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (6) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (7) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (8) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (9) (push) Waiting to run
Tests / flutter-coverage (push) Blocked by required conditions
Tests / web-coverage (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (flutter, flutter-analyze, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,flutter-analyze) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / lock-popup-safety (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (0) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (1) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (2) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (3) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (4) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (5) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (6) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (7) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (8) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (9) (push) Waiting to run
Tests / flutter-coverage (push) Blocked by required conditions
Tests / web-coverage (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
gatelock error_report: uncaught, thread and Tk callback errors plus a frozen lock window over 1 s go to the app-errors spool. The pre-commit pylint env moves to gatelock 0.16.0, the version requirements pin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2faa118ac2
commit
9e7f536f96
@ -141,7 +141,7 @@ repos:
|
||||
# direct URLs for one distribution, so any pin that drifts from
|
||||
# the manifest becomes an unresolvable hook environment rather
|
||||
# than merely an old one.
|
||||
- gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.12.0#subdirectory=gatelock
|
||||
- gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.16.0#subdirectory=gatelock
|
||||
- crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.11.1#subdirectory=crdt-sync
|
||||
- earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.22.0#subdirectory=earned_time
|
||||
- freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.3#subdirectory=freedays
|
||||
@ -164,7 +164,7 @@ repos:
|
||||
# direct URLs for one distribution, so any pin that drifts from
|
||||
# the manifest becomes an unresolvable hook environment rather
|
||||
# than merely an old one.
|
||||
- gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.12.0#subdirectory=gatelock
|
||||
- gatelock @ git+https://github.com/kuhyx/utils@gatelock-v0.16.0#subdirectory=gatelock
|
||||
- crdt-sync @ git+https://github.com/kuhyx/utils@crdt-sync-v0.11.1#subdirectory=crdt-sync
|
||||
- earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.22.0#subdirectory=earned_time
|
||||
- freedays @ git+https://github.com/kuhyx/utils@freedays-v0.4.3#subdirectory=freedays
|
||||
|
||||
@ -69,6 +69,14 @@ until the phone is attached) backs `/sdcard/Documents/RunnerUp` up to
|
||||
once the app's `.workout_app_import.json` matches `processed/`; no app run, no uninstall.
|
||||
`python3 -m screen_locker.runnerup_retire --status` / `--dry-run` change nothing.
|
||||
|
||||
## Error reports
|
||||
|
||||
Every uncaught, thread or Tk callback error, and any freeze of the lock window
|
||||
over 1 s, goes to the shared app-errors spool through `gatelock.error_report`
|
||||
(`screen_locker/_errors.py`, installed by the CLI for every mode). The PC's
|
||||
`app-errors` timer turns each one into a ticket on the todoImplementer board
|
||||
(kuhyx/utils `DOCS-app-errors.md`). Nothing shows on screen.
|
||||
|
||||
## MCP server (Claude Code integration)
|
||||
|
||||
screen-locker exposes a **read-only** MCP server (`screen_locker._mcp`) so
|
||||
|
||||
@ -13,6 +13,7 @@ from pathlib import Path
|
||||
import sys
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from screen_locker import _errors
|
||||
from screen_locker._constants import SHUTDOWN_BASE_FILE
|
||||
from screen_locker._decision_log import record_no_decision
|
||||
from screen_locker._manual_cli import run_manual_log
|
||||
@ -111,6 +112,7 @@ def main(locker_cls: type[ScreenLocker], argv: list[str]) -> None:
|
||||
level=logging.INFO,
|
||||
format="%(levelname)s %(name)s: %(message)s",
|
||||
)
|
||||
_errors.install()
|
||||
if "--status" in argv:
|
||||
run_status(_headless_locker(locker_cls))
|
||||
|
||||
|
||||
33
screen_locker/_errors.py
Normal file
33
screen_locker/_errors.py
Normal file
@ -0,0 +1,33 @@
|
||||
"""Error and slow-wait reporting for screen-locker (utils DOCS-app-errors.md).
|
||||
|
||||
``install`` runs once from the CLI entry point: uncaught, thread and Tk
|
||||
callback errors, and a Tk loop frozen over 1 s, go to the app-errors spool,
|
||||
from which the PC's ingest files a board ticket. Only the CLI installs it, so
|
||||
tests that build a lock window never touch the real spool.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from gatelock import error_report
|
||||
|
||||
APP = "screen-locker"
|
||||
REPO = "kuhyx/screen-locker"
|
||||
|
||||
|
||||
@dataclass
|
||||
class _Slot:
|
||||
"""Holds the process's reporter once installed."""
|
||||
|
||||
reporter: error_report.Reporter | None = None
|
||||
|
||||
|
||||
#: The installed reporter (``SLOT.reporter``); None until ``install``.
|
||||
SLOT = _Slot()
|
||||
|
||||
|
||||
def install() -> error_report.Reporter:
|
||||
"""Hook this process's errors once; return the reporter."""
|
||||
SLOT.reporter = error_report.install(APP, REPO)
|
||||
return SLOT.reporter
|
||||
@ -19,8 +19,9 @@ from gatelock import (
|
||||
LockConfig,
|
||||
LockWindow,
|
||||
)
|
||||
from gatelock.error_report import watch_stalls
|
||||
|
||||
from screen_locker import _instance
|
||||
from screen_locker import _errors, _instance
|
||||
from screen_locker._auto_upgrade import AutoUpgradeMixin
|
||||
from screen_locker._carrot_watch import watch_for_carrot
|
||||
from screen_locker._constants import (
|
||||
@ -141,6 +142,8 @@ class ScreenLocker(
|
||||
self._check_early_exits()
|
||||
try:
|
||||
self.root = GateRoot()
|
||||
if _errors.SLOT.reporter is not None:
|
||||
watch_stalls(self.root, _errors.SLOT.reporter)
|
||||
except tk.TclError as exc:
|
||||
_logger.warning(
|
||||
"Could not open a window on DISPLAY=%s (%s) — this run cannot "
|
||||
|
||||
@ -29,12 +29,27 @@ import pytest
|
||||
import sickdays
|
||||
import sickdays.gui
|
||||
|
||||
from screen_locker import _errors
|
||||
import screen_locker._night_lockdown
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Iterator
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _no_error_hooks(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
||||
"""Keep the CLI from hooking this process's errors into the real spool.
|
||||
|
||||
gatelock installs its hooks once per process: a reporter already in place
|
||||
makes ``install`` return it untouched, so every report lands in tmp_path.
|
||||
"""
|
||||
reporter = _errors.error_report.Reporter(
|
||||
app=_errors.APP, repo=_errors.REPO, spool=tmp_path / "app-errors-spool"
|
||||
)
|
||||
monkeypatch.setattr(_errors.error_report.INSTALLED, "reporter", reporter)
|
||||
monkeypatch.setattr(_errors.SLOT, "reporter", None)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _no_free_days_by_default(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Never let the lock chain read the developer's real free-day pool.
|
||||
|
||||
61
screen_locker/tests/test_errors.py
Normal file
61
screen_locker/tests/test_errors.py
Normal file
@ -0,0 +1,61 @@
|
||||
"""screen-locker's error reporting: installed once, into the shared spool."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
from typing import TYPE_CHECKING
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from screen_locker import _cli, _errors, screen_lock
|
||||
from screen_locker.screen_lock import ScreenLocker
|
||||
from screen_locker.tests._locker_factories import create_locker
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def test_install_keeps_the_reporter_and_writes_the_spool(tmp_path: Path) -> None:
|
||||
"""The CLI's install names this app and its repo in every report."""
|
||||
rep = _errors.install()
|
||||
assert _errors.SLOT.reporter is rep
|
||||
assert rep.app == "screen-locker"
|
||||
rep.report("uncaught.python", ValueError("deliberate"))
|
||||
line = (tmp_path / "app-errors-spool" / "screen-locker.jsonl").read_text()
|
||||
entry = json.loads(line)
|
||||
assert entry["repo"] == "kuhyx/screen-locker"
|
||||
assert entry["error"] == "ValueError: deliberate"
|
||||
|
||||
|
||||
def test_cli_installs_the_reporter_before_any_mode() -> None:
|
||||
"""Every mode, headless ones included, runs with errors hooked."""
|
||||
with (
|
||||
patch.object(_cli, "run_status", side_effect=SystemExit(0)),
|
||||
patch.object(_cli, "_headless_locker"),
|
||||
contextlib.suppress(SystemExit),
|
||||
):
|
||||
_cli.main(ScreenLocker, ["screen_lock.py", "--status"])
|
||||
assert _errors.SLOT.reporter is not None
|
||||
|
||||
|
||||
def test_lock_window_watches_stalls_once_installed(
|
||||
monkeypatch: pytest.MonkeyPatch, mock_tk: MagicMock, tmp_path: Path
|
||||
) -> None:
|
||||
"""A lock window built after install reports its own freezes."""
|
||||
watch = MagicMock()
|
||||
monkeypatch.setattr(screen_lock, "watch_stalls", watch)
|
||||
monkeypatch.setattr(_errors.SLOT, "reporter", MagicMock())
|
||||
locker = create_locker(mock_tk, tmp_path)
|
||||
watch.assert_called_once_with(locker.root, _errors.SLOT.reporter)
|
||||
|
||||
|
||||
def test_lock_window_skips_the_watch_without_install(
|
||||
monkeypatch: pytest.MonkeyPatch, mock_tk: MagicMock, tmp_path: Path
|
||||
) -> None:
|
||||
"""Tests and library callers that never installed get no watch."""
|
||||
watch = MagicMock()
|
||||
monkeypatch.setattr(screen_lock, "watch_stalls", watch)
|
||||
create_locker(mock_tk, tmp_path)
|
||||
watch.assert_not_called()
|
||||
Loading…
Reference in New Issue
Block a user