import assert from "node:assert/strict"; import { spawn } from "node:child_process"; import { existsSync } from "node:fs"; import { readFile } from "node:fs/promises"; import path from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; import { createServer } from "vite"; import { compileSkinCss } from "../../src/shared/skin-css.ts"; const read = (path) => readFile(new URL(path, import.meta.url), "utf8"); const webRoot = fileURLToPath(new URL("../", import.meta.url)); const CHROME = [process.env.WEBSPEAK_TEST_CHROME, "/usr/bin/google-chrome", "/usr/bin/google-chrome-stable"] .find((candidate) => candidate && existsSync(candidate)); const compileHostile = (css) => compileSkinCss(css, "community.hostile-fixture", {}, 3).css; /** * Hostile rules that the compiler still accepts (they are legitimate page / * themable-host styling) but that must not be able to hide, cover, or disable * the recovery entry. `fullscreen-audio-dock` is the case the previous review * reproduced: a public part promoted to a `z-index: 2147483647` fullscreen layer. */ const scenarios = [ { name: "fullscreen-audio-dock", css: compileHostile('[data-ws-part="voice.audio-dock"] { position: fixed; inset: 0; z-index: 2147483647; }'), }, { name: "opacity-launcher", css: compileHostile('[data-ws-part="host.plugins.launcher"] { opacity: 0; }'), }, { name: "filter-launcher", css: compileHostile('[data-ws-part="host.plugins.launcher"] { filter: opacity(0); }'), }, { name: "display-none-overlay", css: compileHostile('[data-ws-part="host.plugins.overlay"] { display: none !important; }'), }, { name: "pointer-events-none", css: compileHostile('[data-ws-part="host.plugins.launcher"], [data-ws-part="host.plugins.overlay"] { pointer-events: none !important; }'), }, { // Decorative host chrome may legitimately be a fixed, viewport-sized, // max-stacking decoration. Recovery lives in a closed-shadow top layer and // must still win the hit test. name: "decorative-watermark-overlay", css: compileHostile(` @keyframes drift { from { transform: translateX(0); } to { transform: translateX(12px); } } [data-ws-part="host.watermark"] { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 2147483647; background: #123; animation: drift 3s ease-in-out infinite alternate; } `), }, ]; test("host chrome renders recovery and authorization in a closed-shadow top layer", async () => { const [hostChrome, authorization, ownedLayer, hostChromeService, publicSkin, recoveryNotice, slotPlacement, floatingPlacement, pluginPanel, presentation, controlTokens] = await Promise.all([ read("../src/components/HostChrome.vue"), read("../src/components/InstanceAuthorization.vue"), read("../src/services/host-owned-layer.ts"), read("../src/services/host-chrome.ts"), read("../src/composables/usePublicSkin.ts"), read("../src/components/SkinLoadRecoveryNotice.vue"), read("../src/services/host-slot-placement.ts"), read("../src/services/host-floating-placement.ts"), read("../src/components/PluginPanel.vue"), read("../src/services/host-recovery-presentation.ts"), read("../src/services/host-control-tokens.ts"), ]); // Recovery: closed shadow root + manual popover + no skin hook. assert.match(hostChrome, /createHostOwnedLayer\("recovery"/); assert.match(hostChrome, /popover="manual"/); assert.match(hostChrome, /data-ws-recovery-action="built-in"/); assert.match(hostChrome, /requestBuiltInSkin/); assert.match(hostChrome, /isThirdPartySkinActive/); // The shortcut runs in the capture phase so a plugin/skin capture listener // cannot swallow it with preventDefault(). assert.match(hostChrome, /addEventListener\("keydown", onKeydown, true\)/); assert.match(hostChrome, /removeEventListener\("keydown", onKeydown, true\)/); // Escape closes the popover from inside its closed shadow root. assert.match(hostChrome, /@keydown\.escape="onRecoveryEscape"/); assert.match(hostChrome, /function onRecoveryEscape\(\) \{\s*shortcutOpen\.value = false;/); assert.doesNotMatch(hostChrome, /event\.defaultPrevented \|\| event\.repeat/); assert.doesNotMatch(hostChrome, /data-ws-part="host\.recovery"/); assert.doesNotMatch(hostChrome, /ws-host-recovery-layer/); // Slots are a declarative anchor, not a skin hook: the host still binds the // capsule itself and switches back to the fixed position at runtime. assert.match(hostChrome, /activeHostSlot\("host\.recovery"\)/); assert.match(hostChrome, /bindHostSlot\(/); assert.match(hostChrome, /onModeChange/); // Explicit toolbar presentation: plain host buttons, no capsule shell, real // host click handlers and i18n labels. The mode is a separate schema field, // not inferred from compact. assert.match(hostChrome, /activeHostSlot\("host\.recovery\.built-in"\)/); assert.match(hostChrome, /activeHostSlot\("host\.recovery\.library"\)/); assert.match(hostChrome, /presentation: "toolbar"/); assert.match(hostChrome, /resolveHostRecoveryPresentation/); assert.match(hostChrome, /class="ws-host-toolbar-action"/); assert.match(hostChrome, /:aria-label="copy\.useBuiltIn"/); assert.match(hostChrome, /:aria-label="copy\.library"/); assert.match(hostChrome, /class="ws-host-toolbar-icon" aria-hidden="true"/); assert.match(hostChrome, /focusable="false"/); assert.match(hostChrome, /--ws-toolbar-hover-background/); assert.match(hostChrome, /--ws-toolbar-hover-border/); assert.match(hostChrome, /--ws-toolbar-gap/); assert.match(hostChrome, /--ws-toolbar-icon-size/); assert.match(hostChrome, /data-ws-recovery-action="built-in"[\s\S]*?@click="useBuiltInSkin"/); assert.match(hostChrome, /data-ws-recovery-action="library"[\s\S]*?@click="openLibrary"/); assert.match(hostChrome, /resolveHostRecoveryPresentation\(/); assert.match(presentation, /suppressLauncher/); assert.match(hostChrome, /setInlineLibraryEntryVisible/); assert.match(pluginPanel, /isInlineLibraryEntryVisible/); assert.match(pluginPanel, /!inlineLibraryEntry/); // Toolbar tokens are sanitized by the same shared reader with their own // geometry defaults; no capsule shadow/radius/pale fixed background. assert.match(controlTokens, /HOST_TOOLBAR_TOKEN_NAMES/); assert.match(controlTokens, /resolveHostControlToolbarTokens/); assert.match(slotPlacement, /applyHostControlToolbarTokens/); assert.match(slotPlacement, /resolveHostControlToolbarTokens/); assert.match(slotPlacement, /presentation === "toolbar"/); assert.match(slotPlacement, /querySelectorAll\("\.ws-skin-root"\)/); assert.match(slotPlacement, /isHostPartReachable\(/); assert.match(slotPlacement, /evaluateSlottedControl/); // Two split recovery toolbars must not cover each other on a narrow screen. assert.match(slotPlacement, /covers-host-control/); assert.match(hostChrome, /otherControls:/); // A fallback capsule must also avoid toolbars that are still docked: they // live in the closed shadow root and are invisible to the light-DOM obstacle // scan, so the document scan alone cannot protect their labels/clicks. assert.match(hostChrome, /avoidRects:/); assert.match(hostChrome, /dockedToolbarRects\(\)/); assert.match(floatingPlacement, /avoidRects\?:/); assert.match(floatingPlacement, /forbiddenAt\(/); assert.match(hostChromeService, /export function activeHostSlot/); assert.match(hostChromeService, /HOST_SLOTTABLE_PART_IDS\.has\(part\)/); assert.match(hostChromeService, /isThirdPartySkinActive\(\)/); // Host-owned controls share one sanitized token reader; no per-control palette copy. assert.match(hostChrome, /bindHostControlTheme/); assert.match(hostChrome, /--ws-control-background/); assert.match(recoveryNotice, /SKIN_LOAD_RECOVERY_CONTROL_DEFAULTS/); assert.match(recoveryNotice, /--ws-control-background/); assert.match(authorization, /PERMISSION_CONTROL_DEFAULTS/); assert.match(authorization, /--ws-control-background/); // Authorization: showModal() inside the same host-owned mechanism. assert.match(authorization, /createHostOwnedLayer\('authorization'/); assert.match(authorization, /showModal\(\)/); assert.doesNotMatch(authorization, /data-ws-part="host\.permission"/); // The load-failure banner is trusted UI too: closed shadow layer, stylesheet // inside the boundary, no document-level scoped stylesheet to override. assert.match(recoveryNotice, /createHostOwnedLayer\("skin-load"/); assert.match(recoveryNotice, /data-ws-part="app\.skin-load-recovery"/); assert.doesNotMatch(recoveryNotice, /