Repository navigation
Description
Overview
This task (milestone M3) adds PeerTransferSession, an immutable value that describes a transfer session as the peer sees it. The Peer protocol in #370 and #371 returns this value.
Background & Motivation
Today the network operations read raw JSON dictionaries from server responses. The disk connection has no JSON, so operations need a value that does not depend on the transport. A typed value also makes invalid stage and status values fail early, at the connection boundary.
Design: spec. Plan: implementation plan, Task 8.
Description & Expected Outcomes
The value has these fields: id, filter, push, records_total, records_transferred, transfer_stage, transfer_stage_status, server_fsic, and client_fsic. Nobody can change a value after it exists. Two values with the same fields are equal.
A network connection builds the value from server JSON. A disk connection builds it from a TransferSession row. The value rejects an unknown stage or status. An empty record count becomes 0.
Deliverables & Contracts
The task delivers:
PeerTransferSessionin the new modulemorango/sync/peer.py.PeerTransferSession.from_api_json(data)andPeerTransferSession.from_model(transfer_session).
Acceptance Criteria
-
from_api_jsonandfrom_modelgive equal values for the same transfer session state. - An unknown
transfer_stageortransfer_stage_statusraisesValueError. - A
records_totalofNonebecomes 0. - An attempt to set an attribute raises
AttributeError. - The class works on Python 3.6.
Technical Pointers & Architecture
- Target Components: New module
morango/sync/peer.py. - Related Patterns:
morango/constants/transfer_stages.pyandmorango/constants/transfer_statuses.pygive the valid values. The server JSON shape comes fromTransferSessionSerializerinmorango/api/serializers.py. - Data Model & Schema Considerations: No schema change. The value is not stored.
- Resilience & Failure Modes: Invalid peer data fails at construction with
ValueError.
Notes & Tradeoffs
- Dependencies: Blocked by: Tests that pin today's legacy network sync behavior #364 (Tests that pin today's legacy network sync behavior). Blocks: Shared connection interface for network and disk syncs #370, Network connection speaks the transport-neutral Peer protocol #371.
- Testing Requirements: Unit tests only.
- Tradeoffs & Alternatives Considered: Python 3.6 has no
dataclasses, so the class uses__slots__and read-only properties.
Metadata
- Complexity: Low
- Target Branch: release-v0.9.x
AI Usage
Drafted with Claude (Claude Code) from the approved design spec and implementation plan. The author reviewed the requirements, and the code references were checked against the release-v0.9.x codebase.
Activity