diff --git a/src/shared/plugins/approval/plugin-consent-fingerprint.test.ts b/src/shared/plugins/approval/plugin-consent-fingerprint.test.ts index 391b82feaa8..58763c2ed4b 100644 --- a/src/shared/plugins/approval/plugin-consent-fingerprint.test.ts +++ b/src/shared/plugins/approval/plugin-consent-fingerprint.test.ts @@ -1,134 +1,10 @@ import { describe, expect, it } from 'vitest' -import type { PluginCapability } from '../capabilities/plugin-capabilities' -import { fingerprintPluginConsent } from './plugin-consent-fingerprint' -import { - getPluginActivationState, - needsReconsent, - normalizePluginConsents -} from './plugin-consent-state' import { parsePluginLockfile, serializePluginLockfile, type PluginLockfile } from '../installation/plugin-install-lockfile' -const storage: PluginCapability = { kind: 'storage:own' } - -describe('fingerprintPluginConsent', () => { - it('drops malformed persisted consent identities and oversized fingerprints', () => { - expect( - normalizePluginConsents({ - __proto__: 'polluted', - constructor: 'polluted', - invalid: 'sha256-invalid', - 'samples.demo': 'sha256-valid', - 'samples.large': 'x'.repeat(257) - }) - ).toEqual({ 'samples.demo': 'sha256-valid' }) - }) - - it('changes when a panel-only plugin gains a trusted Node worker', () => { - const panelOnly = fingerprintPluginConsent({ main: undefined, capabilities: [] }) - const withWorker = fingerprintPluginConsent({ main: 'worker.js', capabilities: [] }) - - expect(withWorker).not.toBe(panelOnly) - const lists = { - pluginConsents: { 'samples.demo': panelOnly }, - disabledPlugins: [] - } - expect(getPluginActivationState('samples.demo', withWorker, lists)).toBe('pending') - expect(needsReconsent('samples.demo', withWorker, lists)).toBe(true) - }) - - it('requires re-consent when declarative content bytes change', () => { - const subject = { - main: undefined, - capabilities: [], - contributes: { - keybindings: [], - vmRecipes: [{ path: 'recipes/cloud.json' }], - agentHarnesses: [] - } - } - const first = fingerprintPluginConsent(subject, 'a'.repeat(64)) - const second = fingerprintPluginConsent(subject, 'b'.repeat(64)) - - expect(second).not.toBe(first) - expect( - getPluginActivationState('samples.recipes', second, { - pluginConsents: { 'samples.recipes': first }, - disabledPlugins: [] - }) - ).toBe('pending') - }) - - it.each([ - ['a v2 panel', { execution: 'sandboxed-ui' as const, capabilities: [] }], - ['a v2 worker', { execution: 'trusted-worker' as const, main: 'worker.js', capabilities: [] }], - ['a v1 worker', { main: 'worker.js', capabilities: [] }], - [ - 'a v1 panel', - { capabilities: [], contributes: { panels: [{ id: 'p', title: 'P', entry: 'p.html' }] } } - ] - ])('binds %s approval to exact package bytes', (_label, subject) => { - const approved = fingerprintPluginConsent(subject, 'a'.repeat(64)) - const updated = fingerprintPluginConsent(subject, 'b'.repeat(64)) - - expect(updated).not.toBe(approved) - expect( - needsReconsent('samples.demo', updated, { - pluginConsents: { 'samples.demo': approved }, - disabledPlugins: [] - }) - ).toBe(true) - }) - - it('requires re-approval when an update adds a capability', () => { - const lists = (approved: string) => ({ - pluginConsents: { 'samples.demo': approved }, - disabledPlugins: [] - }) - for (const execution of ['data', 'sandboxed-ui', 'trusted-worker'] as const) { - const main = execution === 'trusted-worker' ? 'worker.js' : undefined - const approved = fingerprintPluginConsent( - { execution, main, capabilities: [] }, - 'a'.repeat(64) - ) - const updated = fingerprintPluginConsent( - { execution, main, capabilities: [storage] }, - 'a'.repeat(64) - ) - expect(needsReconsent('samples.demo', updated, lists(approved)), execution).toBe(true) - } - }) - - it('requires re-approval whenever an update changes the execution profile', () => { - const profiles = ['data', 'declarative', 'sandboxed-ui', 'trusted-worker'] as const - const fingerprintFor = (execution: (typeof profiles)[number]) => - fingerprintPluginConsent( - { - execution, - main: execution === 'trusted-worker' ? 'worker.js' : undefined, - capabilities: [], - // Alias commands only: nothing that binds bytes, so only the profile differs. - contributes: {} - }, - 'a'.repeat(64) - ) - for (const from of profiles) { - for (const to of profiles.filter((profile) => profile !== from)) { - expect( - needsReconsent('samples.demo', fingerprintFor(to), { - pluginConsents: { 'samples.demo': fingerprintFor(from) }, - disabledPlugins: [] - }), - `${from} -> ${to}` - ).toBe(true) - } - } - }) -}) - describe('plugin install lockfile consent fingerprints', () => { const persistedEntry = { pluginKey: 'samples.demo', @@ -174,15 +50,4 @@ describe('plugin install lockfile consent fingerprints', () => { ] ).not.toHaveProperty('consentFingerprint') }) - - it('drops a lockfile whose record key disagrees with its embedded identity', () => { - const parsed = parsePluginLockfile({ - version: 1, - plugins: { - 'samples.other': persistedEntry - } - }) - - expect(parsed.plugins).toEqual({}) - }) }) diff --git a/src/shared/plugins/declarative/plugin-declarative-catalog-rich.test.ts b/src/shared/plugins/declarative/plugin-declarative-catalog-rich.test.ts index b9b188efd0a..116c32b85f2 100644 --- a/src/shared/plugins/declarative/plugin-declarative-catalog-rich.test.ts +++ b/src/shared/plugins/declarative/plugin-declarative-catalog-rich.test.ts @@ -1,5 +1,4 @@ import { describe, expect, it } from 'vitest' -import { isPluginDeclarativeImagePath } from './plugin-declarative-content-props' import { PLUGIN_DECLARATIVE_LIMITS as LIMITS } from './plugin-declarative-limits' import { parsePluginDeclarativeTree } from './plugin-declarative-tree' @@ -12,21 +11,6 @@ const parse = (raw: unknown) => parsePluginDeclarativeTree(raw) const columns = [{ key: 'name', label: 'Name', sortable: true }] describe('catalog 2 components', () => { - it('keeps Tab inside Tabs and Tabs holding only Tab', () => { - expect(parse(node('Stack', {}, [node('Tab', { value: 'a', label: 'A' })]))).toMatchObject({ - ok: false, - error: expect.stringContaining('Tab must be a direct child of Tabs') - }) - expect(parse(node('Tabs', { label: 'T' }, [node('Text', {}, ['loose'])]))).toMatchObject({ - ok: false, - error: expect.stringContaining('Tabs holds only Tab') - }) - expect(parse(node('Tabs', { label: 'T' }, ['text']))).toMatchObject({ ok: false }) - expect(parse(node('List', {}, [node('Tab', { value: 'a', label: 'A' })]))).toMatchObject({ - ok: false - }) - }) - it('draws a placeholder for a Table or Tree with unusable data, and keeps the rest', () => { const duplicateRows = node('Table', { label: 'T', @@ -56,26 +40,4 @@ describe('catalog 2 components', () => { ) } }) - - it('takes only image files inside the plugin', () => { - for (const path of ['logo.png', 'assets/icons/a.WEBP', 'img/photo.jpeg']) { - expect({ path, ok: isPluginDeclarativeImagePath(path) }).toEqual({ path, ok: true }) - } - for (const path of [ - 'https://example.com/a.png', - 'data:image/png;base64,AAAA.png', - '/etc/a.png', - '../a.png', - 'assets/../../a.png', - './a.png', - 'a\\b.png', - 'a.png?x=1.png', - 'notes.txt', - 'logo.svg', - 'anim.gif', - 'assets//a.png' - ]) { - expect({ path, ok: isPluginDeclarativeImagePath(path) }).toEqual({ path, ok: false }) - } - }) }) diff --git a/src/shared/plugins/declarative/plugin-declarative-example.test.ts b/src/shared/plugins/declarative/plugin-declarative-example.test.ts index 97f0e0033d9..b3c1808ebeb 100644 --- a/src/shared/plugins/declarative/plugin-declarative-example.test.ts +++ b/src/shared/plugins/declarative/plugin-declarative-example.test.ts @@ -3,7 +3,6 @@ import { tmpdir } from 'node:os' import path from 'node:path' import { pathToFileURL } from 'node:url' import { afterAll, expect, it } from 'vitest' -import { pluginDeclarativeRenderPayloadSchema } from './plugin-declarative-messages' import { parsePluginDeclarativeTree } from './plugin-declarative-tree' const ROOT = path.resolve(import.meta.dirname, '..', '..', '..', '..') @@ -78,26 +77,3 @@ it('runs the prebuilt sample against the shipped guest runtime, like the guest i ]) runtime.dispose() }) - -// A missing named import is a link-time SyntaxError in real ES modules (checked with node); the -// test runner's module shim cannot show that, so this covers the documented fallback only. -it('draws a component created by name with h() as a placeholder when Orca does not know it', async () => { - const runtimeCopy = path.join(scratch, 'orca-runtime-compat.mjs') - writeFileSync(runtimeCopy, readFileSync(RUNTIME)) - const orca = await import(/* @vite-ignore */ pathToFileURL(runtimeCopy).href) - const posted: unknown[] = [] - const runtime = orca.installOrcaDeclarativeRuntime({ - post: (_event: string, payload: unknown) => posted.push(payload), - bridge: null - }) - expect(orca.ui.catalog).toBeGreaterThanOrEqual(1) - expect(orca.ui.has('Carousel')).toBe(false) - runtime.mount(() => orca.h('Stack', null, orca.h('Carousel', { label: 'Shots' }), 'rest')) - const tree = parsePluginDeclarativeTree( - pluginDeclarativeRenderPayloadSchema.parse(posted.at(-1)).tree - ) - expect(tree.ok && tree.tree?.children).toEqual([ - { type: 'Unsupported', key: '#0', props: { name: 'Carousel' }, children: [] }, - 'rest' - ]) -}) diff --git a/src/shared/plugins/declarative/plugin-declarative-tree.test.ts b/src/shared/plugins/declarative/plugin-declarative-tree.test.ts index c82be4688ed..79c8c6f9d88 100644 --- a/src/shared/plugins/declarative/plugin-declarative-tree.test.ts +++ b/src/shared/plugins/declarative/plugin-declarative-tree.test.ts @@ -1,9 +1,4 @@ import { describe, expect, it } from 'vitest' -import { PLUGIN_DECLARATIVE_LIMITS } from './plugin-declarative-limits' -import { - parsePluginDeclarativeRender, - pluginDeclarativeEventPayloadSchema -} from './plugin-declarative-messages' import { parsePluginDeclarativeTree } from './plugin-declarative-tree' const node = (type: string, props: Record = {}, children: unknown[] = []) => ({ @@ -12,11 +7,6 @@ const node = (type: string, props: Record = {}, children: unkno children }) -function errorOf(tree: unknown): string { - const result = parsePluginDeclarativeTree(tree) - return result.ok ? '' : result.error -} - describe('parsePluginDeclarativeTree', () => { it('drops unknown props and enum values with a warning instead of refusing', () => { const result = parsePluginDeclarativeTree( @@ -52,98 +42,9 @@ describe('parsePluginDeclarativeTree', () => { { type: 'Unsupported', props: { name: 'Input' }, children: [] } ]) }) - - it.each([ - ['a DOM tag', node('div'), /invalid component name/], - ['a prototype-named component', node('constructor'), /invalid component name/], - ['an unknown node field', { ...node('Stack'), style: {} }, /unknown node field/], - ['text in a leaf', node('Separator', {}, ['x']), /does not accept text/], - ['a block inside Text', node('Text', {}, [node('Stack')]), /accepts only text, Text/], - ['a node inside Button', node('Button', {}, [node('Text')]), /accepts only text/], - ['a stray ListItem', node('Stack', {}, [node('ListItem')]), /ListItem/], - ['a non-item in List', node('List', {}, [node('Text')]), /ListItem/], - [ - 'duplicate sibling keys', - node('Stack', {}, [ - { ...node('Text'), key: 'k' }, - { ...node('Text'), key: 'k' } - ]), - /duplicate key "k"/ - ], - [ - 'a control inside a pressable ListItem', - node('List', {}, [ - node('ListItem', { onPress: { $callback: 'c1' } }, [ - node('Button', { onPress: { $callback: 'c2' } }, ['x']) - ]) - ]), - /cannot contain a Button/ - ], - ['a text root', 'hello', /root/], - ['a non-finite number', node('Text', {}, [Number.NaN]), /finite/] - ])('rejects %s', (_label, tree, message) => { - expect(errorOf(tree)).toMatch(message) - }) - - it('caps depth without recursing', () => { - let tree = node('Text') - for (let depth = 0; depth < 10_000; depth++) { - tree = node('Stack', {}, [tree]) - } - expect(errorOf(tree)).toMatch(/deeper than 64/) - }) - - it('caps node count and total bytes', () => { - const many = node( - 'Stack', - {}, - Array.from({ length: PLUGIN_DECLARATIVE_LIMITS.maxNodes }, () => - node('Spinner', { label: 'x' }) - ) - ) - expect(errorOf(many)).toMatch(/more than 5000 nodes/) - const text = 'x'.repeat(PLUGIN_DECLARATIVE_LIMITS.maxTextLength) - const heavy = node( - 'Stack', - {}, - Array.from({ length: 40 }, () => node('Text', {}, [text])) - ) - expect(errorOf(heavy)).toMatch(/exceeds/) - }) }) describe('ui.* payloads', () => { - it('validates render payloads through the tree parser, keeping the revision', () => { - expect( - parsePluginDeclarativeRender({ - document: 'd1', - revision: 3, - tree: node('Spinner', { label: 'x' }) - }) - ).toMatchObject({ ok: true, document: 'd1', revision: 3 }) - expect( - parsePluginDeclarativeRender({ document: 'd1', revision: 3, tree: node('marquee') }) - ).toMatchObject({ ok: false, document: 'd1', revision: 3 }) - expect(parsePluginDeclarativeRender({ revision: 1, tree: null })).toMatchObject({ - ok: false, - revision: null - }) - }) - - it('accepts plain JSON event args: scalars, scalar lists and one flat object', () => { - const base = { document: 'd1', revision: 1, callback: '1.0' } - const accepts = (args: unknown[]): boolean => - pluginDeclarativeEventPayloadSchema.safeParse({ ...base, args }).success - expect(accepts(['a', 1, true, null])).toBe(true) - expect(accepts([['a', 'b'], { keys: ['a'] }, { column: 'name', direction: 'asc' }])).toBe(true) - expect(accepts([{ nested: { deeper: 1 } }])).toBe(false) - expect(accepts([[['nested']]])).toBe(false) - expect(accepts([Number.NaN])).toBe(false) - expect( - pluginDeclarativeEventPayloadSchema.safeParse({ ...base, args: [], extra: 1 }).success - ).toBe(false) - }) - it('counts text children toward the node cap and charges each one', () => { const many = (count: number) => ({ type: 'Text', diff --git a/src/shared/plugins/view/plugin-editor-shot-acts.test.ts b/src/shared/plugins/view/plugin-editor-shot-acts.test.ts index c8d944b1072..213d116d362 100644 --- a/src/shared/plugins/view/plugin-editor-shot-acts.test.ts +++ b/src/shared/plugins/view/plugin-editor-shot-acts.test.ts @@ -1,39 +1,7 @@ import { describe, expect, it } from 'vitest' -import { parsePluginEditorShotActs, pluginEditorActInputEvents } from './plugin-editor-shot-acts' +import { pluginEditorActInputEvents } from './plugin-editor-shot-acts' describe('editor shot --act', () => { - it('reads clicks, drags and keys, and names the first bad act', () => { - expect( - parsePluginEditorShotActs( - '[{"click":[200,150]},{"drag":[[200,150],[400,300]]},{"key":"r"},{"key":"z","modifiers":["meta"]}]' - ) - ).toEqual({ - ok: true, - acts: [ - { click: [200, 150] }, - { - drag: [ - [200, 150], - [400, 300] - ] - }, - { key: 'r' }, - { key: 'z', modifiers: ['meta'] } - ] - }) - expect(parsePluginEditorShotActs('{"click":[1,2]}')).toMatchObject({ ok: true }) - expect(parsePluginEditorShotActs('[{"click":[1,2]},{"click":[-1,2]}]')).toMatchObject({ - ok: false, - error: expect.stringContaining('action 2 (click)') - }) - expect(parsePluginEditorShotActs('[{"press":{"text":"Go"}}]')).toMatchObject({ - ok: false, - error: 'action 1: expected an object with one of click, drag, key' - }) - expect(parsePluginEditorShotActs('[]')).toMatchObject({ ok: false }) - expect(parsePluginEditorShotActs('not json')).toMatchObject({ ok: false }) - }) - it('turns a click into a press and release at the point, offset into the target', () => { expect(pluginEditorActInputEvents({ click: [10, 20] }, { x: 100, y: 40 }, 2)).toEqual([ { type: 'mouseMove', x: 220, y: 120 }, @@ -56,20 +24,4 @@ describe('editor shot --act', () => { expect(moves.at(-1)).toMatchObject({ x: 80, y: 40 }) expect(events.at(-1)).toMatchObject({ type: 'mouseUp', x: 80, y: 40 }) }) - - it('types a character only for a printable key without a command modifier', () => { - expect(pluginEditorActInputEvents({ key: 'r' }).map((event) => event.type)).toEqual([ - 'keyDown', - 'char', - 'keyUp' - ]) - expect(pluginEditorActInputEvents({ key: 'Enter' }).map((event) => event.type)).toEqual([ - 'keyDown', - 'keyUp' - ]) - expect(pluginEditorActInputEvents({ key: 'z', modifiers: ['meta'] })).toEqual([ - { type: 'keyDown', keyCode: 'z', modifiers: ['meta'] }, - { type: 'keyUp', keyCode: 'z', modifiers: ['meta'] } - ]) - }) }) diff --git a/src/shared/plugins/workers/plugin-hook-chain.test.ts b/src/shared/plugins/workers/plugin-hook-chain.test.ts index 11e11ea27db..30d69a0df02 100644 --- a/src/shared/plugins/workers/plugin-hook-chain.test.ts +++ b/src/shared/plugins/workers/plugin-hook-chain.test.ts @@ -51,13 +51,6 @@ describe('runPluginHookChain', () => { expect(seen).toEqual(['ls -la']) }) - it('keeps fields the hook does not let plugins change', async () => { - const { outcome } = chain({ - 'a.one': [(event, next) => next({ ...read(event), terminalId: 'term_other' })] - }) - await expect(outcome).resolves.toEqual({ kind: 'continue', payload: send }) - }) - it('stops at a deny, so later plugins never run', async () => { const later = vi.fn() const { outcome } = chain({ @@ -101,26 +94,6 @@ describe('runPluginHookChain', () => { expect(logs).toEqual(['a.slow: hook terminal.send skipped after 0ms: timed out after 2000ms']) }) - it('ignores results of observe-only hooks', async () => { - const created = { workspaceId: 'w', kind: 'folder', path: '/tmp/w', branch: '' } - const { outcome } = chain( - { 'a.one': [() => ({ deny: 'no' })] }, - { event: 'workspace.create.after', payload: created } - ) - await expect(outcome).resolves.toEqual({ kind: 'continue', payload: created }) - }) - - it('runs one worker’s handlers in registration order', async () => { - const decision = await runPluginWorkerHookHandlers( - [ - (event, next) => next({ ...read(event), text: 'a' }), - (event, next) => next({ ...read(event), text: `${read(event).text}b` }) - ], - send - ) - expect(decision).toEqual({ decision: 'continue', payload: { ...send, text: 'ab' } }) - }) - it('refuses when a fail-closed plugin throws, misses its deadline or answers nonsense', async () => { const failsClosed = () => true const thrown = chain( @@ -146,15 +119,6 @@ describe('runPluginHookChain', () => { await expect(nonsense.outcome).resolves.toMatchObject({ kind: 'deny', pluginKey: 'a.guard' }) }) - it('refuses when a fail-closed plugin returns a malformed denial', async () => { - const failsClosed = () => true - const tooLong = chain({ 'a.guard': [() => ({ deny: 'x'.repeat(501) })] }, { failsClosed }) - await expect(tooLong.outcome).resolves.toMatchObject({ kind: 'deny', pluginKey: 'a.guard' }) - expect(tooLong.logs[0]).toMatch(/denied after 0ms \(onError: deny\): malformed result/) - const wrongShape = chain({ 'a.guard': [() => ({ deny: 7 })] }, { failsClosed }) - await expect(wrongShape.outcome).resolves.toMatchObject({ kind: 'deny', pluginKey: 'a.guard' }) - }) - it('passes a fail-closed plugin that is gone, and observe-only hooks', async () => { const gone = chain( {},