Files
orca/tests/e2e/plugin-demo.spec.ts
T
NeilandOrca 97e4776dfe feat(plugins): Orca plugin system — kernel, content packs, panels, workers, marketplace v0 (experimental) (#8549)
* feat(plugins): Orca plugin system — kernel, content packs, panels, workers, marketplace v0 (experimental)

Adds Orca's experimental plugin system behind a settings flag: a
supervised kernel, declarative content packs (VM recipes, commands and
keybindings, language packs), sandboxed iframe panels, forked worker
hosts, and a Git-backed marketplace v0 with consent, provenance and
kill-list enforcement.

Theme, icon-theme and terminal-theme contributions are deferred to a
follow-up pass.

* fix(plugins): make unsupported marketplace listings unreachable by key

findPlugin() backs preview/install/previewInstalledUpdate via
requireListing(), so filtering only listPlugins() hid the catalog card
while leaving the dead install path reachable one click later.

* fix(plugins): fan Pi session-only status out to plugin subscribers

The providerSessionOnly early-return in applyNormalizedStatus emitted to
onAgentStatus (main-window fanout) but skipped enrichedStatusListeners, so
plugins subscribed to agent.status.changed silently missed every Pi
session_start event. Route both emit sites through one helper so a future
early return cannot drop the plugin tap again.

Co-authored-by: Orca <help@stably.ai>

* plugins: drop dead code and hoist duplicated trust-boundary patterns

Cleanup pass over the P1 diff, no behavior change:

- Delete `readPluginTreeSnapshot`/`readSnapshotFile` and their types, plus
  the now-vestigial `directories`/`signal` plumbing in `collectFiles`.
- Delete `resolveContainedPluginDirectory` (no callers).
- Delete `plugin-content-load-pool.ts`; it reimplemented the existing
  `mapWithConcurrency`, whose index arg also removes the pairing wrapper
  in `buildPluginList`.
- Hoist `PLUGIN_CONTENT_HASH_PATTERN` and `PLUGIN_COMMIT_PATTERN` into
  the install-lockfile module; 11 sites hand-rolled these identically.
- Point the new reliability gate at the PR instead of gitignored docs
  paths, matching every other gate's link form.

* fix(plugins): retry plugin state renames on Windows AV/EPERM locks

Six plugin write paths (lockfile, provenance, current pointer, kill
list, marketplace cache, staged install dir) did a plain rename, so an
antivirus or indexer holding the target open surfaced as a failed
install. The repo already retries this hazard for issue #1507, but only
through a sync helper; these paths are all async.

Adds one bounded async retry + atomic write used by all six, and trims a
consent-provenance header that restated its own JSX.

* test(plugins): cover the Windows rename retry path

The retry loop shipped untested: both existing cases hit the non-retry path,
and the temp-cleanup test passed identically with the `finally` removed.
Mock `rename` to queue errno codes so CI can exercise locks it cannot provoke.

Co-authored-by: Orca <help@stably.ai>

* fix(plugins): pin bundled plugin resources to LF

Windows CI checks out with autocrlf, so the byte-hashed launch tree arrived
as CRLF and verify-packaged-plugin-resources rejected it — the packaged build
could never pass on Windows. Reproduced locally: CRLF yields the exact CI
error, LF verifies clean. Files are already LF, so nothing renormalizes.

Co-authored-by: Orca <help@stably.ai>

* test: guard the bundled-plugin LF pin against a CRLF checkout

The byte-hash mismatch only surfaced in Windows packaging CI. Assert the
.gitattributes pin and that a CRLF tree is rejected, so a regression fails
on any platform instead of waiting for a packaged Windows build.

Co-authored-by: Orca <help@stably.ai>

* ci: trigger packaged-build check on bundled plugin resource changes

The launch tree is byte-hashed during packaging, but no trigger path covered
it — so the CRLF fix for that check would not have re-run the check. Add the
resources, verifier and .gitattributes paths that can break packaging.

Co-authored-by: Orca <help@stably.ai>

* perf(plugins): rebuild the panel frame only when its baked theme values change

The revision keys the panel iframe, so every bump destroys the sandboxed
frame and its in-panel state. It counted root attribute mutations, but
--workspace-sidebar-live-width is written every rAF of a sidebar drag, so
dragging with a panel open blanked it ~60x/sec. Compare the two values the
shell actually bakes in instead.

Co-authored-by: Orca <help@stably.ai>

* test: stop pinning a plugin name in the CRLF guard

The CRLF case rewrites every launch file, so the reported mismatch is
whichever plugin sorts first. P2 adds theme plugins that sort ahead of
orca-navigation-shortcuts, which broke the assertion there.

Co-authored-by: Orca <help@stably.ai>

* style: drop stray blank lines left by the rebase resolutions

Both sides of the agent-hooks and orca-runtime conflicts contributed a
trailing blank, which oxfmt rejects. Whitespace only.

Co-authored-by: Orca <help@stably.ai>

* test(plugins): stop the startup budget failing on machine load

P95 runs 16-34ms idle but exceeds the 50ms bound under full-suite
parallelism, so the gate flaked. Widen it to catch an order-of-magnitude
regression instead; the no-worker/no-plugin-code assertions are the real
guarantee. Verified a 400ms regression still fails.

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Orca <help@stably.ai>
2026-07-27 01:14:33 -07:00

181 lines
6.6 KiB
TypeScript

/**
* Invariant: the documented hello-orca plugin stays inert before visible
* consent, then its panel, worker command, and event subscription all work.
*/
import { cp, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import type { Page } from '@stablyai/playwright-test'
import { expect, test } from './helpers/orca-app'
async function openPluginSettings(page: Page): Promise<void> {
await page.evaluate(() => {
const state = window.__store?.getState()
if (!state) {
throw new Error('store unavailable')
}
state.openSettingsTarget({ pane: 'plugins', repoId: null })
state.openSettingsPage()
})
await expect(page.locator('[data-settings-section="plugins"]')).toBeVisible()
}
async function openDemoPanel(page: Page): Promise<void> {
await page.evaluate(() => {
const state = window.__store?.getState()
if (!state) {
throw new Error('store unavailable')
}
state.closeSettingsPage()
if (!state.rightSidebarOpen) {
state.toggleRightSidebar()
}
})
const panelButton = page.getByRole('button', { name: 'Hello Orca', exact: true })
await expect(panelButton).toBeVisible({ timeout: 15_000 })
await panelButton.click()
const frame = page.frameLocator('iframe[title="Hello Orca"]')
await expect(frame.getByRole('heading', { name: 'Hello Orca 👋' })).toBeVisible()
await expect(frame.locator('meta[http-equiv="Content-Security-Policy"]')).toHaveAttribute(
'content',
/default-src 'none'/
)
}
async function createWorktree(page: Page, name: string): Promise<string> {
await page.waitForFunction(
() => {
const state = window.__store?.getState()
return Boolean(state && Object.values(state.worktreesByRepo).flat().length > 0)
},
undefined,
{ timeout: 15_000 }
)
return page.evaluate(async (worktreeName) => {
const state = window.__store?.getState()
if (!state) {
throw new Error('store unavailable')
}
const worktrees = Object.values(state.worktreesByRepo).flat()
const active =
worktrees.find((worktree) => worktree.id === state.activeWorktreeId) ?? worktrees[0]
if (!active) {
throw new Error('active worktree was not found')
}
const result = await state.createWorktree(active.repoId, worktreeName)
return result.worktree.id
}, name)
}
test('runs hello-orca panel, command, and event behind visible consent', async ({ orcaPage }) => {
const tempRoot = await mkdtemp(join(tmpdir(), 'orca-hello-plugin-e2e-'))
const pluginRoot = join(tempRoot, 'hello-orca')
let createdWorktreeId: string | null = null
await cp(join(process.cwd(), 'examples', 'plugins', 'hello-orca'), pluginRoot, {
recursive: true
})
try {
const installed = await orcaPage.evaluate(async (sourcePath) => {
const settings = await window.api.settings.set({ pluginSystemEnabled: true })
window.__store?.setState({ settings })
const result = await window.api.plugins.install({ kind: 'local-path', path: sourcePath })
if (!result.ok) {
throw new Error(result.error)
}
const pending = (await window.api.plugins.refresh()).find(
(entry) => entry.pluginKey === result.pluginKey
)
if (!pending) {
throw new Error('installed plugin was not listed')
}
let blocked = false
try {
await window.api.plugins.invokeCommand({
pluginKey: result.pluginKey,
commandId: 'hello-ping',
args: { source: 'before-consent' }
})
} catch {
blocked = true
}
return { pluginKey: result.pluginKey, status: pending.status, blocked }
}, pluginRoot)
expect(installed.status).toBe('pending')
expect(installed.blocked).toBe(true)
await openPluginSettings(orcaPage)
const row = orcaPage.locator(`[data-plugin-key="${installed.pluginKey}"]`)
await expect(row).toContainText('Needs review')
await row.getByRole('button', { name: 'Review permissions' }).click()
const consent = orcaPage.getByRole('dialog', { name: 'Review permissions' })
await expect(consent).toBeVisible()
await expect(consent).toContainText(pluginRoot)
await expect(consent).toContainText('full access to your files, network, and other processes')
await expect(consent.getByRole('button', { name: 'Keep Disabled' })).toBeFocused()
await consent.getByRole('button', { name: 'Enable plugin' }).click()
await expect(consent).toBeHidden()
await expect(row).toContainText('Enabled')
const commandResults = await orcaPage.evaluate(async (pluginKey) => {
const first = await window.api.plugins.invokeCommand({
pluginKey,
commandId: 'hello-ping',
args: { source: 'e2e' }
})
const second = await window.api.plugins.invokeCommand({
pluginKey,
commandId: 'hello-ping',
args: { source: 'e2e' }
})
return { first, second }
}, installed.pluginKey)
expect(commandResults.first).toEqual({ pong: true, count: 1, args: { source: 'e2e' } })
expect(commandResults.second).toEqual({ pong: true, count: 2, args: { source: 'e2e' } })
await orcaPage.evaluate(async (sourcePath) => {
const settings = await window.api.settings.set({ devPluginPaths: [sourcePath] })
window.__store?.setState({ settings })
await window.api.plugins.refresh()
}, pluginRoot)
await openDemoPanel(orcaPage)
const panelPath = join(pluginRoot, 'panel.html')
const panelHtml = await readFile(panelPath, 'utf8')
await writeFile(panelPath, panelHtml.replace('Hello Orca 👋', 'Hello Orca reloaded'))
await expect(
orcaPage.frameLocator('iframe[title="Hello Orca"]').getByRole('heading', {
name: 'Hello Orca reloaded'
})
).toBeVisible({ timeout: 15_000 })
createdWorktreeId = await createWorktree(orcaPage, `plugin-event-${Date.now()}`)
await expect
.poll(
() =>
orcaPage.evaluate(
async ({ pluginKey, worktreeId }) =>
(await window.api.plugins.getLogs({ pluginKey })).some(
(entry) =>
entry.line.includes('worktree created:') && entry.line.includes(worktreeId)
),
{ pluginKey: installed.pluginKey, worktreeId: createdWorktreeId! }
),
{ timeout: 15_000 }
)
.toBe(true)
} finally {
if (createdWorktreeId) {
await orcaPage
.evaluate(async (worktreeId) => {
await window.__store?.getState().removeWorktree(worktreeId, true)
}, createdWorktreeId)
.catch(() => undefined)
}
await rm(tempRoot, { recursive: true, force: true })
}
})