mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
test(plugins): host API 1.9 coverage; regenerate plugin artifacts
This commit is contained in:
@@ -63,7 +63,7 @@ The exact release the catalog vouches for. Orca refuses bytes that differ.
|
||||
| `images` | [CatalogImages](#catalogimages) | no | 1.4.245 | Images extracted from the release by catalog CI, which re-encodes them and strips metadata. Same rules as the manifest: icon PNG, WEBP, static, at least 128×128, square, at most 256 KB. Cover PNG, JPEG, WEBP, static, at least 800×500, at most 1024 KB. Screenshots PNG, JPEG, WEBP, static, at least 1280×800, at most 1536 KB. Images must not imitate Orca's trust badges. |
|
||||
| `themePreview` | [CatalogThemePreview](#catalogthemepreview)[] | no | 1.4.245 | Up to 4 theme palettes for listing art. Display only; the installed theme files decide the real colors. |
|
||||
| `contributes` | [CatalogContribution](#catalogcontribution)[] | no | 1.4.245 | What the release adds, as the listing shows it. Generate it with the catalog tooling; Orca refuses an install whose manifest says otherwise. |
|
||||
| `capabilities` | (`"workspace:read"` \| `"workspace:write"` \| `"agent:read"` \| `"agent:launch"` \| `"terminal:send"` \| `"terminal:read"` \| `"notifications:show"` \| `"storage:own"` \| `"secrets:own"` \| `"settings:own"` \| `"appearance:write"` \| `"workspace:create"` \| `"automation:read"` \| `"automation:write"`)[] | no | 1.4.245 | Every capability the release asks for. Orca refuses an install whose manifest asks for different ones. Example: `["notifications:show"]` |
|
||||
| `capabilities` | (`"workspace:read"` \| `"workspace:write"` \| `"agent:read"` \| `"agent:launch"` \| `"terminal:send"` \| `"terminal:read"` \| `"notifications:show"` \| `"storage:own"` \| `"secrets:own"` \| `"settings:own"` \| `"appearance:write"` \| `"workspace:create"` \| `"automation:read"` \| `"automation:write"` \| `"history:read"`)[] | no | 1.4.245 | Every capability the release asks for. Orca refuses an install whose manifest asks for different ones. Example: `["notifications:show"]` |
|
||||
| `fileTypes` | string[] | no | 1.4.245 | Extensions, without the dot, that this release opens. Orca suggests the plugin when such a file has no viewer. |
|
||||
| `editorFileTypes` | string[] | no | 1.4.245 | The `fileTypes` this release opens in a custom editor. Orca suggests the plugin for such a file even when it already opens it as text. |
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ A host API the plugin may call once the user consents.
|
||||
|
||||
| Field | Type | Required | Since | Description |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `kind` | `"workspace:read"` \| `"workspace:write"` \| `"agent:read"` \| `"agent:launch"` \| `"terminal:send"` \| `"terminal:read"` \| `"notifications:show"` \| `"storage:own"` \| `"secrets:own"` \| `"settings:own"` \| `"appearance:write"` \| `"workspace:create"` \| `"automation:read"` \| `"automation:write"` | yes | 1.4.160 | Capability granted on user consent. |
|
||||
| `kind` | `"workspace:read"` \| `"workspace:write"` \| `"agent:read"` \| `"agent:launch"` \| `"terminal:send"` \| `"terminal:read"` \| `"notifications:show"` \| `"storage:own"` \| `"secrets:own"` \| `"settings:own"` \| `"appearance:write"` \| `"workspace:create"` \| `"automation:read"` \| `"automation:write"` \| `"history:read"` | yes | 1.4.160 | Capability granted on user consent. |
|
||||
|
||||
## Screenshot
|
||||
|
||||
|
||||
@@ -349,7 +349,7 @@
|
||||
"notifications:show"
|
||||
]
|
||||
],
|
||||
"maxItems": 14,
|
||||
"maxItems": 15,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
@@ -367,7 +367,8 @@
|
||||
"appearance:write",
|
||||
"workspace:create",
|
||||
"automation:read",
|
||||
"automation:write"
|
||||
"automation:write",
|
||||
"history:read"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1584,7 +1584,8 @@
|
||||
"appearance:write",
|
||||
"workspace:create",
|
||||
"automation:read",
|
||||
"automation:write"
|
||||
"automation:write",
|
||||
"history:read"
|
||||
],
|
||||
"description": "Capability granted on user consent.",
|
||||
"x-orca-since": "1.4.160",
|
||||
@@ -1602,7 +1603,8 @@
|
||||
"appearance:write": "1.4.249",
|
||||
"workspace:create": "1.4.259",
|
||||
"automation:read": "1.4.259",
|
||||
"automation:write": "1.4.259"
|
||||
"automation:write": "1.4.259",
|
||||
"history:read": "1.4.260"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
+2
-2
@@ -109,8 +109,8 @@ declare module 'orca' {
|
||||
"files.saveAs": { params: { suggestedName?: string; mimeType?: string; data: string | ArrayBuffer }; result: { status: "saved" | "cancelled" } }
|
||||
/** Asks the plugin's own worker to run the handler it registered with `orca.panels.handle(name)`, starting the worker if needed; resolves with what the handler returned. `unknown_method` when no handler has that name. */
|
||||
"plugin.request": { params: { name: string; input?: JsonValue; timeoutMs?: number }; result: { output: JsonValue } }
|
||||
/** The agents in the focused workspace: their terminal, title, agent kind and status. `agent.status.changed` reports each change after. */
|
||||
"agents.list": { params: Record<string, never> | undefined; result: { agents: { terminalId: string | null; title: string | null; agent: string | null; state: "working" | "blocked" | "waiting" | "done"; stateStartedAt: number; sessionId?: string | null }[] } }
|
||||
/** The agents in the focused workspace: their terminal, title, agent kind, status, session and dispatched task. `agent.status.changed` reports each change after. */
|
||||
"agents.list": { params: Record<string, never> | undefined; result: { agents: { terminalId: string | null; title: string | null; agent: string | null; state: "working" | "blocked" | "waiting" | "done"; stateStartedAt: number; sessionId?: string | null; task?: { title: string } | null }[] } }
|
||||
/** Delivers a workspace, agent or editor event to this panel as `orca.on(event)`; needs the event's read capability, when it has one. The frame APIs call it for you. */
|
||||
"events.subscribe": { params: { event: "workspace.created" | "workspace.removed" | "agent.status.changed" | "workspace.changed" | "editor.typography.changed" }; result: { ok: true } }
|
||||
/** The font family, size, weight, line height, ligatures, word wrap and minimap Orca's file editor uses now, editor zoom included. `editor.typography.changed` reports each change after. */
|
||||
|
||||
+10
-4
@@ -1,5 +1,5 @@
|
||||
// Generated by `pnpm generate:plugin-author-typings` from src/shared/plugins. Do not edit.
|
||||
// Host API 1.8 types shared by frames (`window.orca`) and workers (`activate(orca)`).
|
||||
// Host API 1.9 types shared by frames (`window.orca`) and workers (`activate(orca)`).
|
||||
|
||||
declare module 'orca/host' {
|
||||
// Why from 'orca': authors declare `PluginRequests` and `PluginPanelEvents` there once, and
|
||||
@@ -130,10 +130,10 @@ declare module 'orca/host' {
|
||||
result: { output: JsonValue }
|
||||
surfaces: "panel" | "editor"
|
||||
}
|
||||
/** The agents in the focused workspace: their terminal, title, agent kind and status. `agent.status.changed` reports each change after. Since host API 1.2. */
|
||||
/** The agents in the focused workspace: their terminal, title, agent kind, status, session and dispatched task. `agent.status.changed` reports each change after. Since host API 1.2. */
|
||||
"agents.list": {
|
||||
params: Record<string, never> | undefined
|
||||
result: { agents: { terminalId: string | null; title: string | null; agent: string | null; state: "working" | "blocked" | "waiting" | "done"; stateStartedAt: number; sessionId?: string | null }[] }
|
||||
result: { agents: { terminalId: string | null; title: string | null; agent: string | null; state: "working" | "blocked" | "waiting" | "done"; stateStartedAt: number; sessionId?: string | null; task?: { title: string } | null }[] }
|
||||
surfaces: "worker" | "panel" | "editor"
|
||||
}
|
||||
/** Delivers a workspace, agent or editor event to this panel as `orca.on(event)`; needs the event's read capability, when it has one. The frame APIs call it for you. Since host API 1.2. */
|
||||
@@ -238,7 +238,7 @@ declare module 'orca/host' {
|
||||
result: { workspaceId: string; terminalId?: string }
|
||||
surfaces: "worker"
|
||||
}
|
||||
/** Resumes an agent's earlier session by its `sessionId` in a new terminal of a workspace, in the background; `started` is false when an Orca terminal already runs it. In WSL it uses the distro's default agent account, as `agent.launch` does. Since host API 1.8. */
|
||||
/** Resumes an agent's earlier session by its `sessionId` in a new terminal of a workspace, in the background; `started` is false when an Orca terminal already runs it. A past session that Agent Session History lists on this computer is prepared first, as Orca's own Resume does (from host API 1.9); only `agent:launch` is needed, since the plugin must already know the id. In WSL it uses the distro's default agent account, as `agent.launch` does. Since host API 1.8. */
|
||||
"agent.resume": {
|
||||
params: { workspaceId: string; agent: "claude" | "codebuddy" | "codex" | "qoder" | "qoder-cn" | "qwen-code" | "gemini" | "antigravity" | "opencode" | "opencode2" | "pi" | "mimo-code" | "droid" | "grok" | "devin" | "omp" | "prime-agent" | "copilot" | "cursor" | "kimi" | "muse" | "zcode" | "dsh" | "jcode" | "kiro" | "hermes"; sessionId: string }
|
||||
result: { terminalId: string; started: boolean }
|
||||
@@ -268,6 +268,12 @@ declare module 'orca/host' {
|
||||
result: { deleted: boolean; reason?: "cancelled" | "consent-unavailable" | "changed" }
|
||||
surfaces: "worker"
|
||||
}
|
||||
/** Past agent sessions in Orca's Agent Session History on this computer, newest first: title, agent, workspace, branch, times, message and token counts, and whether a terminal runs it. Never the conversation or file paths, though a title can be the start of its first message. `agent.resume` resumes one by its `sessionId`, for agents that resume by id. Since host API 1.9. */
|
||||
"agent.listSessions": {
|
||||
params: { workspaceId?: string; limit?: number } | undefined
|
||||
result: { sessions: { sessionId: string; agent: string; title: string; workspaceId: string | null; hostId: string; branch: string | null; createdAt: number | null; updatedAt: number; messageCount: number; totalTokens: number; running: boolean }[]; truncated: boolean }
|
||||
surfaces: "worker"
|
||||
}
|
||||
/** The font family, size, weight, line height, ligatures, word wrap and minimap Orca's file editor uses now, editor zoom included. `editor.typography.changed` reports each change after. Since host API 1.6. */
|
||||
"editor.readTypography": {
|
||||
params: Record<string, never> | undefined
|
||||
|
||||
@@ -198,7 +198,7 @@ An item in the status bar. Requires the `declarative` profile; a `trusted-worker
|
||||
|
||||
A host API the plugin may call once the user consents.
|
||||
|
||||
- `kind` (one of workspace:read, workspace:write, agent:read, agent:launch, terminal:send, terminal:read, notifications:show, storage:own, secrets:own, settings:own, appearance:write, workspace:create, automation:read, automation:write, required, since 1.4.160): Capability granted on user consent.
|
||||
- `kind` (one of workspace:read, workspace:write, agent:read, agent:launch, terminal:send, terminal:read, notifications:show, storage:own, secrets:own, settings:own, appearance:write, workspace:create, automation:read, automation:write, history:read, required, since 1.4.160): Capability granted on user consent.
|
||||
|
||||
## Screenshot
|
||||
|
||||
|
||||
@@ -26,7 +26,13 @@ function runtime(terminals: { handle: string; title: string | null; paneTitle?:
|
||||
}))
|
||||
})),
|
||||
sendTerminal: vi.fn(),
|
||||
dispatchPluginNotification: vi.fn()
|
||||
dispatchPluginNotification: vi.fn(),
|
||||
listAgentTasksByPaneKey: vi.fn(
|
||||
(): Record<string, { taskTitle?: string; dispatchId: string }> => ({
|
||||
'tab0:worker': { taskTitle: 'Write the tests', dispatchId: 'd-1' },
|
||||
'tab0:untitled': { dispatchId: 'd-2' }
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,3 +106,15 @@ describe('workspace.changed for plugins', () => {
|
||||
expect(change.context).toMatchObject({ workspaceId: 'identity:wt2:local:i1', branch: 'main' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('agents.list task titles for plugins', () => {
|
||||
it("passes each pane's task 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', '']
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,461 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
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 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: [
|
||||
// A project's own folder, with a worktree nested inside it.
|
||||
{ id: 'r1::/src/r1', repoId: 'r1', displayName: 'r1', path: '/src/r1', hostId: 'local' },
|
||||
{
|
||||
id: 'r1::/src/r1/.worktrees/seal',
|
||||
repoId: 'r1',
|
||||
displayName: 'seal',
|
||||
path: '/src/r1/.worktrees/seal',
|
||||
hostId: 'local',
|
||||
identity: { key: 'wt2:local:seal' }
|
||||
},
|
||||
// The same path on an SSH machine is another computer's folder.
|
||||
{ id: 'r2::/src/r1', repoId: 'r2', displayName: 'remote', path: '/src/r1', hostId: 'ssh:box' }
|
||||
]
|
||||
}
|
||||
const FOLDERS = {
|
||||
folderWorkspaces: [{ id: 'notes', name: 'Notes', folderPath: '/notes', executionHostId: null }]
|
||||
}
|
||||
|
||||
function vaultRow(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
id: 'row',
|
||||
executionHostId: 'local',
|
||||
agent: 'claude',
|
||||
sessionId: 's-1',
|
||||
title: 'Fix the login\n page',
|
||||
cwd: '/src/r1/.worktrees/seal/app',
|
||||
branch: 'refs/heads/seal',
|
||||
model: 'opus',
|
||||
filePath: '/home/me/.claude/projects/x/s-1.jsonl',
|
||||
codexHome: null,
|
||||
createdAt: '2026-01-01T00:00:00.000Z',
|
||||
updatedAt: '2026-01-02T00:00:00.000Z',
|
||||
modifiedAt: '2026-01-02T00:00:00.000Z',
|
||||
messageCount: 12,
|
||||
totalTokens: 3400,
|
||||
previewMessages: [{ role: 'user', text: 'secret prompt', timestamp: null }],
|
||||
firstUserPrompt: 'secret prompt',
|
||||
lastUserPrompt: 'another secret',
|
||||
queuedMessageCount: 0,
|
||||
subagentTranscriptCount: 0,
|
||||
resumeCommand: 'claude --resume s-1',
|
||||
subagent: null,
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
function runtime(answers: Record<string, unknown> = {}) {
|
||||
const all: Record<string, unknown> = {
|
||||
'worktree.list': WORKTREES,
|
||||
'repo.list': {
|
||||
repos: [
|
||||
{ id: 'r1', kind: 'git' },
|
||||
{ id: 'r2', connectionId: 'box' }
|
||||
]
|
||||
},
|
||||
'folderWorkspace.list': FOLDERS,
|
||||
'aiVault.listSessions': {
|
||||
sessions: [vaultRow()],
|
||||
issues: [],
|
||||
scannedAt: 'x',
|
||||
fingerprint: 'f1'
|
||||
},
|
||||
...answers
|
||||
}
|
||||
return vi.fn<PluginRuntimeRpc>(async (method, params) => {
|
||||
const answer = all[method]
|
||||
if (answer instanceof Error) {
|
||||
throw answer
|
||||
}
|
||||
return typeof answer === 'function' ? answer(params) : answer
|
||||
})
|
||||
}
|
||||
|
||||
const listSessions = (
|
||||
rpc: PluginRuntimeRpc,
|
||||
params: unknown = {},
|
||||
overrides: Partial<PluginHostServices> = {},
|
||||
granted: PluginCapabilityKind[] = ['history:read']
|
||||
) =>
|
||||
callPluginHost({
|
||||
method: 'agent.listSessions',
|
||||
params,
|
||||
granted,
|
||||
services: pluginHostTestServices(rpc, overrides)
|
||||
})
|
||||
|
||||
const vaultCalls = (rpc: ReturnType<typeof runtime>) =>
|
||||
rpc.mock.calls.filter(([method]) => method === 'aiVault.listSessions').map(([, params]) => params)
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
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('shares one read among calls, then revalidates it by fingerprint', async () => {
|
||||
vi.useFakeTimers()
|
||||
const rpc = runtime({
|
||||
'aiVault.listSessions': (params: { afterFingerprint?: string }) =>
|
||||
params.afterFingerprint === 'f1'
|
||||
? { sessions: [], issues: [], scannedAt: 'y', fingerprint: 'f1', unchanged: true }
|
||||
: { sessions: [vaultRow()], issues: [], scannedAt: 'x', fingerprint: 'f1' }
|
||||
})
|
||||
const [first, second] = await Promise.all([listSessions(rpc), listSessions(rpc)])
|
||||
expect(second).toEqual(first)
|
||||
expect(vaultCalls(rpc)).toHaveLength(1)
|
||||
vi.advanceTimersByTime(PLUGIN_HISTORY_TTL_MS + 1)
|
||||
// Unchanged history keeps the rows already read.
|
||||
expect(await listSessions(rpc)).toEqual(first)
|
||||
expect(vaultCalls(rpc)).toEqual([
|
||||
{ limit: 200, afterFingerprint: null },
|
||||
{ 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('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('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()
|
||||
})
|
||||
})
|
||||
@@ -4,6 +4,7 @@ import { PLUGIN_THEME_VIDEO_BACKGROUND_SINCE } from '../manifest/plugin-schema-f
|
||||
import { PLUGIN_EDITOR_TYPOGRAPHY_SINCE } from '../workers/plugin-host-api-editor-typography'
|
||||
import { PLUGIN_HOST_API_1_7_SINCE } from '../workers/plugin-host-api-workspace-methods'
|
||||
import { PLUGIN_HOST_API_1_8_SINCE } from '../workers/plugin-host-api-1-8'
|
||||
import { PLUGIN_HOST_API_1_9_SINCE } from '../workers/plugin-host-api-1-9'
|
||||
import { pluginHostVersion } from './plugin-host-version'
|
||||
|
||||
describe('pluginHostVersion', () => {
|
||||
@@ -13,7 +14,8 @@ describe('pluginHostVersion', () => {
|
||||
PLUGIN_THEME_VIDEO_BACKGROUND_SINCE,
|
||||
PLUGIN_EDITOR_TYPOGRAPHY_SINCE,
|
||||
PLUGIN_HOST_API_1_7_SINCE,
|
||||
PLUGIN_HOST_API_1_8_SINCE
|
||||
PLUGIN_HOST_API_1_8_SINCE,
|
||||
PLUGIN_HOST_API_1_9_SINCE
|
||||
]) {
|
||||
expect(satisfiesOrcaEngineRange(hostVersion, `>=${since}`)).toBe(true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user