Repository navigation
feat(plugins): compose the Android provider interactor #4728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
thymikee
wants to merge
7
commits into
refactor/0.22-limrun-plugin-factory
from
refactor/0.22-limrun-android-interactor
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7e79e56
refactor(limrun): add transitional v2 plugin factory and move credent…
thymikee 4b7e616
test(limrun): read credential names from plugin inventory
thymikee 2118012
feat(plugins): serve the Android provider interactor through the host…
thymikee ccc9060
docs(plugins): clarify interactor factory preload
thymikee b2e74a3
fix(plugins): keep the Android interactor facet receiver
thymikee 209ba7b
test(plugins): cover scoped Android provider text
thymikee 15c18ec
feat(plugins): export the Android text request type
thymikee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/provider-limrun-credentials.test.ts → ...s/provider-limrun/src/credentials.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /** | ||
| * The seam core composes Limrun through while the provider is still built in. Nothing here loads the | ||
| * Limrun SDK: the runtime, the platform adapters, and the connection verification each load when | ||
| * their own path asks for them. The root entry keeps the SDK-side surface. | ||
| */ | ||
| export { limrunPlugin } from './plugin.ts'; | ||
| export { | ||
| limrunInstanceVariables, | ||
| limrunPlatformForLeaseBackend, | ||
| readLimrunCredentials, | ||
| } from './credentials.ts'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import path from 'node:path'; | ||
| import { test, vi } from 'vitest'; | ||
| import type { ProviderPluginHost } from '@agent-device/plugins/host'; | ||
| import { AppError } from '@agent-device/kernel/errors'; | ||
| import { mkdtempForTestSync } from '@agent-device/test-kit'; | ||
| import type { LimrunRuntimeDependencies } from './runtime-dependencies.ts'; | ||
| import { stubLimrunRuntimeDependencies } from './runtime-dependencies.fixtures.ts'; | ||
| import { limrunPlugin } from './plugin.ts'; | ||
|
|
||
| const sdk = vi.hoisted(() => ({ | ||
| runtimeCalls: [] as { options: Record<string, unknown>; mode: unknown }[], | ||
| })); | ||
|
|
||
| // The runtime module is stubbed so a case reads what the plugin hands the runtime builder without | ||
| // constructing a Limrun client. The provider's own runtime contract is what the plugin must satisfy. | ||
| vi.mock('./runtime.ts', () => ({ | ||
| createLimrunRuntime: (options: Record<string, unknown>, _d: unknown, mode: unknown) => { | ||
| sdk.runtimeCalls.push({ options, mode }); | ||
| return { | ||
| runtime: { | ||
| provider: 'limrun', | ||
| shutdown: async () => undefined, | ||
| leaseLifecycle: {}, | ||
| ownsDevice: () => false, | ||
| getInteractor: () => undefined, | ||
| deviceInventoryProvider: async () => null, | ||
| }, | ||
| platformModule: { | ||
| owner: { kind: 'provider-runtime', provider: 'limrun', instance: 'limrun:test' }, | ||
| loadRuntime: async () => ({}), | ||
| }, | ||
| }; | ||
| }, | ||
| })); | ||
|
|
||
| function pluginHost(env: Record<string, string | undefined> = {}): 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 stubDependencies(): LimrunRuntimeDependencies { | ||
| return stubLimrunRuntimeDependencies(); | ||
| } | ||
|
|
||
| test('the plugin declares its provider and the credential variables per lease backend', () => { | ||
| const plugin = limrunPlugin({ createDependencies: () => stubDependencies() }); | ||
| assert.equal(plugin.apiVersion, 2); | ||
| assert.equal(plugin.provider, 'limrun'); | ||
| assert.deepEqual(plugin.credentials, { | ||
| variables: [ | ||
| 'LIMRUN_API_KEY', | ||
| 'LIMRUN_REGION', | ||
| 'LIM_IOS_INSTANCE_URL', | ||
| 'LIM_IOS_INSTANCE_TOKEN', | ||
| 'LIM_ANDROID_INSTANCE_URL', | ||
| 'LIM_ANDROID_INSTANCE_TOKEN', | ||
| 'LIM_ANDROID_INSTANCE_ADB_URL', | ||
| ], | ||
| byBackend: { | ||
| 'ios-instance': [ | ||
| 'LIMRUN_API_KEY', | ||
| 'LIMRUN_REGION', | ||
| 'LIM_IOS_INSTANCE_URL', | ||
| 'LIM_IOS_INSTANCE_TOKEN', | ||
| ], | ||
| 'android-instance': [ | ||
| 'LIMRUN_API_KEY', | ||
| 'LIMRUN_REGION', | ||
| 'LIM_ANDROID_INSTANCE_URL', | ||
| 'LIM_ANDROID_INSTANCE_TOKEN', | ||
| 'LIM_ANDROID_INSTANCE_ADB_URL', | ||
| ], | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| test('setup builds the runtime over the credentials, host and HAR directory it was given', async () => { | ||
| const host = pluginHost({ LIMRUN_API_KEY: 'lim_test_key', LIMRUN_KEEP_ALIVE: '1' }); | ||
| const dependencies = stubDependencies(); | ||
| const createDependencies = vi.fn(() => dependencies); | ||
| const stateDir = mkdtempForTestSync('limrun-plugin-state-'); | ||
|
|
||
| const setup = await limrunPlugin({ createDependencies, stateDir }).setup(host); | ||
|
|
||
| if (!('runtime' in setup)) throw new Error('Limrun sets up its own runtime'); | ||
| assert.equal(setup.runtime.provider, 'limrun'); | ||
| assert.deepEqual(createDependencies.mock.calls, [[host]]); | ||
| assert.deepEqual(sdk.runtimeCalls, [ | ||
| { | ||
| options: { | ||
| apiKey: 'lim_test_key', | ||
| region: undefined, | ||
| keepAlive: true, | ||
| instances: undefined, | ||
| networkHarDir: path.join(stateDir, 'network-har'), | ||
| }, | ||
| mode: { includePlatformModule: true }, | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| test('setup with only an attached instance builds a runtime without an API key or HAR directory', async () => { | ||
| await limrunPlugin({ createDependencies: () => stubDependencies() }).setup( | ||
| pluginHost({ LIM_IOS_INSTANCE_URL: 'https://x/api', LIM_IOS_INSTANCE_TOKEN: 'token' }), | ||
| ); | ||
| const options = sdk.runtimeCalls.at(-1)?.options; | ||
| assert.equal(options?.apiKey, undefined); | ||
| assert.deepEqual(options?.instances, { | ||
| ios: { apiUrl: 'https://x/api', token: 'token' }, | ||
| android: undefined, | ||
| }); | ||
| assert.equal('networkHarDir' in (options ?? {}), false); | ||
| }); | ||
|
|
||
| test('setup refuses a host with no Limrun credentials before asking for host adapters', async () => { | ||
| const createDependencies = vi.fn(() => stubDependencies()); | ||
| await assert.rejects( | ||
| async () => { | ||
| await limrunPlugin({ createDependencies }).setup(pluginHost({ LIMRUN_REGION: 'eu' })); | ||
| }, | ||
| (error: unknown) => { | ||
| assert.ok(error instanceof AppError); | ||
| assert.equal(error.code, 'INVALID_ARGS'); | ||
| assert.equal(error.details?.reason, 'missing_provider_credentials'); | ||
| return true; | ||
| }, | ||
| ); | ||
| assert.equal(createDependencies.mock.calls.length, 0); | ||
| }); | ||
|
|
||
| test('setup refuses a partial instance set naming the variable it still needs', async () => { | ||
| const createDependencies = vi.fn(() => stubDependencies()); | ||
| await assert.rejects( | ||
| async () => { | ||
| await limrunPlugin({ createDependencies }).setup( | ||
| pluginHost({ | ||
| LIMRUN_API_KEY: 'lim_test_key', | ||
| LIM_ANDROID_INSTANCE_URL: 'https://region.limrun.example/v1/android_x/api', | ||
| LIM_ANDROID_INSTANCE_TOKEN: 'android-token', | ||
| }), | ||
| ); | ||
| }, | ||
| { | ||
| code: 'INVALID_ARGS', | ||
| message: 'Limrun instance access is missing LIM_ANDROID_INSTANCE_ADB_URL.', | ||
| }, | ||
| ); | ||
| assert.equal(createDependencies.mock.calls.length, 0); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.