From b92e657cc5caca45be5044ec95929d7e7785c96b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 16 Nov 2026 17:54:59 +0100 Subject: [PATCH 01/13] Extract AWS Device Farm provider plugin --- .changeset/aws-device-farm-plugin.md | 5 + README.md | 2 +- examples/sdk/tsconfig.json | 1 + package.json | 1 + packages/maestro/src/plugin.test.ts | 3 + packages/plugins/src/host-command.test.ts | 20 ++ packages/plugins/src/host.ts | 16 ++ packages/provider-aws-device-farm/README.md | 9 + .../provider-aws-device-farm/package.json | 53 ++++ .../src/aws-device-farm-artifacts.ts | 2 +- ...vice-farm-connection-verification.test.ts} | 4 +- ...aws-device-farm-connection-verification.ts | 2 +- .../aws-device-farm-profile-fields.test.ts | 20 ++ .../src/aws-device-farm-webdriver.ts} | 46 ++-- .../src/aws-device-farm.test.ts | 2 +- .../src/aws-device-farm.ts | 46 +--- .../src/connection.test.ts} | 72 +++-- .../src/connection.ts} | 29 +- .../src/index.test.ts} | 52 +++- .../provider-aws-device-farm/src/index.ts | 41 +++ .../src/profile-fields.ts | 31 +++ .../provider-aws-device-farm/src/providers.ts | 2 + .../src/run-host-command.ts | 8 + .../test/package-smoke.mjs | 57 ++++ .../provider-aws-device-farm/tsconfig.json | 28 ++ .../provider-aws-device-farm/tsdown.config.ts | 19 ++ .../src/browserstack-connection.test.ts | 3 + .../provider-browserstack/src/index.test.ts | 3 + packages/provider-testmu/src/index.test.ts | 3 + packages/provider-webdriver/package.json | 6 +- .../aws-device-farm-profile-fields.test.ts | 15 -- .../src/connection-verification.ts | 6 - .../provider-webdriver/src/dependencies.ts | 13 - .../src/index-profile-fields.test.ts | 18 -- packages/provider-webdriver/src/index.ts | 28 +- packages/provider-webdriver/src/plugin.ts | 7 +- .../provider-webdriver/src/provider-plugin.ts | 69 ----- packages/provider-webdriver/src/providers.ts | 36 +-- pnpm-lock.yaml | 18 ++ scripts/capability-matrix/collect.ts | 48 ++-- scripts/capability-matrix/seams.ts | 2 +- scripts/layering/architecture-ownership.ts | 1 + scripts/layering/model.ts | 1 + scripts/layering/package-boundaries.test.ts | 1 - scripts/layering/root-module-zones.ts | 1 - .../cloud-connect-aws-device-farm.test.ts | 251 ++++++++++++++++++ src/__tests__/cloud-connect-profile.test.ts | 134 ---------- src/__tests__/cloud-connect-testmu.test.ts | 10 +- .../provider-device-runtimes.test.ts | 33 ++- src/__tests__/remote-connection.test.ts | 10 +- .../aws-device-farm-plugin-inventory.ts | 35 +++ src/builtin-provider-ids.ts | 11 +- src/builtin-provider-plugins.ts | 49 +--- .../connection/connect-provider-adapters.ts | 8 +- src/cli/connection/provider-policy.test.ts | 17 +- src/commands/provider-plugin-catalog.ts | 5 + src/commands/schema/cli-help.ts | 2 +- src/provider-credential-fingerprint.test.ts | 25 +- src/provider-webdriver.test.ts | 82 ------ src/provider-webdriver.ts | 32 --- src/sdk/plugins.ts | 6 +- .../provider-scenarios/aws-runtime.ts | 33 +++ .../bundled-cloud-webdriver-runtimes.ts | 24 +- .../cloud-webdriver-provider-adapters.test.ts | 51 ++-- .../cloud-webdriver-regression-fixtures.ts | 2 +- tsconfig.typecheck.json | 1 + website/docs/docs/aws-device-farm.md | 10 + website/docs/docs/device-clouds.md | 4 +- website/docs/docs/plugins.md | 4 +- 69 files changed, 946 insertions(+), 743 deletions(-) create mode 100644 .changeset/aws-device-farm-plugin.md create mode 100644 packages/plugins/src/host-command.test.ts create mode 100644 packages/provider-aws-device-farm/README.md create mode 100644 packages/provider-aws-device-farm/package.json rename packages/{provider-webdriver => provider-aws-device-farm}/src/aws-device-farm-artifacts.ts (96%) rename packages/{provider-webdriver/src/connection-verification.test.ts => provider-aws-device-farm/src/aws-device-farm-connection-verification.test.ts} (95%) rename packages/{provider-webdriver => provider-aws-device-farm}/src/aws-device-farm-connection-verification.ts (98%) create mode 100644 packages/provider-aws-device-farm/src/aws-device-farm-profile-fields.test.ts rename packages/{provider-webdriver/src/aws-device-farm-provider.ts => provider-aws-device-farm/src/aws-device-farm-webdriver.ts} (63%) rename packages/{provider-webdriver => provider-aws-device-farm}/src/aws-device-farm.test.ts (98%) rename packages/{provider-webdriver => provider-aws-device-farm}/src/aws-device-farm.ts (89%) rename packages/{provider-webdriver/src/aws-device-farm-connection.test.ts => provider-aws-device-farm/src/connection.test.ts} (51%) rename packages/{provider-webdriver/src/aws-device-farm-connection.ts => provider-aws-device-farm/src/connection.ts} (71%) rename packages/{provider-webdriver/src/aws-device-farm-provider.test.ts => provider-aws-device-farm/src/index.test.ts} (54%) create mode 100644 packages/provider-aws-device-farm/src/index.ts create mode 100644 packages/provider-aws-device-farm/src/profile-fields.ts create mode 100644 packages/provider-aws-device-farm/src/providers.ts create mode 100644 packages/provider-aws-device-farm/src/run-host-command.ts create mode 100644 packages/provider-aws-device-farm/test/package-smoke.mjs create mode 100644 packages/provider-aws-device-farm/tsconfig.json create mode 100644 packages/provider-aws-device-farm/tsdown.config.ts delete mode 100644 packages/provider-webdriver/src/aws-device-farm-profile-fields.test.ts delete mode 100644 packages/provider-webdriver/src/connection-verification.ts delete mode 100644 packages/provider-webdriver/src/dependencies.ts delete mode 100644 packages/provider-webdriver/src/index-profile-fields.test.ts delete mode 100644 packages/provider-webdriver/src/provider-plugin.ts create mode 100644 src/__tests__/cloud-connect-aws-device-farm.test.ts create mode 100644 src/__tests__/test-utils/aws-device-farm-plugin-inventory.ts delete mode 100644 src/provider-webdriver.test.ts delete mode 100644 src/provider-webdriver.ts create mode 100644 test/integration/provider-scenarios/aws-runtime.ts diff --git a/.changeset/aws-device-farm-plugin.md b/.changeset/aws-device-farm-plugin.md new file mode 100644 index 0000000000..182e4de28b --- /dev/null +++ b/.changeset/aws-device-farm-plugin.md @@ -0,0 +1,5 @@ +--- +'agent-device': minor +--- + +Install AWS Device Farm support with `agent-device plugins add @agent-device/aws-device-farm`. Close existing sessions and stop the daemon for its state directory before reconnecting after upgrading. diff --git a/README.md b/README.md index bd167f98c0..d2eff7fe11 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ The same session and evidence model works at every step: the agent explores the | --- | --- | --- | | Local | Trying commands and debugging apps on simulators, emulators, physical devices, macOS, and Linux. | Follow the Quick Start. | | CI/CD | Automated pull request and merge validation with replay scripts and captured artifacts. | Try the [EAS workflow template](https://github.com/callstackincubator/eas-agent-device/blob/main/.eas/workflows/agent-qa-mobile.yml). | -| Cloud / remote | Linux runners, managed devices, and remote jobs. | Set up a [remote proxy](https://agent-device.dev/docs/remote-proxy), connect a [device cloud](https://agent-device.dev/docs/device-clouds) (BrowserStack and TestMu AI through `agent-device plugins add`, AWS Device Farm, Limrun), or [contact Callstack](mailto:hello@callstack.com) for team QA. | +| Cloud / remote | Linux runners, managed devices, and remote jobs. | Set up a [remote proxy](https://agent-device.dev/docs/remote-proxy), connect a [device cloud](https://agent-device.dev/docs/device-clouds) (BrowserStack, AWS Device Farm, and TestMu AI through `agent-device plugins add`, Limrun), or [contact Callstack](mailto:hello@callstack.com) for team QA. | ## How it works diff --git a/examples/sdk/tsconfig.json b/examples/sdk/tsconfig.json index aeaa54003a..92426b08d0 100644 --- a/examples/sdk/tsconfig.json +++ b/examples/sdk/tsconfig.json @@ -65,6 +65,7 @@ { "path": "../../packages/provider-limrun" }, { "path": "../../packages/provider-revyl" }, { "path": "../../packages/provider-testmu" }, + { "path": "../../packages/provider-aws-device-farm" }, { "path": "../../packages/provider-browserstack" }, { "path": "../../packages/provider-webos" }, { "path": "../../packages/provider-tizen" }, diff --git a/package.json b/package.json index 4bc62bdc9e..2040fa86c0 100644 --- a/package.json +++ b/package.json @@ -376,6 +376,7 @@ "yaml": "^2.9.0", "yauzl": "^3.4.0", "@agent-device/testmu": "workspace:*", + "@agent-device/aws-device-farm": "workspace:*", "@agent-device/browserstack": "workspace:*", "@agent-device/revyl": "workspace:*", "@agent-device/webos": "workspace:*", diff --git a/packages/maestro/src/plugin.test.ts b/packages/maestro/src/plugin.test.ts index 60f10b158e..f1abaeb694 100644 --- a/packages/maestro/src/plugin.test.ts +++ b/packages/maestro/src/plugin.test.ts @@ -22,6 +22,9 @@ const setupHost = { env: {}, options: {}, clientVersion: '0.22.0-dev', + runHostCommand: async () => { + throw new Error('host command unused'); + }, createError: () => { throw new Error('setup must not use host services'); }, diff --git a/packages/plugins/src/host-command.test.ts b/packages/plugins/src/host-command.test.ts new file mode 100644 index 0000000000..0f80ec3274 --- /dev/null +++ b/packages/plugins/src/host-command.test.ts @@ -0,0 +1,20 @@ +import { expect, test } from 'vitest'; +import { withCommandExecutorOverride } from '@agent-device/host-kit/command'; +import { createPluginHost } from './host.ts'; + +test('plugin host runs commands with the AWS command bounds', async () => { + await withCommandExecutorOverride( + async (command, args, options) => { + expect(command).toBe('aws'); + expect(args).toEqual(['devicefarm', 'get-project']); + expect(options.maxBuffer).toBe(10 * 1024 * 1024); + expect(options.timeoutMs).toBe(30_000); + return { stdout: '{"project":{}}', stderr: '', exitCode: 0 }; + }, + async () => { + await expect( + createPluginHost({}, undefined).runHostCommand('aws', ['devicefarm', 'get-project']), + ).resolves.toEqual({ stdout: '{"project":{}}' }); + }, + ); +}); diff --git a/packages/plugins/src/host.ts b/packages/plugins/src/host.ts index 19ac09c688..d1dfb0cf55 100644 --- a/packages/plugins/src/host.ts +++ b/packages/plugins/src/host.ts @@ -1,11 +1,20 @@ import { AppError, type AppErrorCode, type AppErrorDetails } from '@agent-device/kernel/errors'; import { readVersion } from '@agent-device/host-kit/version'; +import { runCmd } from '@agent-device/host-kit/command'; + +export type HostCommandResult = Readonly<{ stdout: string }>; + +export type RunHostCommand = ( + command: string, + args: readonly string[], +) => Promise; export type ProviderPluginHost = Readonly<{ env: Readonly>; options: Readonly>; clientVersion: string; createError(code: AppErrorCode, message: string, details?: AppErrorDetails): AppError; + runHostCommand: RunHostCommand; }>; export function createPluginHost( @@ -17,5 +26,12 @@ export function createPluginHost( options: Object.freeze({ ...options }), clientVersion: readVersion(), createError: (code, message, details) => new AppError(code, message, details), + runHostCommand: async (command, args) => { + const { stdout } = await runCmd(command, [...args], { + maxBuffer: 10 * 1024 * 1024, + timeoutMs: 30_000, + }); + return { stdout }; + }, } satisfies ProviderPluginHost); } diff --git a/packages/provider-aws-device-farm/README.md b/packages/provider-aws-device-farm/README.md new file mode 100644 index 0000000000..a2273bd6e8 --- /dev/null +++ b/packages/provider-aws-device-farm/README.md @@ -0,0 +1,9 @@ +# AWS Device Farm for agent-device + +Install the plugin on the daemon host: + +```sh +agent-device plugins add @agent-device/aws-device-farm +``` + +Configure AWS CLI credentials and connect using your Device Farm project and device ARNs. See the [AWS Device Farm guide](https://agent-device.dev/docs/aws-device-farm). diff --git a/packages/provider-aws-device-farm/package.json b/packages/provider-aws-device-farm/package.json new file mode 100644 index 0000000000..3a99a5854f --- /dev/null +++ b/packages/provider-aws-device-farm/package.json @@ -0,0 +1,53 @@ +{ + "name": "@agent-device/aws-device-farm", + "version": "0.22.0-dev", + "private": true, + "type": "module", + "description": "AWS Device Farm real-device plugin for agent-device.", + "files": [ + "dist" + ], + "scripts": { + "build": "tsdown --config tsdown.config.ts", + "prepack": "pnpm build" + }, + "exports": { + ".": { + "types": "./src/index.ts", + "default": "./src/index.ts" + }, + "./agent-device": { + "types": "./src/index.ts", + "default": "./src/index.ts" + }, + "./connection-verification": { + "types": "./src/aws-device-farm-connection-verification.ts", + "default": "./src/aws-device-farm-connection-verification.ts" + }, + "./package.json": "./package.json" + }, + "devDependencies": { + "@agent-device/contracts": "workspace:*", + "@agent-device/kernel": "workspace:*", + "@agent-device/provider-webdriver": "workspace:*", + "agent-device": "workspace:*" + }, + "publishConfig": { + "exports": { + ".": { + "import": "./dist/agent-device.mjs" + }, + "./agent-device": { + "import": "./dist/agent-device.mjs" + } + }, + "access": "public" + }, + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/callstack/agent-device.git", + "directory": "packages/provider-aws-device-farm" + }, + "homepage": "https://agent-device.dev/docs/aws-device-farm" +} diff --git a/packages/provider-webdriver/src/aws-device-farm-artifacts.ts b/packages/provider-aws-device-farm/src/aws-device-farm-artifacts.ts similarity index 96% rename from packages/provider-webdriver/src/aws-device-farm-artifacts.ts rename to packages/provider-aws-device-farm/src/aws-device-farm-artifacts.ts index 8dbbdacdd3..2d4722a1ca 100644 --- a/packages/provider-webdriver/src/aws-device-farm-artifacts.ts +++ b/packages/provider-aws-device-farm/src/aws-device-farm-artifacts.ts @@ -1,6 +1,6 @@ import type { CloudArtifact, CloudArtifactsResult } from '@agent-device/contracts/observability'; import type { AwsDeviceFarmClient } from './aws-device-farm.ts'; -import { cloudArtifactsReadyOrPending } from './artifact-results.ts'; +import { cloudArtifactsReadyOrPending } from '@agent-device/provider-webdriver/plugin'; export type AwsDeviceFarmArtifactGroup = 'FILE' | 'LOG' | 'SCREENSHOT'; diff --git a/packages/provider-webdriver/src/connection-verification.test.ts b/packages/provider-aws-device-farm/src/aws-device-farm-connection-verification.test.ts similarity index 95% rename from packages/provider-webdriver/src/connection-verification.test.ts rename to packages/provider-aws-device-farm/src/aws-device-farm-connection-verification.test.ts index cea3f28095..fd3031d6f7 100644 --- a/packages/provider-webdriver/src/connection-verification.test.ts +++ b/packages/provider-aws-device-farm/src/aws-device-farm-connection-verification.test.ts @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; import { afterEach, test, vi } from 'vitest'; -import { verifyAwsDeviceFarmConnection } from './connection-verification.ts'; -import type { RunHostCommand } from './dependencies.ts'; +import { verifyAwsDeviceFarmConnection } from './aws-device-farm-connection-verification.ts'; +import type { RunHostCommand } from './run-host-command.ts'; const awsResources = { project: { arn: 'project-arn', name: 'Agent Device' }, diff --git a/packages/provider-webdriver/src/aws-device-farm-connection-verification.ts b/packages/provider-aws-device-farm/src/aws-device-farm-connection-verification.ts similarity index 98% rename from packages/provider-webdriver/src/aws-device-farm-connection-verification.ts rename to packages/provider-aws-device-farm/src/aws-device-farm-connection-verification.ts index 899cc7938f..1ff03f0392 100644 --- a/packages/provider-webdriver/src/aws-device-farm-connection-verification.ts +++ b/packages/provider-aws-device-farm/src/aws-device-farm-connection-verification.ts @@ -1,6 +1,6 @@ import { AppError } from '@agent-device/kernel/errors'; import { createAwsDeviceFarmCommandRunner } from './aws-device-farm.ts'; -import type { RunHostCommand } from './dependencies.ts'; +import type { RunHostCommand } from './run-host-command.ts'; import type { ProviderConnectionResource, ProviderConnectionVerification, diff --git a/packages/provider-aws-device-farm/src/aws-device-farm-profile-fields.test.ts b/packages/provider-aws-device-farm/src/aws-device-farm-profile-fields.test.ts new file mode 100644 index 0000000000..cb80fdf922 --- /dev/null +++ b/packages/provider-aws-device-farm/src/aws-device-farm-profile-fields.test.ts @@ -0,0 +1,20 @@ +import { test } from 'vitest'; +import assert from 'node:assert/strict'; +import type { ProviderProfileField } from '@agent-device/contracts/provider-profile-fields'; +import { AWS_DEVICE_FARM_PROFILE_FIELDS } from './profile-fields.ts'; + +test('AWS Device Farm consumes only its own fields and the session name', () => { + assert.deepEqual( + (Object.keys(AWS_DEVICE_FARM_PROFILE_FIELDS.fields) as ProviderProfileField[]) + .filter((field) => AWS_DEVICE_FARM_PROFILE_FIELDS.fields[field] === 'consumed') + .sort(), + [ + 'awsAppArn', + 'awsDeviceArn', + 'awsInteractionMode', + 'awsProjectArn', + 'awsRegion', + 'providerSessionName', + ], + ); +}); diff --git a/packages/provider-webdriver/src/aws-device-farm-provider.ts b/packages/provider-aws-device-farm/src/aws-device-farm-webdriver.ts similarity index 63% rename from packages/provider-webdriver/src/aws-device-farm-provider.ts rename to packages/provider-aws-device-farm/src/aws-device-farm-webdriver.ts index 6938e38afa..e946fd6222 100644 --- a/packages/provider-webdriver/src/aws-device-farm-provider.ts +++ b/packages/provider-aws-device-farm/src/aws-device-farm-webdriver.ts @@ -1,6 +1,12 @@ +import type { ProviderPluginHost } from 'agent-device/plugins'; +import type { WebDriverPluginOptions } from 'agent-device/plugins/webdriver'; +import { + readFlag, + requireRequest, + requireRequestPlatform, +} from '@agent-device/provider-webdriver/plugin'; import { AWS_DEVICE_FARM_CAPABILITY_OVERRIDES, - AWS_DEVICE_FARM_PROFILE_FIELDS, createAwsCliDeviceFarmClient, createAwsDeviceFarmPrepareSession, listAwsDeviceFarmCloudArtifacts, @@ -9,32 +15,20 @@ import { readAwsDeviceFarmSelectorFromEnv, requireAwsDeviceFarmSelector, } from './aws-device-farm.ts'; -import type { - BundledCloudWebDriverProvider, - CloudWebDriverConnection, - CloudWebDriverProviderHost, - CloudWebDriverProviderOptions, - CloudWebDriverProviderRegistration, -} from './provider-plugin.ts'; -import { CLOUD_WEBDRIVER_PROVIDERS, cloudWebDriverProviderDeclaration } from './providers.ts'; -import { readFlag, requireRequest, requireRequestPlatform } from './webdriver-utils.ts'; +import { AWS_DEVICE_FARM_PROFILE_FIELDS } from './profile-fields.ts'; +import { AWS_DEVICE_FARM_PROVIDER } from './providers.ts'; -const PROVIDER = CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm; const SERVICE = 'AWS Device Farm'; -export const awsDeviceFarmProvider: BundledCloudWebDriverProvider = { - declaration: cloudWebDriverProviderDeclaration(PROVIDER)!, - create: createAwsDeviceFarmProvider, -}; - -function createAwsDeviceFarmProvider( - host: CloudWebDriverProviderHost, -): CloudWebDriverProviderRegistration { - const { env, runHostCommand } = host; +/** The AWS Device Farm WebDriver descriptor the host drives through its shared engine. */ +export function createAwsDeviceFarmWebDriver(host: ProviderPluginHost): WebDriverPluginOptions { + const { env } = host; + const runHostCommand = (command: string, args: readonly string[]) => + host.runHostCommand(command, args); const client = (region: string | undefined) => createAwsCliDeviceFarmClient({ runHostCommand, region }); - const webDriver: CloudWebDriverProviderOptions = { - provider: PROVIDER, + const webDriver: WebDriverPluginOptions = { + provider: AWS_DEVICE_FARM_PROVIDER, profileFields: AWS_DEVICE_FARM_PROFILE_FIELDS, endpoint: 'http://127.0.0.1/', platform: 'android', @@ -71,11 +65,5 @@ function createAwsDeviceFarmProvider( })({ lease, req, base }); }, }; - const connect = async () => - (await import('./aws-device-farm-connection.ts')).createAwsDeviceFarmConnection(host); - const connection: CloudWebDriverConnection = { - resolve: async (context) => (await connect()).resolve(context), - verify: async (context) => await (await connect()).verify(context), - }; - return { webDriver, connection }; + return webDriver; } diff --git a/packages/provider-webdriver/src/aws-device-farm.test.ts b/packages/provider-aws-device-farm/src/aws-device-farm.test.ts similarity index 98% rename from packages/provider-webdriver/src/aws-device-farm.test.ts rename to packages/provider-aws-device-farm/src/aws-device-farm.test.ts index 0b80b9cd69..9d6afcb895 100644 --- a/packages/provider-webdriver/src/aws-device-farm.test.ts +++ b/packages/provider-aws-device-farm/src/aws-device-farm.test.ts @@ -11,7 +11,7 @@ import { type AwsDeviceFarmClient, type AwsDeviceFarmRemoteAccessSession, } from './aws-device-farm.ts'; -import { buildCloudWebDriverBaseCapabilities } from './runtime.ts'; +import { buildCloudWebDriverBaseCapabilities } from '@agent-device/provider-webdriver/plugin'; const ARN = 'arn:aws:devicefarm:us-west-2:1:session/pending'; diff --git a/packages/provider-webdriver/src/aws-device-farm.ts b/packages/provider-aws-device-farm/src/aws-device-farm.ts similarity index 89% rename from packages/provider-webdriver/src/aws-device-farm.ts rename to packages/provider-aws-device-farm/src/aws-device-farm.ts index 1f649c1745..eddc563081 100644 --- a/packages/provider-webdriver/src/aws-device-farm.ts +++ b/packages/provider-aws-device-farm/src/aws-device-farm.ts @@ -1,48 +1,22 @@ -import type { CloudWebDriverCapabilityOverrides } from './capabilities.ts'; -import { buildCloudWebDriverBaseCapabilities } from './runtime.ts'; +import type { CloudWebDriverCapabilityOverrides } from '@agent-device/provider-webdriver/plugin'; +import { + buildCloudWebDriverBaseCapabilities, + releaseOnFailure, +} from '@agent-device/provider-webdriver/plugin'; import { readAwsArtifacts, type AwsDeviceFarmArtifact, type AwsDeviceFarmArtifactGroup, } from './aws-device-farm-artifacts.ts'; -import type { CloudWebDriverPlatform, CloudWebDriverPrepareSession } from './runtime.ts'; +import type { + CloudWebDriverPlatform, + CloudWebDriverPrepareSession, +} from '@agent-device/provider-webdriver/plugin'; import type { LeaseLifecycleContext } from '@agent-device/contracts/device'; -import type { ProviderProfileFieldDeclaration } from '@agent-device/contracts/provider-profile-fields'; import { PROVIDER_PROFILE_FIELD_FLAGS } from '@agent-device/contracts/remote'; import { setTimeout as sleep } from 'node:timers/promises'; import { AppError } from '@agent-device/kernel/errors'; -import type { RunHostCommand } from './dependencies.ts'; -import { CLOUD_WEBDRIVER_PROVIDERS } from './providers.ts'; -import { releaseOnFailure } from './webdriver-utils.ts'; - -export const AWS_DEVICE_FARM_PROFILE_FIELDS: ProviderProfileFieldDeclaration = { - provider: CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm, - label: 'AWS Device Farm', - fields: { - providerApp: 'refused', - providerOsVersion: 'refused', - providerDeviceType: 'refused', - providerProject: 'refused', - providerBuild: 'refused', - providerSessionName: 'consumed', - providerDeviceOrientation: 'refused', - providerGeoLocation: 'refused', - providerTimezone: 'refused', - providerAppiumVersion: 'refused', - providerLanguage: 'refused', - providerLocale: 'refused', - providerNetworkProfile: 'refused', - providerCustomNetwork: 'refused', - providerNoResignApp: 'refused', - providerNetworkLogs: 'refused', - providerNetworkHosts: 'refused', - awsProjectArn: 'consumed', - awsDeviceArn: 'consumed', - awsAppArn: 'consumed', - awsRegion: 'consumed', - awsInteractionMode: 'consumed', - }, -}; +import type { RunHostCommand } from './run-host-command.ts'; /** Each selector reads its flag first, then the agent-device variable, then the AWS CLI one. */ const AWS_SELECTOR_VARIABLES = { diff --git a/packages/provider-webdriver/src/aws-device-farm-connection.test.ts b/packages/provider-aws-device-farm/src/connection.test.ts similarity index 51% rename from packages/provider-webdriver/src/aws-device-farm-connection.test.ts rename to packages/provider-aws-device-farm/src/connection.test.ts index 9b7c68edb7..d23b97fb5e 100644 --- a/packages/provider-webdriver/src/aws-device-farm-connection.test.ts +++ b/packages/provider-aws-device-farm/src/connection.test.ts @@ -1,12 +1,11 @@ import assert from 'node:assert/strict'; import { afterEach, test, vi } from 'vitest'; +import type { PluginConnectionContext, ProviderPluginHost } from 'agent-device/plugins'; import { AppError } from '@agent-device/kernel/errors'; -import { createAwsDeviceFarmConnection } from './aws-device-farm-connection.ts'; -import { verifyAwsDeviceFarmConnection } from './connection-verification.ts'; -import type { CloudWebDriverProviderHost } from './provider-plugin.ts'; +import { createAwsDeviceFarmConnection } from './connection.ts'; +import { verifyAwsDeviceFarmConnection } from './aws-device-farm-connection-verification.ts'; -vi.mock('./connection-verification.ts', async (importOriginal) => ({ - ...(await importOriginal()), +vi.mock('./aws-device-farm-connection-verification.ts', () => ({ verifyAwsDeviceFarmConnection: vi.fn(), })); @@ -23,16 +22,32 @@ const FLAGS = { awsDeviceArn: DEVICE_ARN, }; -function host(env: Record = {}): CloudWebDriverProviderHost { +function host(env: Record = {}): ProviderPluginHost { return { env, + options: {}, clientVersion: '1.2.3', + createError: (code, message, details) => new AppError(code, message, details), runHostCommand: async () => { throw new Error('this scenario runs no host commands'); }, }; } +function context( + overrides: Partial & { flags?: Record } = {}, +): PluginConnectionContext { + const pluginHost = overrides.host ?? host(); + return { + flags: FLAGS, + stateDir: '/state', + cwd: '/', + env: { ...pluginHost.env }, + host: pluginHost, + ...overrides, + } as PluginConnectionContext; +} + test('connect resolves selectors from flags, then agent-device variables, then AWS variables', async () => { const connection = createAwsDeviceFarmConnection( host({ @@ -41,8 +56,7 @@ test('connect resolves selectors from flags, then agent-device variables, then A AWS_DEFAULT_REGION: 'eu-west-1', }), ); - const { profile, extraFlags } = connection.resolve({ flags: FLAGS, cwd: '/' }); - assert.equal(extraFlags, undefined); + const { profile } = await connection.resolve(context()); assert.deepEqual(profile, { leaseProvider: 'aws-device-farm', platform: 'ios', @@ -55,41 +69,49 @@ test('connect resolves selectors from flags, then agent-device variables, then A providerSessionName: undefined, }); // With no region configured, the project ARN names it. - const fromArn = createAwsDeviceFarmConnection(host()).resolve({ flags: FLAGS, cwd: '/' }); + const fromArn = await createAwsDeviceFarmConnection(host()).resolve(context()); assert.equal(fromArn.profile.awsRegion, 'us-west-2'); }); test('connect names the flag and the AWS variable a missing selector can come from', async () => { const connection = createAwsDeviceFarmConnection(host()); - assert.throws( - () => connection.resolve({ flags: { ...FLAGS, awsDeviceArn: undefined }, cwd: '/' }), + await assert.rejects( + async () => await connection.resolve(context({ flags: { ...FLAGS, awsDeviceArn: undefined } })), { code: 'INVALID_ARGS', message: 'connect aws-device-farm requires --aws-device-arn or AWS_DEVICE_FARM_DEVICE_ARN.', }, ); - assert.throws( - () => connection.resolve({ flags: { ...FLAGS, providerApp: 'app.ipa' }, cwd: '/' }), + await assert.rejects( + async () => await connection.resolve(context({ flags: { ...FLAGS, providerApp: 'app.ipa' } })), (error: unknown) => error instanceof AppError && JSON.stringify(error.details?.flags) === '["--provider-app"]', ); }); -test('verify hands the saved selectors and the host command runner to the verifier', async () => { - const providerHost = host(); +test('verify hands the saved selectors and a host-command runner to the verifier', async () => { + const calls: string[][] = []; + const providerHost = { + ...host(), + runHostCommand: async (command: string, args: readonly string[]) => { + calls.push([command, ...args]); + return { stdout: '{}' }; + }, + }; const connection = createAwsDeviceFarmConnection(providerHost); await connection.verify({ flags: { ...FLAGS, awsRegion: 'us-west-2' } }); - assert.deepEqual(vi.mocked(verifyAwsDeviceFarmConnection).mock.calls[0], [ - { - platform: 'ios', - projectArn: PROJECT_ARN, - deviceArn: DEVICE_ARN, - appArn: undefined, - region: 'us-west-2', - }, - providerHost.runHostCommand, - ]); + const [options, runHostCommand] = vi.mocked(verifyAwsDeviceFarmConnection).mock.calls[0]!; + assert.deepEqual(options, { + platform: 'ios', + projectArn: PROJECT_ARN, + deviceArn: DEVICE_ARN, + appArn: undefined, + region: 'us-west-2', + }); + // The verifier drives the AWS CLI through the host capability, with the plugin host's own bounds. + await runHostCommand('aws', ['devicefarm', 'get-project', '--arn', PROJECT_ARN]); + assert.deepEqual(calls, [['aws', 'devicefarm', 'get-project', '--arn', PROJECT_ARN]]); await assert.rejects(connection.verify({ flags: { ...FLAGS, platform: undefined } }), { code: 'COMMAND_FAILED', message: 'AWS Device Farm profile missed a mobile platform.', diff --git a/packages/provider-webdriver/src/aws-device-farm-connection.ts b/packages/provider-aws-device-farm/src/connection.ts similarity index 71% rename from packages/provider-webdriver/src/aws-device-farm-connection.ts rename to packages/provider-aws-device-farm/src/connection.ts index cddc5725bd..9b9f181c42 100644 --- a/packages/provider-webdriver/src/aws-device-farm-connection.ts +++ b/packages/provider-aws-device-farm/src/connection.ts @@ -1,35 +1,29 @@ +import type { ProviderPluginHost } from 'agent-device/plugins'; +import type { CliFlags } from '@agent-device/contracts/command'; import { rejectRefusedProviderProfileFields, requireResolvedProfilePlatform, requireResolvedProfileValue, } from '@agent-device/contracts/provider-profile-fields'; +import { requireConnectPlatform } from '@agent-device/provider-webdriver/plugin'; import { - AWS_DEVICE_FARM_PROFILE_FIELDS, readAwsDeviceFarmRegionFromArn, readAwsDeviceFarmSelectorFromEnv, requireAwsDeviceFarmSelector, } from './aws-device-farm.ts'; -import { verifyAwsDeviceFarmConnection } from './connection-verification.ts'; -import type { - CloudWebDriverConnection, - CloudWebDriverConnectionContext, - CloudWebDriverConnectProfileResolution, - CloudWebDriverProviderHost, -} from './provider-plugin.ts'; -import { CLOUD_WEBDRIVER_PROVIDERS } from './providers.ts'; -import { requireConnectPlatform } from './webdriver-utils.ts'; +import { AWS_DEVICE_FARM_PROFILE_FIELDS } from './profile-fields.ts'; +import { verifyAwsDeviceFarmConnection } from './aws-device-farm-connection-verification.ts'; +import { AWS_DEVICE_FARM_PROVIDER } from './providers.ts'; -const PROVIDER = CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm; +const PROVIDER = AWS_DEVICE_FARM_PROVIDER; const SERVICE = 'AWS Device Farm'; const CONSUMER = `connect ${PROVIDER}`; /** The `connect aws-device-farm` callbacks, loaded only when the CLI runs them. */ -export function createAwsDeviceFarmConnection(host: CloudWebDriverProviderHost): { - resolve(context: CloudWebDriverConnectionContext): CloudWebDriverConnectProfileResolution; -} & CloudWebDriverConnection { +export function createAwsDeviceFarmConnection(host: ProviderPluginHost) { const { env } = host; return { - resolve: ({ flags }): CloudWebDriverConnectProfileResolution => { + resolve: ({ flags }: { flags: CliFlags; cwd: string }) => { rejectRefusedProviderProfileFields(flags, AWS_DEVICE_FARM_PROFILE_FIELDS); const platform = requireConnectPlatform(flags, PROVIDER); const awsProjectArn = requireAwsDeviceFarmSelector( @@ -60,7 +54,7 @@ export function createAwsDeviceFarmConnection(host: CloudWebDriverProviderHost): }, }; }, - verify: async ({ flags }) => + verify: async ({ flags }: { flags: CliFlags }) => await verifyAwsDeviceFarmConnection( { platform: requireResolvedProfilePlatform(flags.platform, SERVICE), @@ -75,7 +69,8 @@ export function createAwsDeviceFarmConnection(host: CloudWebDriverProviderHost): appArn: flags.awsAppArn, region: flags.awsRegion, }, - host.runHostCommand, + // The plugin drives `aws devicefarm ...` through the host-command capability. + (command, args) => host.runHostCommand(command, args), ), }; } diff --git a/packages/provider-webdriver/src/aws-device-farm-provider.test.ts b/packages/provider-aws-device-farm/src/index.test.ts similarity index 54% rename from packages/provider-webdriver/src/aws-device-farm-provider.test.ts rename to packages/provider-aws-device-farm/src/index.test.ts index dfefb64486..ccba0b59a0 100644 --- a/packages/provider-webdriver/src/aws-device-farm-provider.test.ts +++ b/packages/provider-aws-device-farm/src/index.test.ts @@ -1,30 +1,52 @@ import assert from 'node:assert/strict'; import { test } from 'vitest'; +import type { ProviderPluginHost } from 'agent-device/plugins'; +import { AppError } from '@agent-device/kernel/errors'; import type { DeviceLease } from '@agent-device/contracts/device'; -import { awsDeviceFarmProvider } from './aws-device-farm-provider.ts'; -import type { CloudWebDriverProviderHost } from './provider-plugin.ts'; +import awsDeviceFarm from './index.ts'; const DEVICE_ARN = 'arn:aws:devicefarm:us-west-2::device:device-a'; -function host(env: Record = {}): CloudWebDriverProviderHost { +function host(env: Record = {}): ProviderPluginHost { return { env, + options: {}, clientVersion: '1.2.3', + createError: (code, message, details) => new AppError(code, message, details), runHostCommand: async () => { throw new Error('this scenario runs no host commands'); }, }; } -test('the declaration reserves the provider id without environment credentials', () => { - assert.equal(awsDeviceFarmProvider.declaration.provider, 'aws-device-farm'); - assert.equal(awsDeviceFarmProvider.declaration.credentialVariables, undefined); - assert.equal(awsDeviceFarmProvider.declaration.connection.requiresAppAttachment, true); +test('the plugin declares its provider, capabilities, and no credential variables', () => { + const plugin = awsDeviceFarm(); + assert.equal(plugin.apiVersion, 2); + assert.equal(plugin.provider, 'aws-device-farm'); + // The AWS CLI credential chain has no environment fingerprint. + assert.deepEqual(plugin.credentials, { variables: [] }); + assert.deepEqual(plugin.connection?.capabilities, { + leaseKind: 'direct-device-provider', + requiresAppAttachment: true, + requiresRemoteDaemon: false, + supportsArtifacts: true, + supportsDeferredAppSelection: false, + supportsDirectPortReverse: false, + usesCloudWebDriverLease: true, + }); +}); + +test('setup builds a WebDriver descriptor for the shared engine', async () => { + const setup = await awsDeviceFarm().setup(host()); + if (!('webDriver' in setup)) throw new Error('AWS Device Farm sets up a WebDriver descriptor'); + assert.equal(setup.webDriver.provider, 'aws-device-farm'); + assert.equal(setup.webDriver.profileFields.provider, 'aws-device-farm'); }); test('lease preparation reads the connect selectors before any host command runs', async () => { - const { webDriver } = awsDeviceFarmProvider.create(host()); - assert.equal(webDriver.profileFields.provider, 'aws-device-farm'); + const setup = await awsDeviceFarm().setup(host()); + if (!('webDriver' in setup)) throw new Error('AWS Device Farm sets up a WebDriver descriptor'); + const { webDriver } = setup; const lease: DeviceLease = { leaseId: 'lease-aws', tenantId: 'team-a', @@ -56,15 +78,16 @@ test('lease preparation reads the connect selectors before any host command runs test('artifact lookup runs in the region of the session ARN, not the environment region', async () => { const commands: string[][] = []; - const { webDriver } = awsDeviceFarmProvider.create({ + const setup = await awsDeviceFarm().setup({ ...host({ AWS_REGION: 'eu-west-1' }), runHostCommand: async (command, args) => { commands.push([command, ...args]); - return { stdout: '{"artifacts":[]}', stderr: '', exitCode: 0 }; + return { stdout: '{"artifacts":[]}' }; }, }); + if (!('webDriver' in setup)) throw new Error('AWS Device Farm sets up a WebDriver descriptor'); - await webDriver.listArtifacts!({ + await setup.webDriver.listArtifacts!({ provider: 'aws-device-farm', providerSessionId: 'arn:aws:devicefarm:us-west-2:123:session:project-a/session-a/00000', }); @@ -77,7 +100,7 @@ test('artifact lookup runs in the region of the session ARN, not the environment }); test('the factory connects through the lazy callbacks', async () => { - const { connection } = awsDeviceFarmProvider.create(host({ AWS_REGION: 'eu-west-1' })); + const connection = awsDeviceFarm().connection!; const { profile } = await connection.resolve({ flags: { json: false, @@ -87,7 +110,10 @@ test('the factory connects through the lazy callbacks', async () => { awsProjectArn: 'arn:aws:devicefarm:us-west-2:123:project:project-a', awsDeviceArn: DEVICE_ARN, }, + stateDir: '/state', cwd: '/', + env: {}, + host: host({ AWS_REGION: 'eu-west-1' }), }); assert.equal(profile.leaseProvider, 'aws-device-farm'); assert.equal(profile.awsRegion, 'eu-west-1'); diff --git a/packages/provider-aws-device-farm/src/index.ts b/packages/provider-aws-device-farm/src/index.ts new file mode 100644 index 0000000000..37f86930c1 --- /dev/null +++ b/packages/provider-aws-device-farm/src/index.ts @@ -0,0 +1,41 @@ +import type { AgentDevicePlugin, ProviderPluginHost } from 'agent-device/plugins'; + +// The connection and WebDriver code load when they are first used, so importing the package for its +// declaration stays small. +async function loadConnection(host: ProviderPluginHost) { + return (await import('./connection.ts')).createAwsDeviceFarmConnection(host); +} + +/** + * AWS Device Farm as a plugin. Credentials come from the AWS CLI credential provider chain, which + * no environment fingerprint identifies, so the plugin declares no credential variables and works + * with any non-interactive AWS CLI credential source the daemon's host has. + */ +function awsDeviceFarm(): AgentDevicePlugin { + return { + apiVersion: 2, + provider: 'aws-device-farm', + // The AWS CLI credential chain has no environment fingerprint. + credentials: { variables: [] }, + connection: { + capabilities: { + leaseKind: 'direct-device-provider', + requiresAppAttachment: true, + requiresRemoteDaemon: false, + supportsArtifacts: true, + supportsDeferredAppSelection: false, + supportsDirectPortReverse: false, + usesCloudWebDriverLease: true, + }, + resolve: async (context) => await (await loadConnection(context.host)).resolve(context), + verify: async (context) => await (await loadConnection(context.host)).verify(context), + }, + setup: async (host) => ({ + webDriver: (await import('./aws-device-farm-webdriver.ts')).createAwsDeviceFarmWebDriver( + host, + ), + }), + }; +} + +export { awsDeviceFarm as default }; diff --git a/packages/provider-aws-device-farm/src/profile-fields.ts b/packages/provider-aws-device-farm/src/profile-fields.ts new file mode 100644 index 0000000000..97ab5a932d --- /dev/null +++ b/packages/provider-aws-device-farm/src/profile-fields.ts @@ -0,0 +1,31 @@ +import type { ProviderProfileFieldDeclaration } from '@agent-device/contracts/provider-profile-fields'; +import { AWS_DEVICE_FARM_PROVIDER } from './providers.ts'; + +export const AWS_DEVICE_FARM_PROFILE_FIELDS: ProviderProfileFieldDeclaration = { + provider: AWS_DEVICE_FARM_PROVIDER, + label: 'AWS Device Farm', + fields: { + providerApp: 'refused', + providerOsVersion: 'refused', + providerDeviceType: 'refused', + providerProject: 'refused', + providerBuild: 'refused', + providerSessionName: 'consumed', + providerDeviceOrientation: 'refused', + providerGeoLocation: 'refused', + providerTimezone: 'refused', + providerAppiumVersion: 'refused', + providerLanguage: 'refused', + providerLocale: 'refused', + providerNetworkProfile: 'refused', + providerCustomNetwork: 'refused', + providerNoResignApp: 'refused', + providerNetworkLogs: 'refused', + providerNetworkHosts: 'refused', + awsProjectArn: 'consumed', + awsDeviceArn: 'consumed', + awsAppArn: 'consumed', + awsRegion: 'consumed', + awsInteractionMode: 'consumed', + }, +}; diff --git a/packages/provider-aws-device-farm/src/providers.ts b/packages/provider-aws-device-farm/src/providers.ts new file mode 100644 index 0000000000..e00e051b71 --- /dev/null +++ b/packages/provider-aws-device-farm/src/providers.ts @@ -0,0 +1,2 @@ +/** The provider id the registry, connection profiles, and `connect aws-device-farm` use. */ +export const AWS_DEVICE_FARM_PROVIDER = 'aws-device-farm'; diff --git a/packages/provider-aws-device-farm/src/run-host-command.ts b/packages/provider-aws-device-farm/src/run-host-command.ts new file mode 100644 index 0000000000..84bc4ddd59 --- /dev/null +++ b/packages/provider-aws-device-farm/src/run-host-command.ts @@ -0,0 +1,8 @@ +/** What a plugin's `host.runHostCommand` answers: the command's standard output. */ +export type HostCommandResult = Readonly<{ stdout: string }>; + +/** The host-command capability a plugin calls; `ProviderPluginHost.runHostCommand` has this shape. */ +export type RunHostCommand = ( + command: string, + args: readonly string[], +) => Promise; diff --git a/packages/provider-aws-device-farm/test/package-smoke.mjs b/packages/provider-aws-device-farm/test/package-smoke.mjs new file mode 100644 index 0000000000..7e9e546748 --- /dev/null +++ b/packages/provider-aws-device-farm/test/package-smoke.mjs @@ -0,0 +1,57 @@ +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; + +export const provider = 'aws-device-farm'; +export const args = [ + '--platform', + 'android', + '--aws-project-arn', + 'arn:aws:devicefarm:us-west-2:123456789012:project/example-project', + '--aws-device-arn', + 'arn:aws:devicefarm:us-west-2::device/example-device', + '--aws-app-arn', + 'arn:aws:devicefarm:us-west-2:123456789012:upload/example-upload', +]; + +const RESOURCES = { + 'get-project': { project: { arn: 'project', name: 'Agent Device' } }, + 'get-device': { + device: { + arn: 'device', + name: 'Google Pixel 8', + platform: 'ANDROID', + os: '14', + availability: 'HIGHLY_AVAILABLE', + }, + }, + 'get-upload': { + upload: { + arn: 'upload', + name: 'sample.apk', + type: 'ANDROID_APP', + status: 'SUCCEEDED', + }, + }, +}; + +// The AWS CLI is the plugin's only external call, so the fixture answers it from PATH. It has no +// credentials of its own to reject, so `connect` must pass on its first try. +export function environment(endpoint) { + void endpoint; + const bin = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-aws-fixture-')); + const script = [ + '#!/usr/bin/env node', + `const resources = ${JSON.stringify(RESOURCES)};`, + 'const subcommand = process.argv[3];', + 'const result = resources[subcommand];', + 'if (!result) {', + ' process.stderr.write(`unexpected aws devicefarm ${subcommand}\\n`);', + ' process.exit(1);', + '}', + 'process.stdout.write(JSON.stringify(result));', + ].join('\n'); + fs.writeFileSync(path.join(bin, 'aws'), script, 'utf8'); + fs.chmodSync(path.join(bin, 'aws'), 0o755); + return { PATH: `${bin}${path.delimiter}${process.env.PATH ?? ''}` }; +} diff --git a/packages/provider-aws-device-farm/tsconfig.json b/packages/provider-aws-device-farm/tsconfig.json new file mode 100644 index 0000000000..81ccf03333 --- /dev/null +++ b/packages/provider-aws-device-farm/tsconfig.json @@ -0,0 +1,28 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "composite": true, + "noEmit": false, + "emitDeclarationOnly": true, + "declaration": true, + "declarationDir": "./dist-types", + "tsBuildInfoFile": "./dist-types/index.tsbuildinfo", + "rootDir": ".", + "paths": { + "agent-device/plugins": ["./node_modules/agent-device/src/sdk/plugins.ts"], + "agent-device/plugins/webdriver": ["./node_modules/agent-device/src/sdk/plugin-webdriver.ts"] + } + }, + "include": ["src"], + "references": [ + { + "path": "../contracts" + }, + { + "path": "../kernel" + }, + { + "path": "../provider-webdriver" + } + ] +} diff --git a/packages/provider-aws-device-farm/tsdown.config.ts b/packages/provider-aws-device-farm/tsdown.config.ts new file mode 100644 index 0000000000..b0e02a7587 --- /dev/null +++ b/packages/provider-aws-device-farm/tsdown.config.ts @@ -0,0 +1,19 @@ +import { defineConfig } from 'tsdown'; + +export default defineConfig({ + entry: { 'agent-device': 'src/index.ts' }, + outDir: 'dist', + format: 'esm', + platform: 'node', + target: 'es2022', + minify: true, + dts: false, + hash: false, + deps: { alwaysBundle: [/^@agent-device\//] }, + inputOptions: { + onLog(level, log, handler) { + if (log.code === 'UNRESOLVED_IMPORT') throw new Error(log.message); + handler(level, log); + }, + }, +}); diff --git a/packages/provider-browserstack/src/browserstack-connection.test.ts b/packages/provider-browserstack/src/browserstack-connection.test.ts index 648ad1efa9..bf255de2de 100644 --- a/packages/provider-browserstack/src/browserstack-connection.test.ts +++ b/packages/provider-browserstack/src/browserstack-connection.test.ts @@ -31,6 +31,9 @@ function host(env: Record = CREDENTIALS): ProviderPl env, options: {}, clientVersion: '1.2.3', + runHostCommand: async () => { + throw new Error('host command unused'); + }, createError: (code, message, details) => new AppError(code, message, details), }; } diff --git a/packages/provider-browserstack/src/index.test.ts b/packages/provider-browserstack/src/index.test.ts index 1a1bf73f9a..5fa3cd3632 100644 --- a/packages/provider-browserstack/src/index.test.ts +++ b/packages/provider-browserstack/src/index.test.ts @@ -21,6 +21,9 @@ function host(env: Record): ProviderPluginHost { env, options: {}, clientVersion: '0.0.0-test', + runHostCommand: async () => { + throw new Error('host command unused'); + }, createError: (code, message, details) => new AppError(code, message, details), }; } diff --git a/packages/provider-testmu/src/index.test.ts b/packages/provider-testmu/src/index.test.ts index 005a4182fb..85a84835e7 100644 --- a/packages/provider-testmu/src/index.test.ts +++ b/packages/provider-testmu/src/index.test.ts @@ -19,6 +19,9 @@ function host(env: Record): ProviderPluginHost { env, options: {}, clientVersion: '0.0.0-test', + runHostCommand: async () => { + throw new Error('host command unused'); + }, createError: (code, message, details) => new AppError(code, message, details), }; } diff --git a/packages/provider-webdriver/package.json b/packages/provider-webdriver/package.json index ddb52520ce..4a8ea93d92 100644 --- a/packages/provider-webdriver/package.json +++ b/packages/provider-webdriver/package.json @@ -3,7 +3,7 @@ "version": "0.0.0", "private": true, "type": "module", - "description": "AWS Device Farm WebDriver provider for agent-device. Internal workspace package bundled into the published artifact.", + "description": "Shared hosted-WebDriver engine for agent-device provider plugins. Internal workspace package bundled into the published artifact.", "dependencies": { "@agent-device/capture-kit": "workspace:*", "@agent-device/contracts": "workspace:*", @@ -24,10 +24,6 @@ "types": "./src/plugin.ts", "default": "./src/plugin.ts" }, - "./connection-verification": { - "types": "./src/connection-verification.ts", - "default": "./src/connection-verification.ts" - }, "./android-snapshot": { "types": "./src/webdriver-android-source.ts", "default": "./src/webdriver-android-source.ts" diff --git a/packages/provider-webdriver/src/aws-device-farm-profile-fields.test.ts b/packages/provider-webdriver/src/aws-device-farm-profile-fields.test.ts deleted file mode 100644 index 45efd819eb..0000000000 --- a/packages/provider-webdriver/src/aws-device-farm-profile-fields.test.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { test } from 'vitest'; -import assert from 'node:assert/strict'; -import { AWS_DEVICE_FARM_PROFILE_FIELDS } from './aws-device-farm.ts'; -import { consumedProfileFields } from './profile-fields.fixtures.ts'; - -test('AWS Device Farm consumes only its own fields and the session name', () => { - assert.deepEqual(consumedProfileFields(AWS_DEVICE_FARM_PROFILE_FIELDS), [ - 'awsAppArn', - 'awsDeviceArn', - 'awsInteractionMode', - 'awsProjectArn', - 'awsRegion', - 'providerSessionName', - ]); -}); diff --git a/packages/provider-webdriver/src/connection-verification.ts b/packages/provider-webdriver/src/connection-verification.ts deleted file mode 100644 index 6e3b5f596d..0000000000 --- a/packages/provider-webdriver/src/connection-verification.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * The read-only provider checks `connect` runs before it saves a profile. Published as one subpath - * so a host can substitute every bundled verifier together, the way a plugin's own - * `connection-verification` subpath is substituted. - */ -export { verifyAwsDeviceFarmConnection } from './aws-device-farm-connection-verification.ts'; diff --git a/packages/provider-webdriver/src/dependencies.ts b/packages/provider-webdriver/src/dependencies.ts deleted file mode 100644 index 95507f93e4..0000000000 --- a/packages/provider-webdriver/src/dependencies.ts +++ /dev/null @@ -1,13 +0,0 @@ -export type HostCommandResult = { - stdout: string; -}; - -export type RunHostCommand = ( - command: string, - args: readonly string[], -) => Promise; - -export type ProviderWebDriverDependencies = { - clientVersion: string; - runHostCommand: RunHostCommand; -}; diff --git a/packages/provider-webdriver/src/index-profile-fields.test.ts b/packages/provider-webdriver/src/index-profile-fields.test.ts deleted file mode 100644 index 636b49850b..0000000000 --- a/packages/provider-webdriver/src/index-profile-fields.test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { test } from 'vitest'; -import assert from 'node:assert/strict'; -import { BUNDLED_CLOUD_WEBDRIVER_PROVIDERS } from './index.ts'; - -test('every bundled runtime reads the profile fields declared under its provider id', () => { - const host = { - env: {}, - clientVersion: 'test', - runHostCommand: async () => { - throw new Error('declarations need no host command'); - }, - }; - for (const bundled of BUNDLED_CLOUD_WEBDRIVER_PROVIDERS) { - const { webDriver } = bundled.create(host); - assert.equal(webDriver.provider, bundled.declaration.provider); - assert.equal(webDriver.profileFields.provider, bundled.declaration.provider); - } -}); diff --git a/packages/provider-webdriver/src/index.ts b/packages/provider-webdriver/src/index.ts index c0e7ea7518..7675e7d481 100644 --- a/packages/provider-webdriver/src/index.ts +++ b/packages/provider-webdriver/src/index.ts @@ -1,24 +1,12 @@ -import { awsDeviceFarmProvider } from './aws-device-farm-provider.ts'; -import type { BundledCloudWebDriverProvider } from './provider-plugin.ts'; - -export type { RunHostCommand } from './dependencies.ts'; -export type { - BundledCloudWebDriverProvider, - CloudWebDriverConnection, - CloudWebDriverProviderHost, -} from './provider-plugin.ts'; +import type { CloudWebDriverRuntimeOptions, CloudWebDriverRuntime } from './runtime.ts'; /** - * The hosted WebDriver providers agent-device ships. Each presents the shape an installed plugin - * returns, so moving one out of the bundle is a packaging change, not a provider rewrite. + * The shared hosted-WebDriver engine. A provider plugin contributes the descriptor it drives + * through `agent-device/plugins/webdriver`; this package keeps the engine and its helpers. */ -export const BUNDLED_CLOUD_WEBDRIVER_PROVIDERS: readonly BundledCloudWebDriverProvider[] = - Object.freeze([awsDeviceFarmProvider]); - -export function bundledCloudWebDriverProvider( - provider: string | undefined, -): BundledCloudWebDriverProvider | undefined { - return BUNDLED_CLOUD_WEBDRIVER_PROVIDERS.find( - (bundled) => bundled.declaration.provider === provider, - ); +export async function createCloudWebDriverRuntime( + options: CloudWebDriverRuntimeOptions, +): Promise { + const runtime = await import('./runtime.ts'); + return runtime.createCloudWebDriverRuntime(options); } diff --git a/packages/provider-webdriver/src/plugin.ts b/packages/provider-webdriver/src/plugin.ts index 2f0fc5996e..4afc6a703a 100644 --- a/packages/provider-webdriver/src/plugin.ts +++ b/packages/provider-webdriver/src/plugin.ts @@ -10,8 +10,12 @@ export type { CloudWebDriverRuntimeOptions, CloudWebDriverPlatform, CloudWebDriverUploadApp, + CloudWebDriverPrepareSession, } from './runtime.ts'; -export type { CloudWebDriverProviderOptions } from './provider-plugin.ts'; + +/** The engine options a provider contributes; the host supplies `clientVersion`. */ +export type CloudWebDriverProviderOptions = Omit; + export type { CloudWebDriverCapabilityOverrides } from './capabilities.ts'; export { appFileUploadForm, @@ -28,6 +32,7 @@ export { requireProviderDeviceOrientation, requireRequest, requireRequestPlatform, + releaseOnFailure, resolveHubAppReference, resolveLocalAppArtifact, } from './webdriver-utils.ts'; diff --git a/packages/provider-webdriver/src/provider-plugin.ts b/packages/provider-webdriver/src/provider-plugin.ts deleted file mode 100644 index 7f31d2fab5..0000000000 --- a/packages/provider-webdriver/src/provider-plugin.ts +++ /dev/null @@ -1,69 +0,0 @@ -import type { CliFlags } from '@agent-device/contracts/command'; -import type { - CloudProviderProfileFields, - ProviderConnectionVerification, -} from '@agent-device/contracts/remote'; -import type { LeaseBackend } from '@agent-device/kernel/contracts'; -import type { ProviderWebDriverDependencies } from './dependencies.ts'; -import type { CloudWebDriverProviderDeclaration } from './providers.ts'; -import type { CloudWebDriverPlatform, CloudWebDriverRuntimeOptions } from './runtime.ts'; - -/** - * What a hosted WebDriver provider receives from the process that composes it. A bundled provider - * and an installed plugin see the same shape: the environment, the client version the shared - * engine stamps on provider requests, and a host-command runner for providers that drive a CLI. - */ -export type CloudWebDriverProviderHost = ProviderWebDriverDependencies & - Readonly<{ - env: Readonly>; - }>; - -/** The engine options a provider contributes; the host supplies `clientVersion`. */ -export type CloudWebDriverProviderOptions = Omit; - -/** - * The profile fields a provider contributes to a generated connection profile. The composing - * process adds connection identity, session defaults, and Metro settings, then persists it. - */ -export type CloudWebDriverConnectProfile = CloudProviderProfileFields & - Readonly<{ - leaseProvider: string; - leaseBackend?: LeaseBackend; - platform: CloudWebDriverPlatform; - device?: string; - }>; - -export type CloudWebDriverConnectionContext = Readonly<{ - flags: CliFlags; - cwd: string; -}>; - -export type CloudWebDriverConnectProfileResolution = { - profile: CloudWebDriverConnectProfile; - extraFlags?: Partial; -}; - -/** - * The `connect ` callbacks: validate flags into a profile, then verify it read-only. - * A bundled provider answers `resolve` asynchronously because it loads connect code on first use; - * a daemon composing the runtime never evaluates it. - */ -export type CloudWebDriverConnection = Readonly<{ - resolve( - context: CloudWebDriverConnectionContext, - ): Promise | CloudWebDriverConnectProfileResolution; - verify( - context: Pick, - ): Promise; -}>; - -export type CloudWebDriverProviderRegistration = Readonly<{ - webDriver: CloudWebDriverProviderOptions; - connection: CloudWebDriverConnection; -}>; - -/** A provider shipped inside agent-device: its manifest-shaped declaration plus its factory. */ -export type BundledCloudWebDriverProvider = Readonly<{ - declaration: CloudWebDriverProviderDeclaration; - create(host: CloudWebDriverProviderHost): CloudWebDriverProviderRegistration; -}>; diff --git a/packages/provider-webdriver/src/providers.ts b/packages/provider-webdriver/src/providers.ts index d7495d657b..b2af2bfb41 100644 --- a/packages/provider-webdriver/src/providers.ts +++ b/packages/provider-webdriver/src/providers.ts @@ -1,23 +1,6 @@ import type { ConnectionProviderCapabilities } from '@agent-device/contracts/remote'; -export const CLOUD_WEBDRIVER_PROVIDERS = { - awsDeviceFarm: 'aws-device-farm', -} as const; - -export type CloudWebDriverKnownProviderName = - (typeof CLOUD_WEBDRIVER_PROVIDERS)[keyof typeof CLOUD_WEBDRIVER_PROVIDERS]; - -/** - * What a bundled provider declares before any of its code runs: the same fields an installed - * plugin returns from its factory. Connect policy and the credential fingerprint read this, never - * the provider implementation. - */ -export type CloudWebDriverProviderDeclaration = Readonly<{ - provider: CloudWebDriverKnownProviderName; - connection: ConnectionProviderCapabilities; - /** Absent for a provider whose credentials do not come from the environment. */ - credentialVariables?: readonly string[]; -}>; +export const CLOUD_WEBDRIVER_PROVIDERS = { awsDeviceFarm: 'aws-device-farm' } as const; export const HOSTED_WEBDRIVER_CONNECTION: ConnectionProviderCapabilities = { leaseKind: 'direct-device-provider', @@ -29,23 +12,6 @@ export const HOSTED_WEBDRIVER_CONNECTION: ConnectionProviderCapabilities = { usesCloudWebDriverLease: true, }; -export const CLOUD_WEBDRIVER_PROVIDER_DECLARATIONS: readonly CloudWebDriverProviderDeclaration[] = - Object.freeze([ - { - // AWS Device Farm reads the AWS CLI credential chain, which no environment hash identifies. - provider: CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm, - connection: { ...HOSTED_WEBDRIVER_CONNECTION, requiresAppAttachment: true }, - }, - ]); - -export function cloudWebDriverProviderDeclaration( - provider: string | undefined, -): CloudWebDriverProviderDeclaration | undefined { - return CLOUD_WEBDRIVER_PROVIDER_DECLARATIONS.find( - (declaration) => declaration.provider === provider, - ); -} - /** * URI schemes are case-insensitive, but hosted hubs only match the lower-case spelling, so * `BS://id` is returned as `bs://id`. Anything without the lower-case `scheme` returns undefined. diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3345ab97d6..11fc53fe88 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,6 +29,9 @@ importers: '@agent-device/apple-runner': specifier: workspace:* version: link:packages/apple-runner + '@agent-device/aws-device-farm': + specifier: workspace:* + version: link:packages/provider-aws-device-farm '@agent-device/browserstack': specifier: workspace:* version: link:packages/provider-browserstack @@ -873,6 +876,21 @@ importers: specifier: workspace:* version: link:../test-kit + packages/provider-aws-device-farm: + devDependencies: + '@agent-device/contracts': + specifier: workspace:* + version: link:../contracts + '@agent-device/kernel': + specifier: workspace:* + version: link:../kernel + '@agent-device/provider-webdriver': + specifier: workspace:* + version: link:../provider-webdriver + agent-device: + specifier: workspace:* + version: link:../.. + packages/provider-browserstack: devDependencies: '@agent-device/build-config': diff --git a/scripts/capability-matrix/collect.ts b/scripts/capability-matrix/collect.ts index dd96fab271..ecac3d78c5 100644 --- a/scripts/capability-matrix/collect.ts +++ b/scripts/capability-matrix/collect.ts @@ -16,12 +16,11 @@ import { runtimeModule as webRuntimeModule } from '@agent-device/platform-web'; import { runtimeModule as vegaRuntimeModule } from '@agent-device/platform-vega'; import { runtimeModule as harmonyosRuntimeModule } from '@agent-device/platform-harmonyos'; import { runtimeModule as linuxRuntimeModule } from '@agent-device/platform-linux'; -import { BUNDLED_CLOUD_WEBDRIVER_PROVIDERS } from '@agent-device/provider-webdriver'; import { createCloudWebDriverRuntime } from '@agent-device/provider-webdriver/plugin'; -import { CLOUD_WEBDRIVER_PROVIDERS } from '@agent-device/provider-webdriver/providers'; -import type { RunHostCommand } from '@agent-device/provider-webdriver'; +import { createPluginHost, type RunHostCommand } from '@agent-device/plugins/host'; import testmuPlugin from '@agent-device/testmu'; import browserstackPlugin from '@agent-device/browserstack'; +import awsDeviceFarmPlugin from '@agent-device/aws-device-farm'; import revylPlugin from '@agent-device/revyl'; import type { DeviceLease, ProviderDeviceRuntime } from '@agent-device/contracts/device'; import type { @@ -113,49 +112,32 @@ async function loadLocalRuntimes(host: PlatformRuntimeHost): Promise> = { - [CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm]: 'aws-device-farm', -}; - /** The plugin packages whose factory setup() builds the WebDriver the matrix asks for. */ const CLOUD_WEBDRIVER_PLUGINS: Readonly> = { testmu: testmuPlugin, browserstack: browserstackPlugin, + 'aws-device-farm': awsDeviceFarmPlugin, }; -/** The provider's WebDriver options, from the bundled registration or the plugin package. */ +/** The provider's WebDriver options, from the plugin package the target names. */ async function cloudWebDriverOptions( plugin: string, runHostCommand: RunHostCommand, ): Promise> { const factory = CLOUD_WEBDRIVER_PLUGINS[plugin]; - if (factory) { - // The package's default export is the plugin factory; the WebDriver is what its setup() builds. - const plugin_ = factory(); - if (!plugin_.setup) - throw new Error(`The ${plugin} plugin exposes no setup() to build a WebDriver from.`); - const created = (await plugin_.setup({ - env: PROVIDER_ENV, - clientVersion: '0.0.0', - } as never)) as { - webDriver: Record; - }; - return created.webDriver; - } - const providerName = CLOUD_WEBDRIVER_PLUGIN_PROVIDERS[plugin]; - if (!providerName) throw new Error(`Unknown cloud WebDriver plugin "${plugin}".`); - const registration = BUNDLED_CLOUD_WEBDRIVER_PROVIDERS.find( - (candidate) => candidate.declaration.provider === providerName, - ); - if (!registration) { - throw new Error(`No bundled cloud WebDriver registration for plugin "${plugin}".`); - } - const created = await registration.create({ - env: PROVIDER_ENV, + if (!factory) throw new Error(`Unknown cloud WebDriver plugin "${plugin}".`); + // The package's default export is the plugin factory; the WebDriver is what its setup() builds. + const plugin_ = factory(); + if (!plugin_.setup) + throw new Error(`The ${plugin} plugin exposes no setup() to build a WebDriver from.`); + const created = (await plugin_.setup({ + ...createPluginHost(PROVIDER_ENV, undefined), clientVersion: '0.0.0', runHostCommand, - } as never); - return created.webDriver as unknown as Record; + })) as { + webDriver: Record; + }; + return created.webDriver; } function cloudLease(target: Target & { readonly kind: 'cloud-webdriver' }): DeviceLease { diff --git a/scripts/capability-matrix/seams.ts b/scripts/capability-matrix/seams.ts index 156c436642..4a10951e34 100644 --- a/scripts/capability-matrix/seams.ts +++ b/scripts/capability-matrix/seams.ts @@ -8,7 +8,7 @@ import moduleHooks from 'node:module'; import { createAgentBrowserWebProvider, withWebProvider } from '@agent-device/platform-web'; import { createWebInteractor } from '@agent-device/platform-web/interactor'; -import type { RunHostCommand } from '@agent-device/provider-webdriver'; +import type { RunHostCommand } from '@agent-device/plugins/host'; import type { PlatformRuntimeHost } from '@agent-device/contracts/platform-runtime-operations'; import type { HostEnvironment } from '@agent-device/kernel/source-value'; import { resolveWebNetworkTransport } from '../../src/platform-runtime-network-web-transport.ts'; diff --git a/scripts/layering/architecture-ownership.ts b/scripts/layering/architecture-ownership.ts index c6a6830c96..7c0850a3d5 100644 --- a/scripts/layering/architecture-ownership.ts +++ b/scripts/layering/architecture-ownership.ts @@ -308,6 +308,7 @@ export const ARCHITECTURE_OWNERSHIP = { 'packages/platform-linux/', 'packages/platform-vega/', 'packages/platform-web/', + 'packages/provider-aws-device-farm/', 'packages/provider-browserstack/', 'packages/provider-limrun/', 'packages/provider-revyl/', diff --git a/scripts/layering/model.ts b/scripts/layering/model.ts index e42621b29a..512dafc880 100644 --- a/scripts/layering/model.ts +++ b/scripts/layering/model.ts @@ -120,6 +120,7 @@ export const UNRANKED_ZONES: ReadonlySet = new Set([ 'apple-runner', ...PLATFORMS.map((family) => `platform-${family}`), 'provider-webdriver', + 'provider-aws-device-farm', 'provider-browserstack', 'provider-limrun', 'provider-revyl', diff --git a/scripts/layering/package-boundaries.test.ts b/scripts/layering/package-boundaries.test.ts index 3847da749f..ea0563d8a3 100644 --- a/scripts/layering/package-boundaries.test.ts +++ b/scripts/layering/package-boundaries.test.ts @@ -806,7 +806,6 @@ test('the real tree parses, declares, and passes R11', () => { assert.deepEqual([...providerWebDriverPackage.exportTargets.keys()].sort(), [ '@agent-device/provider-webdriver', '@agent-device/provider-webdriver/android-snapshot', - '@agent-device/provider-webdriver/connection-verification', '@agent-device/provider-webdriver/plugin', '@agent-device/provider-webdriver/providers', ]); diff --git a/scripts/layering/root-module-zones.ts b/scripts/layering/root-module-zones.ts index fe4a230613..19fb419d70 100644 --- a/scripts/layering/root-module-zones.ts +++ b/scripts/layering/root-module-zones.ts @@ -53,7 +53,6 @@ export const ROOT_MODULE_ZONES: Readonly> = { 'src/provider-device-runtimes.ts', 'src/provider-limrun-credentials.ts', 'src/provider-plugin-policy.ts', - 'src/provider-webdriver.ts', ], // The operation host the platform runtime loads through `import()` (`loadHost`) and its facets. // It ranks above every spine zone, so a static import of it is a back-edge from anywhere but diff --git a/src/__tests__/cloud-connect-aws-device-farm.test.ts b/src/__tests__/cloud-connect-aws-device-farm.test.ts new file mode 100644 index 0000000000..930de30423 --- /dev/null +++ b/src/__tests__/cloud-connect-aws-device-farm.test.ts @@ -0,0 +1,251 @@ +import { afterEach, beforeEach, test, vi } from 'vitest'; +import assert from 'node:assert/strict'; +import fs from 'node:fs'; +import path from 'node:path'; +import { runCliCapture } from './cli-capture.ts'; +import { + readActiveConnectionState, + type RemoteConnectionState, +} from '@agent-device/remote/remote-connection-state'; +import { AppError } from '@agent-device/kernel/errors'; +import { verifyAwsDeviceFarmConnection } from '@agent-device/aws-device-farm/connection-verification'; +import awsDeviceFarm from '@agent-device/aws-device-farm'; +import { resolveProviderPlugins } from '@agent-device/plugins/registry'; +import { resolveConnectProviderProfile } from '../cli/connection/connect-provider-adapters.ts'; +import { + mkdtempForTestSync, + pluginHome, + selectV2Plugin, + v2RegistrationSource, + bindTestCommandHost, +} from '@agent-device/test-kit'; +import manifest from '@agent-device/aws-device-farm/package.json' with { type: 'json' }; +import type { PluginConnectionCallbacks } from '@agent-device/plugins/connection'; +import { connectWithGeneratedProviderProfile } from './test-utils/connect-command.ts'; + +bindTestCommandHost(); + +vi.mock('@agent-device/aws-device-farm/connection-verification', () => ({ + verifyAwsDeviceFarmConnection: vi.fn(), +})); +vi.mock('@agent-device/plugins/load', () => ({ + withPluginConnection: async ( + _provider: string, + _builtinProviders: readonly string[], + _env: NodeJS.ProcessEnv, + runConnection: (connection: PluginConnectionCallbacks) => Promise, + ) => { + const { connections } = await resolveProviderPlugins([ + { source: 'store', package: manifest.name, load: () => awsDeviceFarm() }, + ]); + return await runConnection(connections.get('aws-device-farm')!); + }, +})); + +afterEach(() => { + vi.clearAllMocks(); + vi.unstubAllEnvs(); +}); + +const mockedVerifyAwsDeviceFarmConnection = vi.mocked(verifyAwsDeviceFarmConnection); + +let pluginHomeDir = ''; + +beforeEach(() => { + const { home } = pluginHome(); + pluginHomeDir = home; + // The store declares the plugin installed with AWS Device Farm's capabilities; the mocked loader + // above supplies the workspace factory those assertions exercise. + selectV2Plugin( + home, + manifest.name, + v2RegistrationSource('aws-device-farm', { + extra: `connection: { capabilities: ${JSON.stringify(awsDeviceFarm().connection?.capabilities)}, resolve() {}, verify() {} },`, + }), + ); + vi.stubEnv('AGENT_DEVICE_HOME', home); + mockedVerifyAwsDeviceFarmConnection.mockImplementation(async (options) => ({ + provider: 'aws-device-farm', + service: 'AWS Device Farm', + verificationMessage: 'Credentials, project, and device verified.', + project: { name: 'Agent Device', reference: options.projectArn }, + device: { + status: 'verified', + name: 'iPhone 15', + reference: options.deviceArn, + platform: options.platform, + osVersion: '17', + }, + app: { + status: 'missing', + message: + 'No app upload is attached; AWS Device Farm does not support install after allocation.', + }, + })); +}); + +test('connect aws-device-farm generates local provider profile from flags', async () => { + const tempRoot = mkdtempForTestSync('agent-device-connect-aws-'); + const stateDir = path.join(tempRoot, '.state'); + + try { + await connectWithGeneratedProviderProfile({ + stateDir, + positionals: ['aws-device-farm'], + flags: { + platform: 'ios', + device: 'Apple iPhone 15', + awsProjectArn: 'arn:aws:devicefarm:us-west-2:123:project:project-a', + awsDeviceArn: 'arn:aws:devicefarm:us-west-2::device:device-a', + awsAppArn: 'arn:aws:devicefarm:us-west-2:123:upload:app-a', + awsInteractionMode: 'INTERACTIVE', + }, + }); + + const state = readRequiredActiveState(stateDir); + assert.equal(state.tenant, 'aws-device-farm'); + assert.equal(state.leaseProvider, 'aws-device-farm'); + assert.equal(state.daemon?.baseUrl, undefined); + assert.match(state.remoteConfigPath, /generated\/aws-device-farm-[a-f0-9]{16}\.json$/); + const generated = readGeneratedConfig(state.remoteConfigPath); + assert.equal(generated.awsProjectArn, 'arn:aws:devicefarm:us-west-2:123:project:project-a'); + assert.equal(generated.awsDeviceArn, 'arn:aws:devicefarm:us-west-2::device:device-a'); + assert.equal(generated.awsAppArn, 'arn:aws:devicefarm:us-west-2:123:upload:app-a'); + assert.equal(generated.awsRegion, 'us-west-2'); + assert.equal(generated.awsInteractionMode, 'INTERACTIVE'); + // The plugin verifies through the host command, and the profile carries the region its ARN names. + assert.equal(mockedVerifyAwsDeviceFarmConnection.mock.calls[0]?.[0].region, 'us-west-2'); + } finally { + fs.rmSync(tempRoot, { recursive: true, force: true }); + } +}); + +test('connect aws-device-farm JSON exposes verification, device, app, live-session, and next-step state', async () => { + const result = await runCliCapture( + [ + 'connect', + 'aws-device-farm', + '--session=ci', + '--platform', + 'ios', + '--aws-project-arn', + 'project-arn', + '--aws-device-arn', + 'device-arn', + '--json', + ], + { + env: { AGENT_DEVICE_HOME: pluginHomeDir }, + stateDirPrefix: 'agent-device-connect-aws-output-', + }, + ); + + assert.equal(result.code, null); + const output = (JSON.parse(result.stdout) as { data: Record }).data; + assert.equal(output.verification.status, 'verified'); + assert.equal(output.device.name, 'iPhone 15'); + assert.equal(output.app.status, 'missing'); + assert.equal(output.liveSession.status, 'not-created'); + assert.deepEqual(output.nextSteps, [ + `agent-device connect aws-device-farm --platform ios --aws-project-arn project-arn --aws-device-arn device-arn --aws-app-arn --force --session ${output.session}`, + `agent-device open --relaunch --session ${output.session}`, + ]); + assert.deepEqual(output.leasePreparation.nextSteps, output.nextSteps); + assert.deepEqual(output.notes, [ + `After close, run agent-device artifacts --json --session ${output.session} for provider video and logs.`, + ]); +}); + +test('connect aws-device-farm rejects device-feature flags it does not read', async () => { + const tempRoot = mkdtempForTestSync('agent-device-connect-aws-reject-'); + + try { + await assert.rejects( + resolveConnectProviderProfile({ + provider: 'aws-device-farm', + stateDir: path.join(tempRoot, '.state'), + cwd: tempRoot, + env: {}, + flags: { + json: false, + help: false, + version: false, + platform: 'android', + device: 'Google Pixel 8', + providerDeviceOrientation: 'portrait', + providerTimezone: 'New_York', + }, + }), + (error: unknown) => { + assert.ok(error instanceof AppError); + assert.equal(error.code, 'INVALID_ARGS'); + // Names every offending flag, and fires before the provider's own required-arg checks so + // the caller is told what is unsupported rather than what else is missing. + assert.equal(error.details?.provider, 'aws-device-farm'); + assert.deepEqual(error.details?.flags, [ + '--provider-device-orientation', + '--provider-timezone', + ]); + return true; + }, + ); + } finally { + fs.rmSync(tempRoot, { recursive: true, force: true }); + } +}); + +test('connect aws-device-farm refuses --provider-device-type before saving a profile', async () => { + const tempRoot = mkdtempForTestSync('agent-device-connect-aws-device-type-'); + + try { + await assert.rejects( + resolveConnectProviderProfile({ + provider: 'aws-device-farm', + stateDir: path.join(tempRoot, '.state'), + cwd: tempRoot, + env: {}, + flags: { + json: false, + help: false, + version: false, + platform: 'android', + awsProjectArn: 'arn:aws:devicefarm:us-west-2:123:project/p', + awsDeviceArn: 'arn:aws:devicefarm:us-west-2::device/d', + providerDeviceType: 'real', + }, + }), + (error: unknown) => { + assert.ok(error instanceof AppError); + assert.equal(error.code, 'INVALID_ARGS'); + assert.match(error.message, /^--provider-device-type is not supported by /); + assert.equal(error.details?.provider, 'aws-device-farm'); + return true; + }, + ); + assert.equal(fs.existsSync(path.join(tempRoot, '.state')), false); + } finally { + fs.rmSync(tempRoot, { recursive: true, force: true }); + } +}); + +function readGeneratedConfig(configPath: string): { + awsProjectArn?: string; + awsDeviceArn?: string; + awsAppArn?: string; + awsRegion?: string; + awsInteractionMode?: string; +} { + return JSON.parse(fs.readFileSync(configPath, 'utf8')) as { + awsProjectArn?: string; + awsDeviceArn?: string; + awsAppArn?: string; + awsRegion?: string; + awsInteractionMode?: string; + }; +} + +function readRequiredActiveState(stateDir: string): RemoteConnectionState { + const state = readActiveConnectionState({ stateDir }); + assert.ok(state); + return state; +} diff --git a/src/__tests__/cloud-connect-profile.test.ts b/src/__tests__/cloud-connect-profile.test.ts index ea47e76f8f..381416e1f0 100644 --- a/src/__tests__/cloud-connect-profile.test.ts +++ b/src/__tests__/cloud-connect-profile.test.ts @@ -11,17 +11,14 @@ import { type RemoteConnectionState, } from '@agent-device/remote/remote-connection-state'; import type { AgentDeviceClient } from '@agent-device/command-surface'; -import { resolveConnectProviderProfile } from '../cli/connection/connect-provider-adapters.ts'; import { AppError, normalizeError } from '@agent-device/kernel/errors'; import { verifyLimrunConnection } from '@agent-device/provider-limrun'; -import { verifyAwsDeviceFarmConnection } from '@agent-device/provider-webdriver/connection-verification'; import { mkdtempForTestSync, bindTestCommandHost, createTestHostEnvironment, beginStdoutCapture, } from '@agent-device/test-kit'; -import { connectWithGeneratedProviderProfile } from './test-utils/connect-command.ts'; bindTestCommandHost(); @@ -35,13 +32,6 @@ vi.mock('@agent-device/provider-limrun', async (importOriginal) => ({ verifyLimrunConnection: vi.fn(), })); -vi.mock('@agent-device/provider-webdriver/connection-verification', async (importOriginal) => ({ - ...(await importOriginal< - typeof import('@agent-device/provider-webdriver/connection-verification') - >()), - verifyAwsDeviceFarmConnection: vi.fn(), -})); - afterEach(() => { vi.clearAllMocks(); vi.unstubAllGlobals(); @@ -49,7 +39,6 @@ afterEach(() => { const mockedResolveCloudAccessForConnect = vi.mocked(resolveCloudAccessForConnect); const mockedVerifyLimrunConnection = vi.mocked(verifyLimrunConnection); -const mockedVerifyAwsDeviceFarmConnection = vi.mocked(verifyAwsDeviceFarmConnection); beforeEach(() => { mockedVerifyLimrunConnection.mockResolvedValue({ @@ -66,24 +55,6 @@ beforeEach(() => { message: 'Run apps to choose an uploaded asset before allocation.', }, }); - mockedVerifyAwsDeviceFarmConnection.mockImplementation(async (options) => ({ - provider: 'aws-device-farm', - service: 'AWS Device Farm', - verificationMessage: 'Credentials, project, and device verified.', - project: { name: 'Agent Device', reference: options.projectArn }, - device: { - status: 'verified', - name: 'iPhone 15', - reference: options.deviceArn, - platform: options.platform, - osVersion: '17', - }, - app: { - status: 'missing', - message: - 'No app upload is attached; AWS Device Farm does not support install after allocation.', - }, - })); }); test('connect without remote config generates one from cloud connection profile', async () => { @@ -405,40 +376,6 @@ test('connect without remote config reports unsupported cloud profile keys', asy } }); -test('connect aws-device-farm generates local provider profile from flags', async () => { - const tempRoot = mkdtempForTestSync('agent-device-connect-aws-'); - const stateDir = path.join(tempRoot, '.state'); - - try { - await connectWithGeneratedProviderProfile({ - stateDir, - positionals: ['aws-device-farm'], - flags: { - platform: 'ios', - device: 'Apple iPhone 15', - awsProjectArn: 'arn:aws:devicefarm:us-west-2:123:project:project-a', - awsDeviceArn: 'arn:aws:devicefarm:us-west-2::device:device-a', - awsAppArn: 'arn:aws:devicefarm:us-west-2:123:upload:app-a', - awsInteractionMode: 'INTERACTIVE', - }, - }); - - const state = readRequiredActiveState(stateDir); - assert.equal(state.tenant, 'aws-device-farm'); - assert.equal(state.leaseProvider, 'aws-device-farm'); - assert.equal(state.daemon?.baseUrl, undefined); - assert.match(state.remoteConfigPath, /generated\/aws-device-farm-[a-f0-9]{16}\.json$/); - const generated = readGeneratedConfig(state.remoteConfigPath); - assert.equal(generated.awsProjectArn, 'arn:aws:devicefarm:us-west-2:123:project:project-a'); - assert.equal(generated.awsDeviceArn, 'arn:aws:devicefarm:us-west-2::device:device-a'); - assert.equal(generated.awsAppArn, 'arn:aws:devicefarm:us-west-2:123:upload:app-a'); - assert.equal(generated.awsRegion, 'us-west-2'); - assert.equal(generated.awsInteractionMode, 'INTERACTIVE'); - } finally { - fs.rmSync(tempRoot, { recursive: true, force: true }); - } -}); - test('connect output makes verified configuration, deferred device allocation, and app recovery explicit', async () => { const environment = { LIMRUN_API_KEY: 'lim_test_key', AGENT_DEVICE_SESSION: 'ci' }; const result = await runCliCapture(['connect', 'limrun', '--platform', 'android'], { @@ -465,39 +402,6 @@ test('connect output makes verified configuration, deferred device allocation, a assert.doesNotMatch(result.stdout, /lease pending/); }); -test('connect JSON exposes verification, device, app, live-session, and next-step state', async () => { - const result = await runCliCapture( - [ - 'connect', - 'aws-device-farm', - '--session=ci', - '--platform', - 'ios', - '--aws-project-arn', - 'project-arn', - '--aws-device-arn', - 'device-arn', - '--json', - ], - { stateDirPrefix: 'agent-device-connect-aws-output-' }, - ); - - assert.equal(result.code, null); - const output = (JSON.parse(result.stdout) as { data: Record }).data; - assert.equal(output.verification.status, 'verified'); - assert.equal(output.device.name, 'iPhone 15'); - assert.equal(output.app.status, 'missing'); - assert.equal(output.liveSession.status, 'not-created'); - assert.deepEqual(output.nextSteps, [ - `agent-device connect aws-device-farm --platform ios --aws-project-arn project-arn --aws-device-arn device-arn --aws-app-arn --force --session ${output.session}`, - `agent-device open --relaunch --session ${output.session}`, - ]); - assert.deepEqual(output.leasePreparation.nextSteps, output.nextSteps); - assert.deepEqual(output.notes, [ - `After close, run agent-device artifacts --json --session ${output.session} for provider video and logs.`, - ]); -}); - test('connect does not activate provider state when verification fails', async () => { const tempRoot = mkdtempForTestSync('agent-device-connect-verify-fail-'); const stateDir = path.join(tempRoot, '.state'); @@ -531,44 +435,6 @@ test('connect does not activate provider state when verification fails', async ( } }); -test('connect aws-device-farm rejects device-feature flags it does not read', async () => { - const tempRoot = mkdtempForTestSync('agent-device-connect-aws-reject-'); - - try { - await assert.rejects( - resolveConnectProviderProfile({ - provider: 'aws-device-farm', - stateDir: path.join(tempRoot, '.state'), - cwd: tempRoot, - env: {}, - flags: { - json: false, - help: false, - version: false, - platform: 'android', - device: 'Google Pixel 8', - providerDeviceOrientation: 'portrait', - providerTimezone: 'New_York', - }, - }), - (error: unknown) => { - assert.ok(error instanceof AppError); - assert.equal(error.code, 'INVALID_ARGS'); - // Names every offending flag, and fires before the provider's own required-arg checks so - // the caller is told what is unsupported rather than what else is missing. - assert.equal(error.details?.provider, 'aws-device-farm'); - assert.deepEqual(error.details?.flags, [ - '--provider-device-orientation', - '--provider-timezone', - ]); - return true; - }, - ); - } finally { - fs.rmSync(tempRoot, { recursive: true, force: true }); - } -}); - function mockCloudConnectionProfile(connection: Record): ReturnType { mockedResolveCloudAccessForConnect.mockResolvedValue({ accessToken: 'adc_agent_cloud', diff --git a/src/__tests__/cloud-connect-testmu.test.ts b/src/__tests__/cloud-connect-testmu.test.ts index 3ce111086a..f5c8ec96e9 100644 --- a/src/__tests__/cloud-connect-testmu.test.ts +++ b/src/__tests__/cloud-connect-testmu.test.ts @@ -279,15 +279,7 @@ test('providers other than TestMu refuse --provider-device-type before saving a try { for (const [provider, flags, env] of [ - [ - 'aws-device-farm', - { - ...base, - awsProjectArn: 'arn:aws:devicefarm:us-west-2:123:project/p', - awsDeviceArn: 'arn:aws:devicefarm:us-west-2::device/d', - }, - {}, - ], + ['limrun', { ...base, tenant: 'team-a', runId: 'run-a' }, { LIMRUN_API_KEY: 'lim_test_key' }], ] as const) { await assert.rejects( resolveConnectProviderProfile({ diff --git a/src/__tests__/provider-device-runtimes.test.ts b/src/__tests__/provider-device-runtimes.test.ts index 0fee880b70..58c4183215 100644 --- a/src/__tests__/provider-device-runtimes.test.ts +++ b/src/__tests__/provider-device-runtimes.test.ts @@ -31,14 +31,11 @@ test('built-in providers register ahead of the store and an unconfigured Limrun assert.deepEqual( composition.runtimes.map((runtime) => runtime.provider), - ['aws-device-farm', 'example'], + ['example'], ); assert.deepEqual( composition.inventory.map(({ provider, source, state }) => [provider, source, state]), - [ - ['aws-device-farm', 'builtin', 'active'], - ['example', 'store', 'active'], - ], + [['example', 'store', 'active']], ); await composition.shutdown(); }); @@ -58,7 +55,7 @@ test('daemon composition records Limrun as failed for a partial instance set and assert.deepEqual( composition.runtimes.map((runtime) => runtime.provider), - ['aws-device-farm', 'example'], + ['example'], ); const limrun = composition.inventory.find(({ provider }) => provider === 'limrun'); assert.equal(limrun?.state, 'failed'); @@ -68,7 +65,7 @@ test('daemon composition records Limrun as failed for a partial instance set and }); test('a plugin claiming a built-in provider ID is recorded as failed and the built-in keeps the ID', async () => { - for (const provider of ['limrun', 'aws-device-farm']) { + for (const provider of ['limrun']) { const { home, env } = pluginHome(); selectV2Plugin(home, 'example', v2RegistrationSource(provider)); const composition = await createDaemonProviderRuntimeComposition({ @@ -79,10 +76,7 @@ test('a plugin claiming a built-in provider ID is recorded as failed and the bui assert.equal(plugin?.state, 'failed'); assert.equal(plugin?.error?.reason, 'duplicate_provider'); // An unconfigured Limrun claims its id without registering a runtime. - assert.equal( - composition.runtimes.filter((runtime) => runtime.provider === provider).length, - provider === 'limrun' ? 0 : 1, - ); + assert.equal(composition.runtimes.filter((runtime) => runtime.provider === provider).length, 0); await composition.shutdown(); } }); @@ -104,6 +98,23 @@ test('BrowserStack registers as an ordinary store plugin, not a built-in', async await composition.shutdown(); }); +test('AWS Device Farm registers as an ordinary store plugin, not a built-in', async () => { + const { home, env } = pluginHome(); + selectV2Plugin(home, '@agent-device/aws-device-farm', v2RegistrationSource('aws-device-farm')); + const composition = await createDaemonProviderRuntimeComposition({ + env: env, + cwd: process.cwd(), + }); + + assert.deepEqual( + composition.inventory + .filter(({ provider }) => provider === 'aws-device-farm') + .map(({ provider, source, state, package: name }) => [provider, source, state, name]), + [['aws-device-farm', 'store', 'active', '@agent-device/aws-device-farm']], + ); + await composition.shutdown(); +}); + test('a plugin claiming a routing identity is refused before the registry settles claims', async () => { for (const provider of ['cloud', 'proxy']) { const { home, env } = pluginHome(); diff --git a/src/__tests__/remote-connection.test.ts b/src/__tests__/remote-connection.test.ts index f1444be18e..bb006275fa 100644 --- a/src/__tests__/remote-connection.test.ts +++ b/src/__tests__/remote-connection.test.ts @@ -1,6 +1,6 @@ import { afterEach, test, vi } from 'vitest'; import assert from 'node:assert/strict'; -import { withCapturedStdoutAsync } from '@agent-device/test-kit'; +import { withCapturedStdoutAsync, pluginHome } from '@agent-device/test-kit'; import fs from 'node:fs'; import path from 'node:path'; import { @@ -32,6 +32,7 @@ import { REMOTE_LEASE_IDLE_TTL_MS } from '@agent-device/contracts/lease-scope'; import { hasDeferredMetroConfig } from '../cli/commands/connection-metro-runtime.ts'; import { stopMetroTunnel } from '@agent-device/react-native'; import { AppError } from '@agent-device/kernel/errors'; +import { selectAwsDeviceFarmPlugin } from './test-utils/aws-device-farm-plugin-inventory.ts'; import { hashRemoteConfigFile, readActiveConnectionState, @@ -298,7 +299,7 @@ test('connect proxy rejects remote-config and unknown provider combinations', as }, client: createTestClient(), }), - /Supported providers: cloud, proxy, aws-device-farm/, + /Supported providers: cloud, proxy, limrun/, ); fs.rmSync(tempRoot, { recursive: true, force: true }); }); @@ -737,6 +738,11 @@ test('cloud webdriver connection allocates and heartbeats with extended lease TT const { tempRoot, stateDir, remoteConfigPath } = connectionWorkspace( 'agent-device-connect-cloud-ttl-', ); + // The AWS Device Farm capabilities a plugin declares are what earn the extended TTL, so the + // store declares them here the way the installed package does. + const { home } = pluginHome(); + selectAwsDeviceFarmPlugin(home); + vi.stubEnv('AGENT_DEVICE_HOME', home); fs.writeFileSync(remoteConfigPath, JSON.stringify({})); seedConnectionState({ stateDir, diff --git a/src/__tests__/test-utils/aws-device-farm-plugin-inventory.ts b/src/__tests__/test-utils/aws-device-farm-plugin-inventory.ts new file mode 100644 index 0000000000..cabe8e401d --- /dev/null +++ b/src/__tests__/test-utils/aws-device-farm-plugin-inventory.ts @@ -0,0 +1,35 @@ +import type { PluginInventoryEntry } from '@agent-device/contracts/plugin-inventory'; +import type { PluginCandidate } from '@agent-device/plugins/registry'; +import { resolveProviderPlugins } from '@agent-device/plugins/registry'; +import { selectV2Plugin, v2RegistrationSource } from '@agent-device/test-kit'; +import awsDeviceFarm from '@agent-device/aws-device-farm'; +import manifest from '@agent-device/aws-device-farm/package.json' with { type: 'json' }; + +/** The AWS Device Farm package as an installed store plugin, without touching the on-disk store. */ +export function awsDeviceFarmPluginCandidate(): PluginCandidate { + return { + source: 'store', + package: manifest.name as string, + load: async () => (await import('@agent-device/aws-device-farm')).default(), + }; +} + +/** The inventory one installed AWS Device Farm plugin produces, the way the daemon reads it. */ +export async function awsDeviceFarmPluginInventory(): Promise { + const resolved = await resolveProviderPlugins([awsDeviceFarmPluginCandidate()]); + return resolved.inventory(); +} + +/** + * Declares the plugin installed in a store home, with the capabilities of the real package and a + * stub connection, so capability readers that prime the store see what an installed plugin declares. + */ +export function selectAwsDeviceFarmPlugin(home: string): void { + selectV2Plugin( + home, + manifest.name, + v2RegistrationSource('aws-device-farm', { + extra: `connection: { capabilities: ${JSON.stringify(awsDeviceFarm().connection?.capabilities)}, resolve() {}, verify() {} },`, + }), + ); +} diff --git a/src/builtin-provider-ids.ts b/src/builtin-provider-ids.ts index a9d2d79827..6216c7010a 100644 --- a/src/builtin-provider-ids.ts +++ b/src/builtin-provider-ids.ts @@ -1,6 +1,5 @@ import type { ConnectionProviderCapabilities } from '@agent-device/contracts/remote'; import { ROUTING_PROVIDER_IDENTITIES } from '@agent-device/plugins/contract'; -import { CLOUD_WEBDRIVER_PROVIDER_DECLARATIONS } from '@agent-device/provider-webdriver/providers'; export const LIMRUN_ID = 'limrun'; @@ -17,10 +16,7 @@ const LIMRUN_CONNECTION: ConnectionProviderCapabilities = { }; /** Every provider id agent-device registers itself; a plugin cannot claim any of them. */ -export const BUILTIN_PROVIDER_IDS: readonly string[] = [ - ...CLOUD_WEBDRIVER_PROVIDER_DECLARATIONS.map(({ provider }) => provider), - LIMRUN_ID, -]; +export const BUILTIN_PROVIDER_IDS: readonly string[] = [LIMRUN_ID]; /** Provider ids `connect` accepts without a plugin: the routing identities and the built-ins. */ export const BUILTIN_CONNECT_PROVIDER_IDS: readonly string[] = [ @@ -32,8 +28,5 @@ export const BUILTIN_CONNECT_PROVIDER_IDS: readonly string[] = [ export function builtinConnectionCapabilities( provider: string | undefined, ): ConnectionProviderCapabilities | undefined { - if (provider === LIMRUN_ID) return LIMRUN_CONNECTION; - return CLOUD_WEBDRIVER_PROVIDER_DECLARATIONS.find( - (declaration) => declaration.provider === provider, - )?.connection; + return provider === LIMRUN_ID ? LIMRUN_CONNECTION : undefined; } diff --git a/src/builtin-provider-plugins.ts b/src/builtin-provider-plugins.ts index 52708c2b72..d64bd8c402 100644 --- a/src/builtin-provider-plugins.ts +++ b/src/builtin-provider-plugins.ts @@ -1,9 +1,5 @@ import type { AgentDevicePlugin } from '@agent-device/plugins/contract'; import type { PluginCandidate } from '@agent-device/plugins/registry'; -import { - CLOUD_WEBDRIVER_PROVIDER_DECLARATIONS, - type CloudWebDriverProviderDeclaration, -} from '@agent-device/provider-webdriver/providers'; import { LIMRUN_ID } from './builtin-provider-ids.ts'; import type { HostEnvironment } from '@agent-device/kernel/source-value'; import path from 'node:path'; @@ -20,50 +16,7 @@ import { * registering until the environment holds it. */ export function builtinProviderCandidates(host: HostEnvironment): PluginCandidate[] { - return [ - ...CLOUD_WEBDRIVER_PROVIDER_DECLARATIONS.map((declaration): PluginCandidate => ({ - source: 'builtin', - provider: declaration.provider, - load: () => cloudWebDriverPlugin(declaration), - })), - limrunCandidate(host), - ]; -} - -function cloudWebDriverPlugin(declaration: CloudWebDriverProviderDeclaration): AgentDevicePlugin { - const loadProvider = async () => { - const [{ bundledCloudWebDriverProvider }, host] = await Promise.all([ - import('@agent-device/provider-webdriver'), - import('./provider-webdriver.ts'), - ]); - return { bundled: bundledCloudWebDriverProvider(declaration.provider)!, host }; - }; - return { - apiVersion: 2, - provider: declaration.provider, - credentials: { variables: declaration.credentialVariables ?? [] }, - connection: { - capabilities: declaration.connection, - resolve: async (context) => { - const { bundled, host } = await loadProvider(); - return await bundled - .create(host.createBundledCloudWebDriverHost(context.env)) - .connection.resolve(context); - }, - verify: async (context) => { - const { bundled, host } = await loadProvider(); - return await bundled - .create(host.createBundledCloudWebDriverHost(context.env)) - .connection.verify(context); - }, - }, - setup: async (pluginHost) => { - const { bundled, host } = await loadProvider(); - return { - webDriver: bundled.create(host.createBundledCloudWebDriverHost(pluginHost.env)).webDriver, - }; - }, - }; + return [limrunCandidate(host)]; } function limrunCandidate(host: HostEnvironment): PluginCandidate { diff --git a/src/cli/connection/connect-provider-adapters.ts b/src/cli/connection/connect-provider-adapters.ts index 8ca1de5d20..93d2ee33f6 100644 --- a/src/cli/connection/connect-provider-adapters.ts +++ b/src/cli/connection/connect-provider-adapters.ts @@ -19,7 +19,6 @@ import { type ConnectProvider, } from './provider-policy.ts'; import { BUILTIN_PROVIDER_IDS } from '../../builtin-provider-ids.ts'; -import { bundledCloudWebDriverConnection } from '../../provider-webdriver.ts'; import { withPluginConnection } from '@agent-device/plugins/load'; import type { PluginConnectionCallbacks } from '@agent-device/plugins/connection'; import { readMetroProfileFields } from './profile-fields.ts'; @@ -86,16 +85,13 @@ function builtinConnectAdapter(provider: string): ConnectProviderAdapter | undef : undefined; } -/** Runs a provider's connection callbacks: a bundled provider in-process, otherwise its installed plugin. */ +/** Runs a provider's connection callbacks from its installed plugin. */ async function withProviderConnection( provider: string, env: EnvMap, run: (connection: PluginConnectionCallbacks) => Promise, ): Promise { - const bundled = bundledCloudWebDriverConnection(provider, env); - return bundled - ? await run(bundled) - : await withPluginConnection(provider, BUILTIN_PROVIDER_IDS, env, run); + return await withPluginConnection(provider, BUILTIN_PROVIDER_IDS, env, run); } export async function resolveConnectProviderProfile(options: { diff --git a/src/cli/connection/provider-policy.test.ts b/src/cli/connection/provider-policy.test.ts index 9bef132122..4526c03204 100644 --- a/src/cli/connection/provider-policy.test.ts +++ b/src/cli/connection/provider-policy.test.ts @@ -27,10 +27,25 @@ test('provider policy projects provider identity into semantic capabilities', () }); // BrowserStack is a plugin: without an installed one nothing declares its capabilities. assert.equal(connectionProviderCapabilities('browserstack').leaseKind, 'remote-provider'); - assert.equal(connectionProviderCapabilities('aws-device-farm').requiresAppAttachment, true); + assert.equal(connectionProviderCapabilities('aws-device-farm').leaseKind, 'remote-provider'); assert.equal(connectionProviderCapabilities('proxy').leaseKind, 'proxy'); }); +test('an installed AWS Device Farm plugin declares its capabilities once the store is primed', async () => { + const { home, env } = pluginHome(); + selectV2Plugin( + home, + '@agent-device/aws-device-farm', + v2RegistrationSource('aws-device-farm', { + extra: `connection: { capabilities: { leaseKind: 'direct-device-provider', requiresAppAttachment: true, requiresRemoteDaemon: false, supportsArtifacts: true, supportsDeferredAppSelection: false, supportsDirectPortReverse: false, usesCloudWebDriverLease: true }, resolve() {}, verify() {} },`, + }), + ); + + assert.equal(connectionProviderCapabilities('aws-device-farm', env).requiresAppAttachment, false); + await primeProviderConnection('aws-device-farm', env); + assert.equal(connectionProviderCapabilities('aws-device-farm', env).requiresAppAttachment, true); +}); + test('a manifest connection on a store package supplies no capabilities', async () => { const { home, env } = pluginHome(); selectV2Plugin(home, 'example', v2RegistrationSource('example'), { diff --git a/src/commands/provider-plugin-catalog.ts b/src/commands/provider-plugin-catalog.ts index f8bd08e794..2740dd9953 100644 --- a/src/commands/provider-plugin-catalog.ts +++ b/src/commands/provider-plugin-catalog.ts @@ -5,6 +5,11 @@ type ProviderPluginDeclaration = Readonly<{ }>; const PROVIDER_PLUGIN_CATALOG: readonly ProviderPluginDeclaration[] = [ + { + provider: 'aws-device-farm', + package: '@agent-device/aws-device-farm', + label: 'AWS Device Farm', + }, { provider: 'browserstack', package: '@agent-device/browserstack', label: 'BrowserStack' }, { provider: 'revyl', package: '@agent-device/revyl', label: 'Revyl' }, { provider: 'testmu', package: '@agent-device/testmu', label: 'TestMu AI' }, diff --git a/src/commands/schema/cli-help.ts b/src/commands/schema/cli-help.ts index f8c6224af1..43c7aa0ade 100644 --- a/src/commands/schema/cli-help.ts +++ b/src/commands/schema/cli-help.ts @@ -472,7 +472,7 @@ Providers: Remote config: agent-device connect --remote-config ./remote-config.json uses a local profile. Direct proxy: agent-device connect proxy --daemon-base-url stores the shared proxy profile and client identity. BrowserStack (plugin, install separately): agent-device connect browserstack verifies credentials, the exact device, and a bs:// app reference, then stores a local provider profile. It does not create an App Automate session. - AWS Device Farm: agent-device connect aws-device-farm verifies credentials and the exact project, device, and optional app upload, then stores a local provider profile. It does not create a remote access session. + AWS Device Farm: install @agent-device/aws-device-farm with agent-device plugins add, then agent-device connect aws-device-farm verifies credentials and the exact project, device, and optional app upload, then stores a local provider profile. It does not create a remote access session. TestMu AI (plugin, install separately): agent-device connect testmu verifies credentials and the exact virtual device (emulator or simulator) or, with --provider-device-type real, real device and OS version, then stores a local provider profile. --provider-app takes an lt:// app reference, an https URL, or a local path: connect looks an lt:// id up among your uploads for that device pool, while URL and local sources are uploaded and validated when open creates the session. It does not create a hub session. Limrun: agent-device connect limrun verifies access to the selected iOS or Android instance service, then stores a local provider profile. It does not create an instance. Revyl (plugin, install separately): agent-device connect revyl verifies credentials against the Revyl backend, then stores a local provider profile with the platform, optional --device model and --provider-os-version, and a required --provider-app https URL: Revyl downloads and installs that build when it starts the device. It does not rent a device. diff --git a/src/provider-credential-fingerprint.test.ts b/src/provider-credential-fingerprint.test.ts index 8db9d1fcff..bc07da5514 100644 --- a/src/provider-credential-fingerprint.test.ts +++ b/src/provider-credential-fingerprint.test.ts @@ -5,11 +5,17 @@ import type { PluginInventoryEntry } from '@agent-device/contracts/plugin-invent import type { EnvMap } from '@agent-device/kernel/source-value'; import { builtinPluginInventory } from './__tests__/test-utils/builtin-plugin-inventory.ts'; import { browserstackPluginInventory } from './__tests__/test-utils/browserstack-plugin-inventory.ts'; +import { awsDeviceFarmPluginInventory } from './__tests__/test-utils/aws-device-farm-plugin-inventory.ts'; import { pluginHome, selectV2Plugin, v2RegistrationSource } from '@agent-device/test-kit'; import { BUILTIN_PROVIDER_IDS } from './builtin-provider-ids.ts'; -// BrowserStack is an installed plugin, so its credential variables come from its own inventory entry. -const inventory = [...(await builtinPluginInventory()), ...(await browserstackPluginInventory())]; +// BrowserStack and AWS Device Farm are installed plugins, so their credential variables come +// from their own inventory entries. +const inventory = [ + ...(await builtinPluginInventory()), + ...(await browserstackPluginInventory()), + ...(await awsDeviceFarmPluginInventory()), +]; const providerCredentialFingerprint = ( provider: string, env: EnvMap, @@ -197,14 +203,21 @@ test('a plugin provider without declared credential variables has no fingerprint }); test('a plugin declaration never adds a fingerprint to a bundled provider', async () => { - const { env: home } = pluginWithCredentialVariables(['AWS_ACCESS_KEY_ID'], 'aws-device-farm'); + const { env: home } = pluginWithCredentialVariables(['AWS_ACCESS_KEY_ID'], 'limrun'); const inventory = await storeInventory(home); const env = { ...home, AWS_ACCESS_KEY_ID: 'id' }; - expect(providerCredentialFingerprint('aws-device-farm', env, undefined, inventory)).toBe( - undefined, - ); + expect(providerCredentialFingerprint('limrun', env, undefined, inventory)).toBe(undefined); // The built-in's own answer is unchanged by the store package that claims its id. + expect(providerCredentialFingerprint('limrun', env)).toBe(undefined); +}); + +test('an installed AWS Device Farm plugin declares no credential variables', async () => { + const env = { AWS_ACCESS_KEY_ID: 'id', AWS_SECRET_ACCESS_KEY: 'secret' }; + // The package answers through the AWS CLI credential chain, so nothing is hashed. expect(providerCredentialFingerprint('aws-device-farm', env)).toBe(undefined); + expect(readDaemonProviderCredentials(env, '/state').fingerprint('aws-device-farm')).toBe( + undefined, + ); }); test('a store plugin declares per-backend credential variables in code', async () => { diff --git a/src/provider-webdriver.test.ts b/src/provider-webdriver.test.ts deleted file mode 100644 index e048733061..0000000000 --- a/src/provider-webdriver.test.ts +++ /dev/null @@ -1,82 +0,0 @@ -import assert from 'node:assert/strict'; -import fs from 'node:fs'; -import path from 'node:path'; -import { test } from 'vitest'; -import { bundledCloudWebDriverProvider } from '@agent-device/provider-webdriver'; -import { createBundledCloudWebDriverHost } from './provider-webdriver.ts'; -import { mkdtempForTestSync } from '@agent-device/test-kit'; - -test('bundled AWS artifact lookup runs through the host command adapter', async () => { - const tempDir = mkdtempForTestSync('agent-device-provider-webdriver-'); - const awsPath = path.join(tempDir, 'aws'); - const callsPath = path.join(tempDir, 'aws-calls.ndjson'); - const previousPath = process.env.PATH; - const previousCallsPath = process.env.AGENT_DEVICE_TEST_AWS_CALLS_PATH; - fs.writeFileSync( - awsPath, - [ - '#!/usr/bin/env node', - "const fs = require('node:fs');", - 'fs.appendFileSync(process.env.AGENT_DEVICE_TEST_AWS_CALLS_PATH, `${JSON.stringify(process.argv.slice(2))}\\n`);', - "process.stdout.write(JSON.stringify({ artifacts: [{ arn: 'artifact-1', name: 'video', type: 'VIDEO', url: 'https://aws.example/video.mp4' }] }));", - ].join('\n'), - ); - fs.chmodSync(awsPath, 0o755); - process.env.PATH = `${tempDir}${path.delimiter}${previousPath ?? ''}`; - process.env.AGENT_DEVICE_TEST_AWS_CALLS_PATH = callsPath; - - try { - const provider = bundledCloudWebDriverProvider('aws-device-farm'); - assert.ok(provider); - const { webDriver } = provider.create( - createBundledCloudWebDriverHost({ AWS_REGION: 'us-west-2' }), - ); - const providerSessionId = 'arn:aws:devicefarm:us-west-2:123:session/project/session/1'; - const result = await webDriver.listArtifacts?.({ - provider: 'aws-device-farm', - providerSessionId, - }); - - assert.equal(result?.provider, 'aws-device-farm'); - assert.equal(result?.status, 'ready'); - assert.deepEqual( - result?.cloudArtifacts.map(({ kind, url }) => ({ kind, url })), - [ - { kind: 'video', url: 'https://aws.example/video.mp4' }, - { kind: 'video', url: 'https://aws.example/video.mp4' }, - ], - ); - const calls = fs - .readFileSync(callsPath, 'utf8') - .trim() - .split('\n') - .map((line) => JSON.parse(line) as string[]) - .sort((left, right) => (left[7] ?? '').localeCompare(right[7] ?? '')); - assert.deepEqual( - calls.map((args) => args.slice(0, 6)), - [ - ['devicefarm', 'list-artifacts', '--region', 'us-west-2', '--arn', providerSessionId], - ['devicefarm', 'list-artifacts', '--region', 'us-west-2', '--arn', providerSessionId], - ], - ); - assert.deepEqual( - calls.map((args) => args.slice(6)), - [ - ['--type', 'FILE', '--output', 'json'], - ['--type', 'LOG', '--output', 'json'], - ], - ); - } finally { - restoreEnv('PATH', previousPath); - restoreEnv('AGENT_DEVICE_TEST_AWS_CALLS_PATH', previousCallsPath); - fs.rmSync(tempDir, { recursive: true, force: true }); - } -}); - -function restoreEnv(name: string, value: string | undefined): void { - if (value === undefined) { - delete process.env[name]; - return; - } - process.env[name] = value; -} diff --git a/src/provider-webdriver.ts b/src/provider-webdriver.ts deleted file mode 100644 index b2ab2176ed..0000000000 --- a/src/provider-webdriver.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { - bundledCloudWebDriverProvider, - type CloudWebDriverConnection, - type CloudWebDriverProviderHost, -} from '@agent-device/provider-webdriver'; -import { runCmd } from '@agent-device/host-kit/command'; -import { readVersion } from '@agent-device/host-kit/version'; -import type { EnvMap } from '@agent-device/kernel/source-value'; - -/** What this process hands a bundled provider: the plugin host shape plus a host-command runner. */ -export function createBundledCloudWebDriverHost(env: EnvMap): CloudWebDriverProviderHost { - return { - env, - clientVersion: readVersion(), - runHostCommand: async (command, args) => { - const result = await runCmd(command, [...args], { - maxBuffer: 10 * 1024 * 1024, - timeoutMs: 30_000, - }); - return { stdout: result.stdout }; - }, - }; -} - -/** The `connect` callbacks of a bundled provider, or undefined for any other provider name. */ -export function bundledCloudWebDriverConnection( - provider: string, - env: EnvMap, -): CloudWebDriverConnection | undefined { - return bundledCloudWebDriverProvider(provider)?.create(createBundledCloudWebDriverHost(env)) - .connection; -} diff --git a/src/sdk/plugins.ts b/src/sdk/plugins.ts index 411bccad5a..e02ef2c8f5 100644 --- a/src/sdk/plugins.ts +++ b/src/sdk/plugins.ts @@ -6,7 +6,11 @@ import type { } from '@agent-device/plugins/contract'; import type { CloudWebDriverProviderOptions } from '@agent-device/provider-webdriver/plugin'; -export type { ProviderPluginHost } from '@agent-device/plugins/host'; +export type { + HostCommandResult, + ProviderPluginHost, + RunHostCommand, +} from '@agent-device/plugins/host'; export type { PluginConnection, PluginConnectionContext, diff --git a/test/integration/provider-scenarios/aws-runtime.ts b/test/integration/provider-scenarios/aws-runtime.ts new file mode 100644 index 0000000000..f357d7c7a7 --- /dev/null +++ b/test/integration/provider-scenarios/aws-runtime.ts @@ -0,0 +1,33 @@ +import awsDeviceFarm from '@agent-device/aws-device-farm'; +import { createPluginHost } from '@agent-device/plugins/host'; +import { createCloudWebDriverRuntime } from '@agent-device/provider-webdriver/plugin'; +import type { RunHostCommand } from '@agent-device/plugins/host'; + +export const AWS_DEVICE_FARM_PROVIDER = 'aws-device-farm'; + +/** The WebDriver descriptor the AWS Device Farm plugin's `setup` builds from `env`, as `clientVersion` hosted. */ +export async function awsDeviceFarmWebDriver( + env: Record, + clientVersion: string, + runHostCommand: RunHostCommand, +) { + const setup = await awsDeviceFarm().setup({ + ...createPluginHost(env, undefined), + clientVersion, + runHostCommand, + }); + if (!('webDriver' in setup)) throw new Error('AWS Device Farm sets up a WebDriver descriptor'); + return setup.webDriver; +} + +/** An AWS Device Farm runtime composed the way the registry composes a plugin's WebDriver descriptor. */ +export async function createAwsDeviceFarmRuntime(options: { + env: Record; + clientVersion: string; + runHostCommand: RunHostCommand; +}) { + return await createCloudWebDriverRuntime({ + ...(await awsDeviceFarmWebDriver(options.env, options.clientVersion, options.runHostCommand)), + clientVersion: options.clientVersion, + }); +} diff --git a/test/integration/provider-scenarios/bundled-cloud-webdriver-runtimes.ts b/test/integration/provider-scenarios/bundled-cloud-webdriver-runtimes.ts index 08906126cf..50a740e1dc 100644 --- a/test/integration/provider-scenarios/bundled-cloud-webdriver-runtimes.ts +++ b/test/integration/provider-scenarios/bundled-cloud-webdriver-runtimes.ts @@ -1,18 +1,10 @@ -import { - BUNDLED_CLOUD_WEBDRIVER_PROVIDERS, - type CloudWebDriverProviderHost, -} from '@agent-device/provider-webdriver'; -import { createCloudWebDriverRuntime } from '@agent-device/provider-webdriver/plugin'; +import { createAwsDeviceFarmRuntime } from './aws-runtime.ts'; +import type { RunHostCommand } from '@agent-device/plugins/host'; -/** One runtime per bundled provider, composed the way the registry composes a WebDriver descriptor. */ -export async function createBundledCloudWebDriverRuntimes(host: CloudWebDriverProviderHost) { - return await Promise.all( - BUNDLED_CLOUD_WEBDRIVER_PROVIDERS.map( - async (bundled) => - await createCloudWebDriverRuntime({ - ...bundled.create(host).webDriver, - clientVersion: host.clientVersion, - }), - ), - ); +export async function createBundledCloudWebDriverRuntimes(host: { + env: Record; + clientVersion: string; + runHostCommand: RunHostCommand; +}) { + return [await createAwsDeviceFarmRuntime(host)]; } diff --git a/test/integration/provider-scenarios/cloud-webdriver-provider-adapters.test.ts b/test/integration/provider-scenarios/cloud-webdriver-provider-adapters.test.ts index a070ca6ddc..aac37b23b4 100644 --- a/test/integration/provider-scenarios/cloud-webdriver-provider-adapters.test.ts +++ b/test/integration/provider-scenarios/cloud-webdriver-provider-adapters.test.ts @@ -1,21 +1,16 @@ -import { createBundledCloudWebDriverRuntimes } from './bundled-cloud-webdriver-runtimes.ts'; import { BROWSERSTACK_PROVIDER, browserStackWebDriver, createBrowserStackRuntime, } from './browserstack-runtime.ts'; +import { AWS_DEVICE_FARM_PROVIDER, createAwsDeviceFarmRuntime } from './aws-runtime.ts'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import type { IncomingHttpHeaders } from 'node:http'; import path from 'node:path'; import { test } from 'vitest'; import { AppError } from '@agent-device/kernel/errors'; -import type { - DeviceLease, - LeaseLifecycleContext, - ProviderDeviceRuntime, -} from '@agent-device/contracts/device'; -import type { RunHostCommand } from '@agent-device/provider-webdriver'; +import type { DeviceLease, LeaseLifecycleContext } from '@agent-device/contracts/device'; import type { PlatformRuntimeHost } from '@agent-device/contracts/platform-runtime-operations'; import type { CloudArtifactsResult } from '@agent-device/contracts/observability'; import { withProviderScenarioResource, withProviderScenarioTempDir } from './harness.ts'; @@ -28,9 +23,8 @@ import { } from './cloud-webdriver-test-server.ts'; import testmu from '@agent-device/testmu'; -import { createPluginHost } from '@agent-device/plugins/host'; +import { createPluginHost, type RunHostCommand } from '@agent-device/plugins/host'; import { createCloudWebDriverRuntime } from '@agent-device/provider-webdriver/plugin'; -import { CLOUD_WEBDRIVER_PROVIDERS } from '@agent-device/provider-webdriver/providers'; const CLIENT_VERSION = '0.20.3-test'; @@ -146,15 +140,12 @@ test('BrowserStack facade nests device-feature capabilities inside bstack:option test('AWS Device Farm facade rejects device features it does not read at session preparation', async () => { await withProviderScenarioResource(FakeCloudProviderServer.start, async (server) => { const host = new FakeAwsHostCommand(`${server.url}/wd/hub/`); - const runtime = runtimeFor( - await createBundledCloudWebDriverRuntimes({ - env: { AWS_REGION: 'us-west-2' }, - clientVersion: CLIENT_VERSION, - runHostCommand: host.run, - }), - CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm, - ); - const lease = makeLease(CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm); + const runtime = await createAwsDeviceFarmRuntime({ + env: { AWS_REGION: 'us-west-2' }, + clientVersion: CLIENT_VERSION, + runHostCommand: host.run, + }); + const lease = makeLease(AWS_DEVICE_FARM_PROVIDER); const context = awsContext(lease); try { @@ -354,15 +345,12 @@ test('BrowserStack refuses a refused field on a repeat allocation of its live le test('AWS Device Farm facade uses the injected host-command capability for its full lifecycle', async () => { await withProviderScenarioResource(FakeCloudProviderServer.start, async (server) => { const host = new FakeAwsHostCommand(`${server.url}/wd/hub/`); - const runtime = runtimeFor( - await createBundledCloudWebDriverRuntimes({ - env: { AWS_REGION: 'us-west-2' }, - clientVersion: CLIENT_VERSION, - runHostCommand: host.run, - }), - CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm, - ); - const lease = makeLease(CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm); + const runtime = await createAwsDeviceFarmRuntime({ + env: { AWS_REGION: 'us-west-2' }, + clientVersion: CLIENT_VERSION, + runHostCommand: host.run, + }); + const lease = makeLease(AWS_DEVICE_FARM_PROVIDER); try { const allocation = await runtime.leaseLifecycle.allocate?.(lease, awsContext(lease)); assert.equal(allocation?.awsDeviceFarmSessionArn, host.sessionArn); @@ -475,15 +463,6 @@ test('BrowserStack artifact lookup uses the released provider id without allocat }); }); -function runtimeFor( - runtimes: readonly ProviderDeviceRuntime[], - provider: string, -): ProviderDeviceRuntime { - const runtime = runtimes.find((candidate) => candidate.provider === provider); - assert.ok(runtime, `missing ${provider} runtime`); - return runtime; -} - function operationSupport( allocation: Record | undefined, operation: string, diff --git a/test/integration/provider-scenarios/cloud-webdriver-regression-fixtures.ts b/test/integration/provider-scenarios/cloud-webdriver-regression-fixtures.ts index ca2fb6eed7..39dc3b0fb7 100644 --- a/test/integration/provider-scenarios/cloud-webdriver-regression-fixtures.ts +++ b/test/integration/provider-scenarios/cloud-webdriver-regression-fixtures.ts @@ -4,7 +4,7 @@ import type { LeaseLifecycleContext, ProviderDeviceRuntime, } from '@agent-device/contracts/device'; -import type { RunHostCommand } from '@agent-device/provider-webdriver'; +import type { RunHostCommand } from '@agent-device/plugins/host'; import { CloudWebDriverTestServer, type CloudWebDriverHttpCall, diff --git a/tsconfig.typecheck.json b/tsconfig.typecheck.json index dd7d7586f4..294ec3aa87 100644 --- a/tsconfig.typecheck.json +++ b/tsconfig.typecheck.json @@ -31,6 +31,7 @@ { "path": "packages/platform-web" }, { "path": "packages/plugins" }, { "path": "packages/provider-limrun" }, + { "path": "packages/provider-aws-device-farm" }, { "path": "packages/provider-browserstack" }, { "path": "packages/provider-revyl" }, { "path": "packages/provider-testmu" }, diff --git a/website/docs/docs/aws-device-farm.md b/website/docs/docs/aws-device-farm.md index 0206b7b814..603f628895 100644 --- a/website/docs/docs/aws-device-farm.md +++ b/website/docs/docs/aws-device-farm.md @@ -5,6 +5,16 @@ description: Drive AWS Device Farm remote-access sessions with agent-device. Use AWS Device Farm to run agent-device on hosted Android and iOS devices through remote-access WebDriver sessions. You need an AWS account with a Device Farm project and the AWS CLI installed. AWS Device Farm does not cover Vega OS: agent-device rejects a Vega Fire TV ARN. For Vega, use a local Vega Virtual Device (VVD). +## Install the plugin + +Install the plugin on the host that runs the daemon: + +```bash +agent-device plugins add @agent-device/aws-device-farm +``` + +If you used AWS Device Farm before upgrading, close its sessions and stop your daemon with `agent-device daemon stop --state-dir `, then reconnect. If the plugin is missing, install it and retry the command. + ## Set credentials and connect agent-device runs `aws devicefarm ...`, so it uses the AWS CLI credential provider chain and works with any non-interactive AWS CLI credential source in CI. You do not need `aws login`. See the [AWS CLI environment variable reference](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html) for supported credential sources. diff --git a/website/docs/docs/device-clouds.md b/website/docs/docs/device-clouds.md index 5bc4897c10..5e10af18dd 100644 --- a/website/docs/docs/device-clouds.md +++ b/website/docs/docs/device-clouds.md @@ -6,7 +6,7 @@ description: Choose a hosted device provider for agent and CI workflows. Use a device cloud or farm when an agent needs to drive a hosted mobile device without an interactive login. Pick the provider whose account and devices you use: - [BrowserStack](/docs/browserstack): Android and iOS App Automate sessions over WebDriver. Install the `@agent-device/browserstack` plugin first. -- [AWS Device Farm](/docs/aws-device-farm): Android and iOS remote-access sessions through AWS. +- [AWS Device Farm](/docs/aws-device-farm): Android and iOS remote-access sessions through AWS. Install the `@agent-device/aws-device-farm` plugin first. - [TestMu AI](/docs/testmu): Android emulator, iOS simulator, and real-device sessions over WebDriver. - [Limrun](/docs/limrun): direct iOS simulator and Android emulator instances. - [Revyl](/docs/revyl): iOS simulators and Android emulators rented from Revyl's execution API. @@ -16,7 +16,7 @@ Use a device cloud or farm when an agent needs to drive a hosted mobile device w | | BrowserStack | AWS Device Farm | TestMu AI | Limrun | Revyl | | --- | --- | --- | --- | --- | --- | | Devices | Android and iOS real devices | Android and iOS real devices | Android emulators and iOS simulators by default; real devices with `--provider-device-type real` | Android emulators and iOS simulators | Android emulators and iOS simulators | -| Ships as | The `@agent-device/browserstack` plugin | Built in; needs the AWS CLI | The `@agent-device/testmu` plugin | Built in | The `@agent-device/revyl` plugin | +| Ships as | The `@agent-device/browserstack` plugin | The `@agent-device/aws-device-farm` plugin; needs the AWS CLI | The `@agent-device/testmu` plugin | Built in | The `@agent-device/revyl` plugin | | Credentials | `BROWSERSTACK_USERNAME`, `BROWSERSTACK_ACCESS_KEY` | The AWS CLI credential chain, such as `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`, `AWS_REGION` | `LT_USERNAME`, `LT_ACCESS_KEY` | `LIMRUN_API_KEY` (optional `LIMRUN_REGION`), or `LIM_*_INSTANCE_*` for an existing instance | `REVYL_API_KEY` (optional `REVYL_API_URL` for another Revyl backend) | | Device allocated on | `open` | `open` | `open` | First device command, such as `install` or `open` | First device command, such as `open` | | App source | `--provider-app`: `bs://` reference, HTTP(S) URL, or local path | `--aws-app-arn` upload ARN; no install after allocation | `--provider-app`: `lt://` reference, HTTP(S) URL, or local path | `install `, or `open ` for an uploaded asset | `--provider-app`: a public HTTPS URL only, installed when the device starts | diff --git a/website/docs/docs/plugins.md b/website/docs/docs/plugins.md index e141c7d711..2ce77ca43b 100644 --- a/website/docs/docs/plugins.md +++ b/website/docs/docs/plugins.md @@ -2,7 +2,7 @@ title: Plugins --- -Provider plugins add device providers that agent-device does not bundle, such as [BrowserStack](/docs/browserstack), [TestMu AI](/docs/testmu), [LG webOS](/docs/webos), and [Samsung Tizen](/docs/tizen). Installing one requires npm on your host: +Provider plugins add device providers that agent-device does not bundle, such as [BrowserStack](/docs/browserstack), [AWS Device Farm](/docs/aws-device-farm), [TestMu AI](/docs/testmu), [LG webOS](/docs/webos), and [Samsung Tizen](/docs/tizen). Installing one requires npm on your host: ```bash agent-device plugins add @example/agent-device-provider @@ -13,7 +13,7 @@ agent-device plugins remove @example/agent-device-provider `agent-device help connect` and `agent-device help remote` identify known optional providers as `plugin, install separately` and show their installation commands, even before you install them. -For example, BrowserStack requires `agent-device plugins add @agent-device/browserstack`, and TestMu AI requires `agent-device plugins add @agent-device/testmu`. +For example, BrowserStack requires `agent-device plugins add @agent-device/browserstack`, AWS Device Farm requires `agent-device plugins add @agent-device/aws-device-farm`, and TestMu AI requires `agent-device plugins add @agent-device/testmu`. If you run `agent-device connect browserstack` or `agent-device connect testmu` without its plugin, the error gives that installation command and tells you to retry your original command. With `--json`, the error has From e8fa3a9eb5d3def9160b53ece2a9512cfc702eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 16 Nov 2026 18:02:44 +0100 Subject: [PATCH 02/13] refactor(aws-device-farm): consolidate WebDriver imports --- packages/provider-aws-device-farm/src/aws-device-farm.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/provider-aws-device-farm/src/aws-device-farm.ts b/packages/provider-aws-device-farm/src/aws-device-farm.ts index eddc563081..a51dfe0d69 100644 --- a/packages/provider-aws-device-farm/src/aws-device-farm.ts +++ b/packages/provider-aws-device-farm/src/aws-device-farm.ts @@ -1,17 +1,15 @@ -import type { CloudWebDriverCapabilityOverrides } from '@agent-device/provider-webdriver/plugin'; import { buildCloudWebDriverBaseCapabilities, releaseOnFailure, + type CloudWebDriverCapabilityOverrides, + type CloudWebDriverPlatform, + type CloudWebDriverPrepareSession, } from '@agent-device/provider-webdriver/plugin'; import { readAwsArtifacts, type AwsDeviceFarmArtifact, type AwsDeviceFarmArtifactGroup, } from './aws-device-farm-artifacts.ts'; -import type { - CloudWebDriverPlatform, - CloudWebDriverPrepareSession, -} from '@agent-device/provider-webdriver/plugin'; import type { LeaseLifecycleContext } from '@agent-device/contracts/device'; import { PROVIDER_PROFILE_FIELD_FLAGS } from '@agent-device/contracts/remote'; import { setTimeout as sleep } from 'node:timers/promises'; From 617305402aa3c073a48de3faed668ac9de4383f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 16 Nov 2026 18:05:56 +0100 Subject: [PATCH 03/13] test(aws-device-farm): colocate connection coverage --- .../connect-provider-adapters-aws-device-farm.test.ts} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename src/{__tests__/cloud-connect-aws-device-farm.test.ts => cli/connection/connect-provider-adapters-aws-device-farm.test.ts} (97%) diff --git a/src/__tests__/cloud-connect-aws-device-farm.test.ts b/src/cli/connection/connect-provider-adapters-aws-device-farm.test.ts similarity index 97% rename from src/__tests__/cloud-connect-aws-device-farm.test.ts rename to src/cli/connection/connect-provider-adapters-aws-device-farm.test.ts index 930de30423..4bd463a3d3 100644 --- a/src/__tests__/cloud-connect-aws-device-farm.test.ts +++ b/src/cli/connection/connect-provider-adapters-aws-device-farm.test.ts @@ -2,7 +2,7 @@ import { afterEach, beforeEach, test, vi } from 'vitest'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; -import { runCliCapture } from './cli-capture.ts'; +import { runCliCapture } from '../../__tests__/cli-capture.ts'; import { readActiveConnectionState, type RemoteConnectionState, @@ -11,7 +11,7 @@ import { AppError } from '@agent-device/kernel/errors'; import { verifyAwsDeviceFarmConnection } from '@agent-device/aws-device-farm/connection-verification'; import awsDeviceFarm from '@agent-device/aws-device-farm'; import { resolveProviderPlugins } from '@agent-device/plugins/registry'; -import { resolveConnectProviderProfile } from '../cli/connection/connect-provider-adapters.ts'; +import { resolveConnectProviderProfile } from './connect-provider-adapters.ts'; import { mkdtempForTestSync, pluginHome, @@ -21,7 +21,7 @@ import { } from '@agent-device/test-kit'; import manifest from '@agent-device/aws-device-farm/package.json' with { type: 'json' }; import type { PluginConnectionCallbacks } from '@agent-device/plugins/connection'; -import { connectWithGeneratedProviderProfile } from './test-utils/connect-command.ts'; +import { connectWithGeneratedProviderProfile } from '../../__tests__/test-utils/connect-command.ts'; bindTestCommandHost(); From db4ec8068ae5b331d277436e46eef298426e2841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 16 Nov 2026 18:10:15 +0100 Subject: [PATCH 04/13] Test packed AWS provider error boundary --- .../test/package-smoke.mjs | 86 +++++++++++++++++++ scripts/check-provider-plugin.mjs | 19 ++++ 2 files changed, 105 insertions(+) diff --git a/packages/provider-aws-device-farm/test/package-smoke.mjs b/packages/provider-aws-device-farm/test/package-smoke.mjs index 7e9e546748..859aa9b239 100644 --- a/packages/provider-aws-device-farm/test/package-smoke.mjs +++ b/packages/provider-aws-device-farm/test/package-smoke.mjs @@ -1,6 +1,7 @@ import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; +import assert from 'node:assert/strict'; export const provider = 'aws-device-farm'; export const args = [ @@ -55,3 +56,88 @@ export function environment(endpoint) { fs.chmodSync(path.join(bin, 'aws'), 0o755); return { PATH: `${bin}${path.delimiter}${process.env.PATH ?? ''}` }; } + +export async function verifyPacked({ core, contracts, plugin }) { + const flags = { + platform: 'android', + awsProjectArn: 'arn:aws:devicefarm:us-west-2:123:project:project', + awsDeviceArn: 'arn:aws:devicefarm:us-west-2::device:device', + awsAppArn: 'arn:aws:devicefarm:us-west-2:123:upload:upload', + }; + const calls = []; + const host = { + env: {}, + options: {}, + clientVersion: '0.22.0', + createError: (code, message, details) => new core.AppError(code, message, details), + runHostCommand: async (_command, commandArgs) => { + const subcommand = commandArgs[1]; + calls.push(subcommand); + if (subcommand === 'get-project') return { stdout: JSON.stringify(RESOURCES[subcommand]) }; + if (subcommand === 'get-device') return { stdout: JSON.stringify(RESOURCES[subcommand]) }; + if (subcommand === 'get-upload') { + return { stdout: JSON.stringify({ upload: { status: 'PROCESSING' } }) }; + } + if (subcommand === 'create-remote-access-session') { + return { stdout: JSON.stringify({ remoteAccessSession: { arn: 'session-arn' } }) }; + } + if (subcommand === 'get-remote-access-session') { + throw new core.AppError('COMMAND_FAILED', 'host command failed', { + reason: 'host-primary', + hint: 'Retry manually.', + }); + } + if (subcommand === 'stop-remote-access-session') { + throw new core.AppError('COMMAND_FAILED', 'cleanup failed', { reason: 'cleanup-failed' }); + } + throw new Error(`Unexpected AWS command: ${subcommand}`); + }, + }; + const aws = plugin.default(); + const capture = async (run) => { + try { + await run(); + } catch (error) { + assert.ok(error instanceof core.AppError); + return contracts.normalizeError(error); + } + assert.fail('Expected an AWS failure'); + }; + const missing = await capture(() => + aws.connection.resolve({ flags: { platform: 'android' }, cwd: '/', env: {}, host }), + ); + assert.equal(missing.code, 'INVALID_ARGS'); + assert.ok(missing.hint); + + const verification = await capture(() => aws.connection.verify({ flags, env: {}, host })); + assert.equal(verification.code, 'COMMAND_FAILED'); + assert.equal(verification.details.status, 'PROCESSING'); + assert.equal( + verification.hint, + 'Wait for the upload to succeed or reconnect with a different --aws-app-arn.', + ); + + const setup = await aws.setup(host); + const allocation = await capture(() => + setup.webDriver.prepareSession({ + lease: { leaseId: 'lease-1' }, + req: { flags }, + base: { + provider, + platform: 'android', + deviceName: 'device', + endpoint: 'http://localhost', + webdriverCapabilities: {}, + }, + }), + ); + assert.equal(allocation.code, 'COMMAND_FAILED'); + assert.equal(allocation.details.reason, 'host-primary'); + assert.equal(allocation.hint, 'Retry manually.'); + assert.equal(allocation.details.cleanupError, 'cleanup failed'); + assert.deepEqual(calls.slice(-3), [ + 'create-remote-access-session', + 'get-remote-access-session', + 'stop-remote-access-session', + ]); +} diff --git a/scripts/check-provider-plugin.mjs b/scripts/check-provider-plugin.mjs index df1c11dd29..e223b225b3 100644 --- a/scripts/check-provider-plugin.mjs +++ b/scripts/check-provider-plugin.mjs @@ -54,6 +54,14 @@ try { // of packing this checkout, to prove a plugin still loads on a host without the newest contract. const coreSpec = process.env.AGENT_DEVICE_CORE_SPEC ?? (await pack(root)); const pluginTarball = await pack(plugin); + const sha256 = async (file) => + crypto + .createHash('sha256') + .update(await fs.readFile(file)) + .digest('hex'); + if (!process.env.AGENT_DEVICE_CORE_SPEC) + console.log(`Core tarball sha256: ${await sha256(coreSpec)}`); + console.log(`Plugin tarball sha256: ${await sha256(pluginTarball)}`); for (const directory of [consumer, project]) { await fs.mkdir(directory, { recursive: true }); await fs.writeFile(path.join(directory, 'package.json'), '{"private":true,"type":"module"}'); @@ -98,6 +106,17 @@ try { ); const core = path.join(consumer, 'node_modules', 'agent-device'); const coreManifest = JSON.parse(await fs.readFile(path.join(core, 'package.json'), 'utf8')); + if (fixture.verifyPacked) { + const pluginRoot = path.join(project, 'node_modules', manifest.name); + const loadExport = async (directory, exports, name) => + await import(pathToFileURL(path.resolve(directory, exports[name].import)).href); + await fixture.verifyPacked({ + core: await loadExport(core, coreManifest.exports, '.'), + contracts: await loadExport(core, coreManifest.exports, './contracts'), + plugin: await loadExport(pluginRoot, installed.exports, './agent-device'), + }); + console.log(`Packed ${manifest.name}: failure contract passed.`); + } const bin = path.resolve(core, coreManifest.bin['agent-device']); const env = { ...process.env, From 086d2d60c76df6891bde474ff5ec673815c353b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 16 Nov 2026 18:21:23 +0100 Subject: [PATCH 05/13] refactor(provider-webdriver): remove unused extraction scaffolding --- package.json | 3 +-- packages/provider-webdriver/package.json | 4 ---- packages/provider-webdriver/src/index.ts | 12 ------------ pnpm-lock.yaml | 3 --- .../test-utils/aws-device-farm-plugin-inventory.ts | 2 +- test/integration/provider-scenarios/aws-runtime.ts | 2 +- 6 files changed, 3 insertions(+), 23 deletions(-) delete mode 100644 packages/provider-webdriver/src/index.ts diff --git a/package.json b/package.json index 2040fa86c0..3563f9c34b 100644 --- a/package.json +++ b/package.json @@ -380,7 +380,6 @@ "@agent-device/browserstack": "workspace:*", "@agent-device/revyl": "workspace:*", "@agent-device/webos": "workspace:*", - "@agent-device/tizen": "workspace:*", - "@agent-device/build-config": "workspace:*" + "@agent-device/tizen": "workspace:*" } } diff --git a/packages/provider-webdriver/package.json b/packages/provider-webdriver/package.json index 4a8ea93d92..8f6949059b 100644 --- a/packages/provider-webdriver/package.json +++ b/packages/provider-webdriver/package.json @@ -12,10 +12,6 @@ "@agent-device/xml": "workspace:*" }, "exports": { - ".": { - "types": "./src/index.ts", - "default": "./src/index.ts" - }, "./providers": { "types": "./src/providers.ts", "default": "./src/providers.ts" diff --git a/packages/provider-webdriver/src/index.ts b/packages/provider-webdriver/src/index.ts deleted file mode 100644 index 7675e7d481..0000000000 --- a/packages/provider-webdriver/src/index.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type { CloudWebDriverRuntimeOptions, CloudWebDriverRuntime } from './runtime.ts'; - -/** - * The shared hosted-WebDriver engine. A provider plugin contributes the descriptor it drives - * through `agent-device/plugins/webdriver`; this package keeps the engine and its helpers. - */ -export async function createCloudWebDriverRuntime( - options: CloudWebDriverRuntimeOptions, -): Promise { - const runtime = await import('./runtime.ts'); - return runtime.createCloudWebDriverRuntime(options); -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 11fc53fe88..397e9836b6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,9 +35,6 @@ importers: '@agent-device/browserstack': specifier: workspace:* version: link:packages/provider-browserstack - '@agent-device/build-config': - specifier: workspace:* - version: link:packages/build-config '@agent-device/capture-kit': specifier: workspace:* version: link:packages/capture-kit diff --git a/src/__tests__/test-utils/aws-device-farm-plugin-inventory.ts b/src/__tests__/test-utils/aws-device-farm-plugin-inventory.ts index cabe8e401d..7b123878a9 100644 --- a/src/__tests__/test-utils/aws-device-farm-plugin-inventory.ts +++ b/src/__tests__/test-utils/aws-device-farm-plugin-inventory.ts @@ -6,7 +6,7 @@ import awsDeviceFarm from '@agent-device/aws-device-farm'; import manifest from '@agent-device/aws-device-farm/package.json' with { type: 'json' }; /** The AWS Device Farm package as an installed store plugin, without touching the on-disk store. */ -export function awsDeviceFarmPluginCandidate(): PluginCandidate { +function awsDeviceFarmPluginCandidate(): PluginCandidate { return { source: 'store', package: manifest.name as string, diff --git a/test/integration/provider-scenarios/aws-runtime.ts b/test/integration/provider-scenarios/aws-runtime.ts index f357d7c7a7..e9919d5b00 100644 --- a/test/integration/provider-scenarios/aws-runtime.ts +++ b/test/integration/provider-scenarios/aws-runtime.ts @@ -6,7 +6,7 @@ import type { RunHostCommand } from '@agent-device/plugins/host'; export const AWS_DEVICE_FARM_PROVIDER = 'aws-device-farm'; /** The WebDriver descriptor the AWS Device Farm plugin's `setup` builds from `env`, as `clientVersion` hosted. */ -export async function awsDeviceFarmWebDriver( +async function awsDeviceFarmWebDriver( env: Record, clientVersion: string, runHostCommand: RunHostCommand, From 410d9a40018f4978fcb21bc8a49dbec4d4f89173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 16 Nov 2026 18:21:23 +0100 Subject: [PATCH 06/13] chore(gates): register the AWS packed smoke entry --- .fallowrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.fallowrc.json b/.fallowrc.json index 3e0f1195ed..eb98ee2f06 100644 --- a/.fallowrc.json +++ b/.fallowrc.json @@ -5,6 +5,7 @@ "tools/depgraph-view/app.js", "scripts/check-provider-plugin.mjs", "scripts/check-affected/command.ts", + "packages/provider-aws-device-farm/test/package-smoke.mjs", "packages/provider-browserstack/test/package-smoke.mjs", "packages/provider-browserstack/tsdown.config.ts", "packages/provider-testmu/test/package-smoke.mjs", From 4dbfd87e26e0930bba707aff2b67e1168cf98dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 16 Nov 2026 18:24:57 +0100 Subject: [PATCH 07/13] chore(gates): verify the explicit WebDriver plugin subpath --- scripts/layering/package-boundaries.test.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/layering/package-boundaries.test.ts b/scripts/layering/package-boundaries.test.ts index ea0563d8a3..908d3f9af2 100644 --- a/scripts/layering/package-boundaries.test.ts +++ b/scripts/layering/package-boundaries.test.ts @@ -943,9 +943,12 @@ test('Node resolution enforces the exports map at runtime', () => { contractsReactNativeOverlayResolved.endsWith('packages/contracts/src/react-native-overlay.ts'), contractsReactNativeOverlayResolved, ); - const providerWebDriverResolved = import.meta.resolve('@agent-device/provider-webdriver'); + assert.throws(() => import.meta.resolve('@agent-device/provider-webdriver'), { + code: 'ERR_PACKAGE_PATH_NOT_EXPORTED', + }); + const providerWebDriverResolved = import.meta.resolve('@agent-device/provider-webdriver/plugin'); assert.ok( - providerWebDriverResolved.endsWith('packages/provider-webdriver/src/index.ts'), + providerWebDriverResolved.endsWith('packages/provider-webdriver/src/plugin.ts'), providerWebDriverResolved, ); const providerLimrunResolved = import.meta.resolve('@agent-device/provider-limrun'); From 2b67e2f37abb506f97c6f21de1fce2f0cd1555d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 16 Nov 2026 19:10:13 +0100 Subject: [PATCH 08/13] test(layering): update WebDriver export boundary --- scripts/layering/package-boundaries.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/layering/package-boundaries.test.ts b/scripts/layering/package-boundaries.test.ts index 908d3f9af2..01bd9cc385 100644 --- a/scripts/layering/package-boundaries.test.ts +++ b/scripts/layering/package-boundaries.test.ts @@ -804,7 +804,6 @@ test('the real tree parses, declares, and passes R11', () => { ); assert.ok(providerWebDriverPackage, 'provider-webdriver package must exist'); assert.deepEqual([...providerWebDriverPackage.exportTargets.keys()].sort(), [ - '@agent-device/provider-webdriver', '@agent-device/provider-webdriver/android-snapshot', '@agent-device/provider-webdriver/plugin', '@agent-device/provider-webdriver/providers', From 639c74ae4bf922bb48577a7d5889e0e4e96bd43f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 16 Nov 2026 19:12:41 +0100 Subject: [PATCH 09/13] chore(gates): separate root dependency ownership from workspace references --- scripts/layering/project-references.test.ts | 35 ++++++--------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/scripts/layering/project-references.test.ts b/scripts/layering/project-references.test.ts index 1bbeb147c0..333f94614b 100644 --- a/scripts/layering/project-references.test.ts +++ b/scripts/layering/project-references.test.ts @@ -1,11 +1,7 @@ -// The TypeScript project graph is three hand-written views of one fact: the workspace package -// set, the root manifest's `workspace:*` declarations, and the `references` lists in the root -// build node (tsconfig.typecheck.json), examples/sdk, and per-package tsconfigs. `tsc -b` fails -// loudly on a MISSING reference it needs but silently tolerates EXTRA ones (#3289 review), so a -// package added to the workspace while a references list goes un-updated keeps building a stale -// graph that still exits 0. -// These tests read the committed declarations against each other so the four views cannot -// drift: an added, renamed, or removed workspace package must edit every list or fail here. +// The TypeScript project graph covers every workspace package. Root and example references +// must match that set, and each package's references must match its own manifest dependencies. +// Root workspace dependency declarations follow root imports, which R11 checks separately. +// A package-local build dependency does not require a root declaration. import assert from 'node:assert/strict'; import fs from 'node:fs'; @@ -115,7 +111,7 @@ test('the compiled-set predicate is licensed by the tsconfig include/exclude sha } }); -test('root workspace dependencies cover every core package and exclude optional engines', () => { +test('root workspace dependencies name existing packages and exclude optional engines', () => { const manifest = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8')) as { dependencies?: Record; devDependencies?: Record; @@ -127,24 +123,11 @@ test('root workspace dependencies cover every core package and exclude optional .filter(([, range]) => String(range).startsWith('workspace:')) .map(([name]) => name) .sort(); - const expected = readWorkspacePackages(repoRoot) - .filter( - (pkg) => - ![ - '@agent-device/maestro', - '@agent-device/replay', - '@agent-device/ad-replay', - '@agent-device/replay-test', - ].includes(pkg.name), - ) - .map((pkg) => pkg.name) - .sort(); + const workspaceNames = new Set(readWorkspacePackages(repoRoot).map((pkg) => pkg.name)); assert.deepEqual( - declared, - expected, - 'a workspace package the root program consumes must be declared workspace:* in the root ' + - 'manifest (its tsconfig references already name it; the root project resolves package ' + - 'specifiers through these declarations)', + declared.filter((name) => !workspaceNames.has(name)), + [], + 'every root workspace:* dependency must name an existing workspace package', ); assert.ok( ![ From 2327e511566233b9416fae3fd3b6c1606e963d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 16 Nov 2026 19:17:12 +0100 Subject: [PATCH 10/13] chore(gates): check workspace declarations in script test imports --- .../package-boundaries-script-tests.test.ts | 39 +++++++++++++++++++ scripts/layering/package-boundaries.ts | 25 +++++++----- 2 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 scripts/layering/package-boundaries-script-tests.test.ts diff --git a/scripts/layering/package-boundaries-script-tests.test.ts b/scripts/layering/package-boundaries-script-tests.test.ts new file mode 100644 index 0000000000..0470f484bb --- /dev/null +++ b/scripts/layering/package-boundaries-script-tests.test.ts @@ -0,0 +1,39 @@ +import assert from 'node:assert/strict'; +import { execFileSync } from 'node:child_process'; +import fs from 'node:fs'; +import path from 'node:path'; +import { test } from 'node:test'; +import { mkdtempForTestSync } from '@agent-device/test-kit'; +import { checkPackageBoundaries } from './package-boundaries.ts'; + +test('R11 discovers real workspace imports in script tests without parsing fixture strings', () => { + const repo = mkdtempForTestSync('package-boundaries-script-tests-'); + const helper = path.join(repo, 'packages/helper'); + fs.mkdirSync(path.join(helper, 'src'), { recursive: true }); + fs.mkdirSync(path.join(repo, 'scripts/nested'), { recursive: true }); + fs.writeFileSync( + path.join(helper, 'package.json'), + JSON.stringify({ name: '@agent-device/helper', private: true, exports: './src/index.ts' }), + ); + fs.writeFileSync(path.join(helper, 'src/index.ts'), 'export const value = 1;'); + fs.writeFileSync(path.join(repo, 'package.json'), JSON.stringify({ private: true })); + fs.writeFileSync( + path.join(repo, 'scripts/nested/probe.test.ts'), + `import { value } from '@agent-device/helper'; + const fixture = "import { missing } from '@agent-device/absent';";`, + ); + execFileSync('git', ['init', '-q'], { cwd: repo }); + execFileSync('git', ['add', '.'], { cwd: repo }); + const violations = checkPackageBoundaries(repo); + assert.equal(violations.length, 1); + assert.equal(violations[0]!.rule, 'R11 package-boundaries'); + assert.equal(violations[0]!.file, 'scripts/nested/probe.test.ts'); + assert.equal(violations[0]!.line, 1); + assert.match(violations[0]!.message, /helper.*not a.*workspace:\*/); + + fs.writeFileSync( + path.join(repo, 'package.json'), + JSON.stringify({ private: true, devDependencies: { '@agent-device/helper': 'workspace:*' } }), + ); + assert.deepEqual(checkPackageBoundaries(repo), []); +}); diff --git a/scripts/layering/package-boundaries.ts b/scripts/layering/package-boundaries.ts index b19d1dbc57..4c27ffb475 100644 --- a/scripts/layering/package-boundaries.ts +++ b/scripts/layering/package-boundaries.ts @@ -582,18 +582,23 @@ export function checkPackageBoundaries(repoRoot: string): PackageBoundaryViolati } for (const root of ['src', 'test', 'scripts']) { for (const file of walkTsFiles(repoRoot, root)) { - // Gate tests under scripts/ carry import syntax inside fixture strings - // (which is why this reads module records instead of scanning lines); - // src/ and test/ suites stay covered — they import packages for real. - if (root === 'scripts' && file.endsWith('.test.ts')) continue; const source = fs.readFileSync(path.join(repoRoot, file), 'utf8'); + const sites = specifierSites(file, source); + if (root === 'scripts' && file.endsWith('.test.ts')) { + // Script harnesses retain their relative source access. Their actual package imports + // still need root declarations; fixture strings are not module records. + violations.push( + ...checkRootSites( + sites.filter((site) => !site.specifier.startsWith('.')), + packages, + rootDependencies, + true, + ), + ); + continue; + } violations.push( - ...checkRootSites( - specifierSites(file, source), - packages, - rootDependencies, - insideCompiledSources(file), - ), + ...checkRootSites(sites, packages, rootDependencies, insideCompiledSources(file)), ); } } From 7e64f8f905577ef1d18ed19dc0ad5d94c3b56ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 16 Nov 2026 20:08:19 +0100 Subject: [PATCH 11/13] fix(plugins): defer host command execution imports --- packages/plugins/src/host.ts | 2 +- src/commands/schema/cli-help-topics.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/plugins/src/host.ts b/packages/plugins/src/host.ts index d1dfb0cf55..941142d54c 100644 --- a/packages/plugins/src/host.ts +++ b/packages/plugins/src/host.ts @@ -1,6 +1,5 @@ import { AppError, type AppErrorCode, type AppErrorDetails } from '@agent-device/kernel/errors'; import { readVersion } from '@agent-device/host-kit/version'; -import { runCmd } from '@agent-device/host-kit/command'; export type HostCommandResult = Readonly<{ stdout: string }>; @@ -27,6 +26,7 @@ export function createPluginHost( clientVersion: readVersion(), createError: (code, message, details) => new AppError(code, message, details), runHostCommand: async (command, args) => { + const { runCmd } = await import('@agent-device/host-kit/command'); const { stdout } = await runCmd(command, [...args], { maxBuffer: 10 * 1024 * 1024, timeoutMs: 30_000, diff --git a/src/commands/schema/cli-help-topics.test.ts b/src/commands/schema/cli-help-topics.test.ts index 7b8370af4f..3438335f6f 100644 --- a/src/commands/schema/cli-help-topics.test.ts +++ b/src/commands/schema/cli-help-topics.test.ts @@ -415,7 +415,7 @@ test('usageForCommand resolves remote help topic', async () => { help, /BrowserStack \(plugin, install separately\): agent-device connect browserstack/, ); - assert.match(help, /AWS Device Farm: agent-device connect aws-device-farm/); + assert.match(help, /AWS Device Farm: install @agent-device\/aws-device-farm/); assert.match(help, /Limrun: agent-device connect limrun/); assert.match(help, /It does not create an App Automate session/); assert.match(help, /It does not create a remote access session/); From f9a0b34067d409bace935b49b9144869dbaa294d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 16 Nov 2026 20:31:37 +0100 Subject: [PATCH 12/13] refactor(webdriver): remove unused provider exports --- .../src/platform-runtime.test.ts | 7 +++---- packages/provider-webdriver/src/providers.ts | 2 -- packages/provider-webdriver/src/runtime.ts | 2 -- ...oud-webdriver-provider-regressions.test.ts | 19 ++++++++----------- .../stale-provider-runtime-admission.test.ts | 9 +++------ 5 files changed, 14 insertions(+), 25 deletions(-) diff --git a/packages/provider-webdriver/src/platform-runtime.test.ts b/packages/provider-webdriver/src/platform-runtime.test.ts index bc5778a0c9..1a8c8377a9 100644 --- a/packages/provider-webdriver/src/platform-runtime.test.ts +++ b/packages/provider-webdriver/src/platform-runtime.test.ts @@ -10,13 +10,12 @@ import { type CloudWebDriverCapabilityOverrides, } from './capabilities.ts'; import type { CloudWebDriverPlatform } from './runtime.ts'; -import { CLOUD_WEBDRIVER_PROVIDERS } from './providers.ts'; /** The declared map fact generation now reads. Defaults to a provider with no overrides. */ function capabilities( platform: CloudWebDriverPlatform = 'android', overrides?: CloudWebDriverCapabilityOverrides, - provider: string = CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm, + provider: string = 'aws-device-farm', ) { return createCloudWebDriverCapabilities({ provider, @@ -77,9 +76,9 @@ test('direct WebDriver refuses a live network dump instead of answering from ano test('a provider with no capture of its own states the same refusal for a live dump', async () => { const owner = createWebDriverPlatformRuntimeOwner({ host: host(async () => ({ stdout: '', stderr: '', exitCode: 0 })), - owner: providerRuntimeOwner(CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm, 'android'), + owner: providerRuntimeOwner('aws-device-farm', 'android'), ownsDevice: () => true, - capabilities: capabilities('android', undefined, CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm), + capabilities: capabilities('android', undefined, 'aws-device-farm'), }); expect(await owner.inspectFacts({ ...device, id: 'aws-device-farm:lease-one' })).toMatchObject({ diff --git a/packages/provider-webdriver/src/providers.ts b/packages/provider-webdriver/src/providers.ts index b2af2bfb41..55b1941f7e 100644 --- a/packages/provider-webdriver/src/providers.ts +++ b/packages/provider-webdriver/src/providers.ts @@ -1,7 +1,5 @@ import type { ConnectionProviderCapabilities } from '@agent-device/contracts/remote'; -export const CLOUD_WEBDRIVER_PROVIDERS = { awsDeviceFarm: 'aws-device-farm' } as const; - export const HOSTED_WEBDRIVER_CONNECTION: ConnectionProviderCapabilities = { leaseKind: 'direct-device-provider', requiresAppAttachment: false, diff --git a/packages/provider-webdriver/src/runtime.ts b/packages/provider-webdriver/src/runtime.ts index 601d54f1af..2583538cae 100644 --- a/packages/provider-webdriver/src/runtime.ts +++ b/packages/provider-webdriver/src/runtime.ts @@ -117,8 +117,6 @@ export function createCloudWebDriverRuntime( return new CloudWebDriverRuntimeImplementation(options); } -export { buildCloudWebDriverBaseCapabilities } from './capabilities.ts'; - /** Public façade: provider wiring stays small while session/deployment mechanics stay focused. */ class CloudWebDriverRuntimeImplementation implements CloudWebDriverRuntime { readonly provider: string; diff --git a/test/integration/provider-scenarios/cloud-webdriver-provider-regressions.test.ts b/test/integration/provider-scenarios/cloud-webdriver-provider-regressions.test.ts index 41a6ea544e..ebbbb2952b 100644 --- a/test/integration/provider-scenarios/cloud-webdriver-provider-regressions.test.ts +++ b/test/integration/provider-scenarios/cloud-webdriver-provider-regressions.test.ts @@ -25,7 +25,6 @@ import { providerRegressionLease, providerRuntimeFor, } from './cloud-webdriver-regression-fixtures.ts'; -import { CLOUD_WEBDRIVER_PROVIDERS } from '@agent-device/provider-webdriver/providers'; test('AWS Device Farm endpoint selection skips live-control WebSocket URLs', async () => { await withProviderScenarioResource(ProviderRegressionServer.start, async (server) => { @@ -38,9 +37,9 @@ test('AWS Device Farm endpoint selection skips live-control WebSocket URLs', asy clientVersion: PROVIDER_REGRESSION_CLIENT_VERSION, runHostCommand: host.run, }), - CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm, + 'aws-device-farm', ); - const lease = providerRegressionLease(CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm); + const lease = providerRegressionLease('aws-device-farm'); try { await runtime.leaseLifecycle.allocate?.(lease, awsRegressionContext()); assert.equal(server.calls[0]?.path, '/wd/hub/session'); @@ -98,9 +97,9 @@ test('AWS Device Farm rejects local artifact install until upload support exists clientVersion: PROVIDER_REGRESSION_CLIENT_VERSION, runHostCommand: host.run, }), - CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm, + 'aws-device-farm', ); - const lease = providerRegressionLease(CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm); + const lease = providerRegressionLease('aws-device-farm'); try { await runtime.leaseLifecycle.allocate?.(lease, awsRegressionContext()); const [device] = @@ -131,11 +130,9 @@ test('an active AWS Device Farm owner binds no install-family deployment operati clientVersion: PROVIDER_REGRESSION_CLIENT_VERSION, runHostCommand: host.run, }); - const runtime = runtimes.find( - (candidate) => candidate.provider === CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm, - ); + const runtime = runtimes.find((candidate) => candidate.provider === 'aws-device-farm'); assert.ok(runtime, 'Expected AWS Device Farm runtime'); - const lease = providerRegressionLease(CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm); + const lease = providerRegressionLease('aws-device-farm'); try { await runtime.leaseLifecycle.allocate?.(lease, awsRegressionContext()); @@ -205,9 +202,9 @@ test('AWS Device Farm sends the requested platform in WebDriver capabilities', a clientVersion: PROVIDER_REGRESSION_CLIENT_VERSION, runHostCommand: host.run, }), - CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm, + 'aws-device-farm', ); - const lease = providerRegressionLease(CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm); + const lease = providerRegressionLease('aws-device-farm'); try { await runtime.leaseLifecycle.allocate?.(lease, awsRegressionContext('ios')); assert.deepEqual(server.calls[0]?.body, { diff --git a/test/integration/provider-scenarios/stale-provider-runtime-admission.test.ts b/test/integration/provider-scenarios/stale-provider-runtime-admission.test.ts index 8c6a871741..d64e9e4085 100644 --- a/test/integration/provider-scenarios/stale-provider-runtime-admission.test.ts +++ b/test/integration/provider-scenarios/stale-provider-runtime-admission.test.ts @@ -24,7 +24,6 @@ import { awsRegressionContext, } from './cloud-webdriver-regression-fixtures.ts'; import { inspectProviderDeploymentAdmission } from './stale-provider-runtime-admission.fixtures.ts'; -import { CLOUD_WEBDRIVER_PROVIDERS } from '@agent-device/provider-webdriver/providers'; bindTestCommandHost(); @@ -171,14 +170,14 @@ test('an active AWS WebDriver device denies unsupported install from facts befor tenant: 'team-a', runId: 'run-a', leaseId, - leaseProvider: CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm, + leaseProvider: 'aws-device-farm', }; const meta = { tenantId: 'team-a', runId: 'run-a', leaseId, leaseBackend: 'android-instance' as const, - leaseProvider: CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm, + leaseProvider: 'aws-device-farm', deviceKey: 'provider-device-regression', clientId: 'client-a', }; @@ -248,9 +247,7 @@ async function awsWebDriverRuntime(host: AwsRemoteAccessHost) { clientVersion: 'test', runHostCommand: host.run, }); - const runtime = runtimes.find( - (candidate) => candidate.provider === CLOUD_WEBDRIVER_PROVIDERS.awsDeviceFarm, - ); + const runtime = runtimes.find((candidate) => candidate.provider === 'aws-device-farm'); if (!runtime) throw new Error('Expected AWS Device Farm WebDriver runtime'); return runtime; } From 98dfddb46ff137ceadf18560ab8a6aba10619613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 16 Nov 2026 21:12:52 +0100 Subject: [PATCH 13/13] fix(plugins): preserve supplied command host context --- packages/command-surface/src/replay/index.ts | 2 +- .../composite-resource-admission.fixtures.ts | 2 +- .../request-router-replay-plugin.test.ts | 2 +- packages/maestro/test/packed-runtime.mjs | 2 +- packages/plugins/src/connection.ts | 2 +- packages/plugins/src/host-command.test.ts | 129 +++++++++++++++++- packages/plugins/src/host.ts | 7 +- packages/plugins/src/load.test.ts | 2 +- packages/plugins/src/registry.ts | 29 ++-- packages/plugins/src/replay-backend.test.ts | 52 +++++-- .../__tests__/replay-backend-registry.test.ts | 2 +- .../daemon-port/replay-backend-registry.ts | 13 +- .../replay-port/src/script-source-bundle.ts | 2 +- packages/replay/src/plugin.test.ts | 9 +- scripts/capability-matrix/collect.ts | 2 +- scripts/fuzz/targets.ts | 2 +- src/__tests__/replay-plugin-setup.ts | 2 +- src/cli/commands/connection.ts | 2 +- src/cli/commands/replay.ts | 2 +- ...-provider-adapters-aws-device-farm.test.ts | 41 +++++- .../connection/connect-provider-adapters.ts | 7 +- src/provider-device-runtimes.ts | 2 +- src/provider-plugin-policy-revyl.test.ts | 6 +- src/provider-plugin-policy.test.ts | 2 +- .../provider-scenarios/aws-runtime.ts | 2 +- .../browserstack-runtime.ts | 2 +- .../cloud-webdriver-provider-adapters.test.ts | 2 +- 27 files changed, 274 insertions(+), 55 deletions(-) diff --git a/packages/command-surface/src/replay/index.ts b/packages/command-surface/src/replay/index.ts index e5bec6c644..3639075eba 100644 --- a/packages/command-surface/src/replay/index.ts +++ b/packages/command-surface/src/replay/index.ts @@ -319,7 +319,7 @@ export const testDaemonWriter: AsyncDaemonWriter = async (input, host, deps) => await import('@agent-device/replay-port/replay-backend-registry') ).withReplayBackend( 'maestro', - host.env, + host, (backend) => collectSources(async () => backend), deps?.resolveReplayBackend, ) diff --git a/packages/daemon/src/core/composite-resource-admission.fixtures.ts b/packages/daemon/src/core/composite-resource-admission.fixtures.ts index 8ba95b39db..7ec6fc4a89 100644 --- a/packages/daemon/src/core/composite-resource-admission.fixtures.ts +++ b/packages/daemon/src/core/composite-resource-admission.fixtures.ts @@ -211,7 +211,7 @@ export async function resourceAdmissionWorld( ] : []), ]), - input.host.env, + input.host, { adaptWebDriver: async () => { throw new Error('Resource fixture cannot create providers'); diff --git a/packages/daemon/src/server/__tests__/request-router-replay-plugin.test.ts b/packages/daemon/src/server/__tests__/request-router-replay-plugin.test.ts index 10c12915a4..ad297276f5 100644 --- a/packages/daemon/src/server/__tests__/request-router-replay-plugin.test.ts +++ b/packages/daemon/src/server/__tests__/request-router-replay-plugin.test.ts @@ -19,7 +19,7 @@ async function fixture(storeEnv?: NodeJS.ProcessEnv) { const discover = vi.fn(async () => []); const registry = await startProviderRegistry( await resolveProviderPlugins([]), - {}, + { env: {}, cwd: '/' }, { assertReplaySelectionCurrent: storeEnv ? createPluginSelectionGuard([], storeEnv) : undefined, adaptWebDriver: async () => { diff --git a/packages/maestro/test/packed-runtime.mjs b/packages/maestro/test/packed-runtime.mjs index 77e832e622..134c2dc5dc 100644 --- a/packages/maestro/test/packed-runtime.mjs +++ b/packages/maestro/test/packed-runtime.mjs @@ -47,7 +47,7 @@ const { default: maestroPlugin } = await import( async function registry() { const registry = await startProviderRegistry( await resolveProviderPlugins([{ source: 'embedder', load: () => maestroPlugin() }]), - {}, + { env: {}, cwd: '/' }, { adaptWebDriver: async () => { throw new Error('not a provider'); diff --git a/packages/plugins/src/connection.ts b/packages/plugins/src/connection.ts index 7012d89711..d91256e49f 100644 --- a/packages/plugins/src/connection.ts +++ b/packages/plugins/src/connection.ts @@ -8,7 +8,7 @@ import { storePluginCandidates } from './store.ts'; export type PluginConnectionCallbacks = Readonly<{ resolve(context: Omit): ReturnType; verify( - context: Omit, 'host'>, + context: Omit, 'host'>, ): ReturnType; }>; diff --git a/packages/plugins/src/host-command.test.ts b/packages/plugins/src/host-command.test.ts index 0f80ec3274..8f0ffe6c3b 100644 --- a/packages/plugins/src/host-command.test.ts +++ b/packages/plugins/src/host-command.test.ts @@ -13,8 +13,135 @@ test('plugin host runs commands with the AWS command bounds', async () => { }, async () => { await expect( - createPluginHost({}, undefined).runHostCommand('aws', ['devicefarm', 'get-project']), + createPluginHost({ env: {}, cwd: '/' }, undefined).runHostCommand('aws', [ + 'devicefarm', + 'get-project', + ]), ).resolves.toEqual({ stdout: '{"project":{}}' }); }, ); }); + +test('commands use the supplied host and overlay request environment without ambient values', async () => { + const { mkdtempForTestSync } = await import('@agent-device/test-kit'); + const { realpathSync } = await import('node:fs'); + const { withCommandHost } = await import('@agent-device/host-kit/command'); + const cwd = realpathSync(mkdtempForTestSync('plugin-command-host-')); + const host = { cwd, env: { PLUGIN_VALUE: 'host', HOST_ONLY: 'present' } }; + const pluginHost = createPluginHost(host, undefined); + const args = [ + '-e', + 'process.stdout.write(JSON.stringify({cwd:process.cwd(), value:process.env.PLUGIN_VALUE, hostOnly:process.env.HOST_ONLY, ambient:process.env.PLUGIN_AMBIENT}))', + ]; + const previous = process.env.PLUGIN_AMBIENT; + process.env.PLUGIN_AMBIENT = 'ambient'; + try { + const plain = await pluginHost.runHostCommand(process.execPath, args); + expect(JSON.parse(plain.stdout)).toEqual({ cwd, value: 'host', hostOnly: 'present' }); + const scoped = await withCommandHost({ host, requestEnv: { PLUGIN_VALUE: 'request' } }, () => + pluginHost.runHostCommand(process.execPath, args), + ); + expect(JSON.parse(scoped.stdout)).toEqual({ cwd, value: 'request', hostOnly: 'present' }); + } finally { + if (previous === undefined) delete process.env.PLUGIN_AMBIENT; + else process.env.PLUGIN_AMBIENT = previous; + } +}); + +test('connection resolve and verify use each call host independently', async () => { + const { mkdtempForTestSync } = await import('@agent-device/test-kit'); + const { realpathSync } = await import('node:fs'); + const { resolveProviderPlugins } = await import('./registry.ts'); + const dirs = [ + realpathSync(mkdtempForTestSync('plugin-resolve-')), + realpathSync(mkdtempForTestSync('plugin-verify-')), + ]; + const observed: unknown[] = []; + const run = async (host: import('./host.ts').ProviderPluginHost) => { + const result = await host.runHostCommand(process.execPath, [ + '-e', + 'process.stdout.write(JSON.stringify([process.cwd(), process.env.CONNECTION_VALUE]))', + ]); + observed.push(JSON.parse(result.stdout)); + }; + const { connections } = await resolveProviderPlugins([ + { + source: 'embedder', + load: () => ({ + apiVersion: 2, + provider: 'example', + credentials: { variables: [] }, + setup: () => ({}), + connection: { + capabilities: { + leaseKind: 'direct-device-provider', + requiresAppAttachment: false, + requiresRemoteDaemon: false, + supportsArtifacts: true, + supportsDeferredAppSelection: false, + supportsDirectPortReverse: false, + usesCloudWebDriverLease: true, + }, + resolve: async ({ host }: { host: import('./host.ts').ProviderPluginHost }) => { + await run(host); + return { profile: { leaseProvider: 'example', platform: 'ios' } }; + }, + verify: async ({ host }: { host: import('./host.ts').ProviderPluginHost }) => { + await run(host); + return { provider: 'example', service: 'example', verificationMessage: 'ok' }; + }, + }, + }), + }, + ]); + const connection = connections.get('example')!; + const flags = { json: false, help: false, version: false }; + await connection.resolve({ + flags, + stateDir: dirs[0]!, + cwd: dirs[0]!, + env: { CONNECTION_VALUE: 'resolve' }, + }); + await connection.verify({ flags, cwd: dirs[1]!, env: { CONNECTION_VALUE: 'verify' } }); + expect(observed).toEqual([ + [dirs[0], 'resolve'], + [dirs[1], 'verify'], + ]); +}); + +test('provider registry setup receives its supplied command host', async () => { + const { mkdtempForTestSync } = await import('@agent-device/test-kit'); + const { realpathSync } = await import('node:fs'); + const { resolveProviderPlugins, startProviderRegistry } = await import('./registry.ts'); + const cwd = realpathSync(mkdtempForTestSync('plugin-setup-host-')); + let observed: unknown; + const resolved = await resolveProviderPlugins([ + { + source: 'embedder', + load: () => ({ + apiVersion: 2, + provider: 'example', + credentials: { variables: [] }, + setup: async (host: import('./host.ts').ProviderPluginHost) => { + const result = await host.runHostCommand(process.execPath, [ + '-e', + 'process.stdout.write(JSON.stringify([process.cwd(), process.env.SETUP_VALUE]))', + ]); + observed = JSON.parse(result.stdout); + return { webDriver: { provider: 'example' } }; + }, + }), + }, + ]); + const registry = await startProviderRegistry( + resolved, + { cwd, env: { SETUP_VALUE: 'supplied' } }, + { + adaptWebDriver: async () => { + throw new Error('not needed for host assertion'); + }, + }, + ); + expect(observed).toEqual([cwd, 'supplied']); + await registry.close(); +}); diff --git a/packages/plugins/src/host.ts b/packages/plugins/src/host.ts index 941142d54c..c4fa07b30b 100644 --- a/packages/plugins/src/host.ts +++ b/packages/plugins/src/host.ts @@ -1,3 +1,4 @@ +import type { HostEnvironment } from '@agent-device/kernel/source-value'; import { AppError, type AppErrorCode, type AppErrorDetails } from '@agent-device/kernel/errors'; import { readVersion } from '@agent-device/host-kit/version'; @@ -17,17 +18,19 @@ export type ProviderPluginHost = Readonly<{ }>; export function createPluginHost( - env: NodeJS.ProcessEnv, + host: HostEnvironment, options: Record | undefined, ): ProviderPluginHost { return Object.freeze({ - env: Object.freeze({ ...env }), + env: Object.freeze({ ...host.env }), options: Object.freeze({ ...options }), clientVersion: readVersion(), createError: (code, message, details) => new AppError(code, message, details), runHostCommand: async (command, args) => { const { runCmd } = await import('@agent-device/host-kit/command'); const { stdout } = await runCmd(command, [...args], { + cwd: host.cwd, + env: host.env, maxBuffer: 10 * 1024 * 1024, timeoutMs: 30_000, }); diff --git a/packages/plugins/src/load.test.ts b/packages/plugins/src/load.test.ts index d18fca5ce5..7d3eefc12d 100644 --- a/packages/plugins/src/load.test.ts +++ b/packages/plugins/src/load.test.ts @@ -45,7 +45,7 @@ async function startStore(env: NodeJS.ProcessEnv, builtin: readonly string[] = [ ...claimProviderIds(builtin), ...(await storePluginCandidates(env)), ]); - return await startProviderRegistry(resolved, env, FAKE_POLICY); + return await startProviderRegistry(resolved, { env, cwd: '/' }, FAKE_POLICY); } test('a store plugin loads its factory with the selection options and the host error constructor', async () => { diff --git a/packages/plugins/src/registry.ts b/packages/plugins/src/registry.ts index d5c4e47b2a..a83201326b 100644 --- a/packages/plugins/src/registry.ts +++ b/packages/plugins/src/registry.ts @@ -1,3 +1,4 @@ +import type { HostEnvironment } from '@agent-device/kernel/source-value'; import { NATIVE_REPLAY_BACKEND } from '@agent-device/contracts/replay-execution'; import type { ReplayExecution, @@ -179,15 +180,15 @@ export async function resolveProviderPlugins( */ export async function startProviderRegistry( resolved: ResolvedProviderPlugins, - env: NodeJS.ProcessEnv, + host: HostEnvironment, policy: PluginRegistryPolicy, scope: 'all' | 'replay-backends' = 'all', ): Promise { for (const slot of resolved.slots) { if (slot.failure !== undefined) continue; try { - if (slot.replayPlugin) await setUpReplaySlot(slot, slot.replayPlugin, env); - else if (slot.plugin && scope === 'all') await setUpSlot(slot, slot.plugin, env, policy); + if (slot.replayPlugin) await setUpReplaySlot(slot, slot.replayPlugin, host); + else if (slot.plugin && scope === 'all') await setUpSlot(slot, slot.plugin, host, policy); } catch (error) { slot.failure = asPluginFailure(error, 'plugin_setup_failed'); slot.registration = undefined; @@ -299,9 +300,9 @@ function claimProvider(slot: Slot, claimed: Set): void { async function setUpReplaySlot( slot: Slot, plugin: ReplayEnginePlugin, - env: NodeJS.ProcessEnv, + host: HostEnvironment, ): Promise { - const result = await plugin.setup(createPluginHost(env, slot.candidate.hostOptions)); + const result = await plugin.setup(createPluginHost(host, slot.candidate.hostOptions)); try { slot.replaySetup = validateReplayEngineSetup(result, plugin.backend); } catch (error) { @@ -406,25 +407,31 @@ function withConnectionHost( return { capabilities: connection.capabilities, resolve: (context) => - connection.resolve({ ...context, host: createPluginHost(context.env, hostOptions) }), + connection.resolve({ + ...context, + host: createPluginHost({ env: context.env, cwd: context.cwd }, hostOptions), + }), verify: (context) => - connection.verify({ ...context, host: createPluginHost(context.env, hostOptions) }), + connection.verify({ + ...context, + host: createPluginHost({ env: context.env, cwd: context.cwd }, hostOptions), + }), }; } async function setUpSlot( slot: Slot, plugin: AgentDevicePlugin, - env: NodeJS.ProcessEnv, + host: HostEnvironment, policy: PluginRegistryPolicy, ): Promise { - const host = createPluginHost(env, slot.candidate.hostOptions); - const result = await plugin.setup(host); + const pluginHost = createPluginHost(host, slot.candidate.hostOptions); + const result = await plugin.setup(pluginHost); try { const { runtime, platformModule } = await buildRegistration( plugin, result, - host.clientVersion, + pluginHost.clientVersion, policy, ); const dispose = result.dispose?.bind(result); diff --git a/packages/plugins/src/replay-backend.test.ts b/packages/plugins/src/replay-backend.test.ts index 1db62c668e..603b929790 100644 --- a/packages/plugins/src/replay-backend.test.ts +++ b/packages/plugins/src/replay-backend.test.ts @@ -39,7 +39,11 @@ function engine(backend = 'maestro') { test('managed replay setup stays lazy and retains one backend and one cleanup owner', async () => { const e = engine(); const resolved = await resolveProviderPlugins([candidate(e.plugin)]); - const registry = await startProviderRegistry(resolved, { TOKEN: 'host-value' }, policy); + const registry = await startProviderRegistry( + resolved, + { env: { TOKEN: 'host-value' }, cwd: '/' }, + policy, + ); expect(e.create).not.toHaveBeenCalled(); expect(e.setup.mock.calls[0]?.[0]).toMatchObject({ env: { TOKEN: 'host-value' } }); expect(registry.registrations).toEqual([]); @@ -78,7 +82,7 @@ test('backend identity is separate from provider identity and first failure clai candidate(engine().plugin), candidate(other.plugin), ]); - const registry = await startProviderRegistry(resolved, {}, policy); + const registry = await startProviderRegistry(resolved, { env: {}, cwd: '/' }, policy); expect(registry.claimedProviders).toEqual([]); expect(registry.inventory).toMatchObject([ { backend: 'maestro', state: 'failed', error: { reason: 'incompatible_plugin' } }, @@ -104,7 +108,7 @@ test('setup failures stay permanent while failed lazy loads can retry without fa load.create.mockRejectedValueOnce(new Error('engine failed')); const registry = await startProviderRegistry( await resolveProviderPlugins([candidate(setup.plugin), candidate(load.plugin)]), - {}, + { env: {}, cwd: '/' }, policy, ); await expect(registry.resolveReplayBackend('absent', host)).rejects.toMatchObject({ @@ -145,7 +149,7 @@ test('the registry rejects the wrong runtime id and cleans up an invalid setup', const invalid = { ...engine('invalid').plugin, setup: () => ({ replayBackend: {}, dispose }) }; const registry = await startProviderRegistry( await resolveProviderPlugins([candidate(wrong.plugin), candidate(invalid)]), - {}, + { env: {}, cwd: '/' }, policy, ); await expect(registry.resolveReplayBackend('wrong', host)).rejects.toMatchObject({ @@ -170,7 +174,7 @@ test('one backend disposer cannot delay another backend disposer', async () => { ); const registry = await startProviderRegistry( await resolveProviderPlugins([candidate(first.plugin), candidate(second.plugin)]), - {}, + { env: {}, cwd: '/' }, policy, ); const closing = registry.close(); @@ -213,7 +217,7 @@ test('native execution retries failed lazy loads while sharing claims, caching a }), candidate(competingPlugin), ]), - {}, + { env: {}, cwd: '/' }, policy, ); expect(registry.inventory).toMatchObject([ @@ -277,7 +281,7 @@ test.each([ ...override, }), ]), - {}, + { env: {}, cwd: '/' }, policy, ); await expect(registry.resolveReplayExecution()).rejects.toMatchObject({ details: { reason } }); @@ -304,7 +308,7 @@ test('wrong native capability fails inventory, disposes setup and keeps its firs candidate({ apiVersion: 2, kind: 'replay-backend', backend: 'ad', setup: laterSetup }), candidate(engine('maestro').plugin), ]), - {}, + { env: {}, cwd: '/' }, policy, ); expect(registry.inventory).toMatchObject([ @@ -336,7 +340,7 @@ test('a package name cannot select an active foreign backend for native executio }, }, ]), - {}, + { env: {}, cwd: '/' }, policy, ); try { @@ -364,7 +368,7 @@ test('a selected native package load failure cannot masquerade as absence by its }, }, ]), - {}, + { env: {}, cwd: '/' }, policy, ); try { @@ -379,3 +383,31 @@ test('a selected native package load failure cannot masquerade as absence by its await registry.close(); } }); + +test('replay setup receives the supplied command host', async () => { + const { mkdtempForTestSync } = await import('@agent-device/test-kit'); + const { realpathSync } = await import('node:fs'); + const cwd = realpathSync(mkdtempForTestSync('plugin-replay-host-')); + let result = ''; + const e = engine(); + const plugin = { + ...e.plugin, + setup: async (pluginHost: ProviderPluginHost) => { + result = ( + await pluginHost.runHostCommand(process.execPath, [ + '-e', + 'process.stdout.write(JSON.stringify([process.cwd(), process.env.REPLAY_HOST_VALUE]))', + ]) + ).stdout; + return e.setup(pluginHost); + }, + }; + const registry = await startProviderRegistry( + await resolveProviderPlugins([candidate(plugin)]), + { cwd, env: { REPLAY_HOST_VALUE: 'supplied' } }, + policy, + 'replay-backends', + ); + expect(JSON.parse(result)).toEqual([cwd, 'supplied']); + await registry.close(); +}); diff --git a/packages/replay-port/src/daemon-port/__tests__/replay-backend-registry.test.ts b/packages/replay-port/src/daemon-port/__tests__/replay-backend-registry.test.ts index ad78c840db..238784af79 100644 --- a/packages/replay-port/src/daemon-port/__tests__/replay-backend-registry.test.ts +++ b/packages/replay-port/src/daemon-port/__tests__/replay-backend-registry.test.ts @@ -38,7 +38,7 @@ test('client replay absence does not evaluate unrelated provider packages', asyn fs.writeFileSync(${JSON.stringify(evaluated)}, 'evaluated'); throw new Error('Unrelated provider import');`, ); - await expect(openReplayBackend('maestro', env)).rejects.toMatchObject({ + await expect(openReplayBackend('maestro', { env, cwd: '/' })).rejects.toMatchObject({ details: { reason: 'plugin-not-installed', package: '@agent-device/maestro', diff --git a/packages/replay-port/src/daemon-port/replay-backend-registry.ts b/packages/replay-port/src/daemon-port/replay-backend-registry.ts index f74f1b8ad0..5811900a96 100644 --- a/packages/replay-port/src/daemon-port/replay-backend-registry.ts +++ b/packages/replay-port/src/daemon-port/replay-backend-registry.ts @@ -1,3 +1,4 @@ +import type { HostEnvironment } from '@agent-device/kernel/source-value'; import type { ReplayExecution, ReplayExecutionResolver, @@ -63,12 +64,12 @@ async function resolveBackend( /** Uses the embedded registry, or owns a client-side store scope until the task settles. */ export async function withReplayBackend( id: ReplayBackendId, - env: NodeJS.ProcessEnv, + host: HostEnvironment, run: (backend: ReplayBackend) => Promise | T, resolve?: ReplayBackendResolver, ): Promise { if (resolve) return await run(await resolveBackend(id, resolve)); - const scope = await openReplayBackend(id, env); + const scope = await openReplayBackend(id, host); try { return await run(scope.backend); } finally { @@ -77,7 +78,7 @@ export async function withReplayBackend( } /** A client/tooling scope owns its plugin registry until close. It never starts providers. */ -export async function openReplayBackend(id: ReplayBackendId, env: NodeJS.ProcessEnv) { +export async function openReplayBackend(id: ReplayBackendId, host: HostEnvironment) { const { AppError } = await import('@agent-device/kernel/errors'); const packageName = await backendPackage(id); const [{ storePluginCandidates }, { resolveProviderPlugins, startProviderRegistry }] = @@ -87,9 +88,11 @@ export async function openReplayBackend(id: ReplayBackendId, env: NodeJS.Process ]); const registry = await startProviderRegistry( await resolveProviderPlugins( - (await storePluginCandidates(env)).filter((candidate) => candidate.package === packageName), + (await storePluginCandidates(host.env)).filter( + (candidate) => candidate.package === packageName, + ), ), - env, + host, { adaptWebDriver: async () => { throw new AppError('INVALID_ARGS', 'Client replay scope cannot start a provider'); diff --git a/packages/replay-port/src/script-source-bundle.ts b/packages/replay-port/src/script-source-bundle.ts index 97d4715610..b448a204bd 100644 --- a/packages/replay-port/src/script-source-bundle.ts +++ b/packages/replay-port/src/script-source-bundle.ts @@ -32,7 +32,7 @@ export async function loadReplayScriptSourceBundle( await import('@agent-device/replay-port/replay-backend-registry') ).withReplayBackend( backendId, - params.hostEnv, + { env: params.hostEnv, cwd: params.cwd }, (backend) => backend.collectSourceFiles({ entryPath: entry, diff --git a/packages/replay/src/plugin.test.ts b/packages/replay/src/plugin.test.ts index 1e549a3e5d..b76d5e3db5 100644 --- a/packages/replay/src/plugin.test.ts +++ b/packages/replay/src/plugin.test.ts @@ -9,7 +9,7 @@ import replayPlugin from './plugin.ts'; test('the first-party factory uses the managed registry and preserves native script syntax', async () => { const registry = await startProviderRegistry( await resolveProviderPlugins([{ source: 'embedder', load: replayPlugin }]), - {}, + { env: {}, cwd: '/' }, { adaptWebDriver: async () => { throw new Error('Replay cannot create providers'); @@ -65,7 +65,7 @@ test('the first-party factory uses the managed registry and preserves native scr }); test.each(['0.23.0', '0.21.39-dev'])('the package rejects unverified core %s', (clientVersion) => { - const host = { ...createPluginHost({}, undefined), clientVersion }; + const host = { ...createPluginHost({ env: {}, cwd: '/' }, undefined), clientVersion }; expect(() => replayPlugin().setup(host)).toThrow( expect.objectContaining({ details: expect.objectContaining({ reason: 'incompatible_plugin' }), @@ -77,7 +77,10 @@ test.each(['0.21.38-dev', '0.22.0-beta.1', '0.22.0'])( 'the package accepts declared core %s', (clientVersion) => { expect( - replayPlugin().setup({ ...createPluginHost({}, undefined), clientVersion }), + replayPlugin().setup({ + ...createPluginHost({ env: {}, cwd: '/' }, undefined), + clientVersion, + }), ).toMatchObject({ execution: { create: expect.any(Function) } }); }, ); diff --git a/scripts/capability-matrix/collect.ts b/scripts/capability-matrix/collect.ts index ecac3d78c5..2c3e7b08ca 100644 --- a/scripts/capability-matrix/collect.ts +++ b/scripts/capability-matrix/collect.ts @@ -131,7 +131,7 @@ async function cloudWebDriverOptions( if (!plugin_.setup) throw new Error(`The ${plugin} plugin exposes no setup() to build a WebDriver from.`); const created = (await plugin_.setup({ - ...createPluginHost(PROVIDER_ENV, undefined), + ...createPluginHost({ env: PROVIDER_ENV, cwd: '/' }, undefined), clientVersion: '0.0.0', runHostCommand, })) as { diff --git a/scripts/fuzz/targets.ts b/scripts/fuzz/targets.ts index d222bbd0a5..56dd2ccf71 100644 --- a/scripts/fuzz/targets.ts +++ b/scripts/fuzz/targets.ts @@ -18,7 +18,7 @@ import type { ReplayBackend } from '@agent-device/contracts/replay-backend'; let inspectMaestroFlow: ReplayBackend['inspectSource']; async function prepareMaestro(): Promise<() => Promise> { - const scope = await openReplayBackend('maestro', process.env); + const scope = await openReplayBackend('maestro', { env: process.env, cwd: process.cwd() }); inspectMaestroFlow = scope.backend.inspectSource; return async () => { await scope.close(); diff --git a/src/__tests__/replay-plugin-setup.ts b/src/__tests__/replay-plugin-setup.ts index e92e4463d8..b17fda0184 100644 --- a/src/__tests__/replay-plugin-setup.ts +++ b/src/__tests__/replay-plugin-setup.ts @@ -19,7 +19,7 @@ beforeEach(async () => { ]); registry = await startProviderRegistry( await resolveProviderPlugins(await storePluginCandidates(process.env)), - process.env, + { env: process.env, cwd: process.cwd() }, { adaptWebDriver: async () => { throw new Error('Replay test setup cannot start providers'); diff --git a/src/cli/commands/connection.ts b/src/cli/commands/connection.ts index 9ebcafac2a..51ec9254f4 100644 --- a/src/cli/commands/connection.ts +++ b/src/cli/commands/connection.ts @@ -96,7 +96,7 @@ export const connectCommand: ClientCommandHandler = async ({ connection: connectionMetadata, daemon: context.daemon, }); - const verification = await verifyResolvedConnectProvider(resolved, host.env); + const verification = await verifyResolvedConnectProvider(resolved, host); const state = buildConnectedState({ flags: connectFlags, scope, diff --git a/src/cli/commands/replay.ts b/src/cli/commands/replay.ts index 0002cf2bc7..d4dcfa10a2 100644 --- a/src/cli/commands/replay.ts +++ b/src/cli/commands/replay.ts @@ -45,7 +45,7 @@ async function handleReplayExportCommand({ // lazily by the router, and the engine sits one further thunk behind the backend. const result = await ( await import('@agent-device/replay-port/replay-backend-registry') - ).withReplayBackend('maestro', host.env, (backend) => + ).withReplayBackend('maestro', host, (backend) => backend.exportReplayScript(parsed.actions, { actionLines: parsed.actionLines, metadata: readReplayScriptMetadata(script), diff --git a/src/cli/connection/connect-provider-adapters-aws-device-farm.test.ts b/src/cli/connection/connect-provider-adapters-aws-device-farm.test.ts index 4bd463a3d3..9347e75a66 100644 --- a/src/cli/connection/connect-provider-adapters-aws-device-farm.test.ts +++ b/src/cli/connection/connect-provider-adapters-aws-device-farm.test.ts @@ -11,7 +11,10 @@ import { AppError } from '@agent-device/kernel/errors'; import { verifyAwsDeviceFarmConnection } from '@agent-device/aws-device-farm/connection-verification'; import awsDeviceFarm from '@agent-device/aws-device-farm'; import { resolveProviderPlugins } from '@agent-device/plugins/registry'; -import { resolveConnectProviderProfile } from './connect-provider-adapters.ts'; +import { + resolveConnectProviderProfile, + verifyResolvedConnectProvider, +} from './connect-provider-adapters.ts'; import { mkdtempForTestSync, pluginHome, @@ -49,6 +52,42 @@ afterEach(() => { const mockedVerifyAwsDeviceFarmConnection = vi.mocked(verifyAwsDeviceFarmConnection); +test('connection verification carries the caller host to the provider command', async () => { + const cwd = fs.realpathSync(mkdtempForTestSync('connect-aws-host-')); + let observed: unknown; + mockedVerifyAwsDeviceFarmConnection.mockImplementationOnce(async (_options, run) => { + const result = await run(process.execPath, [ + '-e', + 'process.stdout.write(JSON.stringify([process.cwd(), process.env.CONNECT_HOST_VALUE]))', + ]); + observed = JSON.parse(result.stdout); + return { + provider: 'aws-device-farm', + service: 'AWS Device Farm', + verificationMessage: 'ok', + project: { reference: 'project' }, + device: { status: 'verified' }, + app: { status: 'missing' }, + }; + }); + await verifyResolvedConnectProvider( + { + provider: 'aws-device-farm', + remoteConfigPath: '/unused', + flags: { + json: false, + help: false, + version: false, + platform: 'ios', + awsProjectArn: 'project', + awsDeviceArn: 'device', + }, + }, + { cwd, env: { CONNECT_HOST_VALUE: 'supplied' } }, + ); + assert.deepEqual(observed, [cwd, 'supplied']); +}); + let pluginHomeDir = ''; beforeEach(() => { diff --git a/src/cli/connection/connect-provider-adapters.ts b/src/cli/connection/connect-provider-adapters.ts index 93d2ee33f6..2928340f66 100644 --- a/src/cli/connection/connect-provider-adapters.ts +++ b/src/cli/connection/connect-provider-adapters.ts @@ -6,7 +6,7 @@ import { readVersion } from '@agent-device/host-kit/version'; import { leaseBackendForPlatform } from '@agent-device/kernel/contracts'; import { AppError } from '@agent-device/kernel/errors'; import { resolveRemoteConfigProfile } from '@agent-device/remote/remote-config'; -import { type EnvMap } from '@agent-device/kernel/source-value'; +import { type EnvMap, type HostEnvironment } from '@agent-device/kernel/source-value'; import { resolveCloudConnectProfile } from './cloud-profile.ts'; import { resolveLimrunConnectProfile } from './limrun-profile.ts'; @@ -182,7 +182,7 @@ async function resolveProviderConnectionProfile( export async function verifyResolvedConnectProvider( resolved: ResolvedConnectProfile, - env: EnvMap, + host: HostEnvironment, ): Promise { if (!resolved.provider) { return { @@ -194,7 +194,8 @@ export async function verifyResolvedConnectProvider( } const context = { flags: resolved.flags, - env, + env: host.env, + cwd: host.cwd, }; const adapter = builtinConnectAdapter(resolved.provider); return adapter diff --git a/src/provider-device-runtimes.ts b/src/provider-device-runtimes.ts index 72437a93d2..7bc8e5c990 100644 --- a/src/provider-device-runtimes.ts +++ b/src/provider-device-runtimes.ts @@ -55,7 +55,7 @@ async function composeProviderRuntime( ...builtinProviderCandidates(host), ...candidates, ]); - const registry = await startProviderRegistry(resolved, host.env, policy); + const registry = await startProviderRegistry(resolved, host, policy); return Object.freeze({ runtimes: Object.freeze(registry.registrations.map(({ runtime }) => runtime)), platformModules: Object.freeze( diff --git a/src/provider-plugin-policy-revyl.test.ts b/src/provider-plugin-policy-revyl.test.ts index 7dda569b79..8af8ca0127 100644 --- a/src/provider-plugin-policy-revyl.test.ts +++ b/src/provider-plugin-policy-revyl.test.ts @@ -51,7 +51,11 @@ test('a Revyl device the shutdown could not stop is named in the message and hin const resolved = await resolveProviderPlugins([ { source: 'embedder', provider: 'revyl', load: () => revyl({ apiKey: 'test-key', apiUrl }) }, ]); - const registry = await startProviderRegistry(resolved, {}, PROVIDER_PLUGIN_POLICY); + const registry = await startProviderRegistry( + resolved, + { env: {}, cwd: '/' }, + PROVIDER_PLUGIN_POLICY, + ); const runtime = registry.registrations[0]!.runtime; const lease: DeviceLease = { leaseId: 'lease-1', diff --git a/src/provider-plugin-policy.test.ts b/src/provider-plugin-policy.test.ts index 7112f36bb2..2bcd3fa89f 100644 --- a/src/provider-plugin-policy.test.ts +++ b/src/provider-plugin-policy.test.ts @@ -30,7 +30,7 @@ async function startStoreRegistry(env: NodeJS.ProcessEnv) { ...claimProviderIds([]), ...(await storePluginCandidates(env)), ]); - return await startProviderRegistry(resolved, env, PROVIDER_PLUGIN_POLICY); + return await startProviderRegistry(resolved, { env, cwd: '/' }, PROVIDER_PLUGIN_POLICY); } afterEach(() => { diff --git a/test/integration/provider-scenarios/aws-runtime.ts b/test/integration/provider-scenarios/aws-runtime.ts index e9919d5b00..75dcd028b9 100644 --- a/test/integration/provider-scenarios/aws-runtime.ts +++ b/test/integration/provider-scenarios/aws-runtime.ts @@ -12,7 +12,7 @@ async function awsDeviceFarmWebDriver( runHostCommand: RunHostCommand, ) { const setup = await awsDeviceFarm().setup({ - ...createPluginHost(env, undefined), + ...createPluginHost({ env, cwd: '/' }, undefined), clientVersion, runHostCommand, }); diff --git a/test/integration/provider-scenarios/browserstack-runtime.ts b/test/integration/provider-scenarios/browserstack-runtime.ts index cb1f15c622..7a73bffa7e 100644 --- a/test/integration/provider-scenarios/browserstack-runtime.ts +++ b/test/integration/provider-scenarios/browserstack-runtime.ts @@ -7,7 +7,7 @@ export const BROWSERSTACK_PROVIDER = 'browserstack'; /** The WebDriver descriptor the BrowserStack plugin's `setup` builds from `env`, as `clientVersion` hosted. */ export async function browserStackWebDriver(env: Record, clientVersion: string) { const setup = await browserstack().setup({ - ...createPluginHost(env, undefined), + ...createPluginHost({ env, cwd: '/' }, undefined), clientVersion, }); if (!('webDriver' in setup)) throw new Error('BrowserStack sets up a WebDriver descriptor'); diff --git a/test/integration/provider-scenarios/cloud-webdriver-provider-adapters.test.ts b/test/integration/provider-scenarios/cloud-webdriver-provider-adapters.test.ts index aac37b23b4..8852e9c5c9 100644 --- a/test/integration/provider-scenarios/cloud-webdriver-provider-adapters.test.ts +++ b/test/integration/provider-scenarios/cloud-webdriver-provider-adapters.test.ts @@ -180,7 +180,7 @@ test('AWS Device Farm facade rejects device features it does not read at session }, 15_000); async function testMuWebDriver(env: Record) { - const setup = await testmu().setup(createPluginHost(env, undefined)); + const setup = await testmu().setup(createPluginHost({ env, cwd: '/' }, undefined)); if (!('webDriver' in setup)) throw new Error('TestMu AI sets up a WebDriver descriptor'); return setup.webDriver; }