Add shell manifest entrypoint load test
This commit is contained in:
@@ -0,0 +1,204 @@
|
|||||||
|
import QtQuick
|
||||||
|
import Quickshell
|
||||||
|
|
||||||
|
ShellRoot {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
readonly property string resultPath: Quickshell.env("OMARCHY_QML_TEST_RESULT")
|
||||||
|
readonly property string rootPath: Quickshell.env("OMARCHY_PATH")
|
||||||
|
property var failures: []
|
||||||
|
property var createdIds: []
|
||||||
|
property var createdObjects: []
|
||||||
|
property var panelBarIds: [
|
||||||
|
"omarchy.audio",
|
||||||
|
"omarchy.bluetooth",
|
||||||
|
"omarchy.monitor",
|
||||||
|
"omarchy.network",
|
||||||
|
"omarchy.power",
|
||||||
|
"omarchy.weather"
|
||||||
|
]
|
||||||
|
|
||||||
|
function fail(message) {
|
||||||
|
failures.push(String(message))
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertTrue(condition, message) {
|
||||||
|
if (!condition) fail(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
function shellQuote(value) {
|
||||||
|
return "'" + String(value).replace(/'/g, "'\\''") + "'"
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeResult() {
|
||||||
|
var payload = JSON.stringify({
|
||||||
|
ok: failures.length === 0,
|
||||||
|
failures: failures,
|
||||||
|
created: createdIds
|
||||||
|
})
|
||||||
|
|
||||||
|
if (resultPath) {
|
||||||
|
Quickshell.execDetached(["bash", "-lc", "printf '%s' " + shellQuote(payload) + " > " + shellQuote(resultPath)])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function manifests() {
|
||||||
|
try {
|
||||||
|
return JSON.parse(Qt.atob(Quickshell.env("OMARCHY_QML_MANIFESTS") || "W10="))
|
||||||
|
} catch (error) {
|
||||||
|
fail("manifest list failed to parse: " + error)
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function initialProperties(entry) {
|
||||||
|
var props = {}
|
||||||
|
if (entry.kind === "bar") {
|
||||||
|
props.omarchyPath = rootPath
|
||||||
|
props.barWidgetRegistry = fakeBarWidgetRegistry
|
||||||
|
props.barConfig = {
|
||||||
|
position: "top",
|
||||||
|
transparent: false,
|
||||||
|
centerAnchor: "",
|
||||||
|
layout: { left: [], center: [], right: [] }
|
||||||
|
}
|
||||||
|
props.shell = mockShell
|
||||||
|
} else if (entry.kind === "bar-widget" || panelBarIds.indexOf(entry.id) !== -1) {
|
||||||
|
props.bar = fakeBar
|
||||||
|
props.moduleName = entry.id
|
||||||
|
props.settings = {}
|
||||||
|
}
|
||||||
|
return props
|
||||||
|
}
|
||||||
|
|
||||||
|
function injectProperties(item, entry) {
|
||||||
|
if (!item) return
|
||||||
|
if ("omarchyPath" in item) item.omarchyPath = rootPath
|
||||||
|
if ("shell" in item) item.shell = mockShell
|
||||||
|
if ("manifest" in item) item.manifest = entry.manifest
|
||||||
|
if ("pluginRegistry" in item) item.pluginRegistry = mockPluginRegistry
|
||||||
|
if ("barWidgetRegistry" in item) item.barWidgetRegistry = fakeBarWidgetRegistry
|
||||||
|
if ("bar" in item) item.bar = fakeBar
|
||||||
|
if ("moduleName" in item) item.moduleName = entry.id
|
||||||
|
if ("settings" in item) item.settings = {}
|
||||||
|
if ("service" in item) item.service = null
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadEntry(entry) {
|
||||||
|
var component = Qt.createComponent(entry.url, Component.PreferSynchronous)
|
||||||
|
if (component.status !== Component.Ready) {
|
||||||
|
fail(entry.id + " " + entry.kind + " failed to load: " + component.errorString())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var item = component.createObject(host, initialProperties(entry))
|
||||||
|
if (!item) {
|
||||||
|
fail(entry.id + " " + entry.kind + " failed to instantiate: " + component.errorString())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
injectProperties(item, entry)
|
||||||
|
createdObjects.push(item)
|
||||||
|
createdIds.push(entry.id + ":" + entry.kind)
|
||||||
|
}
|
||||||
|
|
||||||
|
Item { id: host }
|
||||||
|
|
||||||
|
QtObject {
|
||||||
|
id: fakeBarWidgetRegistry
|
||||||
|
property var widgets: ({})
|
||||||
|
property int revision: 0
|
||||||
|
signal changed()
|
||||||
|
function register(id, component, metadata) {
|
||||||
|
var next = {}
|
||||||
|
for (var key in widgets) next[key] = widgets[key]
|
||||||
|
next[String(id)] = { component: component, metadata: metadata || {} }
|
||||||
|
widgets = next
|
||||||
|
revision++
|
||||||
|
changed()
|
||||||
|
}
|
||||||
|
function unregister(id) {
|
||||||
|
var next = {}
|
||||||
|
for (var key in widgets) if (key !== String(id)) next[key] = widgets[key]
|
||||||
|
widgets = next
|
||||||
|
revision++
|
||||||
|
changed()
|
||||||
|
}
|
||||||
|
function metadataFor(id) { return widgets[String(id)] ? widgets[String(id)].metadata : null }
|
||||||
|
function availableIds() { return Object.keys(widgets) }
|
||||||
|
function has(id) { return widgets[String(id)] !== undefined }
|
||||||
|
}
|
||||||
|
|
||||||
|
QtObject {
|
||||||
|
id: mockPluginRegistry
|
||||||
|
property var installedPlugins: ({})
|
||||||
|
function isEnabled(id) { return true }
|
||||||
|
function entryPointUrl(manifest, kind) { return "" }
|
||||||
|
function rescan() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
QtObject {
|
||||||
|
id: mockNotificationService
|
||||||
|
property bool doNotDisturb: false
|
||||||
|
property ListModel pendingModel: ListModel {}
|
||||||
|
property ListModel pastModel: ListModel {}
|
||||||
|
function setDoNotDisturb(value) { doNotDisturb = !!value }
|
||||||
|
}
|
||||||
|
|
||||||
|
QtObject {
|
||||||
|
id: mockShell
|
||||||
|
property var bar: fakeBar
|
||||||
|
property var barConfig: ({ position: "top" })
|
||||||
|
property var shellConfig: ({ version: 1, idle: {}, plugins: [], bar: { layout: { left: [], center: [], right: [] } } })
|
||||||
|
function firstPartyServiceFor(id) {
|
||||||
|
if (id === "omarchy.notifications") return mockNotificationService
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
function serviceFor(id) { return firstPartyServiceFor(id) }
|
||||||
|
function summon(id, payloadJson) { return true }
|
||||||
|
function hide(id) { return true }
|
||||||
|
function toggle(id, payloadJson) { return true }
|
||||||
|
function callIfLoaded(id, method, arg) { return "ok" }
|
||||||
|
function mutateShellConfig(mutator) {}
|
||||||
|
function updateEntryInline(moduleName, settings) { return true }
|
||||||
|
}
|
||||||
|
|
||||||
|
QtObject {
|
||||||
|
id: fakeBar
|
||||||
|
property bool vertical: false
|
||||||
|
property int barSize: 26
|
||||||
|
property string omarchyPath: root.rootPath
|
||||||
|
property string fontFamily: "monospace"
|
||||||
|
property color foreground: "white"
|
||||||
|
property color background: "black"
|
||||||
|
property color urgent: "red"
|
||||||
|
property var shell: mockShell
|
||||||
|
function run(command) {}
|
||||||
|
function showTooltip(target, text) {}
|
||||||
|
function hideTooltip(target) {}
|
||||||
|
function requestPopout(owner) {}
|
||||||
|
function releasePopout(owner) {}
|
||||||
|
function registerClickTarget(target) {}
|
||||||
|
function unregisterClickTarget(target) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
interval: 1
|
||||||
|
running: true
|
||||||
|
repeat: false
|
||||||
|
onTriggered: {
|
||||||
|
var entries = manifests()
|
||||||
|
root.assertTrue(entries.length > 0, "manifest entry list is not empty")
|
||||||
|
for (var i = 0; i < entries.length; i++) root.loadEntry(entries[i])
|
||||||
|
|
||||||
|
Qt.callLater(function() {
|
||||||
|
root.assertTrue(root.createdIds.length === entries.length, "all manifest entrypoints instantiate")
|
||||||
|
for (var j = 0; j < root.createdObjects.length; j++) {
|
||||||
|
var item = root.createdObjects[j]
|
||||||
|
if (item && typeof item.destroy === "function") item.destroy()
|
||||||
|
}
|
||||||
|
root.writeResult()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+111
@@ -0,0 +1,111 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
||||||
|
|
||||||
|
TMPDIR=""
|
||||||
|
QS_PID=""
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
if [[ -n $QS_PID ]] && kill -0 "$QS_PID" 2>/dev/null; then
|
||||||
|
kill "$QS_PID" 2>/dev/null || true
|
||||||
|
wait "$QS_PID" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
[[ -n $TMPDIR && -d $TMPDIR ]] && rm -rf "$TMPDIR"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
if [[ -z ${WAYLAND_DISPLAY:-} ]]; then
|
||||||
|
pass "no Wayland compositor; skipping manifest entrypoint load test"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v quickshell >/dev/null 2>&1; then
|
||||||
|
pass "quickshell not installed; skipping manifest entrypoint load test"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
require_command python3
|
||||||
|
|
||||||
|
manifest_entries=$(ROOT="$ROOT" python3 <<'PY'
|
||||||
|
import base64
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
root = Path(os.environ["ROOT"])
|
||||||
|
entries = []
|
||||||
|
|
||||||
|
kind_entry_points = {
|
||||||
|
"bar": "bar",
|
||||||
|
"bar-widget": "barWidget",
|
||||||
|
"menu": "menu",
|
||||||
|
"overlay": "overlay",
|
||||||
|
"panel": "panel",
|
||||||
|
"service": "service",
|
||||||
|
}
|
||||||
|
|
||||||
|
for manifest_path in sorted((root / "shell/plugins").glob("**/manifest.json")) + sorted((root / "shell/plugins").glob("**/*.manifest.json")):
|
||||||
|
manifest = json.loads(manifest_path.read_text())
|
||||||
|
for kind in manifest.get("kinds", []):
|
||||||
|
entry_key = kind_entry_points.get(kind)
|
||||||
|
entry_point = manifest.get("entryPoints", {}).get(entry_key)
|
||||||
|
if not entry_point:
|
||||||
|
continue
|
||||||
|
entry_path = manifest_path.parent / entry_point
|
||||||
|
entries.append({
|
||||||
|
"id": manifest["id"],
|
||||||
|
"kind": kind,
|
||||||
|
"entryKey": entry_key,
|
||||||
|
"entryPoint": entry_point,
|
||||||
|
"url": entry_path.resolve().as_uri(),
|
||||||
|
"manifest": manifest,
|
||||||
|
})
|
||||||
|
|
||||||
|
print(base64.b64encode(json.dumps(entries).encode()).decode())
|
||||||
|
PY
|
||||||
|
)
|
||||||
|
|
||||||
|
TMPDIR=$(mktemp -d)
|
||||||
|
result="$TMPDIR/result.json"
|
||||||
|
log="$TMPDIR/quickshell.log"
|
||||||
|
config_dir="$TMPDIR/manifest-entrypoints"
|
||||||
|
mkdir -p "$config_dir" "$TMPDIR/home"
|
||||||
|
cp "$SHELL_TEST_DIR/fixtures/manifest-entrypoints/shell.qml" "$config_dir/shell.qml"
|
||||||
|
ln -s "$ROOT/shell/Ui" "$config_dir/Ui"
|
||||||
|
ln -s "$ROOT/shell/Commons" "$config_dir/Commons"
|
||||||
|
|
||||||
|
OMARCHY_PATH="$ROOT" \
|
||||||
|
OMARCHY_QML_TEST_RESULT="$result" \
|
||||||
|
OMARCHY_QML_MANIFESTS="$manifest_entries" \
|
||||||
|
HOME="$TMPDIR/home" \
|
||||||
|
QML2_IMPORT_PATH="$ROOT/shell${QML2_IMPORT_PATH:+:$QML2_IMPORT_PATH}" \
|
||||||
|
QML_IMPORT_PATH="$ROOT/shell${QML_IMPORT_PATH:+:$QML_IMPORT_PATH}" \
|
||||||
|
PATH="$ROOT/bin:$PATH" \
|
||||||
|
quickshell -p "$config_dir" --no-color >"$log" 2>&1 &
|
||||||
|
QS_PID=$!
|
||||||
|
|
||||||
|
for _ in {1..80}; do
|
||||||
|
[[ -s $result ]] && break
|
||||||
|
if ! kill -0 "$QS_PID" 2>/dev/null; then
|
||||||
|
sed -n '1,220p' "$log" >&2
|
||||||
|
fail "manifest entrypoint quickshell exited before writing result"
|
||||||
|
fi
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
|
|
||||||
|
[[ -s $result ]] || {
|
||||||
|
sed -n '1,220p' "$log" >&2
|
||||||
|
fail "manifest entrypoint load test timed out"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! jq -e '.ok == true' "$result" >/dev/null; then
|
||||||
|
printf 'Manifest entrypoint result:\n' >&2
|
||||||
|
jq . "$result" >&2
|
||||||
|
printf 'Manifest entrypoint log:\n' >&2
|
||||||
|
sed -n '1,220p' "$log" >&2
|
||||||
|
fail "manifest entrypoints load"
|
||||||
|
fi
|
||||||
|
|
||||||
|
pass "manifest entrypoints load"
|
||||||
Reference in New Issue
Block a user