import assert from 'node:assert/strict'; import test from 'node:test'; import { JSDOM } from 'jsdom'; test('terminal extension pages use actual split panes, focus and session ownership without sharing session data', async () => { const dom = new JSDOM('
', { pretendToBeVisual: true, url: 'http://localhost' }); const previous = new Map(); const install = (key: string, value: unknown) => { previous.set(key, Object.getOwnPropertyDescriptor(globalThis, key)); Object.defineProperty(globalThis, key, { configurable: true, writable: true, value }); }; for (const key of ['window', 'document', 'navigator', 'HTMLElement', 'HTMLInputElement', 'Element', 'SVGElement', 'Node', 'NodeFilter', 'MutationObserver', 'CustomEvent', 'Event', 'KeyboardEvent', 'MouseEvent']) { install(key, key === 'window' ? dom.window : dom.window[key as keyof typeof dom.window]); } install('PointerEvent', dom.window.MouseEvent); install('getComputedStyle', dom.window.getComputedStyle.bind(dom.window)); install('requestAnimationFrame', dom.window.requestAnimationFrame.bind(dom.window)); install('cancelAnimationFrame', dom.window.cancelAnimationFrame.bind(dom.window)); install('IS_REACT_ACT_ENVIRONMENT', true); const rectX = 200; dom.window.HTMLElement.prototype.getBoundingClientRect = () => new dom.window.DOMRect(rectX, 100, 400, 300); const { default: React, act, useCallback, useRef, useState } = await import('react'); const { createRoot } = await import('react-dom/client'); const { I18nProvider } = await import('../application/i18n/I18nProvider'); const { TooltipProvider } = await import('./ui/tooltip'); const { activeTabStore } = await import('../application/state/activeTabStore'); const { sidePanelLiveStore, SIDE_PANEL_INACTIVE_LIVE_SNAPSHOT } = await import('../application/state/sidePanelLiveStore'); const { useTerminalSidePanelLayoutState } = await import('../application/state/useTerminalSidePanelLayoutState'); const { usePluginTerminalSidebar } = await import('../application/state/usePluginTerminalSidebar'); const { PluginTerminalSidebarLauncher, PluginTerminalSidebarPageHost } = await import('./plugins/PluginTerminalSidebar'); const { SidePanelLayoutTree } = await import('./terminalLayer/TerminalLayerSidePanelSection'); const { PersistentSidePanelPortal } = await import('./terminalLayer/terminalLayerSidePanelSlots'); const { collectSidePanelPanes } = await import('../domain/sidePanelLayout'); type Tool = import('../domain/sidePanelLayout').SidePanelTool; let selectedSession = 'synthetic-session-a'; const getSession = () => selectedSession; const a = { id: 'com.example.sidebar.first', title: 'First page', location: 'terminal-sidebar', visible: true }; const b = { ...a, id: 'com.example.sidebar.second', title: 'Second page' }; let snapshot = { locale: 'en', plugins: [{ id: 'com.example.sidebar', displayName: 'Synthetic plugin', version: '1.0.0', commands: [], keybindings: [], menus: [], settings: [], views: [a, b] }] }; const changed = new Set<() => void>(); const opens: NetcattyPluginViewOpenRequest[] = []; Object.assign(dom.window, { netcatty: { async getPluginRuntimeStatus() { return { available: true }; }, async getPluginContributions() { return snapshot; }, onPluginContributionsChanged(fn: () => void) { changed.add(fn); return () => { changed.delete(fn); }; }, onPluginViewClosed() { return () => {}; }, onHostDrawnPluginViewUpdate() { return () => {}; }, async openHostDrawnPluginView(payload: NetcattyPluginViewOpenRequest) { opens.push(payload); return { instanceId: payload.instanceId! }; }, async closeHostDrawnPluginView() {}, } }); let split!: () => void; function Fixture() { const state = useTerminalSidePanelLayoutState(); const latest = useRef(state); latest.current = state; const model = usePluginTerminalSidebar({ layouts: state.sidePanelLayouts, getSession, isTerminalTab: (id) => id === 'workspace-synthetic' || id === 'synthetic-local-terminal', select: (tool) => state.selectSidePanelToolForTab(activeTabStore.getActiveTabId(), tool), withdraw: (tabId, paneId, tool) => { const layout = state.sidePanelLayoutsRef.current.get(tabId); if (layout && collectSidePanelPanes(layout.root).some((pane) => pane.id === paneId && pane.tool === tool)) state.closePane(tabId, paneId); } }); const [hosts, setHosts] = useState(new Map()); const parking = useRef(null); const register = useCallback((tool: Tool, host: HTMLElement | null) => setHosts((prior) => { if ((prior.get(tool) ?? null) === host) return prior; const next = new Map(prior); if (host) next.set(tool, host); else next.delete(tool); return next; }), []); const focusPane = useCallback((id: string) => latest.current.focusPane(activeTabStore.getActiveTabId(), id), []); const closePane = useCallback((id: string) => { latest.current.closePane(activeTabStore.getActiveTabId(), id); }, []); const resize = useCallback(() => {}, []); const layout = model.tabId ? state.sidePanelLayouts.get(model.tabId) : null; const panes = layout ? collectSidePanelPanes(layout.root) : []; split = () => state.splitPane('workspace-synthetic', `plugin-view:${b.id}`, 'vertical', { paneId: 'second-pane', splitId: 'plugin-split' }, 600); return <> {layout && [page.tool, page.title]))} onClose={closePane} onFocus={focusPane} onHostChange={register} onResize={resize} separator="#777" accent="#4488cc" closePaneLabel="Close pane" resizeLabel="Resize" />}