mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-19 23:54:24 +01:00
Dependencies (exact pins): claude-agent-sdk 0.2.183, rtdb-relay 0.1.1, httpx 0.28.1, hypothesis 6.170.15 (dev). The pylint hook env gets the same pins. Entry points, each reachable only through one module attribute: _claude_connect.connect_sealed (RTDB + e2e unlock), _claude_sdk.run_model (the model call), _claude_sync.pull_peers / publish (narrow pull, full tick). SDK and rtdb_relay are imported only by these modules, never by the gate or CLI at load time. Test isolation, all fail closed: connect_sealed and run_model are replaced by a function that raises; pull/publish return None; the sandbox dir and kuhy's real Claude login path point into tmp_path; _test_guard also protects ~/.config/diet_guard_claude and ~/.cache/diet_guard. Each of the six redirects was removed once and its canary went red (fail closed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWZHWP4KZ6x5TcXDBFC
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
"""The relay worker's two sync touch points, behind one module seam.
|
|
|
|
* :func:`pull_peers` runs before a request is served, so the due slot is
|
|
computed from a log that already holds what the phone logged. It is the
|
|
narrow pull (``_sync_refresh.pull_peer_logs``, ~84 ms), not a full tick.
|
|
* :func:`publish` runs after the answer is written: a full tick (15 to 27 s)
|
|
that must never sit in front of the answer (``docs/DOCS-claude-relay.md``
|
|
section 5).
|
|
|
|
Both return ``None`` on success or a short reason, never raise on an outage
|
|
(fail closed: the worker leaves the request pending on a failed pull).
|
|
``conftest`` patches both names here, so a test that logs through the worker
|
|
cannot reach the real remote.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from diet_guard import _sync_events, _sync_refresh
|
|
|
|
|
|
def pull_peers() -> str | None:
|
|
"""Pull every peer's log; None on success, else why not."""
|
|
return _sync_refresh.pull_peer_logs()
|
|
|
|
|
|
def publish() -> str | None:
|
|
"""Run a full sync tick after a write; None on success, else why not."""
|
|
return _sync_events.publish_after_log()
|