fix(wireless,topology): CAPsMAN write guards, MAC neighbour resolution, unified panel (v0.23.0-beta)

Closes #95. Addresses the second round of #94 feedback. Includes a regression
introduced in v0.22.0.

Wireless write paths were not CAPsMAN-aware (regression)
  v0.22.0 widened getAP() and the bulk-SSID selector to include cap/controller
  roles so a controller — normally tagged a router — would stop being invisible to
  the wireless section. Those same helpers gate the write endpoints, so the change
  also allowed writes to devices whose radios a controller owns. Reads needed
  widening; writes needed a guard, and did not get one.

  Five paths now refuse or skip provisioned radios: bulk SSID deployment, single
  interface create, interface edit, interface delete, and guest network setup.
  Delete was the worst of them — RouterOS will not remove a provisioned interface,
  but the cached row was deleted anyway, so it vanished from the UI until the next
  poll brought it back.

  The check is shared: partitionRadios() splits physical radios into locally
  controllable and controller-owned, assertNotCapsmanManaged() refuses an edit to a
  provisioned interface and names the controller.

Neighbours identified only by MAC (#95)
  Topology resolved a neighbour to a managed device by IP address. A trunk port has
  no IP, so LLDP across one reports a MAC and an identity but no address — and
  those links stayed unresolved, drawing an external node beside the very device it
  already had on the map. Two directly connected devices appeared four times.

  Resolution by MAC now runs first, before address matching, because a MAC is
  hardware identity and unique fleet-wide where an address is not. This is the same
  join the CAPsMAN radio matching uses.

CAPsMAN panel, from the reporter's testing
  - Radios and provisioned interfaces were two tables describing the same things
    from different angles; they are now one, per interface, with the access point,
    SSID, band, frequency, channel, clients and status.
  - Provisioning rules sit inside the configuration they apply. Rules referencing a
    configuration we did not collect are listed separately rather than dropped,
    since that usually means a stale reference.
  - The Wireless header reported zero clients while the Clients page reported 32:
    it summed the CAP-local count, which is empty under central forwarding. It now
    takes the greater of that and the controller's per-radio counts, so a controller
    that is also a CAP is not double-counted.
  - A remote radio could be attributed to the controller by the five-octet prefix
    fallback when the two shared a MAC block. Prefix matches now refuse the
    controller for a non-local radio; exact matches are still honoured.

Radios tab followed device_type
  device_type is user-supplied tagging, and a router with radios had no way to
  display them. The tab now follows the detected wifi_role, which is a fact about
  the hardware.

48 tests on the CAPsMAN module, 22 on topology, including a fixture built from the
device output in #95. Verified against the fleet: topology output unchanged, so MAC
resolution merged nothing it should not have; guards correctly permissive on a
standalone AP.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2GT-Rich
2026-08-20 16:48:29 -07:00
co-authored by Claude Opus 5
parent e15556b601
commit 82efcaa371
16 changed files with 415 additions and 132 deletions
@@ -209,3 +209,71 @@ describe('buildTopology — behaviour preserved for unambiguous fleets', () => {
expect(graph.links[0].to_device_id).toBeNull();
});
});
/**
* Issue #95. Two managed devices connected by a trunk port. LLDP across a trunk
* carries no IP, so address matching has nothing to work with — but it does carry
* the peer's port MAC. Without MAC resolution both devices were drawn twice: once
* as themselves and once as an external node.
*/
describe('buildTopology — neighbours identified only by MAC (#95)', () => {
const devices = [
dev(12, 'legacy-core-rt-001', '10.99.0.1'),
dev(13, 'legacy-core-sw-001', '10.99.0.2'),
];
// Trunk-port MACs, which differ from the management-VLAN MACs the devices answer on.
const macs = [
{ device_id: 12, mac_address: '04:F4:1C:9F:3D:A9' },
{ device_id: 13, mac_address: '04:F4:1C:36:B5:E9' },
];
const trunkLinks = () => [
link({
from_device_id: 12, from_interface: 'trunk1', link_type: 'lldp',
neighbor_mac: '04:F4:1C:36:B5:E9', neighbor_identity: 'legacy-core-sw-001',
neighbor_address: null, from_device_name: 'legacy-core-rt-001',
}),
link({
from_device_id: 13, from_interface: 'sfp-sfpplus2', link_type: 'lldp',
neighbor_mac: '04:F4:1C:9F:3D:A9', neighbor_identity: 'legacy-core-rt-001',
neighbor_address: null, from_device_name: 'legacy-core-sw-001',
}),
];
it('resolves both directions to the managed devices', () => {
const graph = buildTopology(devices, trunkLinks(), [], macs);
for (const l of graph.links) expect(l.to_device_id).not.toBeNull();
});
it('draws no external node duplicating a managed device', () => {
const graph = buildTopology(devices, trunkLinks(), [], macs);
expect(graph.externalNodes.filter((n) => n.caps !== 'segment')).toHaveLength(0);
});
it('collapses the bidirectional pair into one link', () => {
const graph = buildTopology(devices, trunkLinks(), [], macs);
expect(graph.links).toHaveLength(1);
expect(graph.links[0].from_device_id).toBe(12);
expect(graph.links[0].to_device_id).toBe(13);
});
it('still produces external nodes for genuinely unmanaged neighbours', () => {
const graph = buildTopology(devices, [
link({ from_device_id: 12, from_interface: 'ether5', link_type: 'lldp',
neighbor_mac: 'FF:FF:FF:00:00:01', neighbor_identity: 'some-switch' }),
], [], macs);
expect(graph.externalNodes.filter((n) => n.caps !== 'segment')).toHaveLength(1);
});
it('never resolves a device to itself through its own MAC', () => {
const graph = buildTopology(devices, [
link({ from_device_id: 12, from_interface: 'ether1', link_type: 'lldp',
neighbor_mac: '04:F4:1C:9F:3D:A9' }),
], [], macs);
expect(graph.links[0].to_device_id).toBeNull();
});
it('works without a MAC index, as before', () => {
const graph = buildTopology(devices, trunkLinks(), []);
expect(graph.links.every((l) => l.to_device_id === null)).toBe(true);
});
});