Skip to content

Commit d6e5544

Browse files
thymikeeclaude
andcommitted
test(interaction): cover the execution-deadline hand-off and restore the timer spy
Assert the daemon hands off an execution deadline earlier than the result deadline, restore the AbortSignal.timeout spy in finally, and word the deadline hint so it fits a deadline that passed before any wait. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d974424 commit d6e5544

3 files changed

Lines changed: 35 additions & 20 deletions

File tree

‎packages/command-runtime/src/commands/interaction/runtime/pre-dispatch-admission.test.ts‎

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,26 +131,29 @@ for (const history of [
131131
] as const) {
132132
test(`an idle press after ${history.name} pays no extra capture, sleep or timer`, async () => {
133133
const timers = vi.spyOn(AbortSignal, 'timeout');
134-
for (const target of ['selector', 'ref'] as const) {
135-
const harness = createAdmissionDevice({
136-
platform: 'android',
137-
trees: [slideTree(10)],
138-
baselineAgeMs: history.baselineAgeMs,
139-
...('stationary' in history ? { baselineTree: slideTree(10) } : {}),
140-
});
134+
try {
135+
for (const target of ['selector', 'ref'] as const) {
136+
const harness = createAdmissionDevice({
137+
platform: 'android',
138+
trees: [slideTree(10)],
139+
baselineAgeMs: history.baselineAgeMs,
140+
...('stationary' in history ? { baselineTree: slideTree(10) } : {}),
141+
});
141142

142-
await harness.device.interactions.press(
143-
target === 'selector' ? selector('label="Slide target"') : ref('@e2'),
144-
{ session: 'default', deadlineAtMs: Date.now() + 60_000 },
145-
);
143+
await harness.device.interactions.press(
144+
target === 'selector' ? selector('label="Slide target"') : ref('@e2'),
145+
{ session: 'default', deadlineAtMs: Date.now() + 60_000 },
146+
);
146147

147-
assert.deepEqual(harness.taps, [{ x: 70, y: BUTTON_Y + 25 }], target);
148-
// A selector spends its resolution capture; a ref resolves against its stored tree.
149-
assert.equal(harness.captureStarts.length, target === 'selector' ? 1 : 0, target);
150-
assert.deepEqual(harness.sleeps, [], target);
148+
assert.deepEqual(harness.taps, [{ x: 70, y: BUTTON_Y + 25 }], target);
149+
// A selector spends its resolution capture; a ref resolves against its stored tree.
150+
assert.equal(harness.captureStarts.length, target === 'selector' ? 1 : 0, target);
151+
assert.deepEqual(harness.sleeps, [], target);
152+
}
153+
assert.equal(timers.mock.calls.length, 0, 'no deadline timer on the accept path');
154+
} finally {
155+
timers.mockRestore();
151156
}
152-
assert.equal(timers.mock.calls.length, 0, 'no deadline timer on the accept path');
153-
timers.mockRestore();
154157
});
155158
}
156159

‎packages/command-runtime/src/commands/interaction/runtime/pre-dispatch-admission.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function requestBudget(runtime: AgentDeviceRuntime, options: CommandContext): Ad
117117
createRequestDeadlineError({
118118
...(options.requestId ? { requestId: options.requestId } : {}),
119119
remainingMs,
120-
hint: `The request had ${remainingMs} ms left, which cannot cover the wait for the target to come to rest, so nothing was dispatched. Retry once the UI is idle, or allow the request more time.`,
120+
hint: `The request had ${remainingMs} ms left when pre-dispatch admission stopped, so nothing was dispatched. Retry once the UI is idle, or allow the request more time.`,
121121
}),
122122
'no',
123123
);

‎packages/daemon/src/execution/interaction/internal/interaction-touch-press.test.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { attachRefs } from '@agent-device/kernel/snapshot';
44
import {
55
clearRequestAbortRegistration,
66
registerRequestAbort,
7+
withRequestDeadline,
78
} from '@agent-device/host-kit/request';
89
import { makeIosSession } from '../../../__tests__/support/session-factories.ts';
910
import { makeSessionStore } from '../../../__tests__/support/store-factory.ts';
@@ -229,7 +230,7 @@ test('press and click hand the earliest request deadline to pre-dispatch admissi
229230
makeIosSession(sessionName, { appBundleId: 'com.example.app' }),
230231
);
231232

232-
for (const command of ['press', 'click']) {
233+
const dispatch = async (command: string) =>
233234
await handleInteractionCommands({
234235
createCommandSurface,
235236
req: {
@@ -245,9 +246,20 @@ test('press and click hand the earliest request deadline to pre-dispatch admissi
245246
contextFromFlags,
246247
...getRuntimeBindings(),
247248
});
248-
}
249249

250+
for (const command of ['press', 'click']) await dispatch(command);
250251
expect(handedOff).toEqual([resultDeadlineMs, resultDeadlineMs]);
252+
253+
// An execution deadline earlier than the result deadline is the one handed off.
254+
const before = Date.now();
255+
await withRequestDeadline(requestId, 1_000, async () => {
256+
await dispatch('press');
257+
return { ok: true };
258+
});
259+
const executionDeadlineMs = handedOff[2]!;
260+
expect(executionDeadlineMs).toBeLessThan(resultDeadlineMs);
261+
expect(executionDeadlineMs).toBeGreaterThanOrEqual(before + 1_000);
262+
expect(executionDeadlineMs).toBeLessThanOrEqual(Date.now() + 1_000);
251263
} finally {
252264
clearRequestAbortRegistration(registration);
253265
}

0 commit comments

Comments
 (0)