Preserve native K1 error causes and distinguish Wi-Fi actions
This commit is contained in:
@@ -97,6 +97,69 @@ def test_journalled_failure_logs_source_without_secret_and_does_not_repeat(caplo
|
||||
assert secret not in caplog.text
|
||||
|
||||
|
||||
def test_real_facade_preserves_native_failure_location_in_journalled_log(caplog):
|
||||
from bleak.exc import BleakError
|
||||
|
||||
secret = secrets.token_hex(20)
|
||||
calls = []
|
||||
|
||||
class Service:
|
||||
current = state()
|
||||
|
||||
def bind_runtime_event_loop(self, _loop):
|
||||
pass
|
||||
|
||||
def require_snapshot_runtime_id(self, expected):
|
||||
assert expected == self.current["snapshot_runtime_id"]
|
||||
|
||||
def state(self):
|
||||
calls.append("state")
|
||||
return copy.deepcopy(self.current)
|
||||
|
||||
async def connect(self, request):
|
||||
calls.append("connect")
|
||||
self.current["operations"] = [{
|
||||
"operation_id": request.operation_id, "status": "failed",
|
||||
"error": {"code": "BleakError"},
|
||||
}]
|
||||
raise BleakError(secret)
|
||||
|
||||
async def run():
|
||||
device = NodeBridge(Path.cwd(), service=Service())
|
||||
command = {
|
||||
"operation_id": "op_" + "c" * 32, "runtime_id": "runtime-one",
|
||||
"deadline_at": (datetime.now(UTC) + timedelta(seconds=60)).isoformat(),
|
||||
"action": "connect", "parameters": {
|
||||
"device_id": "AA:BB:CC:DD:EE:FF", "discovery_generation": 1,
|
||||
"mode_revision": 0, "ssid": "test-network", "password": secret,
|
||||
},
|
||||
}
|
||||
result = await device.deliver(command)
|
||||
assert result["command_result"]["status"] == "failed"
|
||||
assert calls == ["state", "connect", "state"]
|
||||
assert "password" not in command["parameters"]
|
||||
assert secret not in json.dumps(result)
|
||||
|
||||
asyncio.run(run())
|
||||
assert "PluginExecutionError[" in caplog.text
|
||||
assert "BleakError[" in caplog.text
|
||||
assert "test_node_k1_bridge.py:connect:" in caplog.text
|
||||
assert secret not in caplog.text
|
||||
assert "test-network" not in caplog.text
|
||||
|
||||
|
||||
def test_failure_locations_respects_suppression_and_bounds_cyclic_chains():
|
||||
from k1link.device_plugins.xgrids_k1.node_bridge import failure_locations
|
||||
|
||||
first = RuntimeError(secrets.token_hex(20))
|
||||
second = ValueError(secrets.token_hex(20))
|
||||
first.__context__ = second
|
||||
second.__cause__ = first
|
||||
assert failure_locations(first) == "RuntimeError[] <- ValueError[]"
|
||||
first.__suppress_context__ = True
|
||||
assert failure_locations(first) == "RuntimeError[]"
|
||||
|
||||
|
||||
def test_node_scan_reaches_service_through_real_facade_with_runtime_fence():
|
||||
"""Exercise the actual admission boundary, replacing only the BLE service."""
|
||||
from k1link.device_plugins.xgrids_k1.facade import SnapshotRuntimeConflict
|
||||
|
||||
Reference in New Issue
Block a user