repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
quickshell/nuguland/privilege-ui.test.mjs
Rawimport assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { runInNewContext } from "node:vm";
const qml = readFileSync(new URL("./shell.qml", import.meta.url), "utf8");
const privilegeQml = readFileSync(new URL("./Privilege.qml", import.meta.url), "utf8");
const barQml = readFileSync(new URL("./Bar.qml", import.meta.url), "utf8");
const popupQml = readFileSync(new URL("./PopupHost.qml", import.meta.url), "utf8");
const surface = readFileSync(new URL("./PrivilegeSurface.qml", import.meta.url), "utf8");
assert.match(surface, /^Rectangle\s*\{/m, "PrivilegeSurface component exists");
assert.match(surface, /id:\s*commandText/, "privilege surface has dedicated command text");
assert.match(surface, /PrivilegeUi\.commandMarkdown/, "command text uses markdown-style formatter");
assert.match(surface, /textFormat:\s*Text\.RichText/, "command text renders rich text");
assert.match(surface, /elide:\s*Text\.ElideNone/, "command text must not truncate");
// Initial focus, reveal toggle, rejection and traversal have real-input coverage.
// Same-request activation regain and responseVisible remain source-only checks.
assert.match(surface, /echoMode:\s*root\.secretVisible \|\| root\.request\.responseVisible \? TextInput\.Normal : TextInput\.Password/, "request visibility and reveal both control password echo mode");
assert.match(surface, /target:\s*root\.Window\.window[\s\S]*function onActiveChanged\(\)[\s\S]*Qt\.callLater\(root\.focusSecret\)/, "surface focus regain restores password focus");
assert.match(qml, /Variants\s*\{\s*model:\s*shell\.primaryScreens[\s\S]*?objectName:\s*"privilegeSecuritySurface"/, "exactly one primary-screen privilege window is instantiated");
assert.match(qml, /id:\s*privilegeSurface/, "privilege surface instance is addressable from PanelWindow");
assert.match(barQml, /privilegeService:\s*root\.privilegeService/, "bar passes privilege state to its popup host");
assert.match(popupQml, /root\.visible && \(!root\.privilegeService \|\| !root\.privilegeService\.active\) \? WlrKeyboardFocus\.Exclusive/, "popup releases exclusive keyboard focus during authentication");
assert.match(qml, /visible:\s*privilege\.active \|\| privilege\.error\.length > 0 \|\| privilege\.confirming/, "privilege window stays up for success confirmation");
assert.match(qml, /onVisibleChanged:\s*if \(visible\)\s*Qt\.callLater\(privilegeSurface\.focusSecret\)/, "PanelWindow asks password input for focus after mapping");
assert.match(privilegeQml, /property bool confirming:\s*false/, "privilege service exposes transient success confirmation state");
assert.match(privilegeQml, /property bool awaitingCompletion:\s*false/, "privilege service tracks submitted flows");
assert.match(privilegeQml, /id:\s*successClose/, "success confirmation auto-closes");
assert.match(privilegeQml, /function onIsCompletedChanged\(\)/, "polkit completed state is handled before flow detaches");
assert.match(privilegeQml, /function onIsActiveChanged\(\)/, "polkit inactive fallback finishes submitted flows");
assert.match(surface, /readonly property bool confirming: privilegeService \? privilegeService\.confirming/, "surface binds async success state");
assert.match(surface, /id:\s*successTitle/, "success title exists");
assert.match(surface, /text:\s*root\.confirming \? "authorized"/, "success says authorized once, in the title");
assert.doesNotMatch(surface, /successBanner|authorization granted/, "success is not repeated in a banner");
assert.doesNotMatch(surface, /requestIdentityCard/, "debug identity card is not rendered");
assert.doesNotMatch(surface, /actionId/, "debug polkit action id is not rendered");
// Exercise the production completion transition with observable property writes.
// This proves lifecycle ordering, not native authorization or compositor focus.
const finishMethod = privilegeQml.match(/^ function finish\(granted\) \{[\s\S]*?^ }/m)?.[0];
assert(finishMethod, "production completion transition exists");
for (const granted of [true, false]) {
const state = { active: true, confirming: false, error: "" };
const visibility = [];
let confirmations = 0;
const context = { completed: false, authorized: false, cancelled: false, awaitingCompletion: true,
successClose: { restart() { confirmations++; } } };
for (const name of Object.keys(state)) Object.defineProperty(context, name, {
get: () => state[name],
set(value) {
state[name] = value;
visibility.push(state.active || state.confirming || state.error.length > 0);
}
});
runInNewContext(`(${finishMethod})(${granted})`, context);
assert.equal(context.authorized, granted);
assert.equal(state.active, false);
assert.equal(state.confirming, granted);
assert.equal(confirmations, granted ? 1 : 0);
if (granted) assert(visibility.every(Boolean), "success must not transiently unmap authorization surface");
else assert.equal(visibility.at(-1), false, "denial closes the authorization surface");
}
console.log("privilege-ui.test.mjs: ALL PASS");