Skip to content

Commit 87e7be8

Browse files
thymikeeclaude
andcommitted
refactor(provider-webdriver): drop restated facts and unused AWS options
- build the inactive-session facts from the fully-unavailable table instead of restating thirty cells - remove AWS Device Farm options no caller supplies, and the LeaseValue helper that only served them Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent 6aa6f72 commit 87e7be8

3 files changed

Lines changed: 19 additions & 89 deletions

File tree

‎packages/provider-webdriver/src/aws-device-farm.ts‎

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ import {
55
type AwsDeviceFarmArtifact,
66
type AwsDeviceFarmArtifactGroup,
77
} from './aws-device-farm-artifacts.ts';
8-
import type {
9-
CloudWebDriverPlatform,
10-
CloudWebDriverRuntimeOptions,
11-
CloudWebDriverPrepareSession,
12-
} from './runtime.ts';
13-
import type { DeviceLease, LeaseLifecycleContext } from '@agent-device/contracts/device';
8+
import type { CloudWebDriverPlatform, CloudWebDriverPrepareSession } from './runtime.ts';
9+
import type { LeaseLifecycleContext } from '@agent-device/contracts/device';
1410
import { setTimeout as sleep } from 'node:timers/promises';
1511
import { AppError } from '@agent-device/kernel/errors';
1612
import type { RunHostCommand } from './dependencies.ts';
17-
import { releaseOnFailure, resolveLeaseValue, type LeaseValue } from './webdriver-utils.ts';
13+
import { releaseOnFailure } from './webdriver-utils.ts';
1814

1915
export const AWS_DEVICE_FARM_CAPABILITY_OVERRIDES = {
2016
install: {
@@ -72,25 +68,16 @@ export type AwsCreateRemoteAccessSessionInput = {
7268
};
7369

7470
export type AwsDeviceFarmWebDriverRuntimeOptions = {
75-
clientVersion: string;
71+
client: AwsDeviceFarmClient;
7672
projectArn: string;
7773
deviceArn: string;
78-
region?: string;
79-
platform?: CloudWebDriverPlatform;
80-
deviceName?: string;
74+
platform: CloudWebDriverPlatform;
75+
deviceName: string;
8176
appArn?: string;
82-
sessionName?: LeaseValue<string>;
83-
webdriverCapabilities?:
84-
| Record<string, unknown>
85-
| ((lease: DeviceLease) => Record<string, unknown>);
86-
client?: AwsDeviceFarmClient;
77+
sessionName?: string;
8778
pollIntervalMs?: number;
8879
startupTimeoutMs?: number;
8980
interactionMode?: AwsCreateRemoteAccessSessionInput['interactionMode'];
90-
configuration?: AwsCreateRemoteAccessSessionInput['configuration'];
91-
deviceId?: CloudWebDriverRuntimeOptions['deviceId'];
92-
requestPolicy?: CloudWebDriverRuntimeOptions['requestPolicy'];
93-
prepareSession?: CloudWebDriverRuntimeOptions['prepareSession'];
9481
};
9582

9683
export type AwsCliDeviceFarmClientOptions = {
@@ -134,25 +121,15 @@ export function createAwsCliDeviceFarmClient(
134121
}
135122

136123
export function createAwsDeviceFarmPrepareSession(
137-
options: Required<
138-
Pick<
139-
AwsDeviceFarmWebDriverRuntimeOptions,
140-
'client' | 'platform' | 'deviceName' | 'projectArn' | 'deviceArn'
141-
>
142-
> &
143-
Omit<
144-
AwsDeviceFarmWebDriverRuntimeOptions,
145-
'client' | 'platform' | 'deviceName' | 'clientVersion'
146-
>,
124+
options: AwsDeviceFarmWebDriverRuntimeOptions,
147125
): CloudWebDriverPrepareSession {
148126
return async ({ lease, req, base }) => {
149127
const remoteAccess = await options.client.createRemoteAccessSession({
150128
projectArn: options.projectArn,
151129
deviceArn: options.deviceArn,
152130
appArn: options.appArn,
153-
name: resolveLeaseValue(options.sessionName, lease) ?? `agent-device-${lease.leaseId}`,
131+
name: options.sessionName ?? `agent-device-${lease.leaseId}`,
154132
interactionMode: options.interactionMode,
155-
configuration: options.configuration,
156133
});
157134
// The ARN is a billed session from here on; any failure short of RUNNING
158135
// must stop it before surfacing, or it bills until AWS reaps it.
@@ -173,20 +150,17 @@ export function createAwsDeviceFarmPrepareSession(
173150
throw error;
174151
}
175152
const deviceName = running.device?.name ?? options.deviceName;
176-
const configured =
177-
typeof options.webdriverCapabilities === 'function'
178-
? options.webdriverCapabilities(lease)
179-
: (options.webdriverCapabilities ?? {});
180153
const awsDefaults = options.platform === 'android' ? { 'appium:autoLaunch': false } : {};
181154
return {
182155
...base,
183156
endpoint,
184157
platform: options.platform,
185158
deviceName,
186-
webdriverCapabilities: buildCloudWebDriverBaseCapabilities(options.platform, deviceName, {
187-
...awsDefaults,
188-
...configured,
189-
}),
159+
webdriverCapabilities: buildCloudWebDriverBaseCapabilities(
160+
options.platform,
161+
deviceName,
162+
awsDefaults,
163+
),
190164
cleanup: async () => {
191165
await options.client.stopRemoteAccessSession(running.arn);
192166
return { awsDeviceFarmSessionArn: running.arn };

‎packages/provider-webdriver/src/platform-runtime.ts‎

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ import type {
4646
PlatformRuntimeOperations,
4747
PlatformRuntimeOwner,
4848
} from '@agent-device/contracts/platform-runtime-operations';
49-
import { createUnavailablePlatformRuntimeFacts } from '@agent-device/contracts/platform-runtime-unavailable';
49+
import {
50+
createFullyUnavailablePlatformRuntimeFacts,
51+
createUnavailablePlatformRuntimeFacts,
52+
} from '@agent-device/contracts/platform-runtime-unavailable';
5053
import {
5154
bindProviderScreenshotInteractor,
5255
screenshotRuntimeOperationFacts,
@@ -484,45 +487,8 @@ function webDriverFacts(
484487
): RuntimeFacts<PlatformRuntimeOperations> {
485488
if (!webDriverSessionActive(options, device)) {
486489
return createUnavailablePlatformRuntimeFacts(device, options.owner, {
487-
appLog: inactiveSession,
488-
appDeployment: inactiveSession,
489-
network: inactiveSession,
490-
screenRecording: inactiveSession,
491-
screenshot: inactiveSession,
492-
viewport: inactiveSession,
493-
focus: inactiveSession,
494-
gesture: inactiveSession,
495-
scroll: inactiveSession,
496-
typeText: inactiveSession,
497-
touch: inactiveSession,
498-
elementText: inactiveSession,
499-
back: inactiveSession,
500-
orientation: inactiveSession,
501-
tvRemote: inactiveSession,
502-
keyboard: inactiveSession,
503-
clipboard: inactiveSession,
504-
systemButton: inactiveSession,
490+
...createFullyUnavailablePlatformRuntimeFacts(inactiveSession),
505491
fold: foldUnavailable,
506-
triggerAppEvent: inactiveSession,
507-
settings: inactiveSession,
508-
readAlert: inactiveSession,
509-
awaitAlert: inactiveSession,
510-
acceptAlert: inactiveSession,
511-
dismissAlert: inactiveSession,
512-
audioProbeCapture: inactiveSession,
513-
audioProbeQuery: inactiveSession,
514-
perf: inactiveSession,
515-
lifecycle: applicationLifecycleOperationFacts({
516-
resolveOpenTarget: inactiveSession,
517-
prepareApplicationOpen: inactiveSession,
518-
openApplication: inactiveSession,
519-
applyRuntimeHints: inactiveSession,
520-
clearRuntimeHints: inactiveSession,
521-
closeApplication: inactiveSession,
522-
finalizeApplicationClose: inactiveSession,
523-
prepareAppleRunner: inactiveSession,
524-
configureProviderPortReverse: inactiveSession,
525-
}),
526492
});
527493
}
528494
const deployment = options.deployment?.fact(device) ?? deploymentUnavailable;

‎packages/provider-webdriver/src/webdriver-utils.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import fs from 'node:fs';
22
import { readFile, stat } from 'node:fs/promises';
33
import path from 'node:path';
44
import type {
5-
DeviceLease,
65
LeaseLifecycleContext,
76
ProviderDeviceInstallOptions,
87
ProviderDeviceInstallResult,
@@ -14,8 +13,6 @@ import {
1413
import { AppError, errorMessage } from '@agent-device/kernel/errors';
1514
import { agentDeviceRequestHeaders } from './request-headers.ts';
1615

17-
export type LeaseValue<T> = T | ((lease: DeviceLease) => T);
18-
1916
/** Best-effort release after a failure; a failed release rides along as `cleanupError`, never masks the primary. */
2017
export async function releaseOnFailure(
2118
primaryError: unknown,
@@ -30,13 +27,6 @@ export async function releaseOnFailure(
3027
}
3128
}
3229

33-
export function resolveLeaseValue<T>(
34-
value: LeaseValue<T> | undefined,
35-
lease: DeviceLease,
36-
): T | undefined {
37-
return typeof value === 'function' ? (value as (lease: DeviceLease) => T)(lease) : value;
38-
}
39-
4030
export function basicAuthHeader(credentials: { username: string; accessKey: string }): string {
4131
return `Basic ${Buffer.from(`${credentials.username}:${credentials.accessKey}`).toString('base64')}`;
4232
}

0 commit comments

Comments
 (0)