Skip to content

Commit 7ec1b11

Browse files
committed
test(ios): retain bridge circuit diagnostics in smoke
1 parent 2db7c42 commit 7ec1b11

7 files changed

Lines changed: 68 additions & 12 deletions

File tree

‎packages/platform-apple/src/snapshot-route.test.ts‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
13
import { expect, test, vi } from 'vitest';
4+
import { withDiagnosticsScope } from '@agent-device/host-kit/diagnostics';
25
import type { DeviceInfo } from '@agent-device/kernel/device';
36
import { createRequestCanceledError } from '@agent-device/kernel/errors';
47

@@ -11,6 +14,7 @@ vi.mock('./system-surface-presence.ts', () => ({
1114
import { areIosSnapshotComparisonIdentitiesEqual } from '@agent-device/capture-kit/ios-snapshot-planning';
1215
import { IOS_SYSTEM_SURFACE_HOSTS } from '@agent-device/contracts/ios-system-surface';
1316
import { simulatorAddressFor } from './core/simctl.ts';
17+
import { mkdtempForTest } from './__tests__/tmp-dir.ts';
1418
import { createLocalAppleToolProvider, withAppleToolProvider } from './core/tool-provider.ts';
1519
import { platformRuntimeHostFixture } from './runtime.fixtures.ts';
1620
import { createAppleSnapshotRoute } from './snapshot-route.ts';
@@ -285,8 +289,28 @@ test('typed bridge failure falls back once and disables retries for that app gen
285289
resolveTarget: vi.fn(async () => target),
286290
});
287291

288-
const first = await route.capture(ios, input, signal(), fallback);
289-
const second = await route.capture(ios, input, signal(), fallback);
292+
const logPath = path.join(await mkdtempForTest('ios-route-'), 'request.ndjson');
293+
const [first, second] = await withDiagnosticsScope(
294+
{ command: 'snapshot', debug: true, logPath },
295+
async () => {
296+
const first = await route.capture(ios, input, signal(), fallback);
297+
const second = await route.capture(ios, input, signal(), fallback);
298+
return [first, second] as const;
299+
},
300+
);
301+
302+
expect(
303+
fs
304+
.readFileSync(logPath, 'utf8')
305+
.trim()
306+
.split('\n')
307+
.map((line) => JSON.parse(line))
308+
.filter((event) => event.phase === 'ios_snapshot_route_fallback')
309+
.map((event) => event.data),
310+
).toEqual([
311+
{ reason: 'bridge-disconnected', deviceId: ios.id, generation: target.generation },
312+
{ reason: 'circuit-disabled', deviceId: ios.id, generation: target.generation },
313+
]);
290314

291315
expect(source.acquire).toHaveBeenCalledOnce();
292316
expect(fallback).toHaveBeenCalledTimes(2);

‎packages/platform-apple/src/snapshot-route.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export function createAppleSnapshotRoute(
153153
);
154154
}
155155
if (isBridgeDisabled(target)) {
156+
emitRouteDiagnostic('circuit-disabled', device, target.generation);
156157
return await runFallback(
157158
device.id,
158159
input,

‎test/integration/ios-simulator-e2e/live-automation-scenario.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ const AUTOMATION_DEEP_LINK =
2424
'agent-device-test-app:///automation?event=cold.start&payload=%7B%22source%22%3A%22deep-link%22%7D';
2525

2626
async function observeFixtureHome(context: LiveContext) {
27-
await assertWaitText(context, FIXTURE_HOME_TITLE);
27+
await assertWaitText(context, FIXTURE_HOME_TITLE, { debug: true });
2828
const snapshot = await runStep(context, 'capture fixture home', [
2929
'snapshot',
3030
'-i',
3131
'-s',
3232
FIXTURE_HOME_TITLE,
33+
'--debug',
3334
]);
3435
const nodes = Array.isArray(snapshot.json?.data?.nodes) ? snapshot.json.data.nodes : [];
3536
assert.ok(
@@ -60,6 +61,7 @@ export async function assertAutomationInput(context: LiveContext): Promise<void>
6061
'open',
6162
context.appId,
6263
'--relaunch',
64+
'--debug',
6365
]);
6466
assertJsonContains(opened, context.appId, 'open response should retain fixture identity');
6567
const runnerLogPath = opened.json?.data?.runnerLogPath;

‎test/integration/ios-simulator-e2e/live-deep-link-confirmation.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,21 @@ export type DeepLinkConfirmationDevice = {
2929
export function acceptDeepLinkConfirmationIfPresent(
3030
context: LiveContext,
3131
destination: readonly string[],
32+
options: { debug?: boolean } = {},
3233
): Promise<void> {
3334
return answerDeepLinkConfirmation({
3435
waitForDestination: (step) =>
35-
runStep(context, step, ['wait', ...destination, DEEP_LINK_DESTINATION_WAIT_MS], {
36-
allowFailure: true,
37-
}),
36+
runStep(
37+
context,
38+
step,
39+
[
40+
'wait',
41+
...destination,
42+
DEEP_LINK_DESTINATION_WAIT_MS,
43+
...(options.debug ? ['--debug'] : []),
44+
],
45+
{ allowFailure: true },
46+
),
3847
inspectAlert: () =>
3948
runStep(context, 'inspect delayed deep-link system alert', ['alert', 'get'], {
4049
allowFailure: true,

‎test/integration/ios-simulator-e2e/live-runner.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ async function assertFormInput(context: LiveContext): Promise<void> {
256256
'seeded email should survive keyboard dismiss, before any refocus or further typing',
257257
);
258258

259-
const formSnapshot = await runStep(context, 'locate email coordinates', ['snapshot', '-i']);
259+
const formSnapshot = await runStep(context, 'locate email coordinates', [
260+
'snapshot',
261+
'-i',
262+
'--debug',
263+
]);
260264
const emailRect = requireNodeRect(formSnapshot, 'field-email');
261265
await runStep(context, 'focus email by snapshot-derived coordinates', [
262266
'focus',

‎test/integration/ios-simulator-e2e/live-snapshot-depth-frontier.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ export async function assertRegularVisibleDepthFrontier(context: LiveContext): P
2121
'--relaunch',
2222
'--launch-url',
2323
VISIBLE_DEPTH_DEEP_LINK,
24+
'--debug',
2425
]);
25-
await acceptDeepLinkConfirmationIfPresent(context, [`id="${CHILD_ID}"`]);
26+
await acceptDeepLinkConfirmationIfPresent(context, [`id="${CHILD_ID}"`], { debug: true });
2627
// Wait for the target itself so the depth assertion is about the frontier, not route readiness.
27-
await assertWaitSelector(context, `id="${CHILD_ID}"`);
28+
await assertWaitSelector(context, `id="${CHILD_ID}"`, { debug: true });
2829

2930
const regular = await runStep(context, 'capture regular visible-depth frontier', [
3031
'snapshot',
3132
'--depth',
3233
'1',
34+
'--debug',
3335
]);
3436
assertSimulatorBridgeSnapshot(regular, 'regular depth-1 snapshot');
3537
const regularNodes = snapshotNodes(regular);

‎test/integration/live-device-e2e/assertions.ts‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,33 @@ export function createLiveDeviceAssertions<
2121
verifyCommand: (context: Context, command: string, evidence: string) => void,
2222
waitCommand: string,
2323
) {
24-
async function assertWaitText(context: Context, expected: string): Promise<void> {
24+
async function assertWaitText(
25+
context: Context,
26+
expected: string,
27+
options: { debug?: boolean } = {},
28+
): Promise<void> {
2529
const result = await runStep(context, `wait for ${expected}`, [
2630
'wait',
2731
'text',
2832
expected,
2933
'10000',
34+
...(options.debug ? ['--debug'] : []),
3035
]);
3136
assertJsonContains(result, expected, `wait should observe ${expected}`);
3237
verifyCommand(context, waitCommand, `wait observes durable text: ${expected}`);
3338
}
3439

35-
async function assertWaitSelector(context: Context, selector: string): Promise<void> {
36-
await runStep(context, `wait for ${selector}`, ['wait', selector, '10000']);
40+
async function assertWaitSelector(
41+
context: Context,
42+
selector: string,
43+
options: { debug?: boolean } = {},
44+
): Promise<void> {
45+
await runStep(context, `wait for ${selector}`, [
46+
'wait',
47+
selector,
48+
'10000',
49+
...(options.debug ? ['--debug'] : []),
50+
]);
3751
verifyCommand(context, waitCommand, `wait observes durable selector: ${selector}`);
3852
}
3953

0 commit comments

Comments
 (0)