added adaptive quickshell

This commit is contained in:
wt committed 2026-11-17 18:15:16 +07:00
1 parent 6eb56d2065
commit 5b33a73fd8
189 files changed
+8678 -15

No files matched your search

+103
View File
@@ -0,0 +1,103 @@
pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import "."
ShellRoot {
id: test
property var controller: null
property var discovery: null
property var adapter: null
property int scenario: -1
property int step: 0
property int successes: 0
property bool finished: false
readonly property var names: ["status and exact action", "BlueZ error", "malformed response", "watchdog", "invalid action", "close stops own search", "discovery deadline", "foreign search untouched", "disabled adapter", "discovery startup error", "adapter change stops lease", "startup timeout", "close before startup", "missing discovery executable"]
Component { id: controls; BluetoothController { backendCommand: ["python3", Quickshell.shellPath("bluetooth_fake.py"), "success"]; timeoutMs: 2000 } }
Component { id: scans; BluetoothDiscovery { backendCommand: ["python3", Quickshell.shellPath("bluetooth_fake.py"), "success"]; active: true; startTimeoutMs: 1000 } }
Component { id: adapters; QtObject { property bool enabled: true; property bool discovering: false; property string dbusPath: "/org/bluez/hci1" } }
Connections {
target: test.controller
function onSucceeded(action) { test.successes++; }
function onBusyChanged() { if (!test.controller.busy) Qt.callLater(test.advance); }
}
Connections {
target: test.discovery
function onOwnedChanged() { if (test.discovery.owned) Qt.callLater(test.advance); }
function onBusyChanged() { if (!test.discovery.busy) Qt.callLater(test.advance); }
function onStoppingChanged() { if (!test.discovery.stopping) Qt.callLater(test.advance); }
}
function check(value, message) { if (!value) { finished = true; console.error("BLUETOOTH_TEST_FAIL: " + message); Qt.exit(1); throw new Error(message); } }
function complete() { console.log("PASS Bluetooth: " + names[scenario]); Qt.callLater(next); }
function next() {
if (controller) controller.destroy();
if (discovery) discovery.destroy();
if (adapter) adapter.destroy();
controller = null; discovery = null; adapter = null;
scenario++; step = 0; successes = 0;
if (scenario === names.length) { finished = true; console.log("BLUETOOTH_TEST_PASS: 14 scenarios"); Qt.quit(); return; }
if (scenario <= 4) {
controller = controls.createObject(test);
const mode = ["success", "failure", "malformed", "stall", "success"][scenario];
controller.backendCommand = ["python3", Quickshell.shellPath("bluetooth_fake.py"), mode];
if (scenario === 3) controller.timeoutMs = 100;
if (scenario === 4) { check(!controller.start("bad command", ""), "unknown action accepted"); complete(); return; }
check(controller.refresh(), "refresh rejected");
} else {
adapter = adapters.createObject(test);
discovery = scans.createObject(test, {adapter: adapter});
if (scenario === 7) {
adapter.discovering = true;
check(!discovery.start(), "foreign search joined unexpectedly");
discovery.active = false;
check(adapter.discovering, "foreign search stopped"); complete(); return;
}
if (scenario === 8) {
adapter.enabled = false;
check(!discovery.start() && !discovery.busy, "disabled adapter searched"); complete(); return;
}
if (scenario === 9) discovery.backendCommand = ["python3", Quickshell.shellPath("bluetooth_fake.py"), "failure"];
if (scenario === 6) discovery.durationMs = 100;
if (scenario === 11 || scenario === 12) {
discovery.backendCommand = ["python3", Quickshell.shellPath("bluetooth_fake.py"), "stall"];
discovery.startTimeoutMs = 100;
}
if (scenario === 13) { discovery.backendCommand = ["adaptive-nonexistent-executable"]; discovery.startTimeoutMs = 100; }
check(discovery.start(), "discovery rejected");
check(!discovery.start(), "duplicate discovery accepted");
if (scenario === 12) discovery.active = false;
}
}
function advance() {
if (finished) return;
if (scenario <= 4) {
if (!controller || controller.busy) return;
if (scenario === 0) {
if (step === 0) {
check(controller.readiness === "ready" && controller.adapterCount === 2, "status lost");
step = 1;
check(controller.start("connect", "/org/bluez/hci1/dev_AA_BB_CC_DD_EE_FF"), "connect rejected");
check(!controller.refresh(), "duplicate command accepted"); return;
}
check(successes === 1 && controller.error === "", "action failed");
} else if (scenario === 1) check(controller.error.includes("Mock BlueZ NotReady") && controller.readiness === "unavailable", "backend failure lost");
else if (scenario === 2) check(controller.error !== "" && controller.readiness === "unavailable", "invalid response accepted");
else if (scenario === 3) check(controller.timedOut && controller.error !== "", "watchdog failed");
} else {
if (!discovery) return;
if (discovery.owned && step === 0) {
step = 1;
if (scenario === 5) discovery.active = false;
else if (scenario === 10) discovery.adapter = null;
return;
}
if (discovery.busy || discovery.stopping) return;
if (scenario === 9) check(discovery.error.includes("Mock BlueZ NotReady"), "discovery error lost");
else if (scenario === 11 || scenario === 13) check(!discovery.owned && discovery.error !== "", "startup failure not handled");
else check(!discovery.owned && discovery.error === "", "discovery cleanup failed");
}
complete();
}
Component.onCompleted: Qt.callLater(next)
Timer { interval: 18000; running: !test.finished; onTriggered: test.check(false, "harness timeout") }
}
+133
View File
@@ -0,0 +1,133 @@
pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import Quickshell.Networking
import "."
import "components"
ShellRoot {
id: test
property var device: null
property var network: null
property var controller: null
property var card: null
property int scenario: -1
property int successes: 0
property int secretRequests: 0
property bool finished: false
readonly property var names: ["connect and duplicate prevention", "failure and credentials request", "device removal", "disconnect", "timeout", "unmanaged device", "PSK forwarding", "wrong adapter", "credential field lifecycle"]
Component {
id: devices
QtObject {
property bool connected: false
property bool nmManaged: true
property int type: DeviceType.Wifi
property int state: 0
property int disconnects: 0
function disconnect() { disconnects++; connected = false; }
}
}
Component {
id: networks
QtObject {
property var device: null
property bool connected: false
property int state: 0
property int connects: 0
property string name: "Test network"
property bool known: false
property real signalStrength: 0.8
property int security: WifiSecurityType.Wpa2Psk
property int pskConnects: 0
property string captured: ""
signal connectionFailed(int reason)
function connect() { connects++; }
function connectWithPsk(value) { pskConnects++; captured = value; }
}
}
Component { id: cards; NetworkCard { width: 400; active: true; network: test.network; device: test.device; controller: test.controller } }
Component { id: controllers; NetworkController { timeoutMs: 1000 } }
Connections {
target: test.controller
function onSucceeded(action) { test.successes++; }
function onNeedsSecret(network) { test.secretRequests++; }
function onBusyChanged() { if (test.scenario === 4 && !test.controller.busy) Qt.callLater(test.finishTimeout); }
}
function check(value, message) { if (!value) { finished = true; console.error("NETWORK_TEST_FAIL: " + message); Qt.exit(1); throw new Error(message); } }
function complete() { console.log("PASS network controller: " + names[scenario]); Qt.callLater(next); }
function finishTimeout() {
check(controller.error !== "", "timeout error missing");
check(successes === 0 && device.disconnects === 0, "timeout triggered a mutation or success");
complete();
}
function next() {
if (card) { card.destroy(); card = null; }
if (controller) controller.destroy();
if (network) network.destroy();
if (device) device.destroy();
controller = null; network = null; device = null;
scenario++; successes = 0; secretRequests = 0;
if (scenario === names.length) { finished = true; console.log("NETWORK_TEST_PASS: 9 scenarios"); Qt.quit(); return; }
device = devices.createObject(test);
network = networks.createObject(test, {device: device});
controller = controllers.createObject(test, {device: device});
if (scenario === 0) {
check(controller.requestConnect(network), "connect rejected");
check(controller.busy && network.connects === 1, "connect not sent");
check(!controller.requestConnect(network), "duplicate request accepted");
network.connected = true;
check(!controller.busy && successes === 1, "connected state did not complete request");
} else if (scenario === 1) {
controller.requestConnect(network);
network.connectionFailed(ConnectionFailReason.NoSecrets);
check(!controller.busy && controller.error !== "", "failure lost");
check(secretRequests === 1 && successes === 0, "wrong failure result");
} else if (scenario === 2) {
controller.requestConnect(network);
controller.device = null;
check(!controller.busy && controller.error !== "" && successes === 0, "removed device not handled");
} else if (scenario === 3) {
device.connected = true;
check(controller.requestDisconnect(), "disconnect rejected");
check(device.disconnects === 1 && !controller.busy && successes === 1, "disconnect did not complete");
} else if (scenario === 4) {
controller.timeoutMs = 30;
controller.requestConnect(network);
return;
} else if (scenario === 5) {
device.nmManaged = false;
check(!controller.requestConnect(network) && network.connects === 0, "unmanaged device mutated");
} else if (scenario === 6) {
check(controller.requestConnect(network, "synthetic-test-key"), "PSK request rejected");
check(network.pskConnects === 1 && network.connects === 0 && network.captured === "synthetic-test-key", "PSK not forwarded correctly");
network.connectionFailed(ConnectionFailReason.NoSecrets);
check(!controller.error.includes("synthetic-test-key"), "PSK leaked into error");
} else if (scenario === 7) {
network.device = null;
check(!controller.requestConnect(network) && network.connects === 0, "wrong adapter accepted");
} else if (scenario === 8) {
card = cards.createObject(test);
const password = findItem(card, "networkPassword");
check(password !== null, "credential field not found");
card.credentials = true; password.text = "synthetic-test-key";
check(password.echoMode === TextInput.Password, "password is not masked");
card.active = false;
check(password.text === "" && !card.credentials, "password survived page close");
card.active = true;
controller.requestConnect(network);
network.connectionFailed(ConnectionFailReason.NoSecrets);
check(card.credentials, "credential prompt not opened");
password.text = "synthetic-test-key";
network.connected = true;
check(password.text === "" && !card.credentials, "password survived connection");
}
complete();
}
function findItem(parent, name) {
if (parent.objectName === name) return parent;
for (const child of parent.children || []) { const found = findItem(child, name); if (found) return found; }
return null;
}
Component.onCompleted: Qt.callLater(next)
Timer { interval: 15000; running: !test.finished; onTriggered: test.check(false, "harness timeout") }
}
+69
View File
@@ -0,0 +1,69 @@
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") }
}