mirror of
https://github.com/pyMC-dev/pyMC_Repeater.git
synced 2026-10-31 04:01:59 +01:00
fix(companion): skip the scope guard when Core predates the feature
Follow-up to review. The dependency pin is `openhop_core@dev`, so CI installs a Core without the per-message flood scope override until that change lands there. The guard imported symbols from it directly, which meant the module could not import at all and this branch could not be green on its own before Core merged. The constants are now reached through the module and a `skipif` covers the whole file, so the branch stands alone and the guard resumes the moment Core lands. The skip reason names the cause, so a permanent silent skip would be visible in the report rather than reading as a pass. Also corrects the `_flood_scope_applied` comment. It claimed losing the mark would let the dispatcher re-scope the packet to the repeater's own region. It would not: `scope_packet` has already set TRANSPORT_FLOOD and the dispatcher re-scopes only ROUTE_TYPE_FLOOD. The assertion stays, as the contract Core states, but it is no longer described as load-bearing. Still outstanding, deliberately: this stops at the bridge's injector and does not drive PacketRouter.inject_packet, the engine, and the final dispatcher with a conflicting repeater region configured. That is the test worth adding next if this guard is ever to carry real weight.
This commit is contained in:
1 parent
2f560e4723
commit
58f7293b33
1 file changed
+25
-17
@@ -23,21 +23,23 @@ from unittest.mock import AsyncMock, Mock
|
||||
import pytest
|
||||
|
||||
from openhop_core import LocalIdentity
|
||||
from openhop_core.companion.constants import (
|
||||
CMD_SEND_CHANNEL_TXT_MSG,
|
||||
OPENHOP_CHANNEL_SCOPE_PROBE,
|
||||
OPENHOP_CHANNEL_TXT_SCOPED,
|
||||
OPENHOP_EXTENSION_MARKER,
|
||||
OPENHOP_SCOPE_PROBE_RESERVED_LEN,
|
||||
RESP_CODE_OK,
|
||||
RESP_CODE_OPENHOP_EXTENSION,
|
||||
)
|
||||
from openhop_core.companion import constants as core_constants
|
||||
from openhop_core.companion.models import Channel
|
||||
from openhop_core.protocol.constants import ROUTE_TYPE_TRANSPORT_FLOOD
|
||||
from openhop_core.protocol.transport_keys import calc_transport_code, get_auto_key_for
|
||||
from repeater.companion.bridge import RepeaterCompanionBridge
|
||||
from repeater.companion.frame_server import CompanionFrameServer
|
||||
|
||||
# The dependency pin is `openhop_core@dev`, so until the Core change is on that
|
||||
# branch CI installs a Core without these symbols and this module cannot even
|
||||
# import. Skip rather than fail: the branch is then independently green, and
|
||||
# the moment Core lands the guard starts running again. The skip reason names
|
||||
# the cause so a silent permanent skip is visible in the report.
|
||||
pytestmark = pytest.mark.skipif(
|
||||
not hasattr(core_constants, "OPENHOP_CHANNEL_TXT_SCOPED"),
|
||||
reason="installed openhop_core predates the per-message flood scope override",
|
||||
)
|
||||
|
||||
SCOPE_KEY = get_auto_key_for("#USA")
|
||||
|
||||
|
||||
@@ -58,17 +60,21 @@ async def test_frame_server_subclass_inherits_core_extension_handlers():
|
||||
bridge.send_channel_message = AsyncMock(return_value=True)
|
||||
server, frames = _frame_server(bridge)
|
||||
|
||||
probe = bytes([CMD_SEND_CHANNEL_TXT_MSG, OPENHOP_CHANNEL_SCOPE_PROBE])
|
||||
probe += bytes(OPENHOP_SCOPE_PROBE_RESERVED_LEN)
|
||||
probe = bytes(
|
||||
[core_constants.CMD_SEND_CHANNEL_TXT_MSG, core_constants.OPENHOP_CHANNEL_SCOPE_PROBE]
|
||||
)
|
||||
probe += bytes(core_constants.OPENHOP_SCOPE_PROBE_RESERVED_LEN)
|
||||
await server._handle_cmd(probe)
|
||||
|
||||
send = bytes([CMD_SEND_CHANNEL_TXT_MSG, OPENHOP_CHANNEL_TXT_SCOPED, 1])
|
||||
send = bytes(
|
||||
[core_constants.CMD_SEND_CHANNEL_TXT_MSG, core_constants.OPENHOP_CHANNEL_TXT_SCOPED, 1]
|
||||
)
|
||||
send += struct.pack("<I", 1234) + SCOPE_KEY + b"hello"
|
||||
await server._handle_cmd(send)
|
||||
|
||||
assert frames[0][0] == RESP_CODE_OPENHOP_EXTENSION
|
||||
assert frames[0][1:7] == OPENHOP_EXTENSION_MARKER
|
||||
assert frames[1] == bytes([RESP_CODE_OK])
|
||||
assert frames[0][0] == core_constants.RESP_CODE_OPENHOP_EXTENSION
|
||||
assert frames[0][1:7] == core_constants.OPENHOP_EXTENSION_MARKER
|
||||
assert frames[1] == bytes([core_constants.RESP_CODE_OK])
|
||||
bridge.send_channel_message.assert_awaited_once_with(
|
||||
1, "hello", timestamp=1234, flood_scope_key=SCOPE_KEY
|
||||
)
|
||||
@@ -93,6 +99,8 @@ async def test_scoped_send_through_repeater_bridge_reaches_injector_scoped():
|
||||
assert pkt.get_route_type() == ROUTE_TYPE_TRANSPORT_FLOOD
|
||||
assert pkt.transport_codes[0] == calc_transport_code(SCOPE_KEY, pkt)
|
||||
assert pkt.transport_codes[1] == 0
|
||||
# Without this the shared dispatcher would re-scope the packet to the
|
||||
# repeater's own region on its way out.
|
||||
# Ownership metadata. The transport code is in fact protected by the route
|
||||
# change alone -- the dispatcher re-scopes only ROUTE_TYPE_FLOOD -- so this
|
||||
# is asserted as the contract Core states, not as the thing standing
|
||||
# between the message and the repeater's own region.
|
||||
assert pkt._flood_scope_applied is True
|
||||
Reference in new issue
Block a user