Skip to content

Commit d1f89b8

Browse files
feat: add NodeRole enum (VOTER, STANDBY, SPARE)
Adds NodeRole(IntEnum) to constants.py matching Go's protocol.Voter/ StandBy/Spare and C's DQLITE_VOTER/DQLITE_STANDBY/DQLITE_SPARE. Exported from the top-level package. Users no longer need to hardcode magic numbers for cluster role values. Closes #127 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b8161ce commit d1f89b8

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/dqlitewire/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
ROW_DONE_MARKER,
5050
ROW_PART_BYTE,
5151
ROW_PART_MARKER,
52+
NodeRole,
5253
RequestType,
5354
ResponseType,
5455
ValueType,
@@ -60,6 +61,7 @@
6061
"EncodeError",
6162
"MessageDecoder",
6263
"MessageEncoder",
64+
"NodeRole",
6365
"PROTOCOL_VERSION",
6466
"PROTOCOL_VERSION_LEGACY",
6567
"ProtocolError",

src/dqlitewire/constants.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,15 @@ class ValueType(IntEnum):
7474
UNIXTIME = 9 # Unix time (deprecated, maps to INTEGER)
7575
ISO8601 = 10 # ISO8601 string (maps to TEXT)
7676
BOOLEAN = 11 # Boolean (maps to INTEGER)
77+
78+
79+
class NodeRole(IntEnum):
80+
"""Node roles in a dqlite cluster.
81+
82+
Matches Go's protocol.Voter/StandBy/Spare and C's
83+
DQLITE_VOTER/DQLITE_STANDBY/DQLITE_SPARE.
84+
"""
85+
86+
VOTER = 0
87+
STANDBY = 1
88+
SPARE = 2

tests/test_constants.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,30 @@ def test_nodeinfo_importable_from_messages(self) -> None:
133133
assert NodeInfo is DirectNodeInfo
134134

135135

136+
class TestNodeRoleValues:
137+
"""Verify NodeRole enum matches Go's protocol constants."""
138+
139+
def test_voter_is_0(self) -> None:
140+
from dqlitewire.constants import NodeRole
141+
142+
assert NodeRole.VOTER == 0
143+
144+
def test_standby_is_1(self) -> None:
145+
from dqlitewire.constants import NodeRole
146+
147+
assert NodeRole.STANDBY == 1
148+
149+
def test_spare_is_2(self) -> None:
150+
from dqlitewire.constants import NodeRole
151+
152+
assert NodeRole.SPARE == 2
153+
154+
def test_importable_from_top_level(self) -> None:
155+
from dqlitewire import NodeRole
156+
157+
assert NodeRole.VOTER == 0
158+
159+
136160
class TestTypeDictCompleteness:
137161
"""Verify REQUEST_TYPES and RESPONSE_TYPES cover all enum members."""
138162

0 commit comments

Comments
 (0)