Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ jobs:
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testBoundedSystemModalProbeTimeoutRecoversThenReleasesOnDrain \
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testBoundedSystemModalProbeTimeoutRecoversThenReleasesOnDrainForSnapshotRaw \
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testSnapshotTraversalIdentityPreservesSameOriginNodesWithDifferentBounds \
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testPreferredPrivateAXBackendPlansAsPenalized \
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testRunnerScreenshotStabilitySettledNeedsEnoughSamples \
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testRunnerScreenshotStabilitySettledTrueWhenWindowMatches \
-only-testing:AgentDeviceRunnerUITests/RunnerTests/testRunnerScreenshotStabilitySettledFalseOnMidWindowMismatch \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,8 @@ extension RunnerTests {
interactiveOnly: command.interactiveOnly ?? false,
depth: command.depth,
scope: command.scope,
raw: command.raw ?? false
raw: command.raw ?? false,
preferredBackend: command.preferredBackend
)
do {
let payload: DataPayload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ struct Command: Codable {
let fps: Int?
let maxSize: Int?
let interactiveOnly: Bool?
let preferredBackend: String?
let depth: Int?
let scope: String?
let raw: Bool?
Expand Down Expand Up @@ -396,4 +397,8 @@ struct SnapshotOptions {
let depth: Int?
let scope: String?
let raw: Bool
/// Internal daemon ask: capture with this backend first regardless of channel
/// health ("private-ax"). Same-backend evidence probes (tap-outcome
/// corroboration) must be captured the way their baseline was.
var preferredBackend: String? = nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ extension RunnerTests {
}
}

/// Pure gate: a capture is planned as penalized when the channel penalty is
/// active OR the daemon pinned the private-AX backend (same-backend evidence
/// probe) — both mean "do not enter XCTest tree work first, and stamp the
/// pre-selection as 'deferred' rather than a degradation".
static func snapshotXCTestChannelTreatedAsPenalized(
penalized: Bool,
preferredBackend: String?
) -> Bool {
penalized || preferredBackend == SnapshotBackendKind.privateAX.rawValue
}

/// Pure plan-reorder rule: a penalized XCTest accessibility channel uses independent backends
/// when the platform has one, otherwise it keeps XCTest work on a short probe. The raw
/// diagnostic plan keeps tree-first errors, and unknown plans are left untouched.
Expand Down Expand Up @@ -222,9 +233,15 @@ extension RunnerTests {
// Reorder is iOS-only because hostile screens can make XCTest tree/query work grind while
// the app remains visually responsive. Simulators can avoid that channel through private AX;
// physical devices have no independent semantic backend yet, so they use a bounded probe.
// A daemon-preferred private-AX capture (same-backend evidence probe) takes the exact
// penalized route: privateAX-first plan, 'deferred' verdict — the backend was pre-selected
// deliberately, so no degradation warning should render for it.
var xCTestChannelPenalized = false
#if os(iOS)
xCTestChannelPenalized = isSnapshotXCTestChannelPenalized(bundleId: currentBundleId)
xCTestChannelPenalized = Self.snapshotXCTestChannelTreatedAsPenalized(
penalized: isSnapshotXCTestChannelPenalized(bundleId: currentBundleId),
preferredBackend: options.preferredBackend
)
#endif
let effective = Self.effectiveSnapshotCapturePlan(
plan,
Expand Down Expand Up @@ -668,6 +685,30 @@ extension RunnerTests {
XCTAssertEqual(Self.xcTestChannelStateFirstFailure(.boundedXCTestProbe)?.code, "budget")
}

/// Same-backend evidence probes: a daemon-pinned private-AX capture takes the
/// penalized route even with a healthy channel, so tap-outcome corroboration
/// baselines and probes are always captured by the same backend (backends are
/// never comparable views of a screen). Composed with the plan rule, the pin
/// yields the privateAX-first deferred plan.
func testPreferredPrivateAXBackendPlansAsPenalized() {
XCTAssertTrue(
Self.snapshotXCTestChannelTreatedAsPenalized(penalized: false, preferredBackend: "private-ax"))
XCTAssertTrue(
Self.snapshotXCTestChannelTreatedAsPenalized(penalized: true, preferredBackend: nil))
XCTAssertFalse(
Self.snapshotXCTestChannelTreatedAsPenalized(penalized: false, preferredBackend: nil))
XCTAssertFalse(
Self.snapshotXCTestChannelTreatedAsPenalized(penalized: false, preferredBackend: "tree"))

let pinned = Self.effectiveSnapshotCapturePlan(
Self.regularVisiblePlan,
xCTestChannelPenalized: Self.snapshotXCTestChannelTreatedAsPenalized(
penalized: false, preferredBackend: "private-ax")
)
XCTAssertEqual(pinned.plan, [.privateAX])
XCTAssertEqual(pinned.xCTestChannelState, .deferredToIndependentBackend)
}

func testEffectiveSnapshotCapturePlanDefersXCTestBackedTiersOnlyWhenPenalizedRegularPlan() {
let regular = Self.effectiveSnapshotCapturePlan(
Self.regularVisiblePlan,
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/src/cli-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export type CliFlags = CloudProviderProfileFields &
cost?: boolean;
responseLevel?: ResponseLevel;
snapshotInteractiveOnly?: boolean;
/** Internal (no CLI flag): pin the capture backend for same-backend evidence probes. */
snapshotPreferredBackend?: 'private-ax';
snapshotDiff?: boolean;
snapshotDepth?: number;
snapshotScope?: string;
Expand Down
7 changes: 7 additions & 0 deletions packages/kernel/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export type SnapshotOptions = {
depth?: number;
scope?: string;
raw?: boolean;
/**
* Internal (never CLI-exposed): capture with this backend first regardless of
* channel health. Evidence comparisons are only valid same-backend (backends
* are not comparable views of a screen), so a corroboration probe must be
* captured the way its baseline was.
*/
preferredBackend?: 'private-ax';
};

export type SnapshotPresentationFlagInput = {
Expand Down
1 change: 1 addition & 0 deletions src/core/dispatch-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type DispatchContext = ScreenshotDispatchFlags & {
runnerLeaseContext?: RunnerLogicalLeaseContext;
screenshotCaptureBackend?: 'runner';
snapshotInteractiveOnly?: boolean;
snapshotPreferredBackend?: 'private-ax';
snapshotDepth?: number;
snapshotScope?: string;
snapshotRaw?: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/core/dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ async function handleSnapshotCommand(
appBundleId: snapshotContext.appBundleId,
signal: snapshotContext.signal,
interactiveOnly: snapshotContext.snapshotInteractiveOnly,
preferredBackend: snapshotContext.snapshotPreferredBackend,
depth: snapshotContext.snapshotDepth,
scope: snapshotContext.snapshotScope,
raw: snapshotContext.snapshotRaw,
Expand Down
1 change: 1 addition & 0 deletions src/daemon/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function contextFromFlags(
iosXctestEnvDir: flags?.iosXctestEnvDir,
screenshotCaptureBackend: flags?.maestro?.screenshotCaptureBackend,
snapshotInteractiveOnly: flags?.snapshotInteractiveOnly,
snapshotPreferredBackend: flags?.snapshotPreferredBackend,
snapshotDepth: flags?.snapshotDepth,
snapshotScope: flags?.snapshotScope,
snapshotRaw: flags?.snapshotRaw,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ export const imageViewerNodes: RawSnapshotNode[] = [
},
];

export function snapshot(nodes: RawSnapshotNode[]) {
export function snapshot(
nodes: RawSnapshotNode[],
backend: 'tree' | 'queries' | 'private-ax' = 'tree',
) {
return buildSnapshotState(
{
nodes,
backend: 'xctest',
quality: { state: 'healthy', backend: 'tree' },
quality: { state: 'healthy', backend },
},
{ snapshotInteractiveOnly: false },
);
Expand Down
74 changes: 74 additions & 0 deletions src/daemon/handlers/__tests__/interaction-ios-tap-outcome.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const contextFromFlags = (flags: CommandFlags | undefined) => ({
jitterPx: flags?.jitterPx,
doubleTap: flags?.doubleTap,
clickButton: flags?.clickButton,
// Mirrors the production context builder (daemon/context.ts) for the fields
// the corroboration capture path depends on.
snapshotPreferredBackend: flags?.snapshotPreferredBackend,
});

async function runClick(
Expand Down Expand Up @@ -115,6 +118,77 @@ test('an unchanged post-action capture keeps a failed iOS tap failed', async ()
expect(sessionStore.get(sessionName)?.actions).toHaveLength(0);
});

test('a private-ax baseline pins the corroboration probe to private-ax', async () => {
// The recorded-failure screens are exactly where the capture plan flips
// between XCTest and private-AX (the penalty boundary). Without the pin, the
// probe comes back on a different backend, the same-backend requirement
// correctly refuses to compare, and a landed tap surfaces as a failure.
const sessionName = 'ios-private-ax-pinned-corroboration';
const sessionStore = makeSessionStore();
sessionStore.set(
sessionName,
makeIosSession(sessionName, {
appBundleId: 'com.example.app',
snapshot: snapshot(profileNodes, 'private-ax'),
}),
);
const snapshotContexts: Array<Record<string, unknown> | undefined> = [];
mockDispatch.mockImplementation(async (_device, command, _positionals, _outPath, context) => {
if (command === 'press') {
throw new AppError(
'XCTEST_RECORDED_FAILURE',
'XCTest recorded a failure while executing tap; the action may not have been performed.',
);
}
if (command === 'snapshot') {
snapshotContexts.push(context as Record<string, unknown> | undefined);
return snapshotPayload(imageViewerNodes, 'private-ax');
}
return {};
});

const response = await runClick(sessionStore, sessionName);

expect(response?.ok).toBe(true);
if (response?.ok) {
expect(response.data?.warning).toMatch(/post-action accessibility capture changed/);
}
expect(snapshotContexts).toHaveLength(1);
expect(snapshotContexts[0]?.snapshotPreferredBackend).toBe('private-ax');
});

test('a tree baseline does not pin the corroboration probe backend', async () => {
const sessionName = 'ios-tree-baseline-unpinned-corroboration';
const sessionStore = makeSessionStore();
sessionStore.set(
sessionName,
makeIosSession(sessionName, {
appBundleId: 'com.example.app',
snapshot: snapshot(profileNodes),
}),
);
const snapshotContexts: Array<Record<string, unknown> | undefined> = [];
mockDispatch.mockImplementation(async (_device, command, _positionals, _outPath, context) => {
if (command === 'press') {
throw new AppError(
'XCTEST_RECORDED_FAILURE',
'XCTest recorded a failure while executing tap; the action may not have been performed.',
);
}
if (command === 'snapshot') {
snapshotContexts.push(context as Record<string, unknown> | undefined);
return snapshotPayload(imageViewerNodes);
}
return {};
});

const response = await runClick(sessionStore, sessionName);

expect(response?.ok).toBe(true);
expect(snapshotContexts).toHaveLength(1);
expect(snapshotContexts[0]?.snapshotPreferredBackend).toBeUndefined();
});

test('a changed capture from a different iOS backend keeps the tap failure', async () => {
const sessionName = 'ios-cross-backend-tap-corroboration';
const sessionStore = makeSessionStore();
Expand Down
12 changes: 11 additions & 1 deletion src/daemon/handlers/interaction-ios-tap-outcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export async function corroborateIosTapFailure(
const baseline = readCorroborationBaseline(params.session.snapshot);
if (!baseline) return undefined;

const after = await captureCorroborationSnapshot(params, baseline.presentation);
const after = await captureCorroborationSnapshot(
params,
baseline.snapshot.snapshotQuality?.backend,
baseline.presentation,
);
if (!after || !hasMatchingPresentation(baseline.snapshot, after, params.command)) {
return undefined;
}
Expand Down Expand Up @@ -92,6 +96,7 @@ function readCorroborationBaseline(

async function captureCorroborationSnapshot(
params: IosTapCorroborationParams,
baselineBackend: string | undefined,
presentation: SnapshotPresentation | undefined,
): Promise<SnapshotState | undefined> {
try {
Expand All @@ -102,6 +107,11 @@ async function captureCorroborationSnapshot(
params.contextFromFlags,
{
interactiveOnly: presentation?.interactiveOnly ?? true,
// Evidence comparison is only valid same-backend, and the recorded-failure
// screens are exactly where the capture plan flips between XCTest and
// private-AX (the penalty boundary) — pin the probe to the baseline's
// backend instead of failing closed on the mismatch.
...(baselineBackend === 'private-ax' ? { preferredBackend: 'private-ax' as const } : {}),
signal: getRequestSignal(params.requestId),
},
);
Expand Down
3 changes: 3 additions & 0 deletions src/daemon/handlers/interaction-snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type CaptureSnapshotForSession = (
contextFromFlags: ContextFromFlags,
options: {
interactiveOnly: boolean;
preferredBackend?: 'private-ax';
androidFreshnessMode?: 'ref-refresh';
includeRects?: boolean;
signal?: AbortSignal;
Expand All @@ -27,6 +28,7 @@ export async function captureSnapshotForSession(
contextFromFlags: ContextFromFlags,
options: {
interactiveOnly: boolean;
preferredBackend?: 'private-ax';
androidFreshnessMode?: 'ref-refresh';
includeRects?: boolean;
signal?: AbortSignal;
Expand All @@ -35,6 +37,7 @@ export async function captureSnapshotForSession(
const effectiveFlags = {
...(flags ?? {}),
snapshotInteractiveOnly: options.interactiveOnly,
...(options.preferredBackend ? { snapshotPreferredBackend: options.preferredBackend } : {}),
};
const dispatchContext = contextFromFlags(
effectiveFlags,
Expand Down
2 changes: 2 additions & 0 deletions src/platforms/apple/core/runner/runner-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export type RunnerCommand = {
fps?: number;
maxSize?: number;
interactiveOnly?: boolean;
/** Pin the snapshot capture backend (same-backend evidence probes). */
preferredBackend?: 'private-ax';
depth?: number;
scope?: string;
raw?: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/platforms/apple/interactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function createAppleInteractor(
command: 'snapshot',
appBundleId: options?.appBundleId,
interactiveOnly: options?.interactiveOnly,
preferredBackend: options?.preferredBackend,
depth: options?.depth,
scope: options?.scope,
raw: options?.raw,
Expand Down
Loading