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
2 changes: 1 addition & 1 deletion packages/provider-revyl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ customers; a partner integration gets one through Revyl's partner program.
npm install -g agent-device
agent-device plugins add @agent-device/revyl
export REVYL_API_KEY=your-api-key
agent-device connect revyl --platform ios --device "iPhone 16" --provider-os-version 18.0 --provider-app https://apps.example.com/MyApp-simulator.zip
agent-device connect revyl --platform ios --provider-app https://apps.example.com/MyApp-simulator.zip
agent-device open com.example.app
agent-device snapshot -i
agent-device close
Expand Down
38 changes: 35 additions & 3 deletions packages/provider-revyl/src/interactor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,46 @@ test('scroll dispatches the planned finger path as one drag', async () => {
});
assert.equal(report.pixels, 300);
assert.equal(report.direction, 'down');
// Revyl's `/drag` body has no duration field, so the report names none: a duration the worker never
// No duration was asked for, so the report names none: a duration the worker never
// ran must not appear as though it were honored.
assert.equal('durationMs' in report, false);
});

test('a scroll that names a duration sends it when the worker takes one', async () => {
const { fixture, interactor } = await liveInteractor('ios', { dragDuration: true });
const report = (await interactor.scroll?.('down', { pixels: 300, durationMs: 900 })) as Record<
string,
unknown
>;

assert.deepEqual(fixture.bodyFor('drag'), {
start_x: 195,
start_y: 572,
end_x: 195,
end_y: 272,
duration_ms: 900,
});
assert.equal(report.durationMs, 900);
});

test('a zero scroll duration is refused before the drag, since Revyl takes at least 1 ms', async () => {
const { fixture, interactor } = await liveInteractor('ios', { dragDuration: true });
await assert.rejects(
() => interactor.scroll?.('down', { pixels: 300, durationMs: 0 }),
(error: unknown) =>
error instanceof AppError &&
error.code === 'INVALID_ARGS' &&
error.details?.flag === '--duration-ms',
);
assert.equal(
fixture.paths().some((request) => request.endsWith('/drag')),
false,
);
});

test('a scroll that names a duration is refused rather than run at another speed', async () => {
// The caller asked how fast the finger travels and Revyl's drag cannot be told, so the command is
// answered with that fact. Running the drag at Revyl's speed in silence would drop what was asked for.
// This worker reports no drag duration support, so the command is answered with that fact. Running
// the drag at Revyl's speed in silence would drop what was asked for.
const { fixture, interactor } = await liveInteractor('ios');

await assert.rejects(
Expand Down
47 changes: 30 additions & 17 deletions packages/provider-revyl/src/interactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,28 +215,17 @@ class RevylInteractor implements Interactor {
* `pixels` and endpoints. Revyl's own `/swipe` is not used: it moves the finger a distance the
* worker chooses, so `--pixels` and `--amount` would be silently dropped.
*
* Revyl's `/drag` body carries endpoints only — no duration field exists — so the worker chooses
* how fast the finger travels and the report names no `durationMs`. `scroll --duration-ms` is therefore
* refused: a drag that ran at Revyl's own speed while reporting the caller's number would be a false
* echo, and one that said nothing would drop what the caller asked for.
* A worker whose `health` reports `supports_explicit_drag_duration` takes `duration_ms` in the
* `/drag` body, so `scroll --duration-ms` rides it and the report echoes it. Any other worker
* chooses how fast the finger travels, so the flag is refused there: a drag that ran at Revyl's own
* speed while reporting the caller's number would be a false echo.
*/
async scroll(
direction: ScrollDirection,
options?: ScrollExecutionOptions,
): Promise<Record<string, unknown>> {
if (options?.durationMs !== undefined) {
throw new AppError(
'UNSUPPORTED_OPERATION',
'Revyl scrolls with one drag and cannot be told how fast the finger travels.',
{
reason: 'unsupported-provider-mode',
command: 'scroll',
flag: '--duration-ms',
runId: this.session.runId,
hint: 'Scroll without --duration-ms; the drag runs at the speed Revyl gives it.',
},
);
}
const durationMs = options?.durationMs;
if (durationMs !== undefined) this.requireDragDuration(durationMs);
const screen = this.session.screen;
if (!screen) {
throw new AppError(
Expand All @@ -262,13 +251,37 @@ class RevylInteractor implements Interactor {
start_y: plan.y1,
end_x: plan.x2,
end_y: plan.y2,
...(durationMs === undefined ? {} : { duration_ms: durationMs }),
});
return {
...plan,
...(durationMs === undefined ? {} : { durationMs }),
backend: 'revyl-device-proxy',
};
}

/** Refuses a drag duration this worker cannot honor; Revyl's `duration_ms` starts at 1. */
private requireDragDuration(durationMs: number): void {
if (!this.session.dragDuration) {
throw new AppError(
'UNSUPPORTED_OPERATION',
'This Revyl worker scrolls with one drag and cannot be told how fast the finger travels.',
{
reason: 'unsupported-provider-mode',
command: 'scroll',
flag: '--duration-ms',
runId: this.session.runId,
hint: 'Scroll without --duration-ms; the drag runs at the speed Revyl gives it.',
},
);
}
if (durationMs < 1) {
throw new AppError('INVALID_ARGS', 'Revyl drag --duration-ms must be at least 1.', {
flag: '--duration-ms',
});
}
}

/**
* Writes through a temporary file in the same directory and renames it into place, so a caller that
* hangs up mid-write or a process that dies leaves either the previous screenshot or none at all, and
Expand Down
3 changes: 3 additions & 0 deletions packages/provider-revyl/src/revyl-backend.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export type RevylFixtureOptions = Readonly<{
screen?: Readonly<{ width: number; height: number }>;
/** Reports no screen size at all, which is what a health answer without the fields reads as. */
withoutScreen?: boolean;
/** Reports `supports_explicit_drag_duration: true`, which a newer worker does. */
dragDuration?: boolean;
/** The body every `hierarchy` answer carries: iOS JSON or Android XML. */
hierarchy?: string;
/** The start response body; a run id is generated when absent. */
Expand Down Expand Up @@ -234,6 +236,7 @@ export async function startRevylFixtureBackend(
...(options.withoutScreen
? {}
: { screen_width: screen.width, screen_height: screen.height }),
...(options.dragDuration ? { supports_explicit_drag_duration: true } : {}),
},
};
}
Expand Down
22 changes: 22 additions & 0 deletions packages/provider-revyl/src/revyl-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,28 @@ test('replays a retried GET and never a side-effecting action', async () => {
assert.equal(attempts, 1, 'a tap is never replayed: it may already have landed');
});

test('a hierarchy read that Revyl answers with a 500 is replayed', async () => {
// Revyl passes the iOS accessibility service's brief empty answer through as a 500; the next read
// returns the tree.
let attempts = 0;
const client = clientResponding(() => {
attempts += 1;
return attempts === 1
? jsonError(500, 'accessibility unavailable')
: new Response('[]', { status: 200 });
});
assert.equal(await client.getWorkerHierarchy('run-1'), '[]');
assert.equal(attempts, 2);

attempts = 0;
const screenshot = clientResponding(() => {
attempts += 1;
return jsonError(500, 'worker failed');
});
await assert.rejects(async () => await screenshot.captureWorkerScreenshot('run-1'));
assert.equal(attempts, 1, 'only the hierarchy read opts into replaying a 500');
});

test('a readiness read answers the polling loop on its first attempt', async () => {
// The readiness loop owns the poll beat and the deadline, so a transport replay in front of these
// two would hide Revyl's not-ready answer and stall the very wait being polled for.
Expand Down
12 changes: 11 additions & 1 deletion packages/provider-revyl/src/revyl-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ type RevylRequest = Readonly<{
* idempotent, which `/stop` is; a device action is never replayed.
*/
retry?: boolean;
/**
* Also replays a 500, which the status table reads as unconfirmed. Only `hierarchy` sets it: Revyl
* answers it with a 500 while the iOS simulator's accessibility service briefly returns nothing,
* and the read has no side effect to land twice.
*/
retryServerError?: boolean;
/** A device-proxy action carries the agent header; an execution-API call does not. */
workerAction?: boolean;
/** Defaults to `general`, which never reads a 404 or 410 as a gone session. */
Expand Down Expand Up @@ -175,7 +181,10 @@ export function createRevylClient(options: RevylClientOptions): RevylClient {
},
async getWorkerHierarchy(workflowRunId, signal) {
return new TextDecoder().decode(
await body(workerRequest(workflowRunId, 'hierarchy', signal)),
await body({
...workerRequest(workflowRunId, 'hierarchy', signal),
retryServerError: true,
}),
);
},
async captureWorkerScreenshot(workflowRunId, signal) {
Expand Down Expand Up @@ -255,6 +264,7 @@ function isRetryable(request: RevylRequest, outcome: RevylResponse | Error): boo
if (outcome instanceof Error) {
return outcome instanceof AppError && outcome.details?.reason === 'provider-unreachable';
}
if (request.retryServerError === true && outcome.status === 500) return true;
return revylFailure(request.route ?? 'general', outcome.status).retryable;
}

Expand Down
3 changes: 3 additions & 0 deletions packages/provider-revyl/src/revyl-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export type RevylSession = Readonly<{
sessionId: string;
/** Read from `health`; a snapshot without it cannot measure a keyboard band. */
screen: RevylScreenSize | undefined;
/** Read from `health`: whether `/drag` takes the finger's travel time as `duration_ms`. */
dragDuration: boolean;
device: DeviceInfo;
client: RevylClient;
lease: DeviceLease;
Expand Down Expand Up @@ -175,6 +177,7 @@ export async function startRevylSession(
runId,
sessionId,
screen: readRevylScreenSize(health),
dragDuration: health.supports_explicit_drag_duration === true,
device: buildRevylDevice(input.platform, lease, runId),
client,
lease,
Expand Down
2 changes: 2 additions & 0 deletions packages/provider-revyl/src/revyl-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export type RevylWorkerHealth = Readonly<{
platform?: string;
screen_width?: number;
screen_height?: number;
/** Set when the worker's `/drag` body accepts `duration_ms`; without it the worker picks the speed. */
supports_explicit_drag_duration?: boolean;
}>;

export type RevylDeviceSessionStopResponse = Readonly<{
Expand Down
5 changes: 1 addition & 4 deletions src/commands/schema/cli-help-topics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,7 @@ test('usageForCommand resolves remote help topic', async () => {
help.indexOf('Revyl cloud-device flow'),
help.indexOf('Local profile flow'),
);
assert.match(
revylFlow,
/connect revyl --platform ios --device "iPhone 16" --provider-os-version 18\.0 --provider-app https:\/\//,
);
assert.match(revylFlow, /connect revyl --platform ios --provider-app https:\/\//);
assert.match(revylFlow, /must be an https URL/);
assert.match(revylFlow, /agent-device disconnect/);
assert.match(help, /BrowserStack uses BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY/);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/schema/cli-help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,12 +634,12 @@ Limrun direct-device flow:
Revyl cloud-device flow (plugin, install separately):
agent-device plugins add @agent-device/revyl
export REVYL_API_KEY=...
agent-device connect revyl --platform ios --device "iPhone 16" --provider-os-version 18.0 --provider-app https://downloads.example.test/app.zip
agent-device connect revyl --platform ios --provider-app https://downloads.example.test/app.zip
agent-device open com.example.app
agent-device snapshot -i
agent-device close
agent-device disconnect
Revyl starts a device from its own pool, so --device and --provider-os-version are preferences it picks from rather than a catalog lookup, and --provider-app must be an https URL it can download. connect verifies the key without renting a device; the device is rented on the first command that needs it and released on close or disconnect.
Revyl starts a device from its own pool, so --device and --provider-os-version are preferences it picks from rather than a catalog lookup; leave them unset to get a simulator that is already warm. --provider-app must be an https URL it can download. connect verifies the key without renting a device; the device is rented on the first command that needs it and released on close or disconnect.

Local profile flow:
agent-device connect --remote-config ./remote-config.json
Expand Down
16 changes: 10 additions & 6 deletions website/docs/docs/revyl.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ next device command loads the plugin.
export REVYL_API_KEY=...
agent-device connect revyl \
--platform ios \
--device "iPhone 16" \
--provider-os-version 18.0 \
--provider-app https://apps.example.com/MyApp-simulator.zip
```

Expand All @@ -38,6 +36,11 @@ lease, usually `open`. `--device` and `--provider-os-version` are optional; with
from its own pool and reports a device agent-device then uses. A model or OS version Revyl has no
device for is reported when the session starts, not by `connect`.

To start faster, leave `--device` and `--provider-os-version` unset, so Revyl can pick a simulator
that is already running. A session can take longer to start when Revyl also installs the app on the
device. Start the session early and keep it open between steps. To relaunch the app, run `open` again on
the same session instead of `disconnect` and `connect`.

`--provider-app` is required and must be a public HTTPS URL. Revyl downloads and installs the build
when it starts the device, so a local path or a provider-specific app reference has no meaning
there. Pass the zipped `.app` for iOS the way Revyl expects it, and the `.apk` URL for Android.
Expand All @@ -64,8 +67,9 @@ A Revyl session runs the commands that reach a device through Revyl's device act
do on a local device.
- `click`, `press`, `double tap`, `longpress`, and `fill` by point or by snapshot reference, and
`scroll` by direction. `scroll` sends one drag of the planned finger path, so `--pixels` and
`--amount` mean the same distance they mean on a local device. Revyl's drag takes endpoints only, so
`scroll --duration-ms` refuses with that reason rather than running the drag at a speed nobody chose;
`--amount` mean the same distance they mean on a local device. `scroll --duration-ms` sets how long
the drag takes, from 1 to 10000 ms, when Revyl's worker supports it. An older worker picks the
speed itself, so there the flag refuses rather than running the drag at a speed nobody chose.
`fill --delay-ms` is paced by typing one character per pause.
- `open` (the session's app), `open` with a deep link or URL, and `close` for the app the session opened.
- `home`, and `back` on Android. iOS has no system back button; click the app's own back control.
Expand Down Expand Up @@ -134,8 +138,6 @@ const scope = {
const lease = await host.client.leases.allocate({
...scope,
platform: 'ios',
device: 'iPhone 16',
providerOsVersion: '18.0',
providerApp: 'https://apps.example.com/MyApp-simulator.zip',
});
const client = createAgentDeviceClient({ ...host.clientConfig, ...scope, leaseId: lease.leaseId });
Expand Down Expand Up @@ -167,5 +169,7 @@ takes when the daemon loads the plugin from the plugin store.
- A start that never becomes ready reports `provider-not-ready` or `provider-start-failed` and stops
the run it started, so a failed `open` does not leave a rented device. Retry, then check that Revyl
has a device of the requested model and OS version.
- `snapshot` on iOS can fail with HTTP 500 while the simulator's accessibility service briefly
returns nothing. The plugin retries the read; if it still fails, run `snapshot` again.
- A device that Revyl released while your session was open reports `provider-session-gone`. Run
`close` and `open` again to rent a fresh one.
Loading