|
1 | 1 | import { expect, test } from 'vitest'; |
2 | 2 | import { AppError } from '@agent-device/kernel/errors'; |
| 3 | +import { commandAcceptsReadinessBudget } from '@agent-device/command-registry/registry'; |
| 4 | +import { findCommandMetadata, listCommandMetadata } from '../command-metadata.ts'; |
3 | 5 | import { interactionCommandMetadata } from './metadata.ts'; |
4 | 6 |
|
5 | 7 | // `fill <target> ""` is the clear-field primitive (#2063): before it existed, emptying an input |
@@ -50,3 +52,34 @@ test('type keeps refusing an empty text: appending nothing is not a clear', () = |
50 | 52 | expect((error as AppError).code).toBe('INVALID_ARGS'); |
51 | 53 | } |
52 | 54 | }); |
| 55 | + |
| 56 | +const SELECTOR_TARGET = { kind: 'selector', selector: 'label=Continue' }; |
| 57 | + |
| 58 | +test('a command advertises readinessTimeoutMs exactly when its descriptor declares the budget', () => { |
| 59 | + for (const metadata of listCommandMetadata()) { |
| 60 | + const properties = metadata.inputSchema.properties ?? {}; |
| 61 | + expect('readinessTimeoutMs' in properties, metadata.name).toBe( |
| 62 | + commandAcceptsReadinessBudget(metadata.name), |
| 63 | + ); |
| 64 | + } |
| 65 | +}); |
| 66 | + |
| 67 | +test('press reads readinessTimeoutMs', () => { |
| 68 | + const input = findCommandMetadata('press').readInput({ |
| 69 | + target: SELECTOR_TARGET, |
| 70 | + readinessTimeoutMs: 2_000, |
| 71 | + }) as { readinessTimeoutMs?: number }; |
| 72 | + expect(input.readinessTimeoutMs).toBe(2_000); |
| 73 | +}); |
| 74 | + |
| 75 | +test('fill refuses readinessTimeoutMs with an input error, and reads without it', () => { |
| 76 | + const fill = findCommandMetadata('fill'); |
| 77 | + expect(() => fill.readInput({ target: SELECTOR_TARGET, text: 'hi' })).not.toThrow(); |
| 78 | + let refusal: unknown; |
| 79 | + try { |
| 80 | + fill.readInput({ target: SELECTOR_TARGET, text: 'hi', readinessTimeoutMs: 2_000 }); |
| 81 | + } catch (error) { |
| 82 | + refusal = error; |
| 83 | + } |
| 84 | + expect(refusal instanceof AppError && refusal.code).toBe('INVALID_ARGS'); |
| 85 | +}); |
0 commit comments