CI / test (push) Failing after 18s
- New `network` panel module (in the default panel, before the battery and the clock): signal bars and the
Wi-Fi network's name, a plug when wired, crossed-out bars offline or in airplane mode. Its
popup shows the status and the last action's outcome ("Couldn't connect to X: wrong
password?"), switches for Wi-Fi and airplane mode, and the networks in range (strongest
access point per name, the one in use first). Click a saved or open network to connect, a new
secured one to type its password in a field under it (Enter or Connect), the one in use to
disconnect, or "Forget" on a saved one. Opening the popup asks for a scan.
- compositor/network: NetworkManager over D-Bus through a small D-Bus client of our own
(wire format, EXTERNAL auth, async calls) on the existing @sys socket calls, so neither host
needed new imports. One ObjectManager.GetManagedObjects + GetAll every 2 s; GetSettings once
per saved connection; RequestScan, Device.Disconnect, WirelessEnabled / WwanEnabled,
ActivateConnection (saved), AddAndActivateConnection (new: open, WPA/WPA2 PSK, WPA3 SAE) and
Settings.Connection.Delete. Without NetworkManager it falls back to read-only status from
/proc/net/dev, /proc/net/wireless and /sys/class/net (no network names there), and looks for
NetworkManager again every 30 s.
- New `network` capability (wit/capabilities.wit): status, wifi-networks, scan, connect,
disconnect, forget, set-wifi-enabled, set-airplane-mode. Served from host tables 8/9 and a
`network(network-request)` request by the wasmer/wasmtime stub (compositor/wasm), host-wasm
and the MoonBit wasmhost. The stub's build_list learned bool fields; request strings are
wiped after use (Wi-Fi passwords).
- Running out of module instances now says "too many modules loaded".
- Deferred: VPN, hotspot, hidden networks, WEP and 802.1X (enterprise) networks, IP settings,
mobile broadband beyond the airplane switch, D-Bus signals (state is polled).
- Tests: D-Bus wire format (incl. the well-known Hello bytes), NetworkManager objects -> status
and list, security settings, /proc parsing; the module through the shell against a fake
backend (list, connect/forget/disconnect, password entry, switches, read-only); a host-wasm
test; and scripts/test-network-dbus.sh, which runs the backend against python-dbusmock's
NetworkManager on a private bus.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hizqNXcNDuef3gxa7D
132 lines
4.8 KiB
MoonBit
132 lines
4.8 KiB
MoonBit
///| The network panel module (components/network) driven through the shell, against a fake
|
|
/// network backend: the status it shows, its Wi-Fi list, and the actions its clicks and keys ask
|
|
/// for. Needs the modules: run scripts/build-modules.sh.
|
|
|
|
///|
|
|
fn net_status() -> @network.NetStatus {
|
|
{
|
|
state: Wifi,
|
|
name: "Home",
|
|
signal: 72,
|
|
message: "",
|
|
wifi_enabled: true,
|
|
airplane: false,
|
|
managed: true,
|
|
has_wifi: true,
|
|
}
|
|
}
|
|
|
|
///|
|
|
fn net_comp(tag : String) -> (@host.ChandraCompositor, @network.FakeNet) {
|
|
let comp = new_comp(tag)
|
|
let fake = @network.FakeNet::new(net_status(), [
|
|
{ ssid: "Home", signal: 72, secured: true, active: true, saved: true },
|
|
{ ssid: "Office", signal: 55, secured: true, active: false, saved: false },
|
|
{ ssid: "Cafe", signal: 30, secured: false, active: false, saved: false },
|
|
{ ssid: "Lab", signal: 20, secured: true, active: false, saved: true },
|
|
])
|
|
comp.shell.set_network_backend(fake as &@network.NetBackend)
|
|
ignore(comp.compose_frame())
|
|
(comp, fake)
|
|
}
|
|
|
|
///| The middle of popup row `i` (6 px margin, 30 px rows), `dx` from its left edge.
|
|
fn net_row(comp : @host.ChandraCompositor, i : Int, dx? : Int = 60) -> (Int, Int) {
|
|
let pr = comp.shell.slot_popup_rect(comp.shell.slot_of("network"))
|
|
(pr.x + dx, pr.y + 6 + i * 30 + 14)
|
|
}
|
|
|
|
///|
|
|
fn click_row(comp : @host.ChandraCompositor, i : Int, t : UInt, dx? : Int = 60) -> Unit {
|
|
let (x, y) = net_row(comp, i, dx~)
|
|
click_at(comp, x, y, t)
|
|
}
|
|
|
|
///|
|
|
fn last_action(fake : @network.FakeNet) -> @network.NetAction? {
|
|
fake.actions.last()
|
|
}
|
|
|
|
///|
|
|
test "the network module lists Wi-Fi networks and asks to connect, disconnect and forget" {
|
|
let (comp, fake) = net_comp("net-list")
|
|
let slot = comp.shell.slot_of("network")
|
|
assert_true(comp.shell.slot_rect(slot).w > 0) // it is in the default panel
|
|
assert_true(fake.ticks > 0)
|
|
click_module(comp, "network", 1U)
|
|
assert_eq(last_action(fake), Some(Scan)) // opening the popup scans
|
|
// Status, Wi-Fi, Airplane mode, the heading, four networks.
|
|
let pr = comp.shell.slot_popup_rect(slot)
|
|
assert_eq(pr.h, 12 + 8 * 30)
|
|
// An open network connects at once; so does a saved one.
|
|
click_row(comp, 6, 10U)
|
|
assert_eq(last_action(fake), Some(Connect("Cafe", "")))
|
|
click_row(comp, 7, 15U)
|
|
assert_eq(last_action(fake), Some(Connect("Lab", "")))
|
|
// "Forget" at the right of a saved network.
|
|
click_row(comp, 7, 20U, dx=pr.w - 30)
|
|
assert_eq(last_action(fake), Some(Forget("Lab")))
|
|
// The one in use disconnects.
|
|
click_row(comp, 4, 25U)
|
|
assert_eq(last_action(fake), Some(Disconnect))
|
|
assert_eq(fake.actions.length(), 5)
|
|
}
|
|
|
|
///|
|
|
test "a new secured network asks for its password in the popup" {
|
|
let (comp, fake) = net_comp("net-password")
|
|
let slot = comp.shell.slot_of("network")
|
|
click_module(comp, "network", 1U)
|
|
click_row(comp, 5, 5U) // Office: a password field opens under it
|
|
assert_eq(comp.shell.slot_popup_rect(slot).h, 12 + 9 * 30)
|
|
assert_eq(last_action(fake), Some(Scan))
|
|
for k in ["s", "3", "c", "r", "e", "t", "x", "Backspace", "Space", "1"] {
|
|
comp.shell.key_down(k)
|
|
}
|
|
comp.shell.key_down("Enter")
|
|
ignore(comp.compose_frame())
|
|
assert_eq(last_action(fake), Some(Connect("Office", "s3cret 1")))
|
|
assert_eq(comp.shell.slot_popup_rect(slot).h, 12 + 8 * 30) // the field is gone
|
|
// Escape leaves the field first, then the popup.
|
|
click_row(comp, 5, 10U)
|
|
comp.shell.key_down("p")
|
|
comp.shell.key_down("Escape")
|
|
ignore(comp.compose_frame())
|
|
assert_eq(comp.shell.slot_popup_rect(slot).h, 12 + 8 * 30)
|
|
comp.shell.key_down("Escape")
|
|
ignore(comp.compose_frame())
|
|
assert_eq(comp.shell.slot_popup_rect(slot).w, 0)
|
|
assert_eq(last_action(fake), Some(Connect("Office", "s3cret 1"))) // nothing sent for "p"
|
|
}
|
|
|
|
///|
|
|
test "the Wi-Fi and airplane switches, and status only without NetworkManager" {
|
|
let (comp, fake) = net_comp("net-switch")
|
|
let slot = comp.shell.slot_of("network")
|
|
click_module(comp, "network", 1U)
|
|
click_row(comp, 1, 5U) // Wi-Fi off: the list goes
|
|
assert_eq(last_action(fake), Some(SetWifi(false)))
|
|
assert_eq(comp.shell.slot_popup_rect(slot).h, 12 + 3 * 30)
|
|
click_row(comp, 1, 10U)
|
|
assert_eq(last_action(fake), Some(SetWifi(true)))
|
|
click_row(comp, 2, 15U)
|
|
assert_eq(last_action(fake), Some(SetAirplane(true)))
|
|
// A message shows under the status.
|
|
fake.status = { ..fake.status, message: "Couldn't connect to Office: wrong password?" }
|
|
ignore(comp.compose_frame())
|
|
assert_eq(comp.shell.slot_popup_rect(slot).h, 12 + 4 * 30)
|
|
// Read-only (no NetworkManager): the status and why, nothing to switch.
|
|
fake.status = {
|
|
..net_status(),
|
|
state: Wired,
|
|
name: "enp3s0",
|
|
managed: false,
|
|
message: "NetworkManager isn't running: status only",
|
|
}
|
|
ignore(comp.compose_frame())
|
|
assert_eq(comp.shell.slot_popup_rect(slot).h, 12 + 2 * 30)
|
|
let n = fake.actions.length()
|
|
click_row(comp, 1, 20U)
|
|
assert_eq(fake.actions.length(), n)
|
|
}
|