mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-11 17:13:59 +01:00
`requires-python` and the CI pin already said 3.14, but ruff, mypy and pylint were still grading against 3.10 -- three tools judging an interpreter nothing runs any more, and ruff withholding the pyupgrade fixes that only become safe at the newer target. `pin_ci_python.py` rewrites exactly these three knobs. What the stale target was hiding: 118 sites on `datetime.timezone.utc` instead of `datetime.UTC` (UP017), two classes still written with `Generic[...]` rather than PEP 695 syntax, and ruff's stable formatter applying PEP 758 -- `except (A, B):` becomes `except A, B:`. That last one makes the source 3.14-only at the syntax level, which is what `requires-python = ">=3.14"` already promised; kuhy chose it deliberately over holding ruff a release back (2026-08-29). The PEP 695 fix needed a hand: ruff rewrote `class WidgetGroup(Generic[_W])` to `class WidgetGroup[W: tk.Misc]` but left the body annotated with the module-level `_W`, a *different* type variable -- mypy caught it as "a function returning TypeVar should receive at least one argument containing the same TypeVar". Renamed the body to the new parameter, gave `FrameGroup.__init__` the concrete `list[tk.Frame]` it always wrapped, and deleted the two now-dead module-level TypeVars. ruff, ruff-format, mypy --strict and both pylint passes clean at the new target. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SfnJmxxsZ534AKk16rC2Gr
90 lines
3.1 KiB
Python
90 lines
3.1 KiB
Python
"""A backend that answers with stale data must still be called broken.
|
|
|
|
The 2026-08-24 lockout had two causes and only one of them raised. These
|
|
tests cover the silent one: the GitHub mirror answered every request
|
|
correctly while the phone had stopped writing to it nine days earlier.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime, timedelta
|
|
|
|
from screen_locker import _sync_client
|
|
from screen_locker._source_health import (
|
|
SourceFinding,
|
|
collect_source_findings,
|
|
describe_staleness,
|
|
explain_findings,
|
|
)
|
|
|
|
_NOW = datetime(2026, 8, 24, 12, 0, tzinfo=UTC)
|
|
|
|
|
|
class TestCollectSourceFindings:
|
|
"""The healthy machine must produce no findings at all.
|
|
|
|
An always-on warning is one nobody reads. If a fresh, working sync still
|
|
printed "this may be wrong", the panel added for 2026-08-24 would become
|
|
background noise and stop carrying information.
|
|
"""
|
|
|
|
def test_healthy_and_fresh_reports_nothing(self) -> None:
|
|
"""No dead backend and recent data means silence."""
|
|
_sync_client.clear_degraded_sources()
|
|
|
|
findings = collect_source_findings(
|
|
newest_synced=_NOW - timedelta(hours=3), now=_NOW
|
|
)
|
|
|
|
assert findings == []
|
|
|
|
|
|
class TestDescribeStaleness:
|
|
"""Turning "answered fine, but the data is old" into a stated fault."""
|
|
|
|
def test_fresh_source_is_not_a_finding(self) -> None:
|
|
"""Today's data must not raise an alarm."""
|
|
newest = _NOW - timedelta(hours=3)
|
|
|
|
assert describe_staleness("GitHub mirror", newest, now=_NOW) is None
|
|
|
|
def test_nine_day_silence_is_reported_with_its_age(self) -> None:
|
|
"""The real 2026-08-15 mirror silence, named in days."""
|
|
newest = datetime(2026, 8, 15, 18, 0, tzinfo=UTC)
|
|
|
|
finding = describe_staleness("GitHub mirror", newest, now=_NOW)
|
|
|
|
assert finding is not None
|
|
assert "8 days" in finding.headline
|
|
assert "2026-08-15" in finding.detail
|
|
|
|
def test_boundary_is_not_flagged(self) -> None:
|
|
"""Just inside the window stays quiet, so rest days do not cry wolf."""
|
|
newest = _NOW - timedelta(days=1, hours=23)
|
|
|
|
assert describe_staleness("GitHub mirror", newest, now=_NOW) is None
|
|
|
|
def test_empty_backend_is_its_own_finding(self) -> None:
|
|
""" "Answered with nothing" is different from "answered with old"."""
|
|
finding = describe_staleness("Firebase", None, now=_NOW)
|
|
|
|
assert finding is not None
|
|
assert "no workouts at all" in finding.headline
|
|
|
|
|
|
class TestExplainFindings:
|
|
"""The text a locked-out user actually reads."""
|
|
|
|
def test_no_findings_render_nothing(self) -> None:
|
|
"""A healthy machine must not show a diagnostics block."""
|
|
assert explain_findings([]) == ""
|
|
|
|
def test_findings_name_the_backend_and_the_consequence(self) -> None:
|
|
"""The panel must say it is a sync fault, not a missed workout."""
|
|
text = explain_findings(
|
|
[SourceFinding("Firebase", "Firebase is unreadable", "HTTP 400.")]
|
|
)
|
|
|
|
assert "Firebase is unreadable" in text
|
|
assert "sync fault, not a missed workout" in text
|