pragma ComponentBehavior: Bound import QtQuick import Quickshell import "." ShellRoot { id: test property var instance: null property int scenario: -1 property int step: 0 property int successes: 0 property bool finished: false readonly property var names: ["success and duplicate prevention", "denied capability", "backend error", "malformed response", "watchdog", "invalid action", "missing helper"] Component { id: factory PowerController { backendCommand: ["python3", Quickshell.shellPath("power_fake.py"), "success"]; timeoutMs: 3000 } } Connections { target: test.instance function onBusyChanged() { if (!test.instance.busy) Qt.callLater(test.advance); } function onSucceeded(action) { test.successes++; } } function check(value, message) { if (!value) { finished = true; console.error("POWER_TEST_FAIL: " + message); Qt.exit(1); throw new Error(message); } } function next() { if (instance) instance.destroy(); instance = null; scenario++; if (scenario === names.length) { finished = true; console.log("POWER_TEST_PASS: 7 scenarios"); Qt.quit(); return; } step = 0; successes = 0; instance = factory.createObject(test); const mode = ["success", "denied", "failure", "malformed", "stall", "success", "success"][scenario]; instance.backendCommand = ["python3", Quickshell.shellPath("power_fake.py"), mode]; if (scenario === 4) instance.timeoutMs = 150; if (scenario === 5) { check(!instance.start("bad command"), "invalid action accepted"); check(instance.error !== "", "invalid action error missing"); complete(); return; } if (scenario === 6) instance.backendCommand = ["python3", "/nonexistent/adaptive-power.py"]; check(instance.refresh(), "refresh rejected"); } function complete() { console.log("PASS power controller: " + names[scenario]); Qt.callLater(next); } function advance() { if (finished || !instance || instance.busy) return; if (scenario === 0 || scenario === 2) { if (step === 0) { check(instance.available("reboot"), "capability not loaded"); step = 1; check(instance.start("reboot"), "action rejected"); check(!instance.start("poweroff"), "concurrent action accepted"); return; } if (scenario === 0) { check(successes === 1, "success not emitted"); check(instance.error === "", "unexpected error"); } else { check(successes === 0, "error reported as success"); check(instance.error.includes("Mock authorization denied"), "backend error lost"); } } else if (scenario === 1) { check(!instance.available("suspend"), "denied action available"); check(!instance.start("suspend"), "denied action started"); } else if (scenario === 3 || scenario === 6) { check(instance.capabilityError !== "", "capability error missing"); check(!instance.available("reboot"), "action available after backend failure"); } else if (scenario === 4) { check(instance.timedOut, "watchdog did not fire"); check(instance.error !== "", "watchdog error missing"); } complete(); } Component.onCompleted: Qt.callLater(next) Timer { interval: 20000; running: !test.finished; onTriggered: test.check(false, "harness timeout") } }