modify: MQTT Bridge 兼容非信封原始报文(盒子心跳)——不再丢弃,整包视为 data 路由,与 worker 运行时容错语义一致;每主题仅告警一次

This commit is contained in:
2026-08-18 12:31:20 +08:00
parent 39bf39bd86
commit 983afa6957
2 changed files with 38 additions and 18 deletions
+16 -7
View File
@@ -139,16 +139,18 @@ async def test_envelope_meta_fields():
print("✅ 信封 meta 字段 (method/timeout/cacheable) 透传通过")
async def test_flat_payload_dropped():
"""严格信封协议:扁平载荷(无 meta/data)应被丢弃且不调用 worker"""
async def test_flat_payload_routed():
"""非信封(扁平)载荷兼容:整包视为 data、meta 置空照常路由(与 worker 运行时容错一致)"""
wm = FakeWM()
bridge, published = make_bridge(
wm, [{"topic": "devices/+/telemetry", "worker": "device"}]
)
await bridge._handle(make_msg("devices/d1/telemetry", {"_method": "POST", "v": 1}))
assert wm.calls == []
assert published == []
print("✅ 非信封(扁平)载荷被丢弃通过")
assert wm.calls, "扁平载荷不应被丢弃,应照常路由到 worker"
assert wm.calls[-1]["worker_type"] == "device"
assert wm.calls[-1]["payload"] == {"meta": {}, "data": {"_method": "POST", "v": 1}}
assert published[-1][0] == "devices/d1/telemetry/response"
print("✅ 非信封(扁平)载荷按原始报文路由通过")
async def test_non_json_dropped():
@@ -182,7 +184,14 @@ async def test_board_ping_topic():
assert wm.calls[-1]["worker_type"] == "aibox_sophon_adapter"
assert wm.calls[-1]["subject"] == "aibox_sophon_adapter.board_ping"
assert published[-1][0] == "/board_ping/response"
print("✅ /board_ping 自定义主题路由通过")
# 回归:盒子心跳为原始报文(无信封),不得被丢弃,应整包作为 data 路由
wm.calls.clear(); published.clear()
await bridge._handle(make_msg("/board_ping", {"BoardId": "B001", "Status": 1}))
assert wm.calls and wm.calls[-1]["payload"] == {
"meta": {}, "data": {"BoardId": "B001", "Status": 1}
}, wm.calls
assert published[-1][0] == "/board_ping/response"
print("✅ /board_ping 自定义主题路由通过(含原始报文兼容)")
def test_plugin_config_driven_collection():
@@ -209,7 +218,7 @@ async def main():
test_compile_topic()
await test_custom_routing()
await test_envelope_meta_fields()
await test_flat_payload_dropped()
await test_flat_payload_routed()
await test_non_json_dropped()
await test_board_ping_topic()
test_plugin_config_driven_collection()