Files
orca/src/cli/plugin-dev-watch/plugin-dev-watch-check.ts
T
Neil fa7c3f95fe feat(plugins): check custom editors and test them with mockEditorHost (#37293)
* feat(plugins): check custom editors statically and add mockEditorHost

orca plugin check now follows each custom editor entry (local script src,
inline module scripts, relative imports), transpiled and resolved as the
frame loader does, and fails at file:line:column on syntax errors, missing
files, refused imports, string eval/Function and files over their size
cap, with no running Orca. The check ships in the test hooks bundle.

orca/testing gains mockEditorHost: it runs the frame shell's real
window.orca (document API and session) over an in-memory text or bytes
file, with edits, replace, conflictNext, flush, setTheme and dispose.
Typings, docs and the skill guide cover both.

* feat(plugins): warn on editor eval and check editors in dev watch

editor_eval comes from a lexical scan that can misread rare code, so it is
now a warning that does not fail orca plugin check. dev watch --check runs
the editor check beside the panel check and reports it under editors.

* fix(plugins): check editors by the frame protocol's rules; mock blocks lost saves

The static editor check now reads files through the loader's contained
reader (symlinks out of the plugin are refused), runs only JavaScript
script types, honors the page's import map for native modules, classifies
files by the protocol's content types (JSON imports, extensionless HTML
entries), decodes escaped script URLs, and uses the protocol's caps: 10 MiB
entry, 1 MiB transpiled module, 16 MiB checked dependency.

mockEditorHost refuses an oversized edit before reading it and then rejects
flush() until a later edit lands, as Orca blocks the save.

* test(plugins): type mockEditorHost's frame API instead of reflecting on it

* fix(plugins): keep main's case-spelling check and hook typings through the rebase

The rebase onto main resolved plugin-artifact-validation.ts and
orca-testing.d.ts to B4's side; this puts back main's exact-path-spelling
check and hooks typings beside B4's contained reader and mockEditorHost
types, and regenerates the testing bundle.
2026-11-01 21:28:13 -08:00

61 lines
1.9 KiB
TypeScript

import { validatePluginTarget } from '../plugin-authoring/plugin-folder-validation'
import { checkPluginPanels, type PluginPanelCheck } from '../plugin-authoring/plugin-panel-check'
import { checkPluginEditors, type PluginEditorCheck } from '../plugin-authoring/plugin-editor-check'
/** `orca plugin check` for one folder, as data: validation errors, else each panel's render. */
export type PluginDevWatchCheckResult = {
ok: boolean
/** Manifest problems; panels are not rendered while there are any. */
invalid: string[]
panels: PluginPanelCheck[]
/** Each custom editor's static check. */
editors: PluginEditorCheck[]
}
export async function checkPluginDevFolder(dir: string): Promise<PluginDevWatchCheckResult> {
const report = await validatePluginTarget(dir)
if (!report.valid) {
return { ok: false, invalid: report.errors, panels: [], editors: [] }
}
const [rendered, editors] = await Promise.all([
checkPluginPanels(report.path),
checkPluginEditors(report.path)
])
// Why no tree: a watch prints one line per save; the summary says what drew.
const panels = rendered.map(({ tree: _tree, ...panel }) => panel)
const ok = [...panels, ...editors].every((check) => check.issues.length === 0)
return { ok, invalid: [], panels, editors }
}
/** Runs checks one at a time: a request while one runs queues a single rerun of the newest code. */
export function createPluginDevWatchCheckQueue(run: () => Promise<void>): {
request(): void
idle(): Promise<void>
} {
let running: Promise<void> | null = null
let again = false
const start = (): void => {
running = run().finally(() => {
running = null
if (again) {
again = false
start()
}
})
}
return {
request: () => {
if (running) {
again = true
return
}
start()
},
idle: async () => {
while (running) {
await running
}
}
}
}