feat(bridge): BLE 桥接能力——bridge_server.py(Windows原生) + BridgeTransport + --via/PPCLOCK_VIA,149 测试全绿
This commit is contained in:
1 parent
17e2512f6a
commit
49b2010088
7 files changed
+658
-2
No files matched your search
@@ -231,3 +231,55 @@ class TestActivateAuto:
|
||||
expected = keygen_code(bytes([0x9A, 0x01, 0x99, 0x50, 0x10, 0x20]))
|
||||
assert t.rxtx_writes[1] == bytes([0xEF]) + expected
|
||||
assert out["data"]["code"] == expected.hex()
|
||||
|
||||
|
||||
_ORIG_MAKE = cli._make_transport
|
||||
|
||||
|
||||
class TestViaBridge:
|
||||
def test_via_bridge_creates_bridge_transport(self):
|
||||
import argparse
|
||||
from ppclock.bridge import BridgeTransport
|
||||
args = argparse.Namespace(mac="AA:BB", timeout=5.0, via="bridge://192.168.61.35:8971")
|
||||
t = _ORIG_MAKE(args)
|
||||
assert isinstance(t, BridgeTransport)
|
||||
assert (t.host, t.port) == ("192.168.61.35", 8971)
|
||||
assert t.address == "AA:BB"
|
||||
|
||||
def test_via_default_port(self):
|
||||
import argparse
|
||||
args = argparse.Namespace(mac=None, timeout=5.0, via="bridge://10.0.0.2")
|
||||
t = _ORIG_MAKE(args)
|
||||
assert t.port == 8971
|
||||
|
||||
def test_via_local_creates_ble(self):
|
||||
import argparse
|
||||
from ppclock.transport import BLETransport
|
||||
args = argparse.Namespace(mac=None, timeout=5.0, via=None)
|
||||
assert isinstance(_ORIG_MAKE(args), BLETransport)
|
||||
|
||||
def test_scan_uses_bridge(self, capsys, monkeypatch):
|
||||
import ppclock.bridge as br
|
||||
called = {}
|
||||
|
||||
async def fake_scan(host, port, timeout=5.0):
|
||||
called["args"] = (host, port)
|
||||
return [{"name": "NRF-BR", "address": "CC:DD", "rssi": -60}]
|
||||
monkeypatch.setattr(br, "scan", fake_scan)
|
||||
code, out = run_cli(capsys, ["--json", "--via", "bridge://10.0.0.9:9999", "scan"])
|
||||
assert code == 0
|
||||
assert called["args"] == ("10.0.0.9", 9999)
|
||||
assert out["data"]["devices"][0]["name"] == "NRF-BR"
|
||||
|
||||
def test_env_var_fallback(self, capsys, monkeypatch):
|
||||
import ppclock.bridge as br
|
||||
called = {}
|
||||
|
||||
async def fake_scan(host, port, timeout=5.0):
|
||||
called["args"] = (host, port)
|
||||
return []
|
||||
monkeypatch.setattr(br, "scan", fake_scan)
|
||||
monkeypatch.setenv("PPCLOCK_VIA", "bridge://10.0.0.7")
|
||||
code, _ = run_cli(capsys, ["--json", "scan"])
|
||||
assert code == 0
|
||||
assert called["args"] == ("10.0.0.7", 8971)
|
||||
Reference in new issue
Block a user