Skip to content

Commit acc0ee1

Browse files
committed
refactor(daemon): cut the duplicate settle-branch test and the repeated baseline reasoning (#3471)
1 parent c7bacbf commit acc0ee1

6 files changed

Lines changed: 78 additions & 97 deletions

File tree

‎src/daemon/__tests__/moving-target-baseline.test.ts‎

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,16 @@ test('a gesture takes the surface over from a press, rather than joining it', ()
208208
assert.equal(movingTargetBaseline(session), undefined);
209209
});
210210

211-
/** A `--settle` observation. `diff` is the field that means "converged AND stored". */
212-
function settleMark(params: { settled: boolean; diff: boolean }): SettleObservation {
211+
/** A converged `--settle`. `stored` is the load-bearing axis: the runtime attaches `diff` only when
212+
* the loop converged AND stored its settled tree. */
213+
function settleMark(params: { stored: boolean }): SettleObservation {
213214
return {
214-
settled: params.settled,
215+
settled: true,
215216
waitedMs: 120,
216217
captures: 3,
217218
quietMs: 50,
218219
timeoutMs: 1_000,
219-
...(params.diff
220+
...(params.stored
220221
? { diff: { summary: { additions: 1, removals: 0, unchanged: 4 }, lines: [] } }
221222
: {}),
222223
};
@@ -236,35 +237,19 @@ test('a settle that stored its settled tree records that tree, not the tree the
236237
positionals: ['label="Slide target"'],
237238
flags: undefined,
238239
preActionTree: { nodes: appTree('Pre-action').nodes },
239-
settle: settleMark({ settled: true, diff: true }),
240+
settle: settleMark({ stored: true }),
240241
});
241242

242243
assert.equal(movingTargetBaseline(session)?.tree.nodes, settled.nodes);
243244
});
244245

245-
test('a settle that timed out keeps the acted-through tree', () => {
246-
// The loop ran out its budget without two reads agreeing, so the newest capture says nothing about
247-
// rest — recording it would turn an unsettled surface into evidence of quiet.
248-
const session = makeSession('android');
249-
session.snapshot = appTree('Still changing');
250-
const actedThrough = appTree('Pre-action');
251-
252-
markDeferredInteractionOutcome({
253-
session,
254-
command: 'press',
255-
positionals: ['label="Slide target"'],
256-
flags: undefined,
257-
preActionTree: { nodes: actedThrough.nodes },
258-
settle: settleMark({ settled: false, diff: false }),
259-
});
260-
261-
assert.equal(movingTargetBaseline(session)?.tree.nodes, actedThrough.nodes);
262-
});
263-
264246
test('a converged settle that stored nothing keeps the acted-through tree', () => {
265-
// `settled: true` is not the whole claim: a sparse capture is refused by the store and a
266-
// cross-surface transition (#2438) withholds the diff, leaving whatever an earlier capture
267-
// published. Only the stored settled tree may carry a rest claim.
247+
// `settled: true` is not the whole claim, and neither is a settle that merely ran: a sparse
248+
// capture is refused by the store and a cross-surface transition (#2438) withholds the diff,
249+
// leaving whatever an earlier capture published, and a loop that ran out its budget without two
250+
// reads agreeing says nothing about rest either. Only the stored settled tree may carry a rest
251+
// claim; recording the newest capture otherwise would turn an unsettled surface into evidence of
252+
// quiet.
268253
const session = makeSession('android');
269254
session.snapshot = appTree('Published by some earlier capture');
270255
const actedThrough = appTree('Pre-action');
@@ -275,7 +260,7 @@ test('a converged settle that stored nothing keeps the acted-through tree', () =
275260
positionals: ['label="Slide target"'],
276261
flags: undefined,
277262
preActionTree: { nodes: actedThrough.nodes },
278-
settle: settleMark({ settled: true, diff: false }),
263+
settle: settleMark({ stored: false }),
279264
});
280265

281266
assert.equal(movingTargetBaseline(session)?.tree.nodes, actedThrough.nodes);

‎src/daemon/deferred-interaction-outcome.ts‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ function markSurfaceStabilization(
162162
* gate nothing.
163163
*
164164
* `restProved` switches the tree to the session's published one, and is set only when the action's
165-
* own settle loop converged AND stored its settled tree. Everything else keeps the pre-action tree:
166-
* the session's snapshot may hold a freshness capture, a `@ref` press's authorized frame, or a lone
167-
* `--verify` capture, and none of those proves rest. Inferring it from a snapshot that merely
168-
* differs from the tree the action resolved against would attribute to this action a surface it may
169-
* never have looked at — the substitution this marker exists to prevent.
165+
* own settle loop converged AND stored its settled tree. Everything else keeps the pre-action tree,
166+
* a timed-out loop included: the session's snapshot may hold a freshness capture, a `@ref` press's
167+
* authorized frame, a lone `--verify` capture, or the newest read of a surface that never quieted,
168+
* and none of those proves rest. Preferring it because it merely differs from the tree the action
169+
* resolved against is the same forbidden substitution, from the other side.
170170
*/
171171
function markMovingTargetBaseline(
172172
session: SessionState,
@@ -185,12 +185,10 @@ function markMovingTargetBaseline(
185185
}
186186

187187
/**
188-
* Retires the `recheck` variant only. Called from ADR 0014's device side-effect seam: a side effect
189-
* this session did not resolve a target through leaves a tree that predates a change nobody
190-
* measured, and screening a later press against it would be positional coincidence rather than
191-
* evidence. A gate out of evidence goes idle rather than reconstructing a baseline from another
192-
* source. A pending stabilization is left alone — the seam fires on the way INTO every device op,
193-
* including the gesture that just marked one, and the capture side still owes that loop.
188+
* Retires the `recheck` variant only, from ADR 0014's device side-effect seam. A gate out of evidence
189+
* goes idle rather than reconstructing a baseline from another source. A pending stabilization is
190+
* left alone: the seam fires on the way INTO every device op, including the gesture that just marked
191+
* one, and the capture side still owes that loop.
194192
*/
195193
export function retireMovingTargetBaseline(session: SessionState): void {
196194
if (session.deferredSurface?.kind !== 'recheck') return;

‎src/daemon/interaction/internal/interaction-common.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,11 @@ export function finalizeTouchInteraction(params: {
3030
actionFinishedAt: number;
3131
androidFreshnessBaseline?: SnapshotState | undefined;
3232
/**
33-
* The tree this action resolved its target against (#3471), forwarded to the moving-target
34-
* baseline. Absent for the dispatches that acted without a daemon tree.
33+
* The tree this action resolved its target against, plus its own `--settle` observation when it ran
34+
* one — both forwarded to the deferred-outcome marker, which reads the settled-tree signal from the
35+
* second (#3471). Absent for the dispatches that acted without a daemon tree.
3536
*/
3637
preActionTree?: SurfaceScopedNodes | undefined;
37-
/**
38-
* The action's own `--settle` observation, forwarded to the deferred-outcome marker, which reads
39-
* the settled-tree signal from it (#3471).
40-
*/
4138
settle?: SettleObservation | undefined;
4239
}): DaemonResponse {
4340
const {

‎src/daemon/ref-frame.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,8 @@ export function expireRefFrame(session: SessionState): void {
9494
markSessionSnapshotOutdated(session);
9595
session.refFrame = expiredRefFrame(refFrame(session));
9696
session.snapshotScopeSource = undefined;
97-
// #3471: the same seam retires the moving-target baseline, because a side effect this session did
98-
// not resolve a target through leaves a tree that predates a change nobody measured — screening a
99-
// later press against it would be the positional coincidence ADR 0014 exists to stop. A pending
100-
// capture-side stabilization survives this: the seam fires on the way INTO every device op,
101-
// including the gesture that just marked one.
97+
// #3471: a side effect this session did not resolve a target through leaves a tree that predates a
98+
// change nobody measured, so it cannot screen a later press.
10299
retireMovingTargetBaseline(session);
103100
}
104101

‎src/daemon/session-state.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,9 @@ export type SessionState = {
215215
lastComparisonSafeSnapshot?: SnapshotState;
216216
androidSnapshotFreshness?: SnapshotFreshnessWindow;
217217
/**
218-
* What this session's last mutation left owed before its surface can be trusted again: the
219-
* capture-side quiet-window loop, or the #3471 moving-target baseline the next resolved target is
220-
* screened against. One field because one mutation leaves room for one of the two; the transitions
221-
* are `deferred-interaction-outcome.ts`'s (R7).
218+
* The one writer's view of `DeferredSurface`: what this session's last mutation left owed. One
219+
* field because one mutation leaves room for one of the two; the transitions are
220+
* `deferred-interaction-outcome.ts`'s (R7).
222221
*/
223222
deferredSurface?: DeferredSurface;
224223
snapshotDiagnostics?: SnapshotDiagnosticsState;

‎test/integration/interaction-contract/runtime-selector.contract.test.ts‎

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -267,50 +267,55 @@ test(scenarioNames(RUNTIME_SELECTOR_COVERAGE, 'targetStability')[0]!, async () =
267267
assert.equal(captures, 3, 'one resolution capture plus the gate two re-observations');
268268
});
269269

270-
test(scenarioNames(RUNTIME_SELECTOR_COVERAGE, 'targetStability')[1]!, async () => {
271-
const taps: Point[] = [];
272-
let captures = 0;
273-
// Still moving when the window ran out: the two re-observations disagree.
274-
const positions = [
275-
continueButtonAtRect(240, 20),
276-
continueButtonAtRect(300, 20),
277-
continueButtonAtRect(360, 20),
278-
];
279-
const device = createContractDevice(positions[0]!, {
280-
captureSnapshot: async () => ({ snapshot: positions[captures++] ?? positions[2]! }),
281-
tap: async (_context, point) => {
282-
taps.push(point);
283-
},
284-
clock: createContractClock(),
285-
sessionState: {
286-
movingTargetBaseline: { finishedAt: 0, tree: { nodes: viewportOnlySnapshot().nodes } },
287-
},
288-
});
289-
290-
await assert.rejects(
291-
() => device.interactions.press(selector('label=Continue'), { session: 'default' }),
292-
(error: unknown) => {
293-
assert.ok(error instanceof Error);
294-
// Names the failed confirmation, not motion: the unmeasured shape cannot claim that.
295-
assert.match(
296-
error.message,
297-
/label=Continue had no confirmed resting position when the transition window ran out/,
270+
// The wiring, through the real daemon route rather than an injected session record: press A must
271+
// LEAVE the tree it acted through on the session (#3471) and press B must be screened against it.
272+
// Deleting either half of that — the writer in `dispatchRuntimeInteraction` or the carrier in
273+
// `toRuntimeSessionRecord` — leaves B idle, so it taps the vacated point and this fails.
274+
test(
275+
scenarioNames(RUNTIME_SELECTOR_COVERAGE, 'targetStability')[1]!,
276+
async () => {
277+
// The shared runner tree with the Continue button's frame translated to `y`.
278+
const runnerNodesAtY = (y: number) =>
279+
RUNNER_CONTINUE_NODES.map((node) =>
280+
node.index === 1 ? { ...node, rect: { ...node.rect, y } } : node,
298281
);
299-
const details = (error as { details?: Record<string, unknown> }).details;
300-
assert.equal(details?.reason, INTERACTION_ERROR_REASONS.targetStillMoving);
301-
assert.equal(details?.dispatched, 'no');
302-
assert.equal(details?.selector, 'label=Continue');
303-
// The position the caller resolved and the one the re-observations found: the pair that says
304-
// which way the surface is going.
305-
assert.deepEqual(details?.rect, { x: 240, y: 20, width: 100, height: 40 });
306-
assert.deepEqual(details?.movedToRect, { x: 360, y: 20, width: 100, height: 40 });
307-
assert.equal(typeof details?.waitedMs, 'number');
308-
assert.match(String(details?.hint), /label=Continue/);
309-
return true;
310-
},
311-
);
312-
assert.deepEqual(taps, []);
313-
});
282+
await withIosContractDaemon(
283+
[
284+
// A resolves and taps at y=300; B resolves at 360 and its two re-observations disagree.
285+
runnerSnapshotEntry(runnerNodesAtY(300)),
286+
runnerTapEntry({ x: 200, y: 322 }),
287+
runnerSnapshotEntry(runnerNodesAtY(360)),
288+
runnerSnapshotEntry(runnerNodesAtY(420)),
289+
runnerSnapshotEntry(runnerNodesAtY(480)),
290+
],
291+
async (daemon, transcript) => {
292+
assertRpcOk(await daemon.callCommand('press', ['label=Continue']));
293+
const refusal = await daemon.callCommand('press', ['label=Continue']);
294+
const data = assertRpcError(
295+
refusal,
296+
'COMMAND_FAILED',
297+
/label=Continue had no confirmed resting position when the transition window ran out/,
298+
);
299+
const details = data.details as Record<string, unknown>;
300+
assert.equal(details.reason, INTERACTION_ERROR_REASONS.targetStillMoving);
301+
assert.equal(details.dispatched, 'no');
302+
assert.deepEqual(details.rect, { x: 100, y: 360, width: 200, height: 44 });
303+
assert.deepEqual(details.movedToRect, { x: 100, y: 480, width: 200, height: 44 });
304+
// A: one capture. B: its resolution plus the gate's two. Any other count is the harness's
305+
// `assertComplete` failing, which is what makes the unused deletion above visible.
306+
assert.equal(
307+
transcript.calls.filter((call) => call.command === 'ios.runner.snapshot').length,
308+
4,
309+
);
310+
assert.equal(
311+
transcript.calls.filter((call) => call.command === 'ios.runner.tap').length,
312+
1,
313+
);
314+
},
315+
);
316+
},
317+
PARALLEL_PROVIDER_SCENARIO_TIMEOUT_MS,
318+
);
314319

315320
// The cost contract, as a scenario: the gate reads a tree the session already holds, so a press
316321
// whose target the previous action left in place spends the one capture it always spent.

0 commit comments

Comments
 (0)