Push Tracker
ria-toolkit-oss/tests/agent/test_cli_install_udev.py
J jrhughes003 bf64604bcf feat(agent): agent-owned device discovery, identifiers, and udev install
Make `ria-agent stream` work with any SDR the agent has drivers for, with
no per-device config in the hub:

- heartbeat advertises rich `hardware` entries {device, identifier, label,
  connected} via hardware.detect_devices(); USRP is enumerated into concrete
  instances (uhd_find_devices), others advertise driver-only entries. The
  identifier is chosen to round-trip through parse_ident (None=auto-select or
  name=...), so a device address is never a bare value.
- ship udev rules (Pluto/RTL-SDR/HackRF/USRP B2x0/bladeRF) + `ria-agent
  install-udev` so USB radios open without sudo — one privileged step, all
  inside the toolkit.
- streamer surfaces a "run: sudo ria-agent install-udev" hint on USB
  permission errors instead of the cryptic UHD message.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 10:03:14 -04:00

37 lines
1.4 KiB
Python

"""Tests for `ria-agent install-udev` and the bundled udev rules."""
from __future__ import annotations
from importlib.resources import files
from unittest.mock import patch
from ria_toolkit_oss.agent import cli as agent_cli
def test_bundled_udev_rules_present_and_cover_usb_sdrs():
text = files("ria_toolkit_oss.agent").joinpath("udev", "90-ria-sdr.rules").read_text()
# ADALM-Pluto, RTL-SDR, HackRF, and USRP B2x0 VIDs must be covered.
for vid in ("0456", "0bda", "1d50", "2500"):
assert vid in text
def test_install_udev_requires_root(capsys):
args = agent_cli.argparse.Namespace(dest="/etc/udev/rules.d", group="plugdev", no_reload=True)
with patch("os.geteuid", return_value=1000):
rc = agent_cli._cmd_install_udev(args)
assert rc == 1
err = capsys.readouterr().err
assert "requires root" in err
assert "install-udev" in err
def test_install_udev_writes_rules_when_root(tmp_path, monkeypatch, capsys):
args = agent_cli.argparse.Namespace(dest=str(tmp_path), group="plugdev", no_reload=True)
# No SUDO_USER and --no-reload → no subprocess calls; just the file write.
monkeypatch.delenv("SUDO_USER", raising=False)
with patch("os.geteuid", return_value=0):
rc = agent_cli._cmd_install_udev(args)
assert rc == 0
written = (tmp_path / "90-ria-sdr.rules").read_text()
assert "SUBSYSTEM" in written