import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; 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 popoutQml = readFileSync(new URL("./PopoutHost.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"); assert.match(surface, /property bool secretVisible:\s*false/, "password reveal state exists"); assert.match(surface, /id:\s*revealButton/, "password reveal button exists"); assert.match(surface, /echoMode:\s*root\.secretVisible \|\| root\.request\.responseVisible \? TextInput\.Normal : TextInput\.Password/, "reveal button controls password echo mode"); assert.match(surface, /password rejected/, "wrong password message is human-readable"); assert.match(surface, /secretInput\.forceActiveFocus\(\)/, "password input is explicitly focused"); assert.doesNotMatch(surface, /id:\s*focusRetry|repeat:\s*true[\s\S]*focusSecret/, "focus is never continuously retried"); assert.doesNotMatch(surface, /onActiveFocusChanged:[^\n]*focusSecret/, "leaving the password field does not steal focus back"); assert.match(surface, /target:\s*root\.Window\.window[\s\S]*function onActiveChanged\(\)[\s\S]*Qt\.callLater\(root\.focusSecret\)/, "surface focus regain restores password focus"); for (const [id, label] of [["revealButton", "show password"], ["cancelButton", "cancel"], ["authorizeButton", "authorize"]]) { assert.match(surface, new RegExp(`PopupButton \\{\\s*id: ${id}[\\s\\S]*?accessibleName: text[\\s\\S]*?tooltip: text`), `${id} uses the shared named and tooled control`); assert.match(surface, new RegExp(`id: ${id}[\\s\\S]*?${label}`), `${id} retains its action label`); } assert.match(surface, /id:\s*secretInput[\s\S]*KeyNavigation\.tab:\s*revealButton[\s\S]*KeyNavigation\.backtab:\s*authorizeButton/); assert.match(surface, /id:\s*revealButton[\s\S]*KeyNavigation\.tab:\s*cancelButton[\s\S]*KeyNavigation\.backtab:\s*secretInput/); assert.match(surface, /id:\s*cancelButton[\s\S]*KeyNavigation\.tab:\s*authorizeButton[\s\S]*KeyNavigation\.backtab:\s*revealButton/); assert.match(surface, /id:\s*authorizeButton[\s\S]*KeyNavigation\.tab:\s*secretInput[\s\S]*KeyNavigation\.backtab:\s*cancelButton/); 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 popout host"); assert.match(popoutQml, /root\.visible && \(!root\.privilegeService \|\| !root\.privilegeService\.active\) \? WlrKeyboardFocus\.Exclusive/, "popout 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, /function onConfirmingChanged\(\)/, "surface refreshes after async success state changes"); assert.match(surface, /id:\s*successBanner/, "success banner exists"); assert.match(surface, /authorization granted/, "success title is rendered"); assert.match(surface, /text:\s*"authorized"/, "success banner text is rendered"); assert.doesNotMatch(surface, /requestIdentityCard/, "debug identity card is not rendered"); assert.doesNotMatch(surface, /actionId/, "debug polkit action id is not rendered"); console.log("privilege-ui.test.mjs: ALL PASS");