Skip to content

Commit 434e4ad

Browse files
strzhaoclaude
andcommitted
fix(daemon): refuse --expect-screenshot-diff on the touch routes until a capture binds
The touch routes admit the flag but bind no screenshot capture, so the flag was a silent no-op on every shipped surface. The refusal lives at the one place the daemon admits the flag: typed reason screenshot-readback-unavailable, dispatched no, and the #4509 decision owns when the capture binds instead. Co-Authored-By: Claude Code <[email protected]>
1 parent ffff797 commit 434e4ad

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,23 @@ test('after a session reopen, a pin from the previous lifetime rejects (reseeded
351351
}
352352
expect(mockTapPoint).not.toHaveBeenCalled();
353353
});
354+
355+
test('press --expect-screenshot-diff refuses at the route while no capture binds', async () => {
356+
const sessionStore = makeSessionStore();
357+
const sessionName = 'readback-refused-plan';
358+
sessionStore.publish(sessionName, makeStaleRefSession(sessionName));
359+
mockTapPoint.mockRejectedValue(new Error('touch should not be called for an unbound readback'));
360+
361+
for (const positionals of [['@e1,@e2'], ['@e1']]) {
362+
const response = await runInteraction(sessionStore, sessionName, 'press', positionals, {
363+
expectScreenshotDiff: true,
364+
});
365+
expect(response?.ok, positionals.join(' ')).toBe(false);
366+
if (response && !response.ok) {
367+
expect(response.error.code).toBe('INVALID_ARGS');
368+
expect(response.error.details?.reason).toBe('screenshot-readback-unavailable');
369+
expect(response.error.details?.dispatched).toBe('no');
370+
}
371+
expect(mockTapPoint).not.toHaveBeenCalled();
372+
}
373+
});

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { DaemonResponse } from '@agent-device/kernel/contracts';
2+
import { errorResponse } from '@agent-device/kernel/contracts';
23
import { getRequestDeadlineMs } from '@agent-device/host-kit/request';
34
import { bindInteractionSession } from './interaction-session.ts';
45
import type { CommandFlags } from '@agent-device/contracts/command';
@@ -35,13 +36,34 @@ import { prepareTouchDispatch } from './interaction-touch-prepare.ts';
3536
* and payload projection this command family owns.
3637
*/
3738

39+
/**
40+
* `--expect-screenshot-diff` needs a bound screenshot capture, and the touch
41+
* routes bind none (#4509 owns the binding decision). Refusing here — the one
42+
* place the daemon admits the flag — beats a silent no-op, where the caller's
43+
* opt-in would read as verified evidence that never arrived.
44+
*/
45+
function screenshotReadbackRefusal(
46+
params: TargetedTouchParams,
47+
command: TargetedTouchCommand,
48+
): DaemonResponse | undefined {
49+
if (command !== 'press' && command !== 'click') return undefined;
50+
if (!params.req.flags?.expectScreenshotDiff) return undefined;
51+
return errorResponse(
52+
'INVALID_ARGS',
53+
'--expect-screenshot-diff is not available on this route yet: the touch route binds no screenshot capture. Use --settle or --verify meanwhile; #4509 decides when the capture binds.',
54+
{ reason: 'screenshot-readback-unavailable', dispatched: 'no' },
55+
);
56+
}
57+
3858
export async function dispatchTargetedTouchViaRuntime(
3959
params: TargetedTouchParams,
4060
command: TargetedTouchCommand,
4161
): Promise<DaemonResponse> {
4262
params = bindInteractionSession(params);
4363
const admission = await admitTargetedTouch(params, command);
4464
if ('response' in admission) return admission.response;
65+
const readbackRefusal = screenshotReadbackRefusal(params, command);
66+
if (readbackRefusal) return readbackRefusal;
4567
const { admitted } = admission;
4668
const prepared = await prepareTouchDispatch(
4769
params,

0 commit comments

Comments
 (0)