mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-10 21:27:14 +01:00
Some checks are pending
crdt-sync pre-commit / pre-commit (push) Waiting to run
crdt-sync tests / test (3.10) (push) Waiting to run
crdt-sync tests / test (3.11) (push) Waiting to run
crdt-sync tests / test (3.12) (push) Waiting to run
gatelock pre-commit / pre-commit (push) Waiting to run
gatelock tests / test (3.10) (push) Waiting to run
gatelock tests / test (3.11) (push) Waiting to run
gatelock tests / test (3.12) (push) Waiting to run
palette drift / palette (push) Waiting to run
_sync.py 456 -> 245 + _syncstate 131 + _pull 106 + _revisions 34 _firebase_auth 412 -> 242 + _credentials 146 + _autherrors 69 _firebase.py 336 -> 250 + _fbkeys 100 google_id_token 316 -> 232 + tool/_oauth_callback 105 _github.py 255 -> 238 + _gherrors 30 revision_of became its own leaf module because both the push and pull halves need it; without that the two would have imported each other. _fbkeys holds the RTDB key escaping — the escape tables moved with the functions that read them, since the pair has to round-trip exactly or a device silently stops seeing its own writes. crdt-sync/tool/ is outside the coverage source, so the split there has no test net: verified by running it the documented way instead (`python3 -m tool.google_id_token --help` prints its usage, and `from tool.google_id_token import TokenError, fetch_id_token` — what seed_session.py does — still resolves). An AST pass over each pair caught what the suite would not have: _is_revoked needs the error type, so it stayed with it rather than following the credentials; _TERMINAL_AUTH_REASONS and _CONSENT_TIMEOUT_SECONDS had to be carried to their new callers. 259 passed at 100% branch coverage. crdt-sync/tool/seed_session.py and firebase-debug.log are pre-existing local changes and are deliberately not in this commit. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CFSGeWxHPY5rHUGrPqhcmG
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
"""The revision string a device publishes alongside its log.
|
|
|
|
Split from :mod:`crdt_sync._sync` so both the push and pull halves can import
|
|
it without importing each other. Pure: a revision is a function of the encoded
|
|
log and nothing else, which is what lets two devices agree on whether they are
|
|
looking at the same bytes.
|
|
|
|
Re-exported from :mod:`crdt_sync._sync`, so existing imports keep working.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
|
|
def revision_of(encoded_log: str) -> str:
|
|
"""Return the revision of a serialized log: a content hash.
|
|
|
|
A hash rather than the log's maximum HLC because merging a peer's *older*
|
|
record changes the content without raising the maximum -- with three
|
|
devices in one namespace (diet-guard has ``pc``, ``phone`` and
|
|
``desktop``) a clock-based revision can miss a peer's merged state. It is
|
|
also the same value used to suppress no-op pushes, so the two
|
|
optimisations share one mechanism.
|
|
|
|
Parameters
|
|
----------
|
|
encoded_log : str
|
|
The serialized log, exactly as it would be pushed.
|
|
|
|
Returns:
|
|
-------
|
|
str
|
|
A hex SHA-256 digest.
|
|
|
|
"""
|
|
return hashlib.sha256(encoded_log.encode("utf-8")).hexdigest()
|