Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(work-panel): keep Browser visible under tab menu
vastsa9d9a3f1c5e3c
diff --git a/apps/desktop/electron/main/ipc/window-ipc.ts b/apps/desktop/electron/main/ipc/window-ipc.tsindex 8c1722470..20e1abbed 100644--- a/apps/desktop/electron/main/ipc/window-ipc.ts+++ b/apps/desktop/electron/main/ipc/window-ipc.ts@@ -1,4 +1,4 @@-import { BrowserWindow } from "electron";+import { BrowserWindow, Menu } from "electron";import { isWindowBackgroundColor, MAX_WINDOW_CORNER_RADIUS } from "@pi-desktop/plugin-sdk";import {builtinWindowBackground,@@ -12,6 +12,8 @@ import {type WindowControlAction,type LifecycleDialogChoice,type TraySessionPreferences,+ type WorkPanelTabMenuAction,+ type WorkPanelTabMenuRequest,} from "@pi-desktop/shared";import {emptyWorkPanelReservationState,@@ -43,6 +45,41 @@ export type WindowIpcDependencies = {isMacosWindowTranslucent: () => boolean;};+function normalizeWorkPanelMenuLabel(value: unknown): string | null {+ if (typeof value !== "string" || value.length > 1024) return null;+ const label = value.replace(/[\u0000-\u001f\u007f]/g, " ").replace(/\s+/g, " ").trim();+ return label ? label.slice(0, 256) : null;+}++function parseWorkPanelTabMenuRequest(value: unknown): WorkPanelTabMenuRequest | null {+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;+ const input = value as Record<string, unknown>;+ const closeTabLabel = normalizeWorkPanelMenuLabel(input.closeTabLabel);+ const closeOtherTabsLabel = normalizeWorkPanelMenuLabel(input.closeOtherTabsLabel);+ const closeAllTabsLabel = normalizeWorkPanelMenuLabel(input.closeAllTabsLabel);+ if (+ !closeTabLabel ||+ !closeOtherTabsLabel ||+ !closeAllTabsLabel ||+ typeof input.canCloseOthers !== "boolean" ||+ typeof input.x !== "number" ||+ !Number.isFinite(input.x) ||+ input.x < 0 ||+ typeof input.y !== "number" ||+ !Number.isFinite(input.y) ||+ input.y < 0+ ) return null;+ return {+ closeTabLabel,+ closeOtherTabsLabel,+ closeAllTabsLabel,+ canCloseOthers: input.canCloseOthers,+ x: input.x,+ y: input.y,+ };+}++/*** Register renderer-drawn window chrome and work-panel geometry channels.*@@ -272,6 +309,39 @@ export function registerWindowIpc({return { ready: true };});+ handleWithEvent(IPC.invoke.workPanelTabMenu, async (event, input: unknown) => {+ registrar.assertMainWindowSender(event);+ const window = BrowserWindow.fromWebContents(event.sender);+ const mainWindow = getMainWindow();+ if (!window || window !== mainWindow || window.isDestroyed()) {+ throw new Error("main window unavailable for work panel menu");+ }+ const request = parseWorkPanelTabMenuRequest(input);+ if (!request) {+ throw Object.assign(new Error("invalid work panel tab menu request"), {+ errorCode: ErrorCodes.INVALID_ARGUMENT,+ });+ }+ const [contentWidth, contentHeight] = window.getContentSize();+ const x = Math.min(Math.round(request.x), Math.max(0, contentWidth - 1));+ const y = Math.min(Math.round(request.y), Math.max(0, contentHeight - 1));+ let selected: WorkPanelTabMenuAction | null = null;+ const menu = Menu.buildFromTemplate([+ { label: request.closeTabLabel, click: () => { selected = "closeTab"; } },+ { type: "separator" },+ {+ label: request.closeOtherTabsLabel,+ enabled: request.canCloseOthers,+ click: () => { selected = "closeOtherTabs"; },+ },+ { label: request.closeAllTabsLabel, click: () => { selected = "closeAllTabs"; } },+ ]);+ return new Promise<WorkPanelTabMenuAction | null>((resolve) => {+ menu.popup({ window, x, y, callback: () => resolve(selected) });+ });+ });++handle(IPC.invoke.nativeMenuAction, async (input: { action?: string } = {}) => {if (!input.action ||diff --git a/apps/desktop/src/components/workpanel/WorkPanel.tsx b/apps/desktop/src/components/workpanel/WorkPanel.tsxindex 845acdd92..d23926970 100644--- a/apps/desktop/src/components/workpanel/WorkPanel.tsx+++ b/apps/desktop/src/components/workpanel/WorkPanel.tsx@@ -9,6 +9,7 @@ import {type ComponentType,type CSSProperties,type KeyboardEvent as ReactKeyboardEvent,+ type MouseEvent as ReactMouseEvent,} from "react";import { useTranslation } from "react-i18next";import { useBlockingOverlayActive } from "../../lib/blocking-overlay";@@ -25,6 +26,7 @@ import {toolWorkPanelTab,} from "../../lib/work-panel-tabs";import type { PluginViewMeta } from "@pi-desktop/shared";+import { api } from "../../lib/api";import { pluginViewIcon, pluginViewInitial } from "../../lib/plugin-view-icons";import { useAppStore } from "../../stores/app-store";import type { WorkPanelTab } from "../../stores/app-store";@@ -668,6 +670,50 @@ function LocalWorkPanel({closeAllTabs();requestAnimationFrame(() => newTabButtonRef.current?.focus());}, [closeAllTabs]);+ const openNativeTabMenu = useCallback(+ (+ event: ReactMouseEvent<HTMLDivElement>,+ tabId: string,+ label: string,+ ) => {+ event.preventDefault();+ event.stopPropagation();+ const sessionId = activeSessionId;+ const rect = event.currentTarget.getBoundingClientRect();+ const point =+ event.clientX === 0 && event.clientY === 0+ ? { x: rect.left + Math.min(24, rect.width / 2), y: rect.top + Math.min(24, rect.height / 2) }+ : { x: event.clientX, y: event.clientY };+ void api.openWorkPanelTabMenu({+ closeTabLabel: t("panel.closeTab", { name: label }),+ closeOtherTabsLabel: t("panel.closeOtherTabs"),+ closeAllTabsLabel: t("panel.closeAllTabs"),+ canCloseOthers: tabs.length > 1,+ x: point.x,+ y: point.y,+ }).then((action) => {+ if (!action || !sessionId) return;+ const current = useAppStore.getState();+ if (+ current.activeSessionId !== sessionId ||+ !current.workPanelTabs.some((tab) => tab.id === tabId)+ ) return;+ if (action === "closeTab") closeTabAndFocus(tabId);+ else if (action === "closeOtherTabs") closeOtherTabsAndFocus(tabId);+ else closeAllTabsAndFocus();+ }).catch((error) => {+ useAppStore.getState().showToast(String(error), { variant: "error" });+ });+ },+ [+ activeSessionId,+ closeAllTabsAndFocus,+ closeOtherTabsAndFocus,+ closeTabAndFocus,+ t,+ tabs.length,+ ],+ );const onTabKeyDown = useCallback((event: ReactKeyboardEvent<HTMLButtonElement>, tabId: string) => {const index = tabs.findIndex((tab) => tab.id === tabId);@@ -937,6 +983,10 @@ function LocalWorkPanel({// outside the strip, so bring the whole box in first.onPointerEnter={() => revealTab(tab.id)}onContextMenu={(event) => {+ if (activeTab?.kind === "plugin") {+ openNativeTabMenu(event, tab.id, label);+ return;+ }const items: ContextMenuItem[] = [{id: "close-tab",@@ -1089,7 +1139,7 @@ function LocalWorkPanel({location={activeTab.location}tabId={activeTab.id}// Native WebContentsViews composite above renderer content.- blocked={exiting || panelBlocked || blockingOverlayActive || tabContextMenu !== null}+ blocked={exiting || panelBlocked || blockingOverlayActive}/></div>);diff --git a/apps/desktop/src/lib/api.ts b/apps/desktop/src/lib/api.tsindex eeb901160..dee69a5da 100644--- a/apps/desktop/src/lib/api.ts+++ b/apps/desktop/src/lib/api.ts@@ -113,6 +113,8 @@ import type {AppMenuCommand,AppNotification,NativeMenuAction,+ WorkPanelTabMenuAction,+ WorkPanelTabMenuRequest,NotificationListResult,ReviewRollbackResult,PlanProposal,@@ -1723,6 +1725,8 @@ export const api = {IPC.invoke.nativeMenuAction,{ action },),+ openWorkPanelTabMenu: (request: WorkPanelTabMenuRequest) =>+ invoke<WorkPanelTabMenuAction | null>(IPC.invoke.workPanelTabMenu, request),onWindowMaximized: (listener: (event: { maximized: boolean }) => void) => {if (!window.piDesktop?.on) return () => undefined;return window.piDesktop.on(IPC.event.windowMaximized, (payload) =>diff --git a/apps/desktop/test/plugin-work-panel-views.test.mjs b/apps/desktop/test/plugin-work-panel-views.test.mjsindex 5a733caa7..28e5aae42 100644--- a/apps/desktop/test/plugin-work-panel-views.test.mjs+++ b/apps/desktop/test/plugin-work-panel-views.test.mjs@@ -96,11 +96,11 @@ test("plugin views reach the panel body and the empty state", () => {assert.doesNotMatch(panelSource, /openPluginView\(view\)/);});-test("the native surface hides behind the work-panel menu and keeps its full bounds", () => {- assert.match(- panelSource,- /blocked=\{\s*exiting \|\| panelBlocked \|\| blockingOverlayActive \|\| tabContextMenu !== null\s*\}/s,- );+test("the native surface stays visible while a plugin tab uses the native menu", () => {+ assert.match(panelSource, /blocked=\{\s*exiting \|\| panelBlocked \|\| blockingOverlayActive\s*\}/s);+ assert.match(panelSource, /if \(activeTab\?\.kind === "plugin"\)\s*\{\s*openNativeTabMenu/);+ assert.match(panelSource, /api\.openWorkPanelTabMenu\(/);+ assert.doesNotMatch(panelSource, /tabContextMenu !== null/);assert.doesNotMatch(panelSource, /avoid: pluginSurface/);assert.doesNotMatch(panelSource, /menuOpen|work-panel-new-menu|placeWorkPanelMenu/);assert.doesNotMatch(viewTabSource, /occludedById/);diff --git a/apps/desktop/test/window-menu.test.mjs b/apps/desktop/test/window-menu.test.mjsindex 80b1d0a9e..e93053d79 100644--- a/apps/desktop/test/window-menu.test.mjs+++ b/apps/desktop/test/window-menu.test.mjs@@ -3,9 +3,10 @@ import assert from "node:assert/strict";import { readFile } from "node:fs/promises";import test from "node:test";import { loadStyles } from "./helpers/styles.mjs";-import { readMainSource } from "./helpers/main-source.mjs";+import { readMainModule, readMainSource } from "./helpers/main-source.mjs";const mainSource = await readMainSource();+const windowIpcSource = await readMainModule("ipc/window-ipc.ts");const activationSource = await readFile(new URL("../electron/main/bootstrap/app-activation.ts", import.meta.url),"utf8",@@ -281,6 +282,19 @@ test("Windows and Linux use menu-free frameless chrome with window controls", ());});+test("the work-panel tab menu is a validated native popup", () => {+ assert.match(protocolSource, /workPanelTabMenu:\s*"pi-desktop\/workPanel\/tabMenu"/);+ const start = windowIpcSource.indexOf("handleWithEvent(IPC.invoke.workPanelTabMenu");+ const end = windowIpcSource.indexOf("\n });", start);+ const handler = windowIpcSource.slice(start, end);+ assert.ok(start >= 0 && end > start, "native tab-menu IPC handler is registered");+ assert.match(handler, /registrar\.assertMainWindowSender\(event\)/);+ assert.match(handler, /parseWorkPanelTabMenuRequest\(input\)/);+ assert.match(handler, /Menu\.buildFromTemplate/);+ assert.match(handler, /enabled:\s*request\.canCloseOthers/);+ assert.match(handler, /menu\.popup\(\{ window, x, y, callback:/);+});+test("menu and window IPC reject actions outside their shared allowlists", () => {assert.match(protocolSource, /export const APP_MENU_COMMANDS/);assert.match(protocolSource, /export const NATIVE_MENU_ACTIONS/);diff --git a/apps/desktop/test/work-panel.test.mjs b/apps/desktop/test/work-panel.test.mjsindex 8a9ab7f05..c2921e6bf 100644--- a/apps/desktop/test/work-panel.test.mjs+++ b/apps/desktop/test/work-panel.test.mjs@@ -234,7 +234,7 @@ test("work panel uses the fixed-window internal dock", () => {// guest clamped to the plugin view is gone before the dock CSS animation.assert.match(panelSource,- /blocked=\{\s*exiting \|\| panelBlocked \|\| blockingOverlayActive \|\| tabContextMenu !== null\s*\}/s,+ /blocked=\{\s*exiting \|\| panelBlocked \|\| blockingOverlayActive\s*\}/s,);assert.match(panelSource, /nativeSurfaceReadyForExit/);assert.match(panelSource, /is-exit-pending/);@@ -312,7 +312,7 @@ test("work panel header exposes a scrollable tab strip and direct new-page actioconst pluginSurface = panelSource.slice(pluginSurfaceStart, pluginSurfaceEnd);assert.match(pluginSurface,- /blocked=\{\s*exiting \|\| panelBlocked \|\| blockingOverlayActive \|\| tabContextMenu !== null\s*\}/s,+ /blocked=\{\s*exiting \|\| panelBlocked \|\| blockingOverlayActive\s*\}/s,);assert.doesNotMatch(pluginSurface, /isResizing/);assert.doesNotMatch(panelSource, /createPortal|newTabMenuRef|menuOpen/);diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.mdindex 6cc65c5c9..9900a1f36 100644--- a/docs/spec/04-ux/08-component-spec.md+++ b/docs/spec/04-ux/08-component-spec.md@@ -1242,7 +1242,7 @@ entirely inside the plugin's isolated page:| Open with no resource | `Cmd/Ctrl + J` reveals the panel without creating a tab, so the body renders the New launcher. Clicking `+` creates an explicit, closable New tab with the same launcher rows. Activating a row from that tab replaces it with or selects the singleton view. Closing the final tab leaves the panel open in the no-resource state. || Constrained work area | The panel is capped by the shared three-column budget inside the existing client area; MainChat never drops below its 450px floor and the expanded sidebar yields at the threshold || New launcher active | The body hosts concise Review and plugin-view buttons. Each row replaces the launcher tab with its destination or activates the existing singleton; the page is independently closeable. |-| Plugin view active | The body hosts the plugin's own isolated page as a native `WebContentsView`, positioned from the measured surface rect. It remains visible at its full rect while the divider is being resized or a New launcher tab is created; creating a page never pushes the plugin body down or changes its bounds. Embedded plugin documents start with zero root/body margin and border and a transparent background, so the host panel and plugin theme own the visible surface edge. It is hidden whenever the tab is inactive, the panel is animating, a panel-wide blocking overlay is open, or the tab context menu is open — the same rule the Browser preview follows, since both composite above renderer content. Closing the menu restores the view without changing its bounds. A view whose plugin is disabled, uninstalled, reloaded, or crashed is destroyed; the tab stays and re-opens the page on the next lifecycle event (ADR 0104) |+| Plugin view active | The body hosts the plugin's own isolated page as a native `WebContentsView`, positioned from the measured surface rect. It remains visible at its full rect while the divider is being resized or a New launcher tab is created; creating a page never pushes the plugin body down or changes its bounds. Embedded plugin documents start with zero root/body margin and border and a transparent background, so the host panel and plugin theme own the visible surface edge. It is hidden whenever the tab is inactive, the panel is animating, or a panel-wide blocking overlay is open. When the active plugin tab's context menu opens, Main shows a native popup above the `WebContentsView`, keeping the page visible at unchanged bounds. A view whose plugin is disabled, uninstalled, reloaded, or crashed is destroyed; the tab stays and re-opens the page on the next lifecycle event (ADR 0104) || Plugin out of scope | A view contributed by a plugin that is not active in the current project disappears from the New launcher when the project changes. Unlike contributed themes, which are one global setting and stay unfiltered, a view is scoped work |### 5.4 Interactionsdiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex dda901ad6..77655d7af 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -4792,14 +4792,14 @@ window; opening a normal panel afterward must still work.4) Click `+` twice and verify each creates and activates a separate Newlauncher tab. Confirm its body lists Review and each in-scope plugin viewexactly once. Open Browser and confirm its native surface opens at unchanged- bounds. Open that tab's context menu and verify it appears above Browser- chrome while the native view is hidden; Escape closes the menu and restores- the view without changing bounds. 5) Close active middle and edge tabs,- verify neighbor selection, then close the final tab and confirm New remains.- 6) Collapse/reopen the panel and trigger another artifact. In session A, leave- Browser open; switch to B and create another tab set, then switch repeatedly- between sessions and select a project without a conversation. Generate a- background artifact in the non-visible session. 7) Drag the inner divider+ bounds. Open its context menu and verify the native popup appears above Browser+ chrome while the page remains visible. Escape closes it without hiding the page+ or changing bounds. 5) Close active middle/edge tabs, verify neighbor selection,+ then close the final tab and confirm New remains. 6) Collapse/reopen the panel+ and trigger an artifact. In session A, leave Browser open; switch to B and+ create another tab set, then switch repeatedly between sessions and select a+ project without an active conversation. Generate a background artifact. 7)+ Drag the inner dividerpointer-down does not jump the divider or resize the native window, cancel onegesture with Escape, then focus the handle and exercise Arrow/Shift+Arrow/Home/End.Commit a different panel width with Browser active, double-click the divider and@@ -4836,9 +4836,9 @@ window; opening a normal panel afterward must still work.right neighbor then left. A localized, keyboard-navigable tab context menuoffers Close Tab, Close Other Tabs, and Close All Tabs. Close Other Tabsretains and activates its target and is disabled for one tab; Close All Tabs- closes Browser resources and leaves the panel open on New. The Browser tab's- native view is hidden while its context menu is open, placing the menu above- Browser chrome; closing the menu restores the view without changing bounds.+ closes Browser resources and leaves the panel open on New. For an active+ Browser/plugin view, the tab context menu is a Main-owned native popup above+ Browser chrome; the page stays visible and its bounds do not change.New launcher tabs expose Review and plugin views as body buttons, with nooverlapping popup. Dragging a tab shows a before/after insertion indicator;edge-holding scrolls toward hidden tabs, and reordering leaves the active@@ -4873,10 +4873,11 @@ window; opening a normal panel afterward must still work.D357- **Acceptance**: F (persistence), Quality- **Milestone**: M5+- **Status**: Unit-covered (`work-panel-resize.test.mjs`,`work-panel-window.test.mjs`, `work-panel-presentation.test.mjs`,`work-panel-tabs.test.mjs`, `browser-tab-restore.test.mjs`,`work-panel.test.mjs`, `plugin-work-panel-views.test.mjs`); isolated Electron- tab-menu, Browser visibility, and close-geometry path in+ tab-menu, Browser native-menu page visibility, and close geometry in`scripts/e2e-work-panel-tab-close.mjs`; full UI scenario Draft#### E2E-057: Message-owned review history survives commits and rolls back safelydiff --git a/packages/shared/src/protocol.ts b/packages/shared/src/protocol.tsindex 94c172776..e52c9508d 100644--- a/packages/shared/src/protocol.ts+++ b/packages/shared/src/protocol.ts@@ -39,6 +39,16 @@ export const NATIVE_MENU_ACTIONS = [export type NativeMenuAction = (typeof NATIVE_MENU_ACTIONS)[number];+export type WorkPanelTabMenuAction = "closeTab" | "closeOtherTabs" | "closeAllTabs";+export type WorkPanelTabMenuRequest = {+ closeTabLabel: string;+ closeOtherTabsLabel: string;+ closeAllTabsLabel: string;+ canCloseOthers: boolean;+ x: number;+ y: number;+};+export const WINDOW_CONTROL_ACTIONS = ["getState","minimize",@@ -436,6 +446,7 @@ export const IPC = {lifecycleDialogReady: "pi-desktop/window/lifecycleDialog/ready",lifecycleDialogRespond: "pi-desktop/window/lifecycleDialog/respond",menuRendererReady: "pi-desktop/menu/rendererReady",+ workPanelTabMenu: "pi-desktop/workPanel/tabMenu",traySetSessionPreferences: "pi-desktop/tray/setSessionPreferences",nativeMenuAction: "pi-desktop/menu/nativeAction",},diff --git a/scripts/e2e-work-panel-tab-close.mjs b/scripts/e2e-work-panel-tab-close.mjsindex b4c38e9c4..5219e9d39 100644--- a/scripts/e2e-work-panel-tab-close.mjs+++ b/scripts/e2e-work-panel-tab-close.mjs@@ -110,9 +110,10 @@ app.whenReady().then(async () => {continue;}if (result.stage === "plugin-view-menu-layer") {- assert.equal(result.hiddenWhileMenuOpen, true, "native Browser view was not hidden behind the menu");- assert.equal(result.restoredAfterMenuClose, true, "native Browser view was not restored after closing the menu");- console.log("plugin view menu layer: PASS");+ assert.equal(result.nativeMenuRequested, true, "Browser tab did not request the native menu");+ assert.equal(result.pageRemainsVisibleWhileMenuOpen, true, "Browser page disappeared while the menu was open");+ assert.equal(result.pageRemainsVisibleAfterMenuClose, true, "Browser page disappeared after menu close");+ console.log("native menu preserves Browser page: PASS");continue;}console.log(diff --git a/scripts/e2e/work-panel-tab-close.tsx b/scripts/e2e/work-panel-tab-close.tsxindex 5a142599c..4e06c7f02 100644--- a/scripts/e2e/work-panel-tab-close.tsx+++ b/scripts/e2e/work-panel-tab-close.tsx@@ -4,7 +4,7 @@ import { createInstance } from "i18next";import { I18nextProvider } from "react-i18next";import { catalogs } from "@pi-desktop/i18n";import { WorkPanel } from "../../apps/desktop/src/components/workpanel/WorkPanel";-import { IPC } from "@pi-desktop/shared";+import { IPC, type WorkPanelTabMenuAction, type WorkPanelTabMenuRequest } from "@pi-desktop/shared";import { pluginWorkPanelTab } from "../../apps/desktop/src/lib/work-panel-tabs";import { useAppStore } from "../../apps/desktop/src/stores/app-store";@@ -41,8 +41,9 @@ type TabContextMenuPathResult = {type PluginViewMenuLayerResult = {stage: "plugin-view-menu-layer";- hiddenWhileMenuOpen: boolean;- restoredAfterMenuClose: boolean;+ pageRemainsVisibleWhileMenuOpen: boolean;+ pageRemainsVisibleAfterMenuClose: boolean;+ nativeMenuRequested: boolean;};declare global {var tabCloseProbe: (stage: string) => Promise<CloseGeometry | TabContextMenuPathResult | PluginViewMenuLayerResult>;@@ -62,11 +63,25 @@ const ready = i18n.init({resources: { en: { translation: catalogs.en } },interpolation: { escapeValue: false },});+const nativeMenuRequests: WorkPanelTabMenuRequest[] = [];+const nativeMenuSelections: (WorkPanelTabMenuAction | null)[] = [];+let deferNextNativeMenu = false;+let finishNativeMenu: (() => void) | null = null;const pluginViewVisibility: boolean[] = [];window.piDesktop = {channels: IPC,platform: "darwin",invoke: async (channel, ...args) => {+ if (channel === IPC.invoke.workPanelTabMenu) {+ nativeMenuRequests.push(args[0] as WorkPanelTabMenuRequest);+ if (deferNextNativeMenu) {+ deferNextNativeMenu = false;+ return await new Promise((resolve) => {+ finishNativeMenu = () => resolve({ ok: true, data: null });+ });+ }+ return { ok: true, data: nativeMenuSelections.shift() ?? null };+ }if (channel === IPC.invoke.pluginViewSetVisible) {const payload = args[0] as { visible?: boolean } | undefined;if (typeof payload?.visible === "boolean") pluginViewVisibility.push(payload.visible);@@ -264,8 +279,11 @@ async function runTabContextMenuUserPath(): Promise<TabContextMenuPathResult> {async function runPluginViewMenuLayerPath(): Promise<PluginViewMenuLayerResult> {const tab = pluginWorkPanelTab("pi.browser", "browser");- pluginViewVisibility.length = 0;+ nativeMenuRequests.length = 0;+ deferNextNativeMenu = true;+ finishNativeMenu = null;host.style.width = "1000px";+ pluginViewVisibility.length = 0;flushSync(() => {useAppStore.setState({activeSessionId: "tab-close-plugin",@@ -303,26 +321,38 @@ async function runPluginViewMenuLayerPath(): Promise<PluginViewMenuLayerResult>clientY: 32,});flushSync(() => tabWrapper!.dispatchEvent(event));- assert(event.defaultPrevented, "Browser tab menu did not open");+ assert(event.defaultPrevented, "Browser tab did not invoke the native menu");+ assert(nativeMenuRequests.length === 1, "Browser tab did not request the native menu");+ const menuRequest = nativeMenuRequests[0];+ assert(menuRequest?.canCloseOthers === false, "native menu request has incorrect close-other state");+ const pageRemainsVisibleWhileMenuOpen = pluginViewVisibility.at(-1) === true;+ assert(pageRemainsVisibleWhileMenuOpen, "Browser page disappeared while its native menu was open");+ assert(!document.body.querySelector('[role="menu"]'), "native tab menu must not render underneath the Browser view");++ const cancelNativeMenu = finishNativeMenu;+ assert(cancelNativeMenu, "native menu test boundary did not open");+ cancelNativeMenu!();await rendered();- assert(document.body.querySelector('[role="menu"]'), "Browser tab menu is missing");- const hiddenWhileMenuOpen = pluginViewVisibility.at(-1) === false;- assert(hiddenWhileMenuOpen, "native Browser view remained above the tab menu");-- window.dispatchEvent(new KeyboardEvent("keydown", {- key: "Escape",+ const pageRemainsVisibleAfterMenuClose = pluginViewVisibility.at(-1) === true;+ assert(pageRemainsVisibleAfterMenuClose, "Browser page disappeared after cancelling its native menu");+ nativeMenuSelections.push("closeTab");+ const closeEvent = new MouseEvent("contextmenu", {bubbles: true,cancelable: true,- }));+ clientX: 32,+ clientY: 32,+ });+ flushSync(() => tabWrapper!.dispatchEvent(closeEvent));+ assert(closeEvent.defaultPrevented, "native menu action could not be reopened");await rendered();- assert(!document.body.querySelector('[role="menu"]'), "Escape did not close the Browser tab menu");- const restoredAfterMenuClose = pluginViewVisibility.at(-1) === true;- assert(restoredAfterMenuClose, "native Browser view did not return after menu close");+ assert(useAppStore.getState().workPanelTabs.length === 0, "native Close Tab action was not applied");+return {stage: "plugin-view-menu-layer",- hiddenWhileMenuOpen,- restoredAfterMenuClose,+ pageRemainsVisibleWhileMenuOpen,+ pageRemainsVisibleAfterMenuClose,+ nativeMenuRequested: nativeMenuRequests.length === 2,};}