Report hold availability by execution context and cover forced disconnect
This commit is contained in:
1 parent
794cd66634
commit
df280fc4e5
4 files changed
+28
-2
No files matched your search
@@ -319,7 +319,7 @@ it('merges startup capabilities into runtime native fields', async () => {
|
||||
coordinateSpace: 'screenshot-pixels', methods: [
|
||||
'activate', 'click', 'drag', 'findApps', 'getApp', 'getCapabilities', 'getState', 'invoke',
|
||||
'listActions', 'listApps', 'listWindows', 'mouseMove', 'paste', 'performAction', 'pressKey', 'screenshot', 'scroll',
|
||||
'selectText', 'sendKeyEvent', 'setValue', 'show', 'toggleMouse', 'typeText',
|
||||
'selectText', 'setValue', 'show', 'typeText',
|
||||
] })
|
||||
expect(native.request).toHaveBeenCalledExactlyOnceWith('getCapabilities', {}, expect.any(AbortSignal), brandString<ToolCallId>('lifecycle-1'))
|
||||
})
|
||||
|
||||
@@ -185,6 +185,8 @@ describe('Computer Use MCP composition', () => {
|
||||
it('refuses persistent downs outside a turn and still completes clicks through MCP', async () => {
|
||||
const { client, native, run } = await setup()
|
||||
expect(client.getInstructions()).toContain('MCP programs cannot hold keys or mouse buttons')
|
||||
const capabilities = await run('inspect(JSON.stringify((await cua.getCapabilities()).methods))')
|
||||
expect(texts(capabilities).join('')).not.toMatch(/sendKeyEvent|toggleMouse/)
|
||||
const selected = await run('var app = await cua.getApp("test.fixture"); var win = await app.getWindow("7"); await win.getAccessibilityTree()')
|
||||
expect(selected.isError).not.toBe(true)
|
||||
for (const code of ['await app.sendKeyEvent("w", "down")', 'await win.toggleMouse("left", "down")']) {
|
||||
|
||||
@@ -363,10 +363,11 @@ export function installCua(ctx: Context, config: CuaConfig, backend: CuaBackend)
|
||||
if (method === 'getCapabilities') {
|
||||
const runtime = z.record(z.string(), z.json()).parse(result)
|
||||
const capabilities = backend.capabilities
|
||||
const canHoldInput = !inputTurns || inputTurns.scope(agent) !== undefined
|
||||
return {
|
||||
...runtime,
|
||||
platform: capabilities.platform, systemPointer,
|
||||
methods: [...capabilities.methods],
|
||||
methods: capabilities.methods.filter(method => canHoldInput || (method !== 'sendKeyEvent' && method !== 'toggleMouse')),
|
||||
appLevelAccessibility: capabilities.appLevelAccessibility,
|
||||
keyboard: [...capabilities.keyboard],
|
||||
browser: capabilities.browser,
|
||||
|
||||
@@ -527,3 +527,26 @@ it('cleans one task without releasing another connection and prevents a queued t
|
||||
}
|
||||
expect(f.native.held).toEqual([])
|
||||
})
|
||||
|
||||
it('reports disconnect after a dispatched down and blocks a later program in the same turn', async () => {
|
||||
const f = await setup([holdProgram, 'await cua.getApp("test.fixture")'], 'macos', undefined, true, true)
|
||||
const down = f.native.controlNext('sendKeyEvent', { afterDispatch: true })
|
||||
const running = f.run()
|
||||
await down.entered
|
||||
down.disconnect()
|
||||
await running
|
||||
const results = f.agent.session.deriveMessages().filter(message => message.role === 'tool')
|
||||
expect(results.map(result => result.isError)).toEqual([true, true])
|
||||
expect(JSON.stringify(results[1])).toContain('INPUT_CLEANUP_UNCONFIRMED')
|
||||
expect(f.native.calls.filter(call => call.method === 'getApp')).toHaveLength(1)
|
||||
expect(f.native.calls.some(call => call.method === 'releaseHeldInputs')).toBe(false)
|
||||
expect(f.agent.session.snapshotEvents().find(event => event.type === 'turn/end')?.data.reason.kind).toBe('error')
|
||||
})
|
||||
|
||||
it('finalizes without native cleanup when prompt assembly fails before input admission', async () => {
|
||||
const f = await setup([holdProgram], 'macos', undefined, true, true)
|
||||
f.ctx.on('system-prompt/assemble', async () => { throw new Error('Fixture assembly failed') })
|
||||
await f.run()
|
||||
expect(f.native.calls).toEqual([])
|
||||
expect(f.agent.session.snapshotEvents().find(event => event.type === 'turn/end')?.data.reason.kind).toBe('error')
|
||||
})
|
||||
Reference in new issue
Block a user