mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-11 18:53:55 +01:00
_workout_sync.py (332) -> _sync_client.py token, Firebase/GitHub client
_sync_records.py payload predicates + log decoding
_sick_tracker.py (317) -> _sick_budget.py SickHistory + rolling budget
This one was not a pure move until the fixtures followed it. Three autouse
test guards patch names by module, and all three pointed at _workout_sync:
isolate_sync_token SYNC_TOKEN_FILE -> now also on _sync_client
_no_real_firebase_config CONFIG_FILE -> now on _sync_client
_firebase_config helper (7 call sites) -> now passed _sync_client
With them stale, sync_client built a REAL client: the suite went from 14s to
over 120s and test_workout_sync_part5 asserted against live workout data
pulled from the actual backend. Fixed, the same tests run in 0.7s. Both
modules keep SYNC_TOKEN_FILE so either patch point works, and every relocated
guard target is asserted to exist.
977 tests pass at 100% branch coverage; pylint back to 8.70 after fixing the
findings the split introduced (a dropped `return None` in _parse_iso and
leftover dead imports). `screen_lock --status` unchanged.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EveB813BQ8abAP68VSqZ5Y
63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
"""``remote_client`` mirror selection, split from ``test_workout_sync_part2``.
|
|
|
|
Kept separate from the pulls so no workout-sync test file exceeds the repo's
|
|
400-line limit.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import TYPE_CHECKING
|
|
|
|
from crdt_sync import ConfigError
|
|
|
|
from screen_locker import _sync_client, _workout_sync
|
|
from screen_locker.tests._workout_sync_fixtures import _firebase_config
|
|
|
|
if TYPE_CHECKING:
|
|
import pytest
|
|
|
|
|
|
class TestRemoteClient:
|
|
"""Which backend the workout pull reads from during the cutover."""
|
|
|
|
def test_stays_on_github_without_firebase_config(
|
|
self, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
"""An unconfigured machine must not reach the network at all."""
|
|
monkeypatch.setattr(
|
|
_workout_sync, "CONFIG_FILE", Path("/nonexistent/firebase.json")
|
|
)
|
|
github = object()
|
|
|
|
assert _workout_sync.remote_client(github) is github
|
|
|
|
def test_mirrors_to_github_when_configured(
|
|
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
"""Configured: reads union both, so either backend's workout counts."""
|
|
_firebase_config(_sync_client, tmp_path, monkeypatch)
|
|
monkeypatch.setattr(
|
|
_sync_client,
|
|
"mirror_client_for",
|
|
lambda _app, client: ("mirror", client),
|
|
)
|
|
github = object()
|
|
|
|
assert _workout_sync.remote_client(github) == ("mirror", github)
|
|
|
|
def test_falls_back_when_firebase_is_unusable(
|
|
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
"""A broken Firebase must degrade to GitHub, never fail the pull."""
|
|
_firebase_config(_sync_client, tmp_path, monkeypatch)
|
|
|
|
def _boom(*_args: object, **_kwargs: object) -> None:
|
|
message = "no password"
|
|
raise ConfigError(message)
|
|
|
|
monkeypatch.setattr(_sync_client, "mirror_client_for", _boom)
|
|
github = object()
|
|
|
|
assert _workout_sync.remote_client(github) is github
|