Repository navigation
fix(settle): resolve the default quiet window from the capture it settles #3522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
57ce1e5
fix(settle): resolve the default quiet window from the capture that p…
thymikee dc19640
fix(settle): re-check broad-transition arming on every capture until …
thymikee 2f3c314
fix(settle): hold the quiet window in the loop that re-prices it
thymikee 3be3ad5
fix(settle): price the quiet window per producer and report it on eve…
thymikee c09f627
fix(wait): surface a stable-capture failure from wait stable
thymikee 40d8682
test(settle): rewrap the arming-input comment to the column width
thymikee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
184 changes: 184 additions & 0 deletions
184
src/commands/interaction/runtime/settle-default-quiet.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { test } from 'vitest'; | ||
| import type { SnapshotProvenance, SnapshotState } from '@agent-device/kernel/snapshot'; | ||
| import { ref } from './selector-read-utils.ts'; | ||
| import { | ||
| buttonSnapshot, | ||
| createSettleDevice, | ||
| welcomeSnapshot, | ||
| } from './__tests__/settle-device-fixtures.ts'; | ||
|
|
||
| // The `--settle` DEFAULT quiet window keys on the capture the settle loop PERFORMS (#3470 | ||
| // follow-up), because that read is the one the window prices: the loop holds its quiet window open | ||
| // across captures of its own. The pre-action baseline cannot answer this — on the ref route it is | ||
| // the stored ref frame, on the generic route the session's stored tree, and either can be several | ||
| // commands stale and served by a producer other than the one settle then reads through. A caller | ||
| // that asks for a window with `--settle-quiet` always outranks the default. | ||
| // | ||
| // Budgets are injected (fake clock) — no real waiting. | ||
|
|
||
| function withProvenance<P extends SnapshotProvenance>(state: SnapshotState, provenance: P) { | ||
| return { ...state, ...provenance }; | ||
| } | ||
|
|
||
| const BRIDGE = { backend: 'xctest', producer: 'simulator-ax-bridge' } as const; | ||
| const RUNNER = { backend: 'xctest', producer: 'apple-runner' } as const; | ||
|
|
||
| type LoopCapturePath = SnapshotProvenance | undefined | ((capture: number) => SnapshotProvenance); | ||
|
|
||
| /** | ||
| * A press whose baseline and whose loop captures come from declared capture paths, so the two can | ||
| * be made to agree or to disagree. The pressed button stays on screen, so no capture is a broad | ||
| * replacement and the window under test is the one the loop priced, not the confirmation floor. | ||
| */ | ||
| function pressWithCapturePaths(params: { | ||
| baseline?: SnapshotProvenance; | ||
| loop?: LoopCapturePath; | ||
| settle?: { quietMs?: number; timeoutMs?: number }; | ||
| }) { | ||
| const baseline = params.baseline | ||
| ? withProvenance(buttonSnapshot(), params.baseline) | ||
| : buttonSnapshot(); | ||
| let captures = 0; | ||
| const device = createSettleDevice({ | ||
| stored: baseline, | ||
| captureSnapshot: () => { | ||
| // A ref press captures nothing before the action, so every call is the loop's own sample. | ||
| captures += 1; | ||
| const provenance = typeof params.loop === 'function' ? params.loop(captures) : params.loop; | ||
| return { | ||
| snapshot: provenance ? withProvenance(buttonSnapshot(), provenance) : buttonSnapshot(), | ||
| }; | ||
| }, | ||
| }); | ||
| return device.interactions.press(ref('@e1'), { session: 'default', settle: params.settle ?? {} }); | ||
| } | ||
|
|
||
| test('a settle the simulator snapshot bridge performs uses the shorter default window', async () => { | ||
| const result = await pressWithCapturePaths({ loop: BRIDGE }); | ||
|
|
||
| const settle = result.settle; | ||
| assert.ok(settle); | ||
| assert.equal(settle.settled, true); | ||
| assert.equal(settle.quietMs, 300); | ||
| assert.ok(settle.waitedMs < 500, `bridge settle held ${settle.waitedMs}ms`); | ||
| }); | ||
|
|
||
| test('an explicit --settle-quiet outranks the per-capture default window', async () => { | ||
| const result = await pressWithCapturePaths({ loop: BRIDGE, settle: { quietMs: 700 } }); | ||
|
|
||
| const settle = result.settle; | ||
| assert.ok(settle); | ||
| assert.equal(settle.quietMs, 700); | ||
| }); | ||
|
|
||
| // Each of these is a read the 300 ms default was NOT measured on, so shortening its window would be | ||
| // an unmeasured change of behaviour rather than the measured one. The Apple runner shares the | ||
| // `xctest` CHANNEL with the bridge, which is why the rule keys on the producer. | ||
| const UNMEASURED_CAPTURES: Array<[string, SnapshotProvenance?]> = [ | ||
| ['the Apple runner tree read (same channel, different producer)', RUNNER], | ||
| ['an Appium-sourced tree on the same channel', { backend: 'xctest', producer: 'appium-source' }], | ||
| ['the Android helper', { backend: 'android', producer: 'android-uiautomator' }], | ||
| ['a capture that declares no provenance at all', undefined], | ||
| ]; | ||
|
|
||
| for (const [label, provenance] of UNMEASURED_CAPTURES) { | ||
| test(`${label} keeps the 500ms default window`, async () => { | ||
| const result = await pressWithCapturePaths({ loop: provenance }); | ||
|
|
||
| const settle = result.settle; | ||
| assert.ok(settle); | ||
| assert.equal(settle.settled, true); | ||
| assert.equal(settle.quietMs, 500); | ||
| assert.ok(settle.waitedMs >= 500, `${label} settled after ${settle.waitedMs}ms`); | ||
| }); | ||
| } | ||
|
|
||
| test('a bridge read during settle earns the shorter window even from a runner-issued ref frame', async () => { | ||
| // The ref frame the action was authorized against came from the runner, so keying the window on | ||
| // the baseline would hold the unmeasured 500 ms against captures the bridge answered. | ||
| const result = await pressWithCapturePaths({ baseline: RUNNER, loop: BRIDGE }); | ||
|
|
||
| const settle = result.settle; | ||
| assert.ok(settle); | ||
| assert.equal(settle.quietMs, 300); | ||
| assert.ok(settle.waitedMs < 500, `bridge settle held ${settle.waitedMs}ms`); | ||
| }); | ||
|
|
||
| test('a runner read during settle keeps the 500ms window despite a bridge-issued baseline', async () => { | ||
| // The unsafe direction of the same mismatch: holding 300 ms for a read priced at 500 ms would | ||
| // settle on a window the measurement never covered. | ||
| const result = await pressWithCapturePaths({ baseline: BRIDGE, loop: RUNNER }); | ||
|
|
||
| const settle = result.settle; | ||
| assert.ok(settle); | ||
| assert.equal(settle.quietMs, 500); | ||
| assert.ok(settle.waitedMs >= 500, `runner settle held only ${settle.waitedMs}ms`); | ||
| }); | ||
|
|
||
| test('the capture that decides the verdict prices the whole quiet span, even after a producer switch', async () => { | ||
| // The quiet span is elapsed time over which the tree did not change, whichever producer read it. | ||
| // A run that starts on the runner and continues on the bridge settles on the bridge's window. | ||
| const result = await pressWithCapturePaths({ | ||
| loop: (capture) => (capture === 1 ? RUNNER : BRIDGE), | ||
| }); | ||
|
|
||
| const settle = result.settle; | ||
| assert.ok(settle); | ||
| assert.equal(settle.settled, true); | ||
| assert.equal(settle.quietMs, 300); | ||
| assert.ok(settle.waitedMs < 500, `producer switch held ${settle.waitedMs}ms`); | ||
| }); | ||
|
|
||
| test('a capture that breaks mid-settle reports the window the run had priced', async () => { | ||
| let captures = 0; | ||
| const device = createSettleDevice({ | ||
| stored: buttonSnapshot(), | ||
| captureSnapshot: () => { | ||
| captures += 1; | ||
| if (captures === 1) return { snapshot: withProvenance(buttonSnapshot(), BRIDGE) }; | ||
| throw new Error('AX bridge crashed'); | ||
| }, | ||
| }); | ||
|
|
||
| const result = await device.interactions.press(ref('@e1'), { session: 'default', settle: {} }); | ||
|
|
||
| const settle = result.settle; | ||
| assert.ok(settle); | ||
| assert.equal(settle.settled, false); | ||
| assert.match(settle.hint ?? '', /Settle observation unavailable \(AX bridge crashed\)/); | ||
| assert.equal(settle.quietMs, 300); | ||
| }); | ||
|
|
||
| test('the shorter default window never shortens a broad-transition confirmation', async () => { | ||
| // The trap this layer owes layer 1: a 300 ms default sits under the 1.5 s floor, so a rule that | ||
| // armed on `requestedQuietMs >= DEFAULT_STABLE_QUIET_MS` would silently switch the #1831 | ||
| // confirmation off for every default settle the bridge answers. Here the pre-action tree is the | ||
| // tiny-baseline shape, so the confirmation owns the wait and the 300 ms default still holds its | ||
| // 1.5 s floor (#3470). | ||
| const sparseBaseline = withProvenance(buttonSnapshot(), BRIDGE); | ||
| let captures = 0; | ||
| const device = createSettleDevice({ | ||
| stored: sparseBaseline, | ||
| captureSnapshot: () => { | ||
| captures += 1; | ||
| return { | ||
| snapshot: captures === 1 ? sparseBaseline : withProvenance(welcomeSnapshot(), BRIDGE), | ||
| }; | ||
| }, | ||
| }); | ||
|
|
||
| const result = await device.interactions.press(ref('@e1'), { | ||
| session: 'default', | ||
| settle: { timeoutMs: 5_000 }, | ||
| }); | ||
|
|
||
| const settle = result.settle; | ||
| assert.ok(settle); | ||
| assert.equal(settle.settled, true); | ||
| assert.equal(settle.quietMs, 300); | ||
| assert.ok( | ||
| settle.waitedMs >= 1_500, | ||
| `confirmation did not outlast the shorter default: waitedMs=${settle.waitedMs}`, | ||
| ); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.