Skip to content

Commit a304bb7

Browse files
thymikeeclaude
andcommitted
refactor(provider-testmu): the v2 factory owns the provider and reads capabilities from package.json
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent d2b004c commit a304bb7

8 files changed

Lines changed: 195 additions & 183 deletions

File tree

‎.fallowrc.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@
9999
"file": "packages/provider-*/src/index.ts",
100100
"exports": ["default"]
101101
},
102+
{
103+
// The version 1 entry a provider package's `agentDevicePlugin.entry` names; hosts without the version 2 contract import the built file and read `default`.
104+
"file": "packages/provider-*/src/plugin.ts",
105+
"exports": ["default"]
106+
},
102107
{
103108
// packages/platform-apple/src/lifecycle.ts loads this module on demand and reads the member off the memoized import() promise, which Fallow cannot follow.
104109
"file": "packages/platform-apple/src/expo-dev-client-launch.ts",

‎packages/provider-testmu/src/connection.ts‎

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
rejectRefusedProviderProfileFields,
55
requireResolvedProfilePlatform,
66
requireResolvedProfileValue,
7-
type ProviderProfileFieldDeclaration,
87
} from '@agent-device/contracts/provider-profile-fields';
98
import {
109
requireConnectFlag,
@@ -16,30 +15,17 @@ import {
1615
isTestMuAppReference,
1716
requireTestMuCredentials,
1817
} from './providers.ts';
18+
import { TESTMU_PROFILE_FIELDS } from './profile-fields.ts';
1919
import { verifyTestMuConnection } from './testmu-connection-verification.ts';
2020
import { readTestMuDeviceFeatureFields, readTestMuDeviceType } from './testmu-device-features.ts';
2121

22-
/** Mirrors `agentDevicePlugin.connection` in package.json, which hosts without the version 2 contract read. */
23-
export const TESTMU_CONNECTION = {
24-
leaseKind: 'direct-device-provider',
25-
requiresAppAttachment: false,
26-
requiresRemoteDaemon: false,
27-
supportsArtifacts: true,
28-
supportsDeferredAppSelection: false,
29-
supportsDirectPortReverse: false,
30-
usesCloudWebDriverLease: true,
31-
} as const;
32-
3322
const PROVIDER = 'testmu';
3423
const SERVICE = 'TestMu AI';
3524

36-
export function createTestMuConnection(
37-
host: ProviderPluginHost,
38-
fields: ProviderProfileFieldDeclaration,
39-
) {
25+
export function createTestMuConnection(host: ProviderPluginHost) {
4026
return {
4127
resolve: ({ flags, cwd }: { flags: CliFlags; cwd: string }) => {
42-
rejectRefusedProviderProfileFields(flags, fields);
28+
rejectRefusedProviderProfileFields(flags, TESTMU_PROFILE_FIELDS);
4329
requireTestMuCredentials(host.env, `connect ${PROVIDER}`);
4430
const platform = requireConnectPlatform(flags, PROVIDER);
4531
const app = connectAppReference(

‎packages/provider-testmu/src/index.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ test('connect uses the option credentials without an environment and verifies wi
106106
],
107107
['opt-user', 'opt-key'],
108108
);
109-
assert.throws(
110-
() =>
111-
testmu().connection!.resolve({
109+
await assert.rejects(
110+
async () =>
111+
await testmu().connection!.resolve({
112112
flags,
113113
stateDir: '/state',
114114
cwd: '/work',

‎packages/provider-testmu/src/index.ts‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import type { AgentDevicePlugin, ProviderPluginHost } from 'agent-device/plugins';
2-
import { TESTMU_CONNECTION } from './connection.ts';
3-
import testMuV1Plugin from './plugin.ts';
2+
import manifest from '../package.json' with { type: 'json' };
3+
4+
type ConnectionCapabilities = NonNullable<AgentDevicePlugin['connection']>['capabilities'];
45

56
export type TestmuOptions = {
67
/** Used instead of `LT_USERNAME` and `LT_ACCESS_KEY` when set. */
78
credentials?: { username: string; accessKey: string };
89
};
910

11+
// The connection and WebDriver code load when they are first used, so importing the package for its
12+
// declaration stays small.
13+
async function loadConnection(host: ProviderPluginHost) {
14+
return (await import('./connection.ts')).createTestMuConnection(host);
15+
}
16+
1017
/**
1118
* TestMu AI as a plugin. The credentials come from `options.credentials`, with the
1219
* `LT_USERNAME` and `LT_ACCESS_KEY` environment variables as the fallback for each key the options
@@ -38,13 +45,19 @@ function testmu(options: TestmuOptions = {}): AgentDevicePlugin {
3845
provider: 'testmu',
3946
credentials: { variables: environmentVariables },
4047
connection: {
41-
capabilities: TESTMU_CONNECTION,
42-
resolve: (context) =>
43-
testMuV1Plugin(withCredentials(context.host)).connection.resolve(context),
48+
// The declaration hosts without the version 2 contract read from package.json; the registry
49+
// validates it when the plugin loads.
50+
capabilities: manifest.agentDevicePlugin.connection as ConnectionCapabilities,
51+
resolve: async (context) =>
52+
(await loadConnection(withCredentials(context.host))).resolve(context),
4453
verify: async (context) =>
45-
await testMuV1Plugin(withCredentials(context.host)).connection.verify(context),
54+
await (await loadConnection(withCredentials(context.host))).verify(context),
4655
},
47-
setup: (host) => ({ webDriver: testMuV1Plugin(withCredentials(host)).webDriver }),
56+
setup: async (host) => ({
57+
webDriver: (await import('./testmu-webdriver.ts')).createTestMuWebDriver(
58+
withCredentials(host),
59+
),
60+
}),
4861
};
4962
}
5063

Lines changed: 2 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,8 @@
11
import type { ProviderPluginHost } from 'agent-device/plugins';
2-
import type { WebDriverPluginOptions } from 'agent-device/plugins/webdriver';
3-
import type { ProviderProfileFieldDeclaration } from '@agent-device/contracts/provider-profile-fields';
4-
import type { ProviderDeviceType } from '@agent-device/contracts/remote';
5-
import {
6-
buildCloudWebDriverBaseCapabilities,
7-
readFlag,
8-
requireFlag,
9-
requireRequest,
10-
requireRequestPlatform,
11-
} from '@agent-device/provider-webdriver/plugin';
122
import { createTestMuConnection } from './connection.ts';
13-
import { requireTestMuCredentials } from './providers.ts';
14-
import {
15-
buildTestMuCapabilities,
16-
createTestMuUploadApp,
17-
listTestMuCloudArtifacts,
18-
resolveTestMuAppReference,
19-
} from './testmu.ts';
20-
import {
21-
buildTestMuDeviceFeatureCapabilities,
22-
readTestMuDeviceFeatureFields,
23-
readTestMuDeviceType,
24-
} from './testmu-device-features.ts';
25-
const TESTMU_WEBDRIVER_ENDPOINT = 'https://mobile-hub.lambdatest.com/wd/hub/';
26-
const TESTMU_CAPABILITY_OVERRIDES = {
27-
install: {
28-
support: 'partial',
29-
note: 'Local app artifacts are uploaded to TestMu AI as real- or virtual-device apps (lt://), then installed with Appium.',
30-
},
31-
portReverse: {
32-
support: 'unsupported',
33-
note: 'Use the TestMu AI tunnel for network access to local hosts; agent-device port reverse is not available.',
34-
},
35-
artifacts: {
36-
support: 'supported',
37-
note: 'TestMu AI session details expose provider-hosted video, Appium logs, device logs, network logs, and dashboard links.',
38-
},
39-
} as const;
40-
41-
const TESTMU_PROFILE_FIELDS: ProviderProfileFieldDeclaration = {
42-
provider: 'testmu',
43-
label: 'TestMu AI',
44-
fields: {
45-
providerApp: 'consumed',
46-
providerOsVersion: 'consumed',
47-
providerDeviceType: 'consumed',
48-
providerProject: 'consumed',
49-
providerBuild: 'consumed',
50-
providerSessionName: 'consumed',
51-
providerDeviceOrientation: 'consumed',
52-
providerGeoLocation: 'consumed',
53-
providerTimezone: 'consumed',
54-
providerAppiumVersion: 'consumed',
55-
providerLanguage: 'consumed',
56-
providerLocale: 'consumed',
57-
providerNetworkProfile: 'refused',
58-
providerCustomNetwork: 'refused',
59-
providerNoResignApp: 'refused',
60-
awsProjectArn: 'refused',
61-
awsDeviceArn: 'refused',
62-
awsAppArn: 'refused',
63-
awsRegion: 'refused',
64-
awsInteractionMode: 'refused',
65-
},
66-
};
3+
import { createTestMuWebDriver } from './testmu-webdriver.ts';
674

685
/** The version 1 plugin entry, kept so hosts without the version 2 contract still load this package. */
696
export default function testMuPlugin(host: ProviderPluginHost) {
70-
return {
71-
webDriver: createTestMuWebDriver(host),
72-
connection: createTestMuConnection(host, TESTMU_PROFILE_FIELDS),
73-
};
74-
}
75-
76-
function createTestMuWebDriver(host: ProviderPluginHost): WebDriverPluginOptions {
77-
const env = host.env;
78-
async function listTestMuArtifactsFromEnv(
79-
provider: string,
80-
providerSessionId: string | undefined,
81-
env: ProviderPluginHost['env'],
82-
) {
83-
return await listTestMuCloudArtifacts(provider, providerSessionId, {
84-
clientVersion: host.clientVersion,
85-
...requireTestMuCredentials(env, 'TestMu AI artifact lookup'),
86-
endpoint: env.TESTMU_API_ENDPOINT,
87-
});
88-
}
89-
const webDriver: WebDriverPluginOptions = {
90-
provider: 'testmu',
91-
profileFields: TESTMU_PROFILE_FIELDS,
92-
platform: 'android',
93-
deviceName: 'TestMu AI device',
94-
endpoint: env.TESTMU_WEBDRIVER_ENDPOINT ?? TESTMU_WEBDRIVER_ENDPOINT,
95-
capabilityOverrides: TESTMU_CAPABILITY_OVERRIDES,
96-
listArtifacts: async ({ provider, providerSessionId }) =>
97-
await listTestMuArtifactsFromEnv(provider, providerSessionId, env),
98-
prepareSession: async ({ req, lease, base }) => {
99-
const request = requireRequest(req, 'TestMu AI');
100-
const deviceType = readTestMuDeviceType(request.flags);
101-
const uploadEndpoint = testMuAppUploadEndpoint(env, deviceType);
102-
const credentials = requireTestMuCredentials(env, 'TestMu AI');
103-
const platform = requireRequestPlatform(request, 'TestMu AI');
104-
const deviceName = requireFlag(request, 'device', 'TestMu AI requires --device <name>.');
105-
const osVersion = requireFlag(
106-
request,
107-
'providerOsVersion',
108-
'TestMu AI requires --provider-os-version <version>.',
109-
);
110-
const upload = {
111-
clientVersion: host.clientVersion,
112-
113-
...credentials,
114-
deviceType,
115-
endpoint: uploadEndpoint,
116-
};
117-
const app = await resolveTestMuAppReference(
118-
requireFlag(
119-
request,
120-
'providerApp',
121-
'TestMu AI requires --provider-app <lt://app-id, URL, or local path>.',
122-
),
123-
{ ...upload, cwd: request.cwd, signal: request.signal },
124-
);
125-
return {
126-
...base,
127-
platform,
128-
deviceName,
129-
auth: credentials,
130-
uploadApp: createTestMuUploadApp(upload),
131-
webdriverCapabilities: buildTestMuCapabilities({
132-
platform,
133-
deviceType,
134-
deviceName,
135-
osVersion,
136-
app,
137-
projectName: readFlag(request, 'providerProject'),
138-
buildName: readFlag(request, 'providerBuild') ?? lease.runId,
139-
sessionName: readFlag(request, 'providerSessionName') ?? lease.leaseId,
140-
deviceFeatures: buildTestMuDeviceFeatureCapabilities(
141-
readTestMuDeviceFeatureFields(request.flags),
142-
),
143-
configured: buildCloudWebDriverBaseCapabilities(platform, deviceName),
144-
}),
145-
};
146-
},
147-
};
148-
return webDriver;
149-
}
150-
/** Each pool has its own upload API, so each has its own override. */
151-
function testMuAppUploadEndpoint(
152-
env: ProviderPluginHost['env'],
153-
deviceType: ProviderDeviceType,
154-
): string | undefined {
155-
return deviceType === 'real'
156-
? env.TESTMU_REAL_DEVICE_APP_UPLOAD_ENDPOINT
157-
: env.TESTMU_APP_UPLOAD_ENDPOINT;
7+
return { webDriver: createTestMuWebDriver(host), connection: createTestMuConnection(host) };
1588
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { ProviderProfileFieldDeclaration } from '@agent-device/contracts/provider-profile-fields';
2+
3+
export const TESTMU_PROFILE_FIELDS: ProviderProfileFieldDeclaration = {
4+
provider: 'testmu',
5+
label: 'TestMu AI',
6+
fields: {
7+
providerApp: 'consumed',
8+
providerOsVersion: 'consumed',
9+
providerDeviceType: 'consumed',
10+
providerProject: 'consumed',
11+
providerBuild: 'consumed',
12+
providerSessionName: 'consumed',
13+
providerDeviceOrientation: 'consumed',
14+
providerGeoLocation: 'consumed',
15+
providerTimezone: 'consumed',
16+
providerAppiumVersion: 'consumed',
17+
providerLanguage: 'consumed',
18+
providerLocale: 'consumed',
19+
providerNetworkProfile: 'refused',
20+
providerCustomNetwork: 'refused',
21+
providerNoResignApp: 'refused',
22+
awsProjectArn: 'refused',
23+
awsDeviceArn: 'refused',
24+
awsAppArn: 'refused',
25+
awsRegion: 'refused',
26+
awsInteractionMode: 'refused',
27+
},
28+
};

0 commit comments

Comments
 (0)