Skip to content

Commit a4b723e

Browse files
committed
fix: make retired touch observations consistent
1 parent 9902936 commit a4b723e

9 files changed

Lines changed: 64 additions & 23 deletions

File tree

‎src/daemon/__tests__/selector-capture-runtime.test.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ test('selector capture cache is keyed by scoped presentation options', async ()
5454
const runtime = createSelectorCaptureRuntime({
5555
ref: sessionStore.lookup(sessionName),
5656
device: session.device,
57-
session,
5857
sessionStore,
5958
sessionName,
6059
capture: boundCapture,
@@ -228,7 +227,6 @@ function proofRuntime(params: {
228227
const runtime = createSelectorCaptureRuntime({
229228
ref: sessionStore.lookup(params.sessionName),
230229
device: session.device,
231-
session,
232230
sessionStore,
233231
sessionName: params.sessionName,
234232
consumedSnapshot,
@@ -322,7 +320,6 @@ function makeCaptureRuntime(sessionName: string) {
322320
const runtime = createSelectorCaptureRuntime({
323321
ref: sessionStore.lookup(sessionName),
324322
device: session.device,
325-
session,
326323
sessionStore,
327324
sessionName,
328325
capture: boundCapture,
@@ -356,7 +353,6 @@ test('a held selector capture updates the matching rebuilt record without restor
356353
const runtime = createSelectorCaptureRuntime({
357354
ref,
358355
device: ref.session.device,
359-
session: ref.session,
360356
sessionStore,
361357
sessionName: address,
362358
capture: boundCapture,

‎src/daemon/interaction/internal/__tests__/interaction-touch-response.test.ts‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,59 @@ function selectorResult(readiness?: { polls: number; waitedMs: number }): PressC
101101

102102
const WAITED_SELECTOR_RESULT = selectorResult({ polls: 3, waitedMs: 400 });
103103

104+
test.each([false, true])('selector-touch observation after retirement=%s', async (retired) => {
105+
const sessionStore = makeSessionStore();
106+
const address = 'cwd:selector-touch-response:default';
107+
const session = makeSession('default');
108+
session.snapshot = {
109+
nodes: attachRefs([{ index: 0, type: 'Button', label: 'Continue' }]),
110+
createdAt: Date.now(),
111+
backend: 'xctest',
112+
};
113+
session.snapshotGeneration = 3;
114+
const ref = sessionStore.publish(address, session);
115+
const result: PressCommandResult = {
116+
...selectorResult(),
117+
settle: {
118+
settled: true,
119+
waitedMs: 25,
120+
captures: 2,
121+
quietMs: 25,
122+
timeoutMs: 2000,
123+
diff: {
124+
summary: { additions: 1, removals: 0, unchanged: 0 },
125+
lines: [{ kind: 'added', text: 'Continue', ref: 'e1' }],
126+
},
127+
},
128+
};
129+
let successor;
130+
if (retired) {
131+
sessionStore.retire(ref);
132+
successor = sessionStore.publish(address, makeSession('default'));
133+
}
134+
const payloads = await buildTargetedTouchResponsePayloads({
135+
params: {
136+
req: { token: 't', command: 'press', positionals: ['@e1'], session: 'default' },
137+
sessionName: address,
138+
sessionRef: ref,
139+
sessionStore,
140+
contextFromFlags,
141+
captureSnapshotForSession: vi.fn(),
142+
},
143+
result,
144+
staleRefsWarning: undefined,
145+
extra: {},
146+
});
147+
if (retired) {
148+
expect(payloads.responseData.settle).toBeUndefined();
149+
expect(payloads.result.settle).toBeUndefined();
150+
expect(sessionStore.lookup(address)).toEqual(successor);
151+
expect(successor?.session.snapshot).toBeUndefined();
152+
} else {
153+
expect(payloads.responseData.settle).toMatchObject({ refsGeneration: 3, settled: true });
154+
}
155+
});
156+
104157
test.each([false, true])(
105158
'point-touch publication after a held frame probe, retired=%s',
106159
async (retired) => {
@@ -157,7 +210,6 @@ test.each([false, true])(
157210
return sessionStore.requireCurrent(ref).snapshot!;
158211
},
159212
},
160-
session,
161213
result,
162214
staleRefsWarning: undefined,
163215
extra: {},

‎src/daemon/interaction/internal/find-target-capture.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export function createFindTargetCapture(
2121
params: Readonly<{
2222
ref: SessionRef;
2323
device: SessionState['device'];
24-
session: SessionState;
2524
req: DaemonRequest;
2625
logPath: string;
2726
locator: FindLocator;
@@ -36,11 +35,10 @@ export function createFindTargetCapture(
3635
captureProof: RequestCaptureProof;
3736
}>,
3837
): () => Promise<FindTargetTree> {
39-
const { device, session, req, logPath, locator, query, sessionStore, sessionName } = params;
38+
const { device, req, logPath, locator, query, sessionStore, sessionName } = params;
4039
const captureRuntime = createSelectorCaptureRuntime({
4140
ref: params.ref,
4241
device,
43-
session,
4442
sessionStore,
4543
sessionName,
4644
req,

‎src/daemon/interaction/internal/find.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ export async function handleFindCommands(params: FindRouteInput): Promise<Daemon
134134
const readTargetTree = createFindTargetCapture({
135135
ref: sessionRef,
136136
device,
137-
session,
138137
req,
139138
logPath,
140139
locator,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ function buildTargetedRuntimeOptions(
131131
const resultDurationMs = readLongPressResultDuration(result);
132132
return await buildTargetedTouchResponsePayloads({
133133
params,
134-
session,
135134
result,
136135
staleRefsWarning,
137136
publicData: transformTouchResponseData({

‎src/daemon/interaction/internal/interaction-touch-response.ts‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
} from '../../../core/interaction-response-data-transform.ts';
1818
import { issueSettleRefs } from '../../session-snapshot.ts';
1919
import type { RecordedTargetCapture } from '@agent-device/selectors/target-evidence';
20-
import type { SessionState } from '../../session-state.ts';
2120
import type { CaptureSnapshotForSession, InteractionRouteInput } from './types.ts';
2221
import { resolveDirectTouchReferenceFrameSafely } from './interaction-touch-reference-frame.ts';
2322
import { readSnapshotNodesReferenceFrame } from '@agent-device/capture-kit/touch-reference-frame';
@@ -288,14 +287,13 @@ export async function buildTargetedTouchResponsePayloads(params: {
288287
params: InteractionRouteInput & {
289288
captureSnapshotForSession: CaptureSnapshotForSession;
290289
};
291-
session: SessionState;
292290
result: TargetedTouchResult;
293291
staleRefsWarning: string | undefined;
294292
publicData?: Record<string, unknown>;
295293
extra: Record<string, unknown>;
296294
}): Promise<InteractionResponsePayloads> {
297295
const { params: handlerParams, result, publicData, extra } = params;
298-
const referenceFrame =
296+
const probedFrame =
299297
result.kind === 'point'
300298
? await resolveDirectTouchReferenceFrameSafely({
301299
ref: handlerParams.sessionRef!,
@@ -305,13 +303,14 @@ export async function buildTargetedTouchResponsePayloads(params: {
305303
captureSnapshotForSession: handlerParams.captureSnapshotForSession,
306304
observation: handlerParams.androidObservation,
307305
})
308-
: readSnapshotNodesReferenceFrame(
309-
handlerParams.sessionStore.requireCurrent(handlerParams.sessionRef!).snapshot?.nodes ??
310-
[],
311-
);
312-
const currentResult = handlerParams.sessionStore.resolveCurrent(handlerParams.sessionRef!)
313-
? result
314-
: { ...result, settle: undefined };
306+
: undefined;
307+
const current = handlerParams.sessionStore.resolveCurrent(handlerParams.sessionRef!);
308+
const referenceFrame = current
309+
? result.kind === 'point'
310+
? probedFrame
311+
: readSnapshotNodesReferenceFrame(current.snapshot?.nodes ?? [])
312+
: undefined;
313+
const currentResult = current ? result : { ...result, settle: undefined };
315314
return buildInteractionResponseData({
316315
source: { kind: 'runtime', result: currentResult, publicData },
317316
referenceFrame,

‎src/daemon/selector-capture-runtime.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const SELECTOR_CAPTURE_CACHE_TTL_MS = 750;
2626
export type SelectorCaptureRuntimeParams = {
2727
ref: SessionRef | undefined;
2828
device: SessionState['device'];
29-
session: SessionState | undefined;
3029
sessionStore: SessionStore;
3130
sessionName: string;
3231
req: DaemonRequest;

‎src/daemon/selector-runtime-backend.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ function createSelectorBackend(params: SelectorRuntimeDeviceParams): AgentDevice
181181
: createSelectorCaptureRuntime({
182182
ref: params.ref,
183183
device,
184-
session,
185184
sessionStore,
186185
sessionName,
187186
req,

‎src/daemon/session-lifecycle/internal/__tests__/session-open-execution-runtime.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ test('fresh open does not publish when its artifact directory cannot be created'
605605
fs.writeFileSync(path.dirname(store.resolveSessionDir('cwd:held-open:default')), 'blocked');
606606
await expect(
607607
invokeHeldOpen(store, { runtime: { metroHost: 'new-host', metroPort: 9000 } }),
608-
).rejects.toThrow();
608+
).rejects.toMatchObject({ code: 'ENOTDIR' });
609609
expect(mockDispatch).toHaveBeenCalled();
610610
expect(store.get('cwd:held-open:default')).toBeUndefined();
611611
expect(store.getRuntimeHints('cwd:held-open:default')).toBeUndefined();

0 commit comments

Comments
 (0)