// @vitest-environment happy-dom import { readFileSync } from 'node:fs' import { join } from 'node:path' import { afterEach, describe, expect, it, vi } from 'vitest' import { buildPluginGuestShellHtml, buildPluginPanelShellHtml, type PluginFrameSurface } from './plugin-panel-shell' /** The injected `window.orca` is the public frame API; the envelope under it stays internal. */ type FrameOrca = { api: { major: number; minor: number } host: { call: (method: string, params?: unknown, options?: { signal?: AbortSignal }) => Promise has: (method: string) => boolean } on: (event: string, handler: (payload: unknown) => unknown) => { dispose: () => void } locale: string plugin: object storage: object shell?: { openExternal: (url: string) => Promise } files?: { saveAs: (options: { suggestedName?: string mimeType?: string data: unknown }) => Promise } document?: { get: () => Promise onDidChange: (handler: (document: unknown) => void) => { dispose: () => void } applyEdit: (edit: unknown) => Promise } } const realParent = window.parent afterEach(() => { Object.defineProperty(window, 'parent', { value: realParent, configurable: true }) }) function mountShell(surface: PluginFrameSurface = 'panel') { const parent = { postMessage: vi.fn() } Object.defineProperty(window, 'parent', { value: parent, configurable: true }) const script = buildPluginPanelShellHtml('
', surface).match( /