feat: add safe BLE discovery and network baseline tools
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from k1link.artifacts import write_json_atomic
|
||||
|
||||
|
||||
def test_write_json_atomic(tmp_path: Path) -> None:
|
||||
output = tmp_path / "nested" / "artifact.json"
|
||||
write_json_atomic(output, {"value": "тест"})
|
||||
assert json.loads(output.read_text(encoding="utf-8")) == {"value": "тест"}
|
||||
assert not list(output.parent.glob("*.tmp"))
|
||||
@@ -0,0 +1,23 @@
|
||||
from bleak.backends.device import BLEDevice
|
||||
from bleak.backends.scanner import AdvertisementData
|
||||
|
||||
from k1link.ble.scanner import advertisement_record
|
||||
|
||||
|
||||
def test_advertisement_record_marks_k1_candidate() -> None:
|
||||
device = BLEDevice("TEST-UUID", "Unknown", details=None)
|
||||
advertisement = AdvertisementData(
|
||||
local_name="Lixel-K1-1234",
|
||||
manufacturer_data={123: b"\x01\x02"},
|
||||
service_data={"service": b"\xaa"},
|
||||
service_uuids=["B", "a"],
|
||||
tx_power=-4,
|
||||
rssi=-52,
|
||||
platform_data=(),
|
||||
)
|
||||
record = advertisement_record(device, advertisement)
|
||||
assert record["k1_name_candidate"] is True
|
||||
assert record["id_kind"] == "corebluetooth_uuid"
|
||||
assert record["manufacturer_data_hex"] == {"123": "0102"}
|
||||
assert record["service_data_hex"] == {"service": "aa"}
|
||||
assert record["service_uuids"] == ["B", "a"]
|
||||
@@ -0,0 +1,14 @@
|
||||
from k1link.net.snapshot import command_record, snapshot
|
||||
|
||||
|
||||
def test_command_record_captures_success() -> None:
|
||||
result = command_record(["/usr/bin/true"])
|
||||
assert result["returncode"] == 0
|
||||
assert result["error"] is None
|
||||
|
||||
|
||||
def test_snapshot_is_explicitly_sensitive() -> None:
|
||||
result = snapshot()
|
||||
assert result["schema_version"] == 1
|
||||
assert "do not commit" in result["sensitivity"]
|
||||
assert [record["argv"] for record in result["commands"]][-1] == ["arp", "-an"]
|
||||
Reference in New Issue
Block a user