test(power): VM check for battery charge-limit udev re-apply
Add checks.battery-charge-limit (runNixOSTest): the test_power module fakes a Mains adapter, toggling ac_online emits a real power_supply uevent, and the test asserts the udev rule restarts the oneshot (changed InvocationID). Verifies the re-apply *trigger* at runtime, beyond the earlier eval check; the sysfs write still needs real hardware. Also records the SSH_AUTH_SOCK rendered-artifact verification in the roadmap. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
47
flake.nix
47
flake.nix
@@ -159,6 +159,53 @@
|
||||
machine.succeed("grep -q pam_fprintd /etc/pam.d/sudo")
|
||||
'';
|
||||
};
|
||||
|
||||
# Runtime VM check for the battery-charge-limit re-apply: the udev
|
||||
# rule must restart the oneshot on an AC state change (firmware can
|
||||
# clear the threshold on unplug). The `test_power` module fakes a
|
||||
# Mains adapter we can toggle to emit a real power_supply uevent —
|
||||
# so this exercises the trigger, not just the config wiring. (The
|
||||
# sysfs *write* needs a real charge_control_end_threshold and stays
|
||||
# an on-hardware check.) Imports options.nix (where the power
|
||||
# options live) + power.nix, so the VM stays minimal.
|
||||
battery-charge-limit = pkgs.testers.runNixOSTest {
|
||||
name = "nomarchy-battery-charge-limit";
|
||||
nodes.machine = { ... }: {
|
||||
imports = [ ./modules/nixos/options.nix ./modules/nixos/power.nix ];
|
||||
boot.kernelModules = [ "test_power" ]; # fake Mains + battery
|
||||
nomarchy.system.power = {
|
||||
enable = true;
|
||||
laptop = true;
|
||||
batteryChargeLimit = 80;
|
||||
};
|
||||
};
|
||||
testScript = ''
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
|
||||
# The oneshot exists and the fake Mains adapter is present.
|
||||
machine.succeed("systemctl cat nomarchy-battery-charge-limit.service")
|
||||
machine.succeed("udevadm settle")
|
||||
machine.succeed("grep -lx Mains /sys/class/power_supply/*/type")
|
||||
|
||||
# Let any add-event restart settle, then sample the invocation.
|
||||
machine.succeed("sleep 2")
|
||||
before = machine.succeed(
|
||||
"systemctl show -p InvocationID --value "
|
||||
"nomarchy-battery-charge-limit.service"
|
||||
).strip()
|
||||
|
||||
# Simulate an AC unplug → 'change' uevent on the Mains device.
|
||||
machine.succeed("echo off > /sys/module/test_power/parameters/ac_online")
|
||||
machine.succeed("udevadm settle")
|
||||
|
||||
# The udev rule must have restarted the oneshot (new InvocationID).
|
||||
machine.wait_until_succeeds(
|
||||
'test "$(systemctl show -p InvocationID --value '
|
||||
'nomarchy-battery-charge-limit.service)" != "' + before + '"',
|
||||
timeout=30,
|
||||
)
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
# ─── Reference host ────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user