Repository navigation
fix(settle): observe a settled screen through the capture the request admitted #3553
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
137 changes: 137 additions & 0 deletions
137
src/daemon/__tests__/settle-observation-capture.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,137 @@ | ||
| import { beforeEach, expect, test, vi } from 'vitest'; | ||
| import { IOS_SIMULATOR } from '@agent-device/test-kit/device-fixtures'; | ||
| import { makeIosSession } from './support/session-factories.ts'; | ||
| import { daemonPlatformServicesFixture } from './platform-services-fixture.ts'; | ||
| import { selectorCaptureFixture } from './selector-capture-fixture.ts'; | ||
| import { resolveSettleObservationCapture } from '../settle-observation-capture.ts'; | ||
| import { emitDiagnostic } from '@agent-device/host-kit/diagnostics'; | ||
|
|
||
| vi.mock('@agent-device/host-kit/diagnostics', async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import('@agent-device/host-kit/diagnostics')>(); | ||
| return { ...actual, emitDiagnostic: vi.fn(actual.emitDiagnostic) }; | ||
| }); | ||
|
|
||
| // #3510: the capture a `--settle` observation polls on a route whose action runtime use carries | ||
| // none. The guarantee it owes is producer identity with the command the caller runs next; the one it | ||
| // must not break is that settling never fails the action it follows. These pin which plan gets | ||
| // admitted, how often, and that every way an observation capture goes away degrades to no capture | ||
| // while disclosing its typed reason. | ||
|
|
||
| const unavailablePhase = ['settle_observation_capture_unavailable']; | ||
|
|
||
| /** Level included: a degrade the caller cannot see must not be info-only, which success drops. */ | ||
| function disclosures(): { level: string | undefined; data: Record<string, unknown> }[] { | ||
| return vi | ||
| .mocked(emitDiagnostic) | ||
| .mock.calls.flatMap(([event]) => | ||
| event.phase === unavailablePhase[0] && event.data | ||
| ? [{ level: event.level, data: event.data }] | ||
| : [], | ||
| ); | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| vi.mocked(emitDiagnostic).mockClear(); | ||
| }); | ||
|
|
||
| test('an available plan inspects once and binds once for the whole observation', async () => { | ||
| const fixture = selectorCaptureFixture(); | ||
|
|
||
| const capture = await resolveSettleObservationCapture({ | ||
| command: 'back', | ||
| session: makeIosSession('settle', { appBundleId: 'com.example.app' }), | ||
| inspectFacts: fixture.inspectFacts, | ||
| platformServices: daemonPlatformServicesFixture(), | ||
| bindDevice: fixture.bindDevice, | ||
| }); | ||
| if (!capture) throw new Error('expected an admitted capture'); | ||
|
|
||
| expect(fixture.inspections).toEqual([IOS_SIMULATOR]); | ||
| expect(fixture.binds).toEqual([IOS_SIMULATOR]); | ||
|
|
||
| await capture({}); | ||
| await capture({}); | ||
| expect(fixture.binds).toEqual([IOS_SIMULATOR]); | ||
| expect(fixture.captures).toHaveLength(2); | ||
| }); | ||
|
|
||
| // One rule over the two plan cells: an owner that refuses the observation's plan keeps the loop on | ||
| // its own snapshot path, and the refusal is disclosed with the typed fact rather than passing as a | ||
| // silently unchanged observation. The first row is the Apple no-tracked-app cell, where the owner's | ||
| // own `snapshot` refuses for the same declared reason. | ||
| test.each([ | ||
| { | ||
| plan: 'without-active-app', | ||
| refusal: { withoutActiveApp: { available: false, reason: 'owner-capability-missing' } }, | ||
| session: () => makeIosSession('no-app'), | ||
| operation: 'captureSnapshotWithoutActiveApp', | ||
| reason: 'owner-capability-missing', | ||
| }, | ||
| { | ||
| plan: 'active-app', | ||
| refusal: { capture: { available: false, reason: 'unsupported-platform-leaf' } }, | ||
| session: () => makeIosSession('settle', { appBundleId: 'com.example.app' }), | ||
| operation: 'captureSnapshot', | ||
| reason: 'unsupported-platform-leaf', | ||
| }, | ||
| ] as const)( | ||
| 'a $plan plan the owner refuses binds nothing and discloses its reason', | ||
| async ({ refusal, session, operation, reason }) => { | ||
| const fixture = selectorCaptureFixture(refusal); | ||
|
|
||
| const capture = await resolveSettleObservationCapture({ | ||
| command: 'back', | ||
| session: session(), | ||
| inspectFacts: fixture.inspectFacts, | ||
| platformServices: daemonPlatformServicesFixture(), | ||
| bindDevice: fixture.bindDevice, | ||
| }); | ||
|
|
||
| expect(capture).toBeUndefined(); | ||
| expect(fixture.binds).toEqual([]); | ||
| expect(disclosures()).toEqual([ | ||
| { level: 'warn', data: { command: 'back', outcome: 'refused', operation, reason } }, | ||
| ]); | ||
| }, | ||
| ); | ||
|
|
||
| // The two ways the owner's own machinery can fail the observation after a valid plan. Both are | ||
| // best-effort by contract: the command the loop follows must still run, and each is disclosed at | ||
| // `warn` — an info-only record is dropped on the success path, and these cells answer `ok: true`. | ||
| test.each([ | ||
| // Apple's inspection reads the host's screen-recording state and re-throws on a cancelled probe. | ||
| ['admission-probe-failed', Object.assign(new Error('probe cancelled'), { name: 'AbortError' })], | ||
| ['bind-failed', Object.assign(new Error('gateway closed'), { name: 'AppError' })], | ||
| ] as const)( | ||
| 'a %s costs the action nothing and discloses its own failure', | ||
| async (outcome, failure) => { | ||
| const fixture = selectorCaptureFixture(); | ||
| const failing = | ||
| outcome === 'admission-probe-failed' | ||
| ? { | ||
| inspectFacts: async () => { | ||
| throw failure; | ||
| }, | ||
| bindDevice: fixture.bindDevice, | ||
| } | ||
| : { | ||
| inspectFacts: fixture.inspectFacts, | ||
| bindDevice: async () => { | ||
| throw failure; | ||
| }, | ||
| }; | ||
|
|
||
| const capture = await resolveSettleObservationCapture({ | ||
| command: 'back', | ||
| session: makeIosSession('settle', { appBundleId: 'com.example.app' }), | ||
| platformServices: daemonPlatformServicesFixture(), | ||
| ...failing, | ||
| }); | ||
|
|
||
| expect(capture).toBeUndefined(); | ||
| expect(fixture.binds).toEqual([]); | ||
| expect(disclosures()).toEqual([ | ||
| { level: 'warn', data: { command: 'back', outcome, errorName: failure.name } }, | ||
| ]); | ||
| }, | ||
| ); |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: This overstates the guarantee: admission or binding failure can leave the settle loop with its prior observation instead of reading through that producer. Qualify the guarantee to cases where admission and binding succeed.
Prompt for AI agents