Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
50 changes: 50 additions & 0 deletions examples/test-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ It is intentionally small, but each surface is dense with durable accessibility
- `Settings`: switch rows, accordion content, loading and error states, retry flow, destructive-confirm modal
- `Automation lab`: long-press, alert-result, app-event, app-state, appearance, orientation, permission-recovery, log canaries, a flattened (`accessible={true}`) text input, and an Apple Pay sheet hosted in `com.apple.PassbookUIService`
- `WebView accessibility`: a deterministic semantic fixture plus live websites with varied HTML for native accessibility snapshot verification
- `Sign-in sheet lab`: a real `ASWebAuthenticationSession` sheet hosted out of process in `com.apple.SafariViewService`, opened against a loopback fixture identity provider (see [Sign-in sheet lab](#sign-in-sheet-lab))
- `Perf lab`: seeded JavaScript render problems for `react-devtools profile`, one per scenario (see [Perf lab](#perf-lab))
- `Settle lab`: timed effects with known final screens for `--settle` regression runs (an in-place counter; results 500 and 800 ms after an immediate `Run N` acknowledgement; a 750 ms fading overlay; two-stage transitions with and without a spinner; a toast that precedes navigation), reached by the `agent-device-test-app://settle-lab` deep link
- `Heavy feed`: a Bluesky-shaped home feed whose accessibility tree is deeper than 65 levels (see [Heavy feed](#heavy-feed))
Expand Down Expand Up @@ -334,6 +335,55 @@ The stable ids are `heavy-feed-title`, `heavy-feed-liked-count`, `heavy-feed-las
post `heavy-post-<n>`, `heavy-post-<n>-like`, `-reply`, `-repost`, and `-more`. A like press updates
`Liked posts: <count>`, and a long press on a post sets `Last action: held post <n>`.

## Sign-in sheet lab

**Settings → Open sign-in sheet lab** (`open-auth-session-lab`, route `auth-session-lab`) presents a
real `ASWebAuthenticationSession` sheet. iOS hosts that sheet out of the app's process in
`com.apple.SafariViewService`, over this screen and with the app still the accessibility primaryApp,
so it is the committed fixture for reading and driving a hosted web sign-in sheet in place (#2438,
#2449). The native module is `modules/auth-session-lab`; nothing about the flow activates or
relaunches anything, which is what keeps the sheet alive.

The sheet opens a page served over loopback by the fixture identity provider, so the flow involves
no real identity provider and no credential: `src/auth-idp-fixture.ts` owns the page and `Email`,
`Password`, and `LOGIN` are the vocabulary a lane asserts on. Submitting the fixture form navigates
to the app's own callback scheme, which ends the sheet and returns the app; `auth-session-status`
then reports `completed` and `auth-session-message` carries the callback URL.

Run the lane with the sheet's page served by the same script that owns its lifecycle:

```bash
pnpm test-app:maestro:auth:ios -- --udid "<simulator udid>"
```

The launcher starts the provider at `127.0.0.1:4593` and runs
`examples/test-app/maestro-ios/auth-session-sheet.yaml` through `agent-device test --maestro`. When
the flow ends or you cancel it, the launcher closes the provider.

To drive the sheet by hand and see its loading state, start the provider from the repo root:

```bash
node --experimental-strip-types examples/test-app/scripts/serve-auth-idp.mjs --delay-ms 6000
```

Omit `--delay-ms` to show the form immediately.

The committed flow reads the sheet and stops at its form controls. Driving past that point is not
committed, because on iOS 27.0 the same steps alternate between passing and refusing the capture,
which is the intermittency #4593 reports. Fill the sheet's fields and submit it when you want that
state, and expect to see one of three capture refusals on the step that follows the first `inputText`
or the submit: `regular iOS snapshot presentation requires a valid viewport`, `regular iOS snapshot
node escaped its cumulative clip`, or `main thread execution timed out`. The first two come from
`packages/capture-kit/src/ios-snapshot-engine/invariants.ts`. The XCTest runner reports the third, which
`packages/apple-runner/src/runner-failure-diagnostics.ts` classifies. The viewport refusal carries no
`retriable` flag, so the step aborts during stability re-capture.

The app needs a build that includes the module: a development client (`pnpm test-app:ios`) or a
Release build (`pnpm --dir examples/test-app exec expo run:ios --configuration Release --device
generic --no-bundler`). It is a native change, so it produces one new fingerprinted build that
consumers then share. A build without it shows `unavailable` in `auth-session-status` instead of
opening a sheet.

## Local Agent Device suites

The repo includes two local suites for iterating on the fixture app:
Expand Down
1 change: 1 addition & 0 deletions examples/test-app/app/(tabs)/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function SettingsRoute() {
onConfirmReset={state.resetLabState}
onLoadDiagnostics={state.loadDiagnostics}
onOpenAccessorySetup={() => router.push('/accessory-setup')}
onOpenAuthSessionLab={() => router.push('/auth-session-lab')}
onOpenAutomationLab={() => router.push('/automation')}
onOpenHeavyFeed={() => router.push('/heavy-feed')}
onOpenInertSurface={() => router.push('/inert')}
Expand Down
1 change: 1 addition & 0 deletions examples/test-app/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function RootLayoutContent() {
>
<Stack.Screen name="(tabs)" />
<Stack.Screen name="accessory-setup" />
<Stack.Screen name="auth-session-lab" />
<Stack.Screen name="automation" options={{ headerShown: true, title: 'Automation' }} />
<Stack.Screen name="inert" options={{ presentation: 'fullScreenModal' }} />
<Stack.Screen name="snapshot-depth" />
Expand Down
14 changes: 14 additions & 0 deletions examples/test-app/app/auth-session-lab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useRouter } from 'expo-router';

import { AppFrame } from '../src/components';
import { AuthSessionLabScreen } from '../src/screens/AuthSessionLabScreen';

export default function AuthSessionLabRoute() {
const router = useRouter();

return (
<AppFrame>
<AuthSessionLabScreen onBack={() => router.back()} />
</AppFrame>
);
}
32 changes: 32 additions & 0 deletions examples/test-app/maestro-ios/auth-session-sheet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
appId: com.callstack.agentdevicelab
name: Sign-in sheet
# Read SafariViewService in place while the app remains the accessibility primaryApp (#2438).
# Stop before typing or submitting, which can encounter the capture refusals in #4593.
env:
AUTH_SHEET_TIMEOUT: '20000'
onFlowStart:
- launchApp:
clearState: true
- assertVisible: Agent Device Tester
---
- tapOn:
text: Settings
- scrollUntilVisible:
element:
id: open-auth-session-lab
- tapOn:
id: open-auth-session-lab
- assertVisible: Sign-in sheet lab
- assertVisible:
id: auth-session-open
- tapOn:
id: auth-session-open
- extendedWaitUntil:
visible: Fixture sign-in
timeout: ${AUTH_SHEET_TIMEOUT}
- assertVisible:
text: Email
- assertVisible:
text: Password
- assertVisible:
text: LOGIN
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"platforms": ["ios"],
"apple": {
"modules": ["AuthSessionLabModule"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Pod::Spec.new do |s|
s.name = 'AuthSessionLab'
s.version = '1.0.0'
s.summary = 'ASWebAuthenticationSession fixture for Agent Device Tester'
s.description = s.summary
s.license = { :type => 'MIT' }
s.author = { 'Callstack' => 'opensource@callstack.com' }
s.homepage = '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/callstack/agent-device'
s.platforms = { :ios => '15.1' }
s.source = { :git => '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/callstack/agent-device.git' }
s.static_framework = true

s.dependency 'ExpoModulesCore'
s.frameworks = 'AuthenticationServices', 'Foundation', 'UIKit'
s.source_files = '**/*.{h,m,mm,swift,hpp,cpp}'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import AuthenticationServices
import ExpoModulesCore
import UIKit

// Presents a real sign-in sheet through ASWebAuthenticationSession. iOS hosts that sheet out of
// process in com.apple.SafariViewService, which makes this the #2449 fixture: the sheet is read and
// driven in place (#2438), the app stays the accessibility primaryApp while the sheet is up, and no
// step may activate or relaunch anything.
//
// The page itself is served by the fixture identity provider, not by the app: see
// `src/auth-idp-fixture.ts` for its content and `scripts/serve-auth-idp.mjs`, in this app's folder,
// for the server a lane starts. It holds fixture values only, so this flow needs no credentials.
// `startSignInAsync` resolves with the callback URL the sheet ended on, which is the observable end
// of the flow.
public final class AuthSessionLabModule: Module {
public func definition() -> ModuleDefinition {
Name("AuthSessionLab")

AsyncFunction("startSignInAsync") { (url: String, callbackScheme: String, promise: Promise) in
AuthSessionLabController.shared.start(url: url, callbackScheme: callbackScheme, promise: promise)
}.runOnQueue(.main)
}
}

private final class AuthSessionLabController: NSObject {
static let shared = AuthSessionLabController()

private struct Session {
let controller: ASWebAuthenticationSession
let promise: Promise
}

// One sheet at a time: two concurrent sessions would make which sheet answered ambiguous.
private var session: Session?

func start(url: String, callbackScheme: String, promise: Promise) {
guard session == nil else {
promise.reject(
Exception(
name: "AuthSessionAlreadyPresented",
description: "A sign-in sheet is already presented."
)
)
return
}

guard let url = URL(string: url), url.scheme != nil else {
promise.reject(
Exception(name: "InvalidAuthURL", description: "The sign-in URL is not a valid URL.")
)
return
}

let controller = ASWebAuthenticationSession(url: url, callbackURLScheme: callbackScheme) {
callbackURL, error in
guard let session = self.session else { return }
self.session = nil
if let callbackURL {
session.promise.resolve(callbackURL.absoluteString)
return
}
let sessionError = error as? ASWebAuthenticationSessionError
session.promise.reject(
Exception(
name: sessionError?.code == .canceledLogin ? "AuthSessionCanceled" : "AuthSessionFailed",
description: error?.localizedDescription ?? "The sign-in session failed."
)
)
}

// Ephemeral so the sheet shares no cookies or website data with anything else on the device.
controller.prefersEphemeralWebBrowserSession = true
controller.presentationContextProvider = self
session = Session(controller: controller, promise: promise)
controller.start()
}
}

extension AuthSessionLabController: ASWebAuthenticationPresentationContextProviding {
public func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {
let windows = UIApplication.shared.connectedScenes
.compactMap { $0 as? UIWindowScene }
.flatMap(\.windows)
return windows.first(where: \.isKeyWindow) ?? ASPresentationAnchor()
}
}
24 changes: 24 additions & 0 deletions examples/test-app/scripts/serve-auth-idp.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env node
import { AUTH_IDP_DEFAULT_URL } from '../src/auth-idp-fixture.ts';
import { startAuthIdpServer } from '../src/auth-idp-server.mjs';

const [flag, value, ...rest] = process.argv.slice(2);
const delayMs = Number(value ?? 0);
if (
flag !== undefined &&
(flag !== '--delay-ms' ||
!value?.trim() ||
!Number.isFinite(delayMs) ||
delayMs < 0 ||
rest.length)
) {
console.error(
'Usage: node --experimental-strip-types examples/test-app/scripts/serve-auth-idp.mjs [--delay-ms <n>]',
);
process.exitCode = 1;
} else {
const provider = await startAuthIdpServer({ delayMs });
console.log(`[auth-idp] ${AUTH_IDP_DEFAULT_URL} delayMs=${delayMs}`);
process.once('SIGINT', () => provider.close());
process.once('SIGTERM', () => provider.close());
}
69 changes: 69 additions & 0 deletions examples/test-app/src/auth-idp-fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
export const AUTH_IDP_DEFAULT_PORT = 4593;

export const AUTH_IDP_PATH = '/auth-idp';

export const AUTH_IDP_DEFAULT_URL = `http://127.0.0.1:${AUTH_IDP_DEFAULT_PORT}${AUTH_IDP_PATH}`;

export const AUTH_IDP_FIXTURE_REDIRECT =
'agent-device-test-app://auth-callback?code=fixture-code&state=fixture-state';
// The words a lane asserts on. Keep the Maestro flow and this page changed together.
export const AUTH_IDP_TEXT = {
loading: 'Loading sign-in',
title: 'Fixture sign-in',
email: 'Email',
password: 'Password',
submit: 'LOGIN',
} as const;

// On iOS 27.0 the sheet intercepts native form submission to the callback scheme.
// Redirecting from page script with `location.assign` leaves the sheet open.
export function renderAuthIdpPage(options: { delayMs?: number } = {}): string {
const delayMs = options.delayMs ?? 0;
if (delayMs > 0) {
return `<!doctype html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>${AUTH_IDP_TEXT.loading}</title>
<script>
setTimeout(function () {
location.replace(${JSON.stringify(AUTH_IDP_PATH)});
}, ${delayMs});
</script>
</head>
<body>
<p>${AUTH_IDP_TEXT.loading}</p>
</body>
</html>
`;
}

return `<!doctype html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>${AUTH_IDP_TEXT.title}</title>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, sans-serif; margin: 24px; }
form { display: grid; gap: 16px; }
label { display: grid; gap: 6px; }
input, button { font: inherit; min-height: 44px; }
</style>
</head>
<body>
<h1>${AUTH_IDP_TEXT.title}</h1>
<form method="get" action="${AUTH_IDP_FIXTURE_REDIRECT}">
<label>
${AUTH_IDP_TEXT.email}
<input name="email" type="email" autocomplete="off" />
</label>
<label>
${AUTH_IDP_TEXT.password}
<input name="password" type="password" autocomplete="off" />
</label>
<button type="submit">${AUTH_IDP_TEXT.submit}</button>
</form>
</body>
</html>
`;
}
46 changes: 46 additions & 0 deletions examples/test-app/src/auth-idp-server.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { once } from 'node:events';
import { createServer } from 'node:http';
import { AUTH_IDP_DEFAULT_URL, AUTH_IDP_PATH, renderAuthIdpPage } from './auth-idp-fixture.ts';

export async function startAuthIdpServer({ delayMs = 0 } = {}) {
let nextDelayMs = delayMs;
const server = createServer((request, response) => {
if (request.url?.split('?', 1)[0] !== AUTH_IDP_PATH) {
response.writeHead(404, { 'content-type': 'text/plain' });
response.end('not found\n');
return;
}

const html = renderAuthIdpPage({ delayMs: nextDelayMs });
nextDelayMs = 0;
response.writeHead(200, {
'content-type': 'text/html; charset=utf-8',
'content-length': Buffer.byteLength(html),
'cache-control': 'no-store',
});
response.end(html);
});

const url = new URL(AUTH_IDP_DEFAULT_URL);
const startup = new AbortController();
const timeout = setTimeout(
() => startup.abort(new Error('provider was not ready within 15s')),
15_000,
);
try {
server.listen({ host: url.hostname, port: Number(url.port), signal: startup.signal });
await once(server, 'listening', { signal: startup.signal });
} finally {
clearTimeout(timeout);
}

let closed;
return {
close() {
return (closed ??= new Promise((resolve, reject) => {
server.close((error) => (error ? reject(error) : resolve()));
server.closeAllConnections();
}));
},
};
}
Loading
Loading