test: remove low-value plugin frame and wrapper suites

This commit is contained in:
OrcaWin
2026-11-12 14:21:54 -08:00
parent 5bf95d06b5
commit 3eab6dae72
8 changed files with 3 additions and 282 deletions
@@ -6607,10 +6607,7 @@
"src/shared/plugins/declarative/testing/testing-editor-host.test.ts": 197,
"src/shared/plugins/frames/plugin-frame-document-session.test.ts": 404,
"src/shared/plugins/frames/plugin-frame-document.test.ts": 426,
"src/shared/plugins/frames/plugin-frame-facades.test.ts": 383,
"src/shared/plugins/frames/plugin-frame-guest.test.ts": 50,
"src/shared/plugins/frames/plugin-panel-call-admission.test.ts": 89,
"src/shared/plugins/frames/plugin-panel-message-budget.test.ts": 99,
"src/shared/plugins/frames/plugin-panel-shell.test.ts": 376,
"src/shared/plugins/images/plugin-image-format.test.ts": 104,
"src/shared/plugins/images/plugin-image-url.test.ts": 42,
@@ -50,18 +50,6 @@ afterEach(() => {
})
describe('orca.document.session', () => {
it('answers editor.flush only once the change it posted is accepted', async () => {
const { session, fromHost, posted } = await open()
session.change('b')
const flushRequest = { orca: 1, kind: 'req', id: 9, method: 'editor.flush' }
fromHost(flushRequest)
await settle()
expect(posted().at(-1)).toMatchObject({ method: 'editor.applyEdit' })
fromHost(accept(0))
await settle()
expect(posted().at(-1)).toEqual({ orca: 1, kind: 'res', id: 9, result: null })
})
it('keeps one edit in flight through a save, so the baseline never goes back', async () => {
const { orca, session, fromHost, edits, posted } = await open({ debounceMs: 0 })
session.change('a1')
@@ -1,7 +1,7 @@
// @vitest-environment happy-dom
import { describe, expect, it, vi } from 'vitest'
import { flush, mountShell } from './plugin-frame-shell-mount.test-fixture'
import { describe, expect, it } from 'vitest'
import { mountShell } from './plugin-frame-shell-mount.test-fixture'
const doc = (version: number, text: string) => ({
orca: 1,
@@ -80,40 +80,4 @@ describe('orca.document.get after applyEdit', () => {
content: text('outside')
})
})
it('does not report an accepted edit as a change', async () => {
const { orca, fromHost } = mountShell('editor')
fromHost(doc(1, 'a'))
const changes = vi.fn()
orca.document!.onDidChange(changes)
await flush()
const applied = orca.document!.applyEdit({ baseVersion: 1, content: text('b') })
fromHost(answer(0))
await applied
expect(changes).toHaveBeenCalledTimes(1)
})
})
describe('orca.document.onDidChange replay', () => {
it('skips the replay for a subscription disposed before it runs', async () => {
const { orca, fromHost } = mountShell('editor')
fromHost(doc(1, 'a'))
const changes = vi.fn()
orca.document!.onDidChange(changes).dispose()
await flush()
fromHost(doc(2, 'b'))
expect(changes).not.toHaveBeenCalled()
})
it('replays to subscriptions still live', async () => {
const { orca, fromHost } = mountShell('editor')
fromHost(doc(1, 'a'))
const kept = vi.fn()
const dropped = vi.fn()
orca.document!.onDidChange(kept)
orca.document!.onDidChange(dropped).dispose()
await flush()
expect(kept).toHaveBeenCalledWith(expect.objectContaining({ version: 1 }))
expect(dropped).not.toHaveBeenCalled()
})
})
@@ -1,77 +0,0 @@
// @vitest-environment happy-dom
import { afterEach, describe, expect, it, vi } from 'vitest'
import { buildPluginPanelShellHtml } from './plugin-panel-shell'
type Disposable = { dispose: () => void }
type FrameOrca = {
on: (event: string, handler: (payload: unknown) => unknown) => Disposable
plugin: {
request: (name: string, input?: unknown, options?: { timeoutMs?: number }) => Promise<unknown>
on: (event: string, handler: (payload: unknown) => unknown) => Disposable
}
storage: {
get: (key: string) => Promise<unknown>
set: (key: string, value: unknown) => Promise<void>
onDidChange: (handler: (change: { key: string }) => void) => Disposable
}
settings: { get: (key?: string) => Promise<unknown> }
}
const realParent = window.parent
afterEach(() => {
Object.defineProperty(window, 'parent', { value: realParent, configurable: true })
})
function mountShell() {
const parent = { postMessage: vi.fn() }
Object.defineProperty(window, 'parent', { value: parent, configurable: true })
const script = buildPluginPanelShellHtml('<main></main>').match(
/<script>\n([\s\S]*?)<\/script>/
)?.[1]
window.eval(script!.replaceAll('configurable: false', 'configurable: true'))
const orca: FrameOrca = Object.getOwnPropertyDescriptor(window, 'orca')?.value
const fromHost = (data: unknown) =>
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the shim only compares source identity.
window.dispatchEvent(new MessageEvent('message', { data, source: parent as never as Window }))
const requests = () =>
parent.postMessage.mock.calls
.map(([message]) => message)
.filter((message) => message.kind === 'req')
const answer = (id: number, result: unknown) => fromHost({ orca: 1, kind: 'res', id, result })
const push = (payload: unknown) =>
fromHost({ orca: 1, kind: 'evt', event: 'plugin.push', payload })
return { orca, requests, answer, push }
}
describe('window.orca.plugin', () => {
it('asks the worker through plugin.request and resolves with its output', async () => {
const { orca, requests, answer } = mountShell()
const todos = orca.plugin.request('todos.list', { done: false }, { timeoutMs: 999_999 })
const [sent] = requests()
expect(sent).toMatchObject({
method: 'plugin.request',
params: { name: 'todos.list', input: { done: false }, timeoutMs: 120_000 }
})
answer(sent.id, { output: [{ id: '1' }] })
await expect(todos).resolves.toEqual([{ id: '1' }])
})
})
describe('window.orca events and data', () => {
it('subscribes to a workspace or agent event once, on the first listener', () => {
const { orca, requests, push } = mountShell()
const first = vi.fn()
orca.on('agent.status.changed', first)
orca.on('agent.status.changed', vi.fn())
orca.on('theme', vi.fn())
expect(requests()).toEqual([
expect.objectContaining({
method: 'events.subscribe',
params: { event: 'agent.status.changed' }
})
])
push({ kind: 'event', event: 'agent.status.changed', payload: { state: 'done' } })
expect(first).toHaveBeenCalledWith({ state: 'done' })
})
})
@@ -1,64 +0,0 @@
import { describe, expect, it } from 'vitest'
import {
isPluginFrameOriginUrl,
parsePluginFrameUrl,
pluginFrameKey,
pluginFramePartition,
readPluginFramePartitionKey
} from './plugin-frame-guest'
const KEY = pluginFrameKey('acme.charts')
describe('plugin frame guest identity', () => {
it('round-trips the partition and refuses look-alikes', () => {
expect(pluginFramePartition(KEY)).toBe(`persist:orca-plugin-${KEY}`)
expect(readPluginFramePartitionKey(pluginFramePartition(KEY))).toBe(KEY)
expect(readPluginFramePartitionKey(`persist:orca-plugin-${KEY}x`)).toBeNull()
expect(readPluginFramePartitionKey(`orca-plugin-${KEY}`)).toBeNull()
expect(readPluginFramePartitionKey('persist:orca-plugin-../../x')).toBeNull()
})
})
describe('plugin frame URLs', () => {
it('parses contained paths into decoded segments', () => {
expect(parsePluginFrameUrl(`orca-plugin-frame://${KEY}/ui/app.js?v=1`)).toEqual({
frameKey: KEY,
segments: ['ui', 'app.js'],
reserved: false
})
expect(parsePluginFrameUrl(`orca-plugin-frame://${KEY}/a%20b/x.wasm`)?.segments).toEqual([
'a b',
'x.wasm'
])
expect(parsePluginFrameUrl(`orca-plugin-frame://${KEY}/__orca/sdk.js`)?.reserved).toBe(true)
expect(parsePluginFrameUrl(`orca-plugin-frame://${KEY}/__ORCA/sdk.js`)?.reserved).toBe(true)
expect(parsePluginFrameUrl(`orca-plugin-frame://${KEY}/__Orca/sdk.js`)?.reserved).toBe(true)
})
it.each([
`orca-plugin-frame://${KEY}/`,
`orca-plugin-frame://${KEY}/..%2Fsecret`,
`orca-plugin-frame://${KEY}/a%5C..%5Cb`,
`orca-plugin-frame://${KEY}/a%00b`,
`orca-plugin-frame://${KEY}/__orca./runtime.mjs`,
`orca-plugin-frame://${KEY}/__orca%20/runtime.mjs`,
`orca-plugin-frame://${KEY}/panel.html.`,
`orca-plugin-frame://${KEY}/C:%5Cwindows`,
`orca-plugin-frame://${KEY}/bad%E0%A4%A`,
`orca-plugin-frame://${KEY}:8080/x`,
`orca-plugin-frame://user@${KEY}/x`,
'orca-plugin-frame://NOTAKEY/x',
`https://${KEY}/x`
])('refuses %s', (url) => {
expect(parsePluginFrameUrl(url)).toBeNull()
})
it('matches only the exact plugin origin', () => {
expect(isPluginFrameOriginUrl(`orca-plugin-frame://${KEY}/x.html`, KEY)).toBe(true)
expect(isPluginFrameOriginUrl(`orca-plugin-frame://${pluginFrameKey('a.b')}/x`, KEY)).toBe(
false
)
expect(isPluginFrameOriginUrl(`blob:orca-plugin-frame://${KEY}/uuid`, KEY)).toBe(false)
expect(isPluginFrameOriginUrl('not a url', KEY)).toBe(false)
})
})
@@ -1,12 +0,0 @@
import { describe, expect, it } from 'vitest'
import { structuredCloneMessageBytes } from './plugin-panel-message-budget'
describe('structuredCloneMessageBytes', () => {
it('counts binary backing stores instead of JSON object projections', () => {
const buffer = new ArrayBuffer(128)
const tinyView = new Uint8Array(buffer, 0, 1)
expect(structuredCloneMessageBytes(tinyView, 256)).toBeGreaterThanOrEqual(128)
expect(structuredCloneMessageBytes(new Blob([new Uint8Array(80)]), 256)).toBe(80)
})
})
@@ -1,47 +1,9 @@
// @vitest-environment happy-dom
import { describe, expect, it } from 'vitest'
import { buildPluginGuestShellHtml, buildPluginPanelShellHtml } from './plugin-panel-shell'
import { buildPluginPanelShellHtml } from './plugin-panel-shell'
describe('buildPluginPanelShellHtml', () => {
it('removes WebRTC peer connections before plugin code can reach them', () => {
const html = buildPluginPanelShellHtml('<main>Plugin</main>')
const script = html.match(/<script>\n([\s\S]*?)<\/script>/)?.[1]
Object.assign(window, { RTCPeerConnection: class {}, webkitRTCPeerConnection: class {} })
// Configurable only so happy-dom can tear down; the iframe copy stays locked.
window.eval(script!.replaceAll('configurable: false', 'configurable: true'))
expect(window.eval('typeof RTCPeerConnection')).toBe('undefined')
expect(window.eval('typeof webkitRTCPeerConnection')).toBe('undefined')
window.eval('RTCPeerConnection = function () {}')
expect(window.eval('typeof RTCPeerConnection')).toBe('undefined')
})
it('cancels anchor and form default navigation in the fallback path', () => {
const html = buildPluginPanelShellHtml('<main>Plugin</main>')
const script = html.match(/<script>\n([\s\S]*?)<\/script>/)?.[1]
expect(script).toBeTruthy()
// Keep happy-dom's global removable for Vitest teardown; production shell
// keeps the override non-configurable inside the disposable iframe.
window.eval(script!.replaceAll('configurable: false', 'configurable: true'))
const anchor = document.createElement('a')
anchor.href = 'https://example.com/'
document.body.appendChild(anchor)
const clickAccepted = anchor.dispatchEvent(
new MouseEvent('click', { bubbles: true, cancelable: true })
)
const form = document.createElement('form')
document.body.appendChild(form)
const submitAccepted = form.dispatchEvent(
new Event('submit', { bubbles: true, cancelable: true })
)
expect(clickAccepted).toBe(false)
expect(submitAccepted).toBe(false)
expect(window.open('https://example.com/')).toBeNull()
})
it('applies a theme message from the host in place, and only from the host', () => {
const html = buildPluginPanelShellHtml('<main>Plugin</main>')
const script = html.match(/<script>\n([\s\S]*?)<\/script>/)?.[1]
@@ -76,17 +38,3 @@ describe('buildPluginPanelShellHtml', () => {
style.remove()
})
})
describe('buildPluginGuestShellHtml', () => {
it('paints the host theme before any script, so boot-time token reads get values', () => {
const html = buildPluginGuestShellHtml('<main></main>', 'panel', {
theme: { colorScheme: 'dark', tokens: '--orca-background:#000;}</style><script>x' }
})
expect(html).toMatch(/^<!doctype html>\n<html class="dark">/)
expect(html).toContain(
'<style id="orca-design-tokens">:root{--orca-background:#000;/stylescriptx}</style>'
)
expect(html.indexOf('orca-design-tokens')).toBeLessThan(html.indexOf('<script>'))
expect(buildPluginGuestShellHtml('<main></main>')).toContain('<html>\n')
})
})
@@ -1,23 +0,0 @@
import { describe, expect, it } from 'vitest'
import { classifyPluginGitAccessFailure } from './plugin-git-access-failure'
const HOST = 'the Orca host (build-box)'
describe('classifyPluginGitAccessFailure', () => {
it('leaves other failures alone and strips credentials from the detail', () => {
expect(
classifyPluginGitAccessFailure({
error: 'fatal: unable to access: Could not resolve host: github.com',
url: 'https://github.com/acme/notes',
executionHost: HOST
})
).toBeNull()
expect(
classifyPluginGitAccessFailure({
error: "fatal: Authentication failed for 'https://user:tok3n@github.com/acme/notes'",
url: 'https://github.com/acme/notes',
executionHost: HOST
})?.detail
).not.toContain('tok3n')
})
})