mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 19:34:29 +00:00
test: remove low-value plugin lifecycle and authoring checks
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
||||
import { mkdtemp, readFile, rm } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { createPluginFromTemplate } from './plugin-create'
|
||||
import { inspectPluginFolder, validatePluginTarget } from './plugin-folder-validation'
|
||||
import { inspectPluginFolder } from './plugin-folder-validation'
|
||||
import { PLUGIN_TEMPLATE_NAMES } from './plugin-template-names'
|
||||
|
||||
const roots: string[] = []
|
||||
@@ -33,35 +33,4 @@ describe('orca plugin create templates', () => {
|
||||
expect(readme).toContain('orca plugin dev watch .')
|
||||
expect(readme).not.toContain('dev load')
|
||||
})
|
||||
|
||||
it('refuses a non-empty folder and never overwrites', async () => {
|
||||
const dir = await tempRoot()
|
||||
await writeFile(join(dir, 'keep.txt'), 'mine')
|
||||
await expect(createPluginFromTemplate({ dir, template: 'theme' })).rejects.toThrow(
|
||||
'is not empty'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('orca plugin validate', () => {
|
||||
it('reports artifact errors Orca would otherwise skip silently', async () => {
|
||||
const dir = join(await tempRoot(), 'broken')
|
||||
await createPluginFromTemplate({ dir, template: 'theme', publisher: 'acme' })
|
||||
await writeFile(
|
||||
join(dir, 'themes', 'dark.json'),
|
||||
JSON.stringify({ base: 'dark', tokens: { '--background': '#000', '--fooground': '#fff' } })
|
||||
)
|
||||
const report = await validatePluginTarget(dir)
|
||||
expect(report.valid).toBe(false)
|
||||
expect(report.errors.join('\n')).toContain('contributes.themes')
|
||||
})
|
||||
|
||||
it('reports a missing panel entry', async () => {
|
||||
const dir = join(await tempRoot(), 'panel')
|
||||
await createPluginFromTemplate({ dir, template: 'panel', publisher: 'acme' })
|
||||
await rm(join(dir, 'panel', 'index.html'))
|
||||
const report = await validatePluginTarget(dir)
|
||||
expect(report.valid).toBe(false)
|
||||
expect(report.errors.join('\n')).toContain('panel/index.html')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -8,9 +8,7 @@ import { parsePluginDeclarativeTree } from '../../../shared/plugins/declarative/
|
||||
import {
|
||||
checkPluginPanels,
|
||||
formatPluginPanelCheck,
|
||||
readPluginCheckScenarioNames,
|
||||
pluginPanelCheckIssues,
|
||||
pluginStackLocation
|
||||
readPluginCheckScenarioNames
|
||||
} from './plugin-panel-check'
|
||||
import { findPluginTestFiles, PLUGIN_TEST_FILE, runPluginTests } from './plugin-test-runner'
|
||||
|
||||
@@ -298,26 +296,6 @@ describe('orca plugin check', () => {
|
||||
60_000
|
||||
)
|
||||
|
||||
it(
|
||||
'renders the template panel cleanly',
|
||||
async () => {
|
||||
const dir = await componentsPlugin()
|
||||
expect(await checkPluginPanels(dir)).toEqual([
|
||||
{
|
||||
panel: 'todo-panel',
|
||||
entry: 'src/panel.tsx',
|
||||
elements: expect.any(Number),
|
||||
summary: ['Heading "Counter"'],
|
||||
tree: expect.objectContaining({ type: 'Stack' }),
|
||||
issues: [],
|
||||
warnings: []
|
||||
}
|
||||
])
|
||||
},
|
||||
// Each run starts its own Node (or vitest) process and transpiles the plugin.
|
||||
60_000
|
||||
)
|
||||
|
||||
it(
|
||||
'reports a throw with its file:line, a refused layout, and dropped props',
|
||||
async () => {
|
||||
@@ -369,22 +347,6 @@ describe('orca plugin check', () => {
|
||||
60_000
|
||||
)
|
||||
|
||||
it('locates transpile errors from their message and lists a repeated error once', () => {
|
||||
const stack = 'Error: kaboom\n at Panel (file:///p/src/panel.tsx:4:41)'
|
||||
expect(
|
||||
pluginPanelCheckIssues('/p', [
|
||||
{ kind: 'plugin', message: 'kaboom', stack },
|
||||
{ kind: 'plugin', message: 'kaboom', stack },
|
||||
{ kind: 'plugin', message: 'src/lib/a.ts:3:9: Unexpected token', stack: 'SyntaxError' },
|
||||
{ kind: 'refused', message: 'kaboom' }
|
||||
])
|
||||
).toEqual([
|
||||
{ kind: 'plugin', message: 'kaboom', location: 'src/panel.tsx:4:41' },
|
||||
{ kind: 'plugin', message: 'Unexpected token', location: 'src/lib/a.ts:3:9' },
|
||||
{ kind: 'refused', message: 'kaboom' }
|
||||
])
|
||||
})
|
||||
|
||||
it(
|
||||
'warns about host calls Orca would refuse, and reports a repeated throw once',
|
||||
async () => {
|
||||
@@ -416,14 +378,4 @@ describe('orca plugin check', () => {
|
||||
// Each run starts its own Node process and transpiles the plugin.
|
||||
60_000
|
||||
)
|
||||
|
||||
it('finds the first plugin frame in a stack', () => {
|
||||
const dir = '/p'
|
||||
expect(
|
||||
pluginStackLocation(
|
||||
dir,
|
||||
'Error: x\n at f (file:///p/node_modules/a.js:1:2)\n at Panel (file:///p/src/panel.tsx:9:11)'
|
||||
)
|
||||
).toBe('src/panel.tsx:9:11')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -49,47 +49,6 @@ describe('host confirmations for workers', () => {
|
||||
installPluginDesktopFrameServices(shown, store)
|
||||
const services = getPluginDesktopFrameServices()!
|
||||
|
||||
it('ask in a window the person can see, one question per plugin at a time', async () => {
|
||||
let answer: (value: { response: number }) => void = () => {}
|
||||
showMessageBox.mockReturnValueOnce(new Promise((resolve) => (answer = resolve)))
|
||||
const first = services.confirm('acme.one', subject, scope)
|
||||
await expect(services.confirm('acme.one', subject, scope)).rejects.toMatchObject({
|
||||
code: 'rate_limited'
|
||||
})
|
||||
answer({ response: 0 })
|
||||
await expect(first).resolves.toBe('allowed')
|
||||
expect(showMessageBox).toHaveBeenCalledWith(shown, expect.anything())
|
||||
})
|
||||
|
||||
it('wait after the person declines before asking again', async () => {
|
||||
showMessageBox.mockResolvedValueOnce({ response: 1 })
|
||||
await expect(services.confirm('acme.two', subject, scope)).resolves.toBe('cancelled')
|
||||
await expect(services.confirm('acme.two', subject, scope)).rejects.toMatchObject({
|
||||
code: 'rate_limited'
|
||||
})
|
||||
expect(showMessageBox).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it('spend the dialog budget a frame dialog spends', async () => {
|
||||
showMessageBox.mockResolvedValue({ response: 0 })
|
||||
const answers: unknown[] = []
|
||||
await [0, 1, 2, 3].reduce(
|
||||
(previous) =>
|
||||
previous.then(() =>
|
||||
services.confirm('acme.three', subject, scope).then(
|
||||
(answer) => {
|
||||
answers.push(answer)
|
||||
},
|
||||
(error: unknown) => {
|
||||
answers.push(error instanceof Error && 'code' in error ? error.code : error)
|
||||
}
|
||||
)
|
||||
),
|
||||
Promise.resolve()
|
||||
)
|
||||
expect(answers).toEqual(['allowed', 'allowed', 'allowed', 'rate_limited'])
|
||||
})
|
||||
|
||||
it("close a question whose worker went away, so the plugin's next one is not refused", async () => {
|
||||
const worker = new AbortController()
|
||||
showMessageBox.mockImplementationOnce(
|
||||
|
||||
@@ -4,7 +4,6 @@ import { join } from 'node:path'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { Automation } from '../../shared/automations/automation-definition'
|
||||
import { installPluginAutomationOwnershipEnd } from './plugin-automation-ownership'
|
||||
import { notifyPluginRemoved } from './installation/plugin-removal-events'
|
||||
import { PluginService } from './plugin-service'
|
||||
|
||||
vi.mock('electron', () => ({ ipcMain: { handle() {}, on() {} } }))
|
||||
@@ -36,66 +35,6 @@ function automationStore(initial: Automation[]) {
|
||||
const settle = () => new Promise((resolve) => setImmediate(resolve))
|
||||
|
||||
describe('automations of a plugin the person took away', () => {
|
||||
it('are paused and no longer its own; re-enabling it resumes nothing', async () => {
|
||||
const settings = { disabled: ['acme.off'], killed: ['acme.bad'] }
|
||||
const listeners: (() => void)[] = []
|
||||
const store = automationStore([
|
||||
automation('a-removed', 'acme.gone'),
|
||||
automation('a-disabled', 'acme.off'),
|
||||
automation('a-killed', 'acme.bad'),
|
||||
automation('a-kept', 'acme.ok')
|
||||
])
|
||||
installPluginAutomationOwnershipEnd(
|
||||
{
|
||||
options: {
|
||||
isPluginSystemEnabled: () => true,
|
||||
getDisabledPlugins: () => settings.disabled,
|
||||
getPluginKillListEntry: (key) =>
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: only presence is read.
|
||||
settings.killed.includes(key) ? ({ reason: 'blocked' } as never) : null
|
||||
},
|
||||
whenReady: async () => undefined,
|
||||
onChanged: (listener) => {
|
||||
listeners.push(listener)
|
||||
return () => undefined
|
||||
}
|
||||
},
|
||||
store.source
|
||||
)
|
||||
notifyPluginRemoved('acme.gone')
|
||||
await settle()
|
||||
for (const id of ['a-removed', 'a-disabled', 'a-killed']) {
|
||||
expect(store.get(id)).toMatchObject({
|
||||
enabled: false,
|
||||
createdBy: { endedAt: expect.any(Number) }
|
||||
})
|
||||
}
|
||||
expect(store.get('a-kept')?.createdBy?.endedAt).toBeUndefined()
|
||||
|
||||
store.updateAutomation.mockClear()
|
||||
settings.disabled = []
|
||||
listeners.forEach((listener) => listener())
|
||||
await settle()
|
||||
expect(store.updateAutomation).not.toHaveBeenCalled()
|
||||
expect(store.get('a-disabled')?.enabled).toBe(false)
|
||||
})
|
||||
|
||||
it('keeps what a reinstall under the same key creates after the removal', async () => {
|
||||
// Created after any removal time the test can record.
|
||||
const store = automationStore([automation('a-new', 'acme.again', Number.MAX_SAFE_INTEGER)])
|
||||
installPluginAutomationOwnershipEnd(
|
||||
{
|
||||
options: { isPluginSystemEnabled: () => true, getDisabledPlugins: () => [] },
|
||||
whenReady: async () => undefined,
|
||||
onChanged: () => () => undefined
|
||||
},
|
||||
store.source
|
||||
)
|
||||
notifyPluginRemoved('acme.again')
|
||||
await settle()
|
||||
expect(store.updateAutomation).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('never ends ownership because discovery could not read the plugins folder', async () => {
|
||||
const userData = await mkdtemp(join(tmpdir(), 'orca-plugin-ownership-'))
|
||||
// A file where the plugins folder belongs: every discovery fails to list it.
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
createPluginAgentStatusForwarder,
|
||||
pluginRuntimeDelegate,
|
||||
readPluginWorkspaceChange
|
||||
} from './plugin-runtime-binding'
|
||||
import { createPluginAgentStatusForwarder, pluginRuntimeDelegate } from './plugin-runtime-binding'
|
||||
|
||||
import { PluginPanelBridge } from './panels/plugin-panel-bridge'
|
||||
import type { AgentStatusOrchestrationContext } from '../../shared/agent-status/contracts/agent-status-types'
|
||||
@@ -100,48 +96,3 @@ describe('agent.status.changed for plugins', () => {
|
||||
expect(panels[1]).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('workspace.changed for plugins', () => {
|
||||
it('carries the same workspace id workspace.readContext answers', async () => {
|
||||
const source = {
|
||||
...runtime([]),
|
||||
resolveActiveWorktreeContext: async () => ({
|
||||
worktreeId: 'repo::/w',
|
||||
identityKey: 'wt2:local:i1',
|
||||
path: '/w',
|
||||
branch: 'refs/heads/main',
|
||||
displayName: 'w'
|
||||
})
|
||||
}
|
||||
const { change } = await readPluginWorkspaceChange(pluginRuntimeDelegate(source, () => []))
|
||||
expect(change.context).toMatchObject({ workspaceId: 'identity:wt2:local:i1', branch: 'main' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('agents.list task titles for plugins', () => {
|
||||
it("passes each open task's title on, and nothing else of its dispatch", () => {
|
||||
const titles = pluginRuntimeDelegate(runtime([]), () => []).listAgentTaskTitles?.()
|
||||
expect(titles).toEqual(
|
||||
new Map([
|
||||
['tab0:worker', 'Write the tests'],
|
||||
['tab0:untitled', '']
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it('reads the orchestration projection at most once a second', () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
const source = runtime([])
|
||||
const delegate = pluginRuntimeDelegate(source, () => [])
|
||||
delegate.listAgentTaskTitles?.()
|
||||
delegate.listAgentTaskTitles?.()
|
||||
expect(source.listAgentTasksByPaneKey).toHaveBeenCalledOnce()
|
||||
vi.advanceTimersByTime(1001)
|
||||
delegate.listAgentTaskTitles?.()
|
||||
expect(source.listAgentTasksByPaneKey).toHaveBeenCalledTimes(2)
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,7 +4,6 @@ import { defineMethod } from '../runtime/rpc/core'
|
||||
import type { OrcaRuntimeService } from '../runtime/orca-runtime'
|
||||
import { pluginHostCallRevoked } from './workers/host-api/plugin-host-call-scope'
|
||||
import { pluginRuntimeRpc } from './plugin-runtime-rpc'
|
||||
import { AUTOMATION_METHODS } from '../runtime/rpc/methods/automations/automations'
|
||||
|
||||
function harness() {
|
||||
const ran: unknown[] = []
|
||||
@@ -44,38 +43,3 @@ describe('pluginRuntimeRpc', () => {
|
||||
expect(ran).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('automation.create provenance', () => {
|
||||
function automationHarness() {
|
||||
const createAutomation = vi.fn(async (input: Record<string, unknown>) => ({
|
||||
id: 'a1',
|
||||
...input
|
||||
}))
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: automation.create reads only these runtime members.
|
||||
const runtime = {
|
||||
getRuntimeId: () => 'rt',
|
||||
recordFeatureInteraction: vi.fn(),
|
||||
createAutomation
|
||||
} as unknown as OrcaRuntimeService
|
||||
return { rpc: pluginRuntimeRpc(runtime, AUTOMATION_METHODS), createAutomation }
|
||||
}
|
||||
const create = {
|
||||
name: 'Nightly',
|
||||
prompt: 'Check dependencies',
|
||||
agentId: 'claude',
|
||||
repo: 'id:r1',
|
||||
rrule: 'FREQ=DAILY;BYHOUR=9;BYMINUTE=0',
|
||||
dtstart: 1,
|
||||
createdBy: { kind: 'plugin', pluginKey: 'forged.key', name: 'Forged' }
|
||||
}
|
||||
|
||||
it('records the calling plugin, never a creator the params claim', async () => {
|
||||
const { rpc, createAutomation } = automationHarness()
|
||||
await rpc('automation.create', create, { plugin: { key: 'acme.deps', name: 'Deps' } })
|
||||
expect(createAutomation.mock.calls[0]?.[0]).toMatchObject({
|
||||
createdBy: { kind: 'plugin', pluginKey: 'acme.deps', name: 'Deps' }
|
||||
})
|
||||
await rpc('automation.create', create)
|
||||
expect(createAutomation.mock.calls[1]?.[0]).not.toHaveProperty('createdBy')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -2,16 +2,11 @@ import { mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync } from 'node:
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { invalidateAiVaultSessionListCache } from '../../../ai-vault/listing/cached-session-list'
|
||||
import type { PluginCapabilityKind } from '../../../../shared/plugins/capabilities/plugin-capabilities'
|
||||
import { PLUGIN_HOST_API } from '../../../../shared/plugins/workers/plugin-host-api'
|
||||
import { PluginRuntimeRpcError } from '../../plugin-runtime-rpc'
|
||||
import { callPluginHost, pluginHostTestServices } from './__mocks__/plugin-host-services-fixture'
|
||||
import { PLUGIN_HISTORY_TTL_MS } from './plugin-agent-history'
|
||||
import { bindPluginHostServices } from './plugin-host-service-bindings'
|
||||
import type { PluginRuntimeRpc } from './plugin-host-runtime-call'
|
||||
import type { PluginHostServices } from './plugin-host-method-bindings'
|
||||
import type { PluginAgentStatusRow } from './plugin-workspace-projection'
|
||||
|
||||
const WORKTREES = {
|
||||
worktrees: [
|
||||
@@ -109,213 +104,6 @@ afterEach(() => {
|
||||
})
|
||||
|
||||
describe('agent.listSessions', () => {
|
||||
it('needs history:read', async () => {
|
||||
const rpc = runtime()
|
||||
expect(await listSessions(rpc, {}, {}, ['agent:read'])).toMatchObject({
|
||||
ok: false,
|
||||
code: 'capability_denied'
|
||||
})
|
||||
expect(rpc).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('gives public fields only: no messages, prompts, file paths or account homes', async () => {
|
||||
const rpc = runtime({
|
||||
'aiVault.listSessions': {
|
||||
sessions: [
|
||||
vaultRow({ title: `${'x'.repeat(600)}\nmore`, agent: 'codex', codexHome: '/h/.codex' }),
|
||||
// A subagent transcript is its parent's; an id agent.resume would refuse is left out.
|
||||
vaultRow({ sessionId: 'child', subagent: { parentSessionId: 's-1' } }),
|
||||
vaultRow({ sessionId: '--all' })
|
||||
],
|
||||
issues: [],
|
||||
scannedAt: 'x'
|
||||
}
|
||||
})
|
||||
const outcome = await listSessions(rpc)
|
||||
const parsed = PLUGIN_HOST_API['agent.listSessions'].result.safeParse(
|
||||
outcome.ok ? outcome.value : null
|
||||
)
|
||||
const sessions = parsed.success ? parsed.data.sessions : []
|
||||
expect(sessions).toHaveLength(1)
|
||||
const [session] = sessions
|
||||
expect(Object.keys(session).toSorted()).toEqual(
|
||||
[
|
||||
'agent',
|
||||
'branch',
|
||||
'createdAt',
|
||||
'hostId',
|
||||
'messageCount',
|
||||
'running',
|
||||
'sessionId',
|
||||
'title',
|
||||
'totalTokens',
|
||||
'updatedAt',
|
||||
'workspaceId'
|
||||
].toSorted()
|
||||
)
|
||||
expect(session).toMatchObject({
|
||||
agent: 'codex',
|
||||
branch: 'seal',
|
||||
createdAt: Date.parse('2026-01-01T00:00:00.000Z'),
|
||||
updatedAt: Date.parse('2026-01-02T00:00:00.000Z'),
|
||||
hostId: 'local'
|
||||
})
|
||||
expect(session.title).toHaveLength(512)
|
||||
expect(JSON.stringify(outcome)).not.toMatch(/secret|\.jsonl|\/h\/\.codex|resume/)
|
||||
})
|
||||
|
||||
it('maps each session to the deepest workspace on this computer, never an SSH twin', async () => {
|
||||
const rpc = runtime({
|
||||
'aiVault.listSessions': {
|
||||
sessions: [
|
||||
vaultRow({ sessionId: 'nested', updatedAt: '2026-01-05T00:00:00.000Z' }),
|
||||
vaultRow({
|
||||
sessionId: 'project',
|
||||
cwd: '/src/r1/docs',
|
||||
updatedAt: '2026-01-04T00:00:00.000Z'
|
||||
}),
|
||||
vaultRow({ sessionId: 'folder', cwd: '/notes', updatedAt: '2026-01-03T00:00:00.000Z' }),
|
||||
vaultRow({ sessionId: 'elsewhere', cwd: '/tmp', updatedAt: '2026-01-02T00:00:00.000Z' })
|
||||
],
|
||||
issues: [],
|
||||
scannedAt: 'x'
|
||||
}
|
||||
})
|
||||
const outcome = await listSessions(rpc)
|
||||
expect(outcome.ok && outcome.value).toEqual({
|
||||
sessions: [
|
||||
expect.objectContaining({ sessionId: 'nested', workspaceId: 'identity:wt2:local:seal' }),
|
||||
expect.objectContaining({ sessionId: 'project', workspaceId: 'r1::/src/r1' }),
|
||||
expect.objectContaining({ sessionId: 'folder', workspaceId: 'folder:notes' }),
|
||||
expect.objectContaining({ sessionId: 'elsewhere', workspaceId: null })
|
||||
],
|
||||
truncated: false
|
||||
})
|
||||
// One depth for every caller; previews never asked for.
|
||||
expect(vaultCalls(rpc)).toEqual([{ limit: 200, afterFingerprint: null }])
|
||||
})
|
||||
|
||||
it("reads one workspace's sessions by its folder, leaving those of worktrees nested in it", async () => {
|
||||
const rpc = runtime({
|
||||
'aiVault.listSessions': {
|
||||
sessions: [
|
||||
vaultRow({ sessionId: 'nested' }),
|
||||
vaultRow({ sessionId: 'own', cwd: '/src/r1' })
|
||||
],
|
||||
issues: [],
|
||||
scannedAt: 'x'
|
||||
}
|
||||
})
|
||||
const outcome = await listSessions(rpc, { workspaceId: 'r1::/src/r1' })
|
||||
expect(outcome.ok && outcome.value).toEqual({
|
||||
sessions: [expect.objectContaining({ sessionId: 'own', workspaceId: 'r1::/src/r1' })],
|
||||
truncated: false
|
||||
})
|
||||
expect(vaultCalls(rpc)).toEqual([
|
||||
{ limit: 200, scopePaths: ['/src/r1'], scopeOnly: true, afterFingerprint: null }
|
||||
])
|
||||
})
|
||||
|
||||
it('answers no sessions for an SSH workspace, whose history is not on this computer', async () => {
|
||||
const rpc = runtime()
|
||||
expect(await listSessions(rpc, { workspaceId: 'r2::/src/r1' })).toEqual({
|
||||
ok: true,
|
||||
value: { sessions: [], truncated: false }
|
||||
})
|
||||
expect(vaultCalls(rpc)).toEqual([])
|
||||
})
|
||||
|
||||
it('refuses an unknown workspace with a fixed message', async () => {
|
||||
const rpc = runtime({
|
||||
'worktree.show': new PluginRuntimeRpcError('selector_not_found', 'no match for /x')
|
||||
})
|
||||
expect(await listSessions(rpc, { workspaceId: 'r9::/x' })).toEqual({
|
||||
ok: false,
|
||||
code: 'action_failed',
|
||||
error: 'no workspace has this id'
|
||||
})
|
||||
})
|
||||
|
||||
it('marks sessions an Orca pane on this computer runs, and reports truncation', async () => {
|
||||
const running = (connectionId: string | null, id: string): PluginAgentStatusRow => ({
|
||||
paneKey: `t:${id}`,
|
||||
state: 'working',
|
||||
stateStartedAt: 1,
|
||||
agentType: 'claude',
|
||||
connectionId,
|
||||
providerSession: { id }
|
||||
})
|
||||
const rpc = runtime({
|
||||
'aiVault.listSessions': {
|
||||
sessions: [vaultRow({ sessionId: 'a' }), vaultRow({ sessionId: 'b' })],
|
||||
issues: [],
|
||||
scannedAt: 'x'
|
||||
}
|
||||
})
|
||||
const outcome = await listSessions(
|
||||
rpc,
|
||||
{ limit: 1 },
|
||||
{ listAgentStatuses: () => [running(null, 'a'), running('box', 'b')] }
|
||||
)
|
||||
expect(outcome.ok && outcome.value).toEqual({
|
||||
sessions: [expect.objectContaining({ sessionId: 'a', running: true })],
|
||||
truncated: true
|
||||
})
|
||||
})
|
||||
|
||||
it('prefers a project workspace over a project-group folder of the same path', async () => {
|
||||
const rpc = runtime({
|
||||
'folderWorkspace.list': {
|
||||
folderWorkspaces: [
|
||||
{ id: 'twin', name: 'Twin', folderPath: '/src/r1', executionHostId: null }
|
||||
]
|
||||
},
|
||||
'aiVault.listSessions': {
|
||||
sessions: [vaultRow({ cwd: '/src/r1/docs' })],
|
||||
issues: [],
|
||||
scannedAt: 'x'
|
||||
}
|
||||
})
|
||||
const outcome = await listSessions(rpc)
|
||||
expect(outcome.ok && outcome.value).toMatchObject({
|
||||
sessions: [{ workspaceId: 'r1::/src/r1' }]
|
||||
})
|
||||
})
|
||||
|
||||
it('maps a workspace registered through a symlink, scoped or not', async () => {
|
||||
const root = realpathSync(mkdtempSync(join(tmpdir(), 'orca-history-')))
|
||||
try {
|
||||
mkdirSync(join(root, 'real'))
|
||||
// A junction on Windows, which needs no symlink privilege.
|
||||
symlinkSync(
|
||||
join(root, 'real'),
|
||||
join(root, 'link'),
|
||||
process.platform === 'win32' ? 'junction' : 'dir'
|
||||
)
|
||||
const link = join(root, 'link')
|
||||
const rpc = runtime({
|
||||
'worktree.list': {
|
||||
worktrees: [
|
||||
{ id: `r1::${link}`, repoId: 'r1', displayName: 'l', path: link, hostId: 'local' }
|
||||
]
|
||||
},
|
||||
'folderWorkspace.list': { folderWorkspaces: [] },
|
||||
// Agents record the resolved folder.
|
||||
'aiVault.listSessions': {
|
||||
sessions: [vaultRow({ cwd: join(root, 'real', 'src') })],
|
||||
issues: [],
|
||||
scannedAt: 'x'
|
||||
}
|
||||
})
|
||||
const outcome = await listSessions(rpc)
|
||||
expect(outcome.ok && outcome.value).toMatchObject({
|
||||
sessions: [{ workspaceId: `r1::${link}` }]
|
||||
})
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
it('ranks a symlinked workspace by its resolved folder', async () => {
|
||||
const root = realpathSync(mkdtempSync(join(tmpdir(), 'orca-history-')))
|
||||
try {
|
||||
@@ -349,57 +137,6 @@ describe('agent.listSessions', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('counts OpenCode sessions running under either version as running', async () => {
|
||||
const rpc = runtime({
|
||||
'aiVault.listSessions': {
|
||||
sessions: [vaultRow({ agent: 'opencode2', sessionId: 'ses_1' })],
|
||||
issues: [],
|
||||
scannedAt: 'x'
|
||||
}
|
||||
})
|
||||
const outcome = await listSessions(
|
||||
rpc,
|
||||
{},
|
||||
{
|
||||
listAgentStatuses: () => [
|
||||
{
|
||||
paneKey: 't:o',
|
||||
state: 'working',
|
||||
stateStartedAt: 1,
|
||||
agentType: 'opencode',
|
||||
providerSession: { id: 'ses_1' }
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
expect(outcome.ok && outcome.value).toMatchObject({ sessions: [{ running: true }] })
|
||||
})
|
||||
|
||||
it('reports a workspace read that reached the vault budget as truncated', async () => {
|
||||
const rpc = runtime({
|
||||
'aiVault.listSessions': {
|
||||
sessions: Array.from({ length: 200 }, (_, index) =>
|
||||
vaultRow({ sessionId: `s-${index}`, cwd: '/src/r1' })
|
||||
),
|
||||
issues: [],
|
||||
scannedAt: 'x'
|
||||
}
|
||||
})
|
||||
const outcome = await listSessions(rpc, { workspaceId: 'r1::/src/r1', limit: 200 })
|
||||
expect(outcome.ok && outcome.value).toMatchObject({ truncated: true })
|
||||
})
|
||||
|
||||
it('reads afresh after the history list is invalidated, as a delete does', async () => {
|
||||
const rpc = runtime()
|
||||
await listSessions(rpc)
|
||||
invalidateAiVaultSessionListCache()
|
||||
await listSessions(rpc)
|
||||
expect(vaultCalls(rpc)).toEqual([
|
||||
{ limit: 200, afterFingerprint: null },
|
||||
{ limit: 200, afterFingerprint: null }
|
||||
])
|
||||
})
|
||||
|
||||
it('shares one read among calls, then revalidates it by fingerprint', async () => {
|
||||
vi.useFakeTimers()
|
||||
const rpc = runtime({
|
||||
@@ -419,295 +156,4 @@ describe('agent.listSessions', () => {
|
||||
{ limit: 200, afterFingerprint: 'f1' }
|
||||
])
|
||||
})
|
||||
|
||||
it('does not keep a failed read', async () => {
|
||||
let fail = true
|
||||
const rpc = runtime({
|
||||
'aiVault.listSessions': () => {
|
||||
if (fail) {
|
||||
fail = false
|
||||
throw new PluginRuntimeRpcError('runtime_error', 'scan failed')
|
||||
}
|
||||
return { sessions: [vaultRow()], issues: [], scannedAt: 'x' }
|
||||
}
|
||||
})
|
||||
expect(await listSessions(rpc)).toMatchObject({ ok: false, code: 'action_failed' })
|
||||
expect(await listSessions(rpc)).toMatchObject({ ok: true })
|
||||
})
|
||||
})
|
||||
|
||||
describe('agent.resume of a past session', () => {
|
||||
const resume = (rpc: PluginRuntimeRpc, agent = 'claude', statuses: PluginAgentStatusRow[] = []) =>
|
||||
callPluginHost({
|
||||
method: 'agent.resume',
|
||||
params: { workspaceId: 'identity:wt2:local:seal', agent, sessionId: 's-1' },
|
||||
granted: ['agent:launch'],
|
||||
services: pluginHostTestServices(rpc, { listAgentStatuses: () => statuses })
|
||||
})
|
||||
const pastRuntime = (answers: Record<string, unknown> = {}) =>
|
||||
runtime({
|
||||
'worktree.show': {
|
||||
worktree: {
|
||||
id: WORKTREES.worktrees[1].id,
|
||||
hostId: 'local',
|
||||
path: '/src/r1/.worktrees/seal'
|
||||
}
|
||||
},
|
||||
'aiVault.prepareSessionResume': { useRealCodexHome: false },
|
||||
'terminal.ensureAgentSession': { terminal: { handle: 'term_r' }, disposition: 'created' },
|
||||
...answers
|
||||
})
|
||||
const paramsOf = (rpc: ReturnType<typeof runtime>, method: string) =>
|
||||
rpc.mock.calls.find(([name]) => name === method)?.[1]
|
||||
|
||||
it('prepares it as Orca’s Resume does, and resumes from its transcript, with agent:launch only', async () => {
|
||||
const rpc = pastRuntime()
|
||||
expect(await resume(rpc)).toEqual({ ok: true, value: { terminalId: 'term_r', started: true } })
|
||||
// The workspace's own sessions are looked up first.
|
||||
expect(vaultCalls(rpc)[0]).toEqual({
|
||||
limit: 200,
|
||||
scopePaths: ['/src/r1/.worktrees/seal'],
|
||||
scopeOnly: true,
|
||||
afterFingerprint: null
|
||||
})
|
||||
expect(paramsOf(rpc, 'aiVault.prepareSessionResume')).toEqual({
|
||||
agent: 'claude',
|
||||
sessionId: 's-1',
|
||||
filePath: '/home/me/.claude/projects/x/s-1.jsonl',
|
||||
codexHome: null,
|
||||
executionHostId: 'local'
|
||||
})
|
||||
expect(paramsOf(rpc, 'terminal.ensureAgentSession')).toMatchObject({
|
||||
providerSession: {
|
||||
key: 'session_id',
|
||||
id: 's-1',
|
||||
transcriptPath: '/home/me/.claude/projects/x/s-1.jsonl'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it("passes a Codex session's managed home only where it needs readying", async () => {
|
||||
const home = '/u/.orca/codex-accounts/a1/home'
|
||||
const rpc = pastRuntime({
|
||||
'aiVault.listSessions': {
|
||||
sessions: [
|
||||
vaultRow({ agent: 'codex', codexHome: home, filePath: `${home}/sessions/r.jsonl` })
|
||||
],
|
||||
issues: [],
|
||||
scannedAt: 'x'
|
||||
}
|
||||
})
|
||||
expect(await resume(rpc, 'codex')).toMatchObject({ ok: true })
|
||||
expect(paramsOf(rpc, 'aiVault.prepareSessionResume')).toMatchObject({ codexHome: home })
|
||||
})
|
||||
|
||||
it("starts a Codex session of account A in account B's copy when B is selected, as the desktop does", async () => {
|
||||
const homeA = '/u/.orca/codex-accounts/a/home'
|
||||
const homeB = '/u/.orca/codex-accounts/b/home'
|
||||
const rollout = 'sessions/2026/01/02/rollout-2026-01-02T00-00-00-s-1.jsonl'
|
||||
const rpc = pastRuntime({
|
||||
'aiVault.listSessions': {
|
||||
sessions: [vaultRow({ agent: 'codex', codexHome: homeA, filePath: `${homeA}/${rollout}` })],
|
||||
issues: [],
|
||||
scannedAt: 'x'
|
||||
},
|
||||
// The host repins a hard-linked session to the selected account's home.
|
||||
'aiVault.prepareSessionResume': { useRealCodexHome: false, substituteCodexHome: homeB }
|
||||
})
|
||||
expect(await resume(rpc, 'codex')).toMatchObject({ ok: true })
|
||||
expect(paramsOf(rpc, 'aiVault.prepareSessionResume')).toEqual({
|
||||
agent: 'codex',
|
||||
sessionId: 's-1',
|
||||
filePath: `${homeA}/${rollout}`,
|
||||
codexHome: homeA,
|
||||
executionHostId: 'local'
|
||||
})
|
||||
// The launch picks the account whose home holds the transcript it is given.
|
||||
expect(paramsOf(rpc, 'terminal.ensureAgentSession')).toMatchObject({
|
||||
providerSession: { key: 'session_id', id: 's-1', transcriptPath: `${homeB}/${rollout}` }
|
||||
})
|
||||
})
|
||||
|
||||
it('starts a legacy Codex session from its recorded transcript, which the launch moves itself', async () => {
|
||||
const legacy = '/u/.orca/codex-runtime-home/home'
|
||||
const rollout = 'sessions/2026/01/02/rollout-2026-01-02T00-00-00-s-1.jsonl'
|
||||
const rpc = pastRuntime({
|
||||
'aiVault.listSessions': {
|
||||
sessions: [
|
||||
vaultRow({ agent: 'codex', codexHome: legacy, filePath: `${legacy}/${rollout}` })
|
||||
],
|
||||
issues: [],
|
||||
scannedAt: 'x'
|
||||
},
|
||||
'aiVault.prepareSessionResume': { useRealCodexHome: true }
|
||||
})
|
||||
expect(await resume(rpc, 'codex')).toMatchObject({ ok: true })
|
||||
expect(paramsOf(rpc, 'terminal.ensureAgentSession')).toMatchObject({
|
||||
providerSession: { transcriptPath: `${legacy}/${rollout}` }
|
||||
})
|
||||
})
|
||||
|
||||
it('ignores a home answer for a session that needs no readying, as the desktop does', async () => {
|
||||
const rpc = pastRuntime({
|
||||
'aiVault.prepareSessionResume': { useRealCodexHome: false, substituteCodexHome: '/elsewhere' }
|
||||
})
|
||||
expect(await resume(rpc)).toMatchObject({ ok: true })
|
||||
expect(paramsOf(rpc, 'terminal.ensureAgentSession')).toMatchObject({
|
||||
providerSession: { transcriptPath: '/home/me/.claude/projects/x/s-1.jsonl' }
|
||||
})
|
||||
})
|
||||
|
||||
it('refuses a malformed preparation answer', async () => {
|
||||
const rpc = pastRuntime({ 'aiVault.prepareSessionResume': { useRealCodexHome: 'yes' } })
|
||||
expect(await resume(rpc)).toMatchObject({ ok: false, code: 'action_failed' })
|
||||
expect(paramsOf(rpc, 'terminal.ensureAgentSession')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('refuses when preparation fails, before any terminal opens', async () => {
|
||||
const rpc = pastRuntime({
|
||||
'aiVault.prepareSessionResume': new PluginRuntimeRpcError(
|
||||
'runtime_error',
|
||||
'This session is open in an Orca chat.'
|
||||
)
|
||||
})
|
||||
expect(await resume(rpc)).toEqual({
|
||||
ok: false,
|
||||
code: 'action_failed',
|
||||
error: 'Orca could not prepare this session to resume'
|
||||
})
|
||||
expect(paramsOf(rpc, 'terminal.ensureAgentSession')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('resumes by id, unprepared, when history lists no such session or cannot be read', async () => {
|
||||
for (const listing of [
|
||||
{ sessions: [], issues: [], scannedAt: 'x' },
|
||||
new PluginRuntimeRpcError('runtime_error', 'scan failed')
|
||||
]) {
|
||||
const rpc = pastRuntime({ 'aiVault.listSessions': listing })
|
||||
expect(await resume(rpc)).toMatchObject({ ok: true })
|
||||
expect(paramsOf(rpc, 'aiVault.prepareSessionResume')).toBeUndefined()
|
||||
expect(paramsOf(rpc, 'terminal.ensureAgentSession')).toMatchObject({
|
||||
providerSession: { key: 'session_id', id: 's-1' }
|
||||
})
|
||||
expect(paramsOf(rpc, 'terminal.ensureAgentSession')).not.toHaveProperty(
|
||||
'providerSession.transcriptPath'
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('prepares a session whose only status row carries its id, as a past one', async () => {
|
||||
const rpc = pastRuntime()
|
||||
await resume(rpc, 'claude', [
|
||||
{
|
||||
paneKey: 't:l',
|
||||
worktreeId: WORKTREES.worktrees[1].id,
|
||||
state: 'done',
|
||||
stateStartedAt: 1,
|
||||
agentType: 'claude',
|
||||
providerSessionOnly: true,
|
||||
providerSession: { id: 's-1' }
|
||||
}
|
||||
])
|
||||
expect(paramsOf(rpc, 'aiVault.prepareSessionResume')).toMatchObject({ sessionId: 's-1' })
|
||||
})
|
||||
|
||||
it('leaves a live session and an SSH workspace out of history', async () => {
|
||||
const live = pastRuntime()
|
||||
await resume(live, 'claude', [
|
||||
{
|
||||
paneKey: 't:l',
|
||||
worktreeId: WORKTREES.worktrees[1].id,
|
||||
state: 'done',
|
||||
stateStartedAt: 1,
|
||||
agentType: 'claude',
|
||||
providerSession: { id: 's-1' }
|
||||
}
|
||||
])
|
||||
const remote = pastRuntime({
|
||||
'worktree.show': { worktree: { id: 'r2::/src/r1', hostId: 'ssh:box', path: '/src/r1' } }
|
||||
})
|
||||
await resume(remote)
|
||||
for (const rpc of [live, remote]) {
|
||||
expect(vaultCalls(rpc)).toEqual([])
|
||||
expect(paramsOf(rpc, 'terminal.ensureAgentSession')).toMatchObject({
|
||||
providerSession: { id: 's-1' }
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('agents.list task', () => {
|
||||
it('names the dispatched task a pane runs, and null for one that runs none', async () => {
|
||||
const status = (paneKey: string, stateStartedAt: number): PluginAgentStatusRow => ({
|
||||
paneKey,
|
||||
worktreeId: 'r1::/w',
|
||||
state: 'working',
|
||||
stateStartedAt
|
||||
})
|
||||
const listAgentTaskTitles = vi.fn(() => new Map([['t:worker', 'Write the tests']]))
|
||||
const outcome = await callPluginHost({
|
||||
method: 'agents.list',
|
||||
params: {},
|
||||
granted: ['agent:read'],
|
||||
services: pluginHostTestServices(runtime(), {
|
||||
resolveActiveWorktreeContext: vi
|
||||
.fn()
|
||||
.mockResolvedValue({ worktreeId: 'r1::/w', branch: '', displayName: 'w' }),
|
||||
listAgentStatuses: () => [status('t:worker', 2), status('t:solo', 1)],
|
||||
listAgentTaskTitles
|
||||
})
|
||||
})
|
||||
expect(outcome.ok && outcome.value).toMatchObject({
|
||||
agents: [{ task: { title: 'Write the tests' } }, { task: null }]
|
||||
})
|
||||
expect(JSON.stringify(outcome)).not.toMatch(/dispatch/i)
|
||||
})
|
||||
|
||||
it('does not read task titles for a workspace without agents', async () => {
|
||||
const listAgentTaskTitles = vi.fn(() => new Map<string, string>())
|
||||
await callPluginHost({
|
||||
method: 'agents.list',
|
||||
params: {},
|
||||
granted: ['agent:read'],
|
||||
services: pluginHostTestServices(runtime(), {
|
||||
resolveActiveWorktreeContext: vi
|
||||
.fn()
|
||||
.mockResolvedValue({ worktreeId: 'r1::/w', branch: '', displayName: 'w' }),
|
||||
listAgentTaskTitles
|
||||
})
|
||||
})
|
||||
expect(listAgentTaskTitles).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('agents.list task title failures', () => {
|
||||
it('keep the agent rows, with no task', async () => {
|
||||
const services = bindPluginHostServices({
|
||||
pluginsDataDir: '/nonexistent',
|
||||
delegate: {
|
||||
resolveActiveWorktreeContext: async () => ({
|
||||
worktreeId: 'r1::/w',
|
||||
path: '/w',
|
||||
branch: '',
|
||||
displayName: 'w'
|
||||
}),
|
||||
listTerminals: async () => ({ terminals: [] }),
|
||||
sendTerminal: async () => ({ accepted: true }),
|
||||
dispatchPluginNotification: async () => ({ delivered: true }),
|
||||
listAgentStatuses: () => [
|
||||
{ paneKey: 't:a', worktreeId: 'r1::/w', state: 'working', stateStartedAt: 1 }
|
||||
],
|
||||
listAgentTaskTitles: () => {
|
||||
throw new Error('database is locked')
|
||||
}
|
||||
}
|
||||
})
|
||||
const outcome = await callPluginHost({
|
||||
method: 'agents.list',
|
||||
params: {},
|
||||
granted: ['agent:read'],
|
||||
services
|
||||
})
|
||||
expect(outcome.ok && outcome.value).toMatchObject({ agents: [{ task: null }] })
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,345 +0,0 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { PluginRuntimeRpc } from './plugin-host-runtime-call'
|
||||
import type { PluginHostServices } from './plugin-host-method-bindings'
|
||||
import { callPluginHost, pluginHostTestServices } from './__mocks__/plugin-host-services-fixture'
|
||||
|
||||
const AUTOMATION = {
|
||||
id: 'a1',
|
||||
name: 'Nightly sweep',
|
||||
prompt: 'p'.repeat(5000),
|
||||
agentId: 'claude',
|
||||
projectId: 'r1',
|
||||
runContext: { repoId: 'r1', hostId: 'local', projectId: 'p1', path: '/src/r1' },
|
||||
workspaceMode: 'existing',
|
||||
workspaceId: 'r1::/src/r1',
|
||||
rrule: 'FREQ=DAILY;BYHOUR=9;BYMINUTE=0',
|
||||
timezone: 'UTC',
|
||||
enabled: true,
|
||||
nextRunAt: 10,
|
||||
updatedAt: 3,
|
||||
precheck: { command: 'secret-check', timeoutSeconds: 30 },
|
||||
extraAgentArgs: '--dangerously-skip-permissions'
|
||||
}
|
||||
const OWN = {
|
||||
...AUTOMATION,
|
||||
id: 'a2',
|
||||
createdBy: { kind: 'plugin', pluginKey: 'samples.demo', name: 'Demo' }
|
||||
}
|
||||
|
||||
const OWN_ELEVATED = { ...OWN, id: 'a3', launchPreferences: { permissionMode: 'bypass' } }
|
||||
const ENDED = {
|
||||
...AUTOMATION,
|
||||
id: 'a4',
|
||||
createdBy: { kind: 'plugin', pluginKey: 'samples.demo', name: 'Demo', endedAt: 5 }
|
||||
}
|
||||
const BY_ID: Record<string, unknown> = { a2: OWN, a3: OWN_ELEVATED, a4: ENDED }
|
||||
|
||||
function runtime(overrides: Record<string, unknown> = {}, shows: unknown[] = []) {
|
||||
const answers: Record<string, unknown> = {
|
||||
'repo.list': {
|
||||
repos: [
|
||||
{ id: 'r1', displayName: 'App', executionHostId: 'local' },
|
||||
{ id: 'twin', displayName: 'Twin', executionHostId: 'local' },
|
||||
{ id: 'twin', displayName: 'Twin', connectionId: 'box' }
|
||||
]
|
||||
},
|
||||
'projectHostSetup.list': {
|
||||
setups: [
|
||||
{
|
||||
id: 's-box',
|
||||
projectId: 'p-twin',
|
||||
hostId: 'ssh:box',
|
||||
repoId: 'twin',
|
||||
path: '/srv/twin',
|
||||
setupState: 'ready'
|
||||
}
|
||||
]
|
||||
},
|
||||
'automation.list': { automations: [AUTOMATION, OWN, ENDED] },
|
||||
'worktree.list': { worktrees: [{ id: 'r1::/src/r1', identity: { key: 'wt2:local:i1' } }] },
|
||||
'automation.create': { automation: { id: 'new' } },
|
||||
'automation.update': { automation: AUTOMATION },
|
||||
'automation.delete': { removed: true, id: 'a1' },
|
||||
...overrides
|
||||
}
|
||||
return vi.fn<PluginRuntimeRpc>(async (method, params) => {
|
||||
if (method === 'automation.show' && shows.length > 0) {
|
||||
return { automation: shows.shift() }
|
||||
}
|
||||
if (method === 'automation.show') {
|
||||
const id = typeof params === 'object' && params !== null && 'id' in params ? params.id : ''
|
||||
return { automation: BY_ID[String(id)] ?? AUTOMATION }
|
||||
}
|
||||
return answers[method]
|
||||
})
|
||||
}
|
||||
const methods = (rpc: ReturnType<typeof runtime>) => rpc.mock.calls.map(([method]) => method)
|
||||
|
||||
const call = (
|
||||
method: string,
|
||||
params: unknown,
|
||||
rpc: PluginRuntimeRpc,
|
||||
overrides: Partial<PluginHostServices> = {}
|
||||
) =>
|
||||
callPluginHost({
|
||||
method,
|
||||
params,
|
||||
granted: ['automation:read', 'automation:write'],
|
||||
services: pluginHostTestServices(rpc, overrides)
|
||||
})
|
||||
|
||||
describe('automation.list', () => {
|
||||
it('shows what an automation does, never its precheck or agent arguments', async () => {
|
||||
const outcome = await call('automation.list', {}, runtime())
|
||||
expect(outcome.ok && outcome.value).toEqual({
|
||||
automations: [
|
||||
{
|
||||
id: 'a1',
|
||||
name: 'Nightly sweep',
|
||||
agent: 'claude',
|
||||
prompt: 'p'.repeat(4096),
|
||||
promptTruncated: true,
|
||||
projectId: 'r1',
|
||||
hostId: 'local',
|
||||
workspaceId: 'identity:wt2:local:i1',
|
||||
workspaceMode: 'existing',
|
||||
schedule: 'FREQ=DAILY;BYHOUR=9;BYMINUTE=0',
|
||||
timezone: 'UTC',
|
||||
enabled: true,
|
||||
nextRunAt: 10,
|
||||
lastRunAt: null,
|
||||
createdByThisPlugin: false
|
||||
},
|
||||
expect.objectContaining({ id: 'a2', createdByThisPlugin: true }),
|
||||
// Its plugin was removed or disabled since: the plugin no longer owns it.
|
||||
expect.objectContaining({ id: 'a4', createdByThisPlugin: false })
|
||||
],
|
||||
truncated: false
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('automation.create', () => {
|
||||
it('forwards only what a plugin may set, and names the plugin as its creator', async () => {
|
||||
const rpc = runtime()
|
||||
expect(
|
||||
await call(
|
||||
'automation.create',
|
||||
{
|
||||
name: 'Deps',
|
||||
prompt: 'Check dependencies',
|
||||
agent: 'codex',
|
||||
projectId: 'r1',
|
||||
schedule: '0 9 * * 1-5'
|
||||
},
|
||||
rpc
|
||||
)
|
||||
).toEqual({ ok: true, value: { automationId: 'new' } })
|
||||
const [, params, options] =
|
||||
rpc.mock.calls.find(([method]) => method === 'automation.create') ?? []
|
||||
expect(params).toEqual({
|
||||
name: 'Deps',
|
||||
prompt: 'Check dependencies',
|
||||
agentId: 'codex',
|
||||
repo: 'id:r1',
|
||||
workspaceMode: 'new_per_run',
|
||||
rrule: '0 9 * * 1-5',
|
||||
dtstart: expect.any(Number),
|
||||
enabled: true
|
||||
})
|
||||
expect(options?.plugin).toEqual({ key: 'samples.demo', name: 'samples.demo' })
|
||||
})
|
||||
|
||||
it('refuses a precheck, agent arguments, launch setup and setup choices', async () => {
|
||||
const rpc = runtime()
|
||||
const base = { name: 'x', prompt: 'y', agent: 'claude', projectId: 'r1', schedule: '0 9 * * *' }
|
||||
const outcomes = await Promise.all(
|
||||
[
|
||||
{ precheck: { command: 'rm -rf ~', timeoutSeconds: 1 } },
|
||||
{ agentArgs: '--yolo' },
|
||||
{ extraAgentArgs: '--yolo' },
|
||||
{ launchSetupPatch: { choices: {} } },
|
||||
{ setupDecision: 'run' },
|
||||
{ createdBy: { kind: 'plugin', pluginKey: 'other.plugin' } }
|
||||
].map((extra) => call('automation.create', { ...base, ...extra }, rpc))
|
||||
)
|
||||
for (const outcome of outcomes) {
|
||||
expect(outcome).toMatchObject({ ok: false, code: 'invalid_params' })
|
||||
}
|
||||
expect(rpc).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('automation.update and automation.delete', () => {
|
||||
it("change the plugin's own automations without asking", async () => {
|
||||
const rpc = runtime()
|
||||
const confirm = vi.fn()
|
||||
expect(
|
||||
await call('automation.update', { automationId: 'a2', enabled: false }, rpc, { confirm })
|
||||
).toEqual({ ok: true, value: { updated: true } })
|
||||
expect(confirm).not.toHaveBeenCalled()
|
||||
expect(rpc.mock.calls.find(([method]) => method === 'automation.update')?.[1]).toEqual({
|
||||
id: 'a2',
|
||||
updates: { enabled: false }
|
||||
})
|
||||
})
|
||||
|
||||
it("ask before touching another's, and change nothing when refused or nobody can answer", async () => {
|
||||
const cancelled = runtime()
|
||||
const confirm = vi.fn().mockResolvedValue('cancelled')
|
||||
expect(await call('automation.delete', { automationId: 'a1' }, cancelled, { confirm })).toEqual(
|
||||
{ ok: true, value: { deleted: false, reason: 'cancelled' } }
|
||||
)
|
||||
expect(confirm).toHaveBeenCalledWith(
|
||||
'samples.demo',
|
||||
{
|
||||
kind: 'automation.delete',
|
||||
// Names repeat: the question says which one, where and when it runs.
|
||||
automation: {
|
||||
id: 'a1',
|
||||
name: 'Nightly sweep',
|
||||
project: 'App',
|
||||
workspace: 'r1',
|
||||
schedule: 'FREQ=DAILY;BYHOUR=9;BYMINUTE=0'
|
||||
}
|
||||
},
|
||||
expect.anything()
|
||||
)
|
||||
expect(methods(cancelled)).not.toContain('automation.delete')
|
||||
|
||||
// Headless serve has no window to ask in.
|
||||
const headless = runtime()
|
||||
expect(
|
||||
await call('automation.update', { automationId: 'a1', prompt: 'new' }, headless)
|
||||
).toEqual({ ok: true, value: { updated: false, reason: 'consent-unavailable' } })
|
||||
expect(methods(headless)).not.toContain('automation.update')
|
||||
|
||||
const allowed = runtime()
|
||||
const allow = vi.fn().mockResolvedValue('allowed')
|
||||
expect(
|
||||
await call('automation.delete', { automationId: 'a1' }, allowed, { confirm: allow })
|
||||
).toEqual({
|
||||
ok: true,
|
||||
value: { deleted: true }
|
||||
})
|
||||
})
|
||||
|
||||
it("ask before a new prompt or resuming for one that runs with extra agent settings, even the plugin's own", async () => {
|
||||
const confirm = vi.fn().mockResolvedValue('allowed')
|
||||
const rpc = runtime()
|
||||
await call('automation.update', { automationId: 'a3', prompt: 'Do more' }, rpc, { confirm })
|
||||
expect(confirm).toHaveBeenCalledWith(
|
||||
'samples.demo',
|
||||
{
|
||||
kind: 'automation.update',
|
||||
automation: expect.objectContaining({ id: 'a3', name: 'Nightly sweep' }),
|
||||
fields: ['prompt'],
|
||||
elevated: true,
|
||||
prompt: 'Do more'
|
||||
},
|
||||
expect.anything()
|
||||
)
|
||||
confirm.mockClear()
|
||||
// A new time zone moves when it runs.
|
||||
await call('automation.update', { automationId: 'a3', timezone: 'Asia/Tokyo' }, rpc, {
|
||||
confirm
|
||||
})
|
||||
expect(confirm).toHaveBeenCalledWith(
|
||||
'samples.demo',
|
||||
expect.objectContaining({ elevated: true, fields: ['timezone'] }),
|
||||
expect.anything()
|
||||
)
|
||||
confirm.mockClear()
|
||||
// A rename runs nothing new.
|
||||
await call('automation.update', { automationId: 'a3', name: 'Renamed' }, rpc, { confirm })
|
||||
expect(confirm).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('ask once the plugin that made it was removed or disabled', async () => {
|
||||
const confirm = vi.fn().mockResolvedValue('cancelled')
|
||||
const rpc = runtime()
|
||||
expect(await call('automation.delete', { automationId: 'a4' }, rpc, { confirm })).toEqual({
|
||||
ok: true,
|
||||
value: { deleted: false, reason: 'cancelled' }
|
||||
})
|
||||
})
|
||||
|
||||
it("show the new prompt for another's automation too", async () => {
|
||||
const confirm = vi.fn().mockResolvedValue('allowed')
|
||||
await call('automation.update', { automationId: 'a1', prompt: 'Delete the repo' }, runtime(), {
|
||||
confirm
|
||||
})
|
||||
expect(confirm).toHaveBeenCalledWith(
|
||||
'samples.demo',
|
||||
expect.objectContaining({ prompt: 'Delete the repo' }),
|
||||
expect.anything()
|
||||
)
|
||||
})
|
||||
|
||||
it('change nothing when the automation changed while the person was asked', async () => {
|
||||
const rpc = runtime({}, [AUTOMATION, { ...AUTOMATION, name: 'Repurposed', updatedAt: 4 }])
|
||||
const confirm = vi.fn().mockResolvedValue('allowed')
|
||||
expect(await call('automation.delete', { automationId: 'a1' }, rpc, { confirm })).toEqual({
|
||||
ok: true,
|
||||
value: { deleted: false, reason: 'changed' }
|
||||
})
|
||||
expect(methods(rpc)).not.toContain('automation.delete')
|
||||
})
|
||||
})
|
||||
|
||||
describe('automation.create targets', () => {
|
||||
const base = { name: 'x', prompt: 'y', agent: 'claude', schedule: '0 9 * * *' }
|
||||
const sent = (rpc: ReturnType<typeof runtime>) =>
|
||||
rpc.mock.calls.find(([method]) => method === 'automation.create')?.[1]
|
||||
|
||||
it("runs on the host hostId names, through that host's project setup", async () => {
|
||||
expect(await call('automation.create', { ...base, projectId: 'twin' }, runtime())).toEqual({
|
||||
ok: false,
|
||||
code: 'action_failed',
|
||||
error: 'two hosts have this project; pass the hostId project.list gives'
|
||||
})
|
||||
const rpc = runtime()
|
||||
await call('automation.create', { ...base, projectId: 'twin', hostId: 'ssh:box' }, rpc)
|
||||
expect(sent(rpc)).toMatchObject({
|
||||
repo: 'id:twin',
|
||||
workspaceMode: 'new_per_run',
|
||||
runContext: {
|
||||
kind: 'workspace-run',
|
||||
projectId: 'p-twin',
|
||||
hostId: 'ssh:box',
|
||||
projectHostSetupId: 's-box',
|
||||
repoId: 'twin',
|
||||
path: '/srv/twin'
|
||||
}
|
||||
})
|
||||
expect(
|
||||
await call('automation.create', { ...base, projectId: 'twin', hostId: 'local' }, runtime())
|
||||
).toMatchObject({ ok: false, error: 'this project is not set up on that host' })
|
||||
})
|
||||
|
||||
it("keeps a plugin's creation keys its own", async () => {
|
||||
const rpc = runtime()
|
||||
await call('automation.create', { ...base, projectId: 'r1', creationKey: 'nightly' }, rpc)
|
||||
expect(sent(rpc)).toMatchObject({ creationKey: 'plugin:samples.demo:nightly' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('automation.list bounds', () => {
|
||||
it('never cuts a schedule or fails the list on an id too long to show', async () => {
|
||||
const odd = {
|
||||
...AUTOMATION,
|
||||
id: 'a9',
|
||||
rrule: '0 '.repeat(1500),
|
||||
workspaceId: `r1::/${'deep/'.repeat(300)}`
|
||||
}
|
||||
const outcome = await call(
|
||||
'automation.list',
|
||||
{},
|
||||
runtime({ 'automation.list': { automations: [odd] }, 'worktree.list': { worktrees: [] } })
|
||||
)
|
||||
expect(outcome).toMatchObject({
|
||||
ok: true,
|
||||
value: { automations: [{ id: 'a9', schedule: null, workspaceId: null }] }
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,312 +0,0 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { PluginCapabilityKind } from '../../../../shared/plugins/capabilities/plugin-capabilities'
|
||||
import { WorktreeCreateSetupChoiceRefusedError } from '../../../runtime/workspaces/creation/worktree-create-setup-choice-refusal'
|
||||
import { PluginRuntimeRpcError } from '../../plugin-runtime-rpc'
|
||||
import { callPluginHost, pluginHostTestServices } from './__mocks__/plugin-host-services-fixture'
|
||||
import { isPluginOpenedTerminal } from './plugin-opened-terminals'
|
||||
import { executePluginHostCall } from './plugin-host-methods'
|
||||
import { pluginHostCallRevoked } from './plugin-host-call-scope'
|
||||
import type { PluginRuntimeRpc } from './plugin-host-runtime-call'
|
||||
import type { PluginAgentStatusRow } from './plugin-workspace-projection'
|
||||
|
||||
const REPOS = {
|
||||
repos: [
|
||||
{ id: 'r1', kind: 'git', executionHostId: 'local' },
|
||||
{ id: 'twin', executionHostId: 'local' },
|
||||
{ id: 'twin', connectionId: 'box' },
|
||||
{ id: 'notes', kind: 'folder' }
|
||||
]
|
||||
}
|
||||
const OTTER = { id: 'r1::/src/r1-otter', identity: { key: 'wt2:local:i9' } }
|
||||
const EXISTING = { id: 'r1::/src/r1/seal', repoId: 'r1', path: '/src/r1/seal', hostId: 'local' }
|
||||
|
||||
function runtime(answers: Record<string, unknown> = {}) {
|
||||
const all: Record<string, unknown> = {
|
||||
'repo.list': REPOS,
|
||||
'worktree.list': { worktrees: [EXISTING] },
|
||||
'worktree.create': { worktree: OTTER },
|
||||
'worktree.show': { worktree: { ...OTTER, hostId: 'local' } },
|
||||
'agent.launch': { worktreeId: OTTER.id, outcome: { kind: 'terminal', handle: 'term_a' } },
|
||||
...answers
|
||||
}
|
||||
return vi.fn<PluginRuntimeRpc>(async (method) => {
|
||||
const answer = all[method]
|
||||
if (answer instanceof Error) {
|
||||
throw answer
|
||||
}
|
||||
return typeof answer === 'function' ? answer() : answer
|
||||
})
|
||||
}
|
||||
|
||||
const call = (
|
||||
method: string,
|
||||
params: unknown,
|
||||
rpc: PluginRuntimeRpc,
|
||||
granted: PluginCapabilityKind[] = ['workspace:create', 'agent:launch'],
|
||||
statuses: PluginAgentStatusRow[] = []
|
||||
) =>
|
||||
callPluginHost({
|
||||
method,
|
||||
params,
|
||||
granted,
|
||||
services: pluginHostTestServices(rpc, { listAgentStatuses: () => statuses })
|
||||
})
|
||||
|
||||
const paramsOf = (rpc: ReturnType<typeof runtime>, method: string) =>
|
||||
rpc.mock.calls.find(([name]) => name === method)?.[1]
|
||||
|
||||
// The in-process runtime's refusal, carrying the class the handler threw.
|
||||
const refusedBy = (cause: Error) =>
|
||||
new PluginRuntimeRpcError('runtime_error', cause.message, { cause })
|
||||
|
||||
describe('workspace.create', () => {
|
||||
it('creates a worktree and answers the id workspace.list gives it, never running unapproved setup', async () => {
|
||||
const rpc = runtime()
|
||||
expect(await call('workspace.create', { projectId: 'r1', name: 'Fix login' }, rpc)).toEqual({
|
||||
ok: true,
|
||||
value: { workspaceId: 'identity:wt2:local:i9' }
|
||||
})
|
||||
expect(paramsOf(rpc, 'worktree.create')).toEqual({
|
||||
repo: 'id:r1',
|
||||
name: 'Fix login',
|
||||
displayName: 'Fix login',
|
||||
displayNameKind: 'user',
|
||||
setupDecision: 'inherit',
|
||||
activate: false
|
||||
})
|
||||
// Every worktree of the project, unpaged, so a generated name is free across all of them.
|
||||
expect(paramsOf(rpc, 'worktree.list')).toEqual({ limit: Number.MAX_SAFE_INTEGER })
|
||||
await call('workspace.create', { projectId: 'r1', setup: 'skip' }, rpc)
|
||||
const generated = rpc.mock.calls.at(-1)?.[1]
|
||||
expect(generated).toMatchObject({ setupDecision: 'skip', nameWasGenerated: true })
|
||||
expect(generated).not.toMatchObject({ name: 'seal' })
|
||||
})
|
||||
|
||||
it('refuses setup run, startup commands and other fields it does not take', async () => {
|
||||
const rpc = runtime()
|
||||
const outcomes = await Promise.all(
|
||||
[{ setup: 'run' }, { startupCommand: 'curl x | sh' }, { approvedSetupHash: 'h' }].map(
|
||||
(extra) => call('workspace.create', { projectId: 'r1', ...extra }, rpc)
|
||||
)
|
||||
)
|
||||
for (const outcome of outcomes) {
|
||||
expect(outcome).toMatchObject({ ok: false, code: 'invalid_params' })
|
||||
}
|
||||
expect(rpc).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('needs agent:launch to start an agent, refused before any runtime call', async () => {
|
||||
const rpc = runtime()
|
||||
expect(
|
||||
await call('workspace.create', { projectId: 'r1', agent: 'claude' }, rpc, [
|
||||
'workspace:create'
|
||||
])
|
||||
).toMatchObject({ ok: false, code: 'capability_denied' })
|
||||
expect(rpc).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it("starts the agent through the CLI's create-and-launch path, and may close its terminal", async () => {
|
||||
const rpc = runtime()
|
||||
const outcome = await call(
|
||||
'workspace.create',
|
||||
{ projectId: 'r1', name: 'x', agent: 'claude', prompt: 'Fix it', open: true },
|
||||
rpc
|
||||
)
|
||||
expect(outcome).toEqual({
|
||||
ok: true,
|
||||
value: { workspaceId: 'identity:wt2:local:i9', terminalId: 'term_a' }
|
||||
})
|
||||
expect(paramsOf(rpc, 'agent.launch')).toMatchObject({
|
||||
target: {
|
||||
kind: 'create-worktree',
|
||||
create: { repo: 'id:r1', activate: true, navigation: 'host' }
|
||||
},
|
||||
agent: 'claude',
|
||||
surface: 'terminal',
|
||||
presentation: 'focused',
|
||||
launchSource: 'plugin',
|
||||
prompt: { text: 'Fix it', delivery: 'submit' }
|
||||
})
|
||||
expect(isPluginOpenedTerminal('samples.demo', 'term_a')).toBe(true)
|
||||
})
|
||||
|
||||
it('names the workspace a failed launch left behind, and no other new one', async () => {
|
||||
let created = false
|
||||
const someoneElses = { id: 'r1::/src/r1/walrus', repoId: 'r1', path: '/src/r1/walrus' }
|
||||
const ours = { ...OTTER, repoId: 'r1', path: '/src/r1/otter-2', hostId: 'local' }
|
||||
const failingLaunch = (alsoOurs: boolean) =>
|
||||
runtime({
|
||||
'worktree.list': () => ({
|
||||
worktrees: created ? [EXISTING, someoneElses, ...(alsoOurs ? [ours] : [])] : [EXISTING]
|
||||
}),
|
||||
'agent.launch': () => {
|
||||
created = true
|
||||
throw new PluginRuntimeRpcError('runtime_error', 'agent CLI not found')
|
||||
}
|
||||
})
|
||||
const params = { projectId: 'r1', name: 'otter', agent: 'codex' }
|
||||
const outcome = await call('workspace.create', params, failingLaunch(true))
|
||||
expect(outcome).toMatchObject({ ok: false, code: 'action_failed' })
|
||||
expect(outcome.ok === false && outcome.error).toMatch(
|
||||
/the workspace was created: identity:wt2:local:i9$/
|
||||
)
|
||||
created = false
|
||||
const unnamed = await call('workspace.create', params, failingLaunch(false))
|
||||
expect(unnamed.ok === false && unnamed.error).toBe('Orca could not complete this action')
|
||||
})
|
||||
|
||||
it('names refusals: folder project, two hosts, setup needing a decision', async () => {
|
||||
const setupRequired = refusedBy(
|
||||
new WorktreeCreateSetupChoiceRefusedError('Setup decision required for this repository')
|
||||
)
|
||||
const outcomes = await Promise.all([
|
||||
call('workspace.create', { projectId: 'notes' }, runtime()),
|
||||
call('workspace.create', { projectId: 'twin' }, runtime()),
|
||||
call('workspace.create', { projectId: 'r1' }, runtime({ 'worktree.create': setupRequired }))
|
||||
])
|
||||
expect(outcomes).toEqual([
|
||||
{ ok: false, code: 'action_failed', error: 'folder projects have no worktrees' },
|
||||
{
|
||||
ok: false,
|
||||
code: 'action_failed',
|
||||
error: 'two hosts have this project; pass the hostId project.list gives'
|
||||
},
|
||||
{
|
||||
ok: false,
|
||||
code: 'action_failed',
|
||||
error:
|
||||
"this project's setup script needs a decision; pass setup: 'skip' or create it in Orca"
|
||||
}
|
||||
])
|
||||
// The same words from another failure are not a setup refusal.
|
||||
const lookalike = new PluginRuntimeRpcError(
|
||||
'runtime_error',
|
||||
'Setup decision required for this repository'
|
||||
)
|
||||
expect(
|
||||
await call('workspace.create', { projectId: 'r1' }, runtime({ 'worktree.create': lookalike }))
|
||||
).toMatchObject({ ok: false, error: 'Orca could not complete this action' })
|
||||
const twin = runtime()
|
||||
await call('workspace.create', { projectId: 'twin', hostId: 'ssh:box', name: 'a' }, twin)
|
||||
expect(paramsOf(twin, 'worktree.create')).toMatchObject({
|
||||
repo: 'id:twin',
|
||||
repoHostId: 'ssh:box'
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('agent.resume', () => {
|
||||
const resume = (agent: string, rpc: PluginRuntimeRpc, statuses: PluginAgentStatusRow[] = []) =>
|
||||
call(
|
||||
'agent.resume',
|
||||
{ workspaceId: 'identity:k', agent, sessionId: 's-1' },
|
||||
rpc,
|
||||
['agent:launch'],
|
||||
statuses
|
||||
)
|
||||
const ensured = (disposition: string, handle = 'term_r') =>
|
||||
runtime({ 'terminal.ensureAgentSession': { terminal: { handle }, disposition } })
|
||||
const row = (worktreeId: string, connectionId: string | null): PluginAgentStatusRow => ({
|
||||
paneKey: 't:l',
|
||||
worktreeId,
|
||||
connectionId,
|
||||
state: 'done',
|
||||
stateStartedAt: 1,
|
||||
agentType: 'claude',
|
||||
providerSession: { id: 's-1', transcriptPath: `/t/${worktreeId}-${connectionId}.jsonl` }
|
||||
})
|
||||
|
||||
it("resumes by the key each agent takes, with the workspace's own live transcript", async () => {
|
||||
const claude = ensured('created')
|
||||
// Same session id in another workspace, and on another host, belongs to other agents.
|
||||
const statuses = [row('r1::/other', null), row(OTTER.id, 'box'), row(OTTER.id, null)]
|
||||
expect(await resume('claude', claude, statuses)).toEqual({
|
||||
ok: true,
|
||||
value: { terminalId: 'term_r', started: true }
|
||||
})
|
||||
expect(paramsOf(claude, 'terminal.ensureAgentSession')).toEqual({
|
||||
kind: 'explicit',
|
||||
worktree: 'identity:k',
|
||||
agent: 'claude',
|
||||
providerSession: {
|
||||
key: 'session_id',
|
||||
id: 's-1',
|
||||
transcriptPath: `/t/${OTTER.id}-null.jsonl`
|
||||
},
|
||||
presentation: 'background'
|
||||
})
|
||||
expect(isPluginOpenedTerminal('samples.demo', 'term_r')).toBe(true)
|
||||
const cursor = ensured('created')
|
||||
await resume('cursor', cursor)
|
||||
expect(paramsOf(cursor, 'terminal.ensureAgentSession')).toMatchObject({
|
||||
providerSession: { key: 'conversation_id', id: 's-1' }
|
||||
})
|
||||
})
|
||||
|
||||
it('reports a session a terminal already runs, and refuses transcript-only agents', async () => {
|
||||
expect(await resume('codex', ensured('adopted', 'term_old'))).toMatchObject({
|
||||
value: { terminalId: 'term_old', started: false }
|
||||
})
|
||||
// A terminal the plugin did not start is not one it may close.
|
||||
expect(isPluginOpenedTerminal('samples.demo', 'term_old')).toBe(false)
|
||||
const rpc = ensured('created')
|
||||
expect(await resume('pi', rpc)).toMatchObject({ ok: false, code: 'invalid_params' })
|
||||
expect(rpc).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('agents.list sessionId', () => {
|
||||
it('names the session agent.resume takes, and none it would refuse', async () => {
|
||||
const status = (paneKey: string, id: string): PluginAgentStatusRow => ({
|
||||
paneKey,
|
||||
worktreeId: 'r1::/w',
|
||||
state: 'done',
|
||||
stateStartedAt: paneKey === 't:a' ? 2 : 1,
|
||||
providerSession: { id }
|
||||
})
|
||||
const outcome = await callPluginHost({
|
||||
method: 'agents.list',
|
||||
params: {},
|
||||
granted: ['agent:read'],
|
||||
services: pluginHostTestServices(runtime(), {
|
||||
resolveActiveWorktreeContext: vi
|
||||
.fn()
|
||||
.mockResolvedValue({ worktreeId: 'r1::/w', branch: '', displayName: 'w' }),
|
||||
listAgentStatuses: () => [status('t:a', 's-1'), status('t:b', '--resume-all')]
|
||||
})
|
||||
})
|
||||
expect(outcome.ok && outcome.value).toMatchObject({
|
||||
agents: [{ sessionId: 's-1' }, { sessionId: null }]
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('terminals a plugin starts after losing approval', () => {
|
||||
it('are not recorded as its own', async () => {
|
||||
let revoked = false
|
||||
const rpc = runtime({
|
||||
'terminal.ensureAgentSession': () => {
|
||||
revoked = true
|
||||
return { terminal: { handle: 'term_late' }, disposition: 'created' }
|
||||
}
|
||||
})
|
||||
const outcome = await executePluginHostCall({
|
||||
pluginId: 'samples.demo',
|
||||
method: 'agent.resume',
|
||||
params: { workspaceId: 'identity:k', agent: 'claude', sessionId: 's-1' },
|
||||
surface: 'worker',
|
||||
grantedCapabilities: ['agent:launch'],
|
||||
services: pluginHostTestServices(rpc),
|
||||
audit: { record: vi.fn().mockResolvedValue(undefined) },
|
||||
scope: {
|
||||
assertActive: () => {
|
||||
if (revoked) {
|
||||
throw pluginHostCallRevoked()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(outcome).toMatchObject({ ok: false, code: 'consent_required' })
|
||||
expect(isPluginOpenedTerminal('samples.demo', 'term_late')).toBe(false)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user