Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
72d8771
fix(platform-web): send fill and type text to agent-browser on stdin
claude Nov 10, 2026
4f4a2c7
fix(provider-webdriver): retry session delete and keep status on non-…
claude Nov 10, 2026
7d6a730
fix(provider-webdriver): route system buttons and app opens per Appiu…
claude Nov 10, 2026
ec5e57c
fix(contracts): carry open --relaunch through the direct lifecycle bi…
claude Nov 10, 2026
7c01598
fix(tv-cdp): drop unreadable CDP frames instead of throwing in the so…
claude Nov 10, 2026
890dd17
fix(provider-webdriver): bound and type hosted app uploads, stream th…
claude Nov 10, 2026
66cc078
fix(provider-webdriver): look up Device Farm artifacts in the session…
claude Nov 10, 2026
f488459
fix(platform-linux): launch an app binary detached from daemon pipes
claude Nov 10, 2026
1a90944
style: format provider remediation changes
claude Nov 10, 2026
5fe13fc
test(provider-webdriver): keep new cases within the file line limit
claude Nov 10, 2026
0ea8e90
test: fix typecheck in the new web and CDP test cases
claude Nov 10, 2026
bb5054c
fix(providers): address review findings on text entry, CDP frames, an…
claude Nov 10, 2026
cfed7a3
fix(platform-web): drop backend output from text-entry failures
claude Nov 10, 2026
6997818
fix(tv-cdp): load the diagnostics emitter only on the error path
claude Nov 10, 2026
51da707
fix(platform-web): scrub only executed backend output from text-entry…
claude Nov 10, 2026
5e8b88d
fix(platform-linux): report app launch exits and inject the detached …
claude Nov 10, 2026
aa7de0d
test(platform-linux): assert each launch exit outcome reports its own…
claude Nov 10, 2026
beb299d
fix(provider-webdriver): never read a non-JSON error page as an unsup…
claude Nov 10, 2026
df1edbb
fix(platform-linux): launch through an injected executor unless a lau…
claude Nov 10, 2026
0f6aa69
fix(platform-web): point a refused text entry at a fresh snapshot, no…
claude Nov 10, 2026
1cce2ef
merge: origin/main into providers remediation
claude Nov 10, 2026
7047de8
fix(platform-linux): keep the detached app launch on the ambient prov…
claude Nov 10, 2026
712fb0e
merge: origin/main into providers remediation
claude Nov 10, 2026
373b157
refactor(platform-linux): require a launcher beside an injected executor
claude Nov 10, 2026
f1d7af3
test(platform-web): pin each text-entry operation to its own hint
claude Nov 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions packages/contracts/src/application-lifecycle-interaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { OpenApplicationInput } from './application-lifecycle-runtime.ts';
import {
bindDirectApplicationLifecycle,
bindLocalApplicationLifecycleInteractor,
bindLocalDirectApplicationLifecycle,
bindProviderApplicationLifecycleInteractor,
invokeApplicationOpen,
} from './application-lifecycle-interaction.ts';
Expand Down Expand Up @@ -74,6 +75,7 @@ test('direct lifecycle owners preserve the daemon runtime launch URL follow-up',
binding,
owner: 'Linux',
openTargetIdentity: 'app-name',
closeBeforeRelaunch: true,
});

await lifecycle.openApplication(
Expand All @@ -92,6 +94,68 @@ test('direct lifecycle owners preserve the daemon runtime launch URL follow-up',
expect(calls[1]?.options).toHaveProperty('launchArgs', undefined);
});

/** An interactor that records each open and close it receives, in order. */
function lifecycleRecordingInteractor(calls: string[]): Interactor {
return {
open: async (app: string, options?: { terminateRunningApp?: boolean }) => {
calls.push(`open ${app} terminate=${String(options?.terminateRunningApp)}`);
},
openDevice: async () => undefined,
close: async (app: string) => {
calls.push(`close ${app}`);
},
setSetting: async () => undefined,
} as unknown as Interactor;
}

// The local direct owners (Linux, web, HarmonyOS, Vega) do not replace a running app on
// open, so a relaunch that reached only `open` left the app running as it was.
test('a local direct owner closes the running app before a relaunch open', async () => {
const calls: string[] = [];
const lifecycle = bindLocalDirectApplicationLifecycle({
owner: 'Linux',
openTargetIdentity: 'app-name',
host: { resolve: async () => lifecycleRecordingInteractor(calls) },
device: LINUX_DEVICE,
signal: new AbortController().signal,
});

await lifecycle.openApplication(
openInput({ target: 'gedit', positionals: ['gedit'], appBundleId: undefined, relaunch: true }),
);
await lifecycle.openApplication(
openInput({ target: 'gedit', positionals: ['gedit'], appBundleId: undefined }),
);

expect(calls).toEqual([
'close gedit',
'open gedit terminate=undefined',
'open gedit terminate=undefined',
]);
});

test('an owner whose open restarts the app receives the relaunch as terminateRunningApp', async () => {
const calls: string[] = [];
const lifecycle = bindDirectApplicationLifecycle({
binding: bindProviderApplicationLifecycleInteractor({
device: IOS_SIMULATOR,
signal: new AbortController().signal,
resolveInteractor: () => lifecycleRecordingInteractor(calls),
}),
owner: 'provider',
openTargetIdentity: 'bundle-id',
closeBeforeRelaunch: false,
});

await lifecycle.openApplication(openInput({ relaunch: true }));
await lifecycle.openApplication(openInput());

expect(calls).toEqual([
'open com.example.app terminate=true',
'open com.example.app terminate=false',
]);
});

test.each([
{
name: 'more than two positionals',
Expand Down
11 changes: 9 additions & 2 deletions packages/contracts/src/application-lifecycle-interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,12 @@ export type DirectApplicationLifecycleParams = Readonly<{
/** Names the owner in the failure reported for an operation it does not implement. */
owner: string;
openTargetIdentity: DirectOpenTargetIdentity;
/** Owners whose native open does not replace a running application close it first. */
closeBeforeRelaunch?: boolean;
/**
* How `open --relaunch` restarts a running application. `true`: the binding closes it before the
* open, for owners whose native open does not replace a running application. `false`: the
* interactor's open receives `terminateRunningApp` and owns the restart.
*/
closeBeforeRelaunch: boolean;
/** Port reverse is the one non-direct operation a provider owner may still implement. */
configureProviderPortReverse?: ApplicationLifecycleRuntimeOperations['configureProviderPortReverse'];
}>;
Expand Down Expand Up @@ -327,6 +331,7 @@ async function openDirectApplication(
positionals: input.positionals,
appBundleId: input.appBundleId,
execution: input.execution,
...(params.closeBeforeRelaunch ? {} : { terminateRunningApp: input.relaunch }),
});
const followUpUrl = followUpRuntimeLaunchUrl(input);
if (followUpUrl) {
Expand Down Expand Up @@ -405,6 +410,8 @@ export function bindLocalDirectApplicationLifecycle(
return bindDirectApplicationLifecycle({
owner: params.owner,
openTargetIdentity: params.openTargetIdentity,
// No local direct owner (Linux, web, HarmonyOS, Vega) replaces a running app on open.
closeBeforeRelaunch: true,
binding: bindLocalApplicationLifecycleInteractor({
device: params.device,
signal: params.signal,
Expand Down
152 changes: 149 additions & 3 deletions packages/platform-linux/src/__tests__/tool-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
import { bindTestCommandHost } from '@agent-device/test-kit';
import { afterAll, beforeEach, test } from 'vitest';
import { bindTestCommandHost, mkdtempForTest } from '@agent-device/test-kit';
import fs from 'node:fs';
import path from 'node:path';
import { afterAll, beforeEach, test, vi } from 'vitest';
import {
countDiagnosticEventsByPhase,
withDiagnosticsScope,
} from '@agent-device/host-kit/diagnostics';
import assert from 'node:assert/strict';
import { pressLinux } from '../input-actions.ts';
import { createLocalLinuxToolProvider, withLinuxToolProvider } from '../tool-provider.ts';
import {
createLocalLinuxToolProvider,
resolveLinuxToolProvider,
withLinuxToolProvider,
type LinuxToolCommandExecutor,
type LinuxToolDetachedLauncher,
type LinuxToolProviderOverrides,
} from '../tool-provider.ts';
import type { ExecDetachedExit } from '@agent-device/host-kit/command';

bindTestCommandHost();

/** For a provider that injects an executor and launches no app in the scenario. */
const launchesNoApp: LinuxToolDetachedLauncher = (cmd) => {
throw new Error(`this scenario launches no app: ${cmd}`);
};

const originalPlatform = process.platform;
const originalEnv = { ...process.env };

Expand All @@ -18,6 +37,7 @@ beforeEach(() => {
test('scoped Linux tool provider handles input discovery and command execution', async () => {
const commands: Array<[string, string[]]> = [];
const provider = createLocalLinuxToolProvider({
launchDetached: launchesNoApp,
host: { env: { ...process.env, XDG_SESSION_TYPE: 'x11' }, cwd: process.cwd() },
whichCommand: async (cmd) => cmd === 'xdotool',
runCommand: async (cmd, args) => {
Expand All @@ -41,6 +61,7 @@ test('scoped Linux tool provider handles input discovery and command execution',
test('xdotool press skips the --sync move when the pointer already sits on the target', async () => {
const commands: Array<[string, string[]]> = [];
const provider = createLocalLinuxToolProvider({
launchDetached: launchesNoApp,
host: { env: { ...process.env, XDG_SESSION_TYPE: 'x11' }, cwd: process.cwd() },
whichCommand: async (cmd) => cmd === 'xdotool',
runCommand: async (cmd, args) => {
Expand All @@ -64,6 +85,7 @@ test('xdotool press skips the --sync move when the pointer already sits on the t
test('scoped Linux input provider handles semantic input without host tool discovery', async () => {
const inputCalls: Array<[string, string, string, string]> = [];
const provider = createLocalLinuxToolProvider({
launchDetached: launchesNoApp,
host: { env: { ...process.env, XDG_SESSION_TYPE: 'x11' }, cwd: process.cwd() },
whichCommand: async (cmd) => {
throw new Error(`unexpected input discovery: ${cmd}`);
Expand Down Expand Up @@ -93,6 +115,7 @@ test('scoped Linux input provider handles semantic input without host tool disco

test('Linux tool provider scopes do not share cached input tool resolution', async () => {
const providerA = createLocalLinuxToolProvider({
launchDetached: launchesNoApp,
host: {
env: { ...process.env, XDG_SESSION_TYPE: 'x11', WAYLAND_DISPLAY: '' },
cwd: process.cwd(),
Expand All @@ -101,6 +124,7 @@ test('Linux tool provider scopes do not share cached input tool resolution', asy
runCommand: async () => ({ exitCode: 0, stdout: '', stderr: '' }),
});
const providerB = createLocalLinuxToolProvider({
launchDetached: launchesNoApp,
host: {
env: { ...process.env, XDG_SESSION_TYPE: 'wayland', WAYLAND_DISPLAY: 'wayland-0' },
cwd: process.cwd(),
Expand Down Expand Up @@ -143,6 +167,7 @@ test('Linux tool provider scopes do not share cached input tool resolution', asy
test('local Linux desktop provider translates semantic lifecycle calls to host tools', async () => {
const commands: Array<[string, string[], boolean | undefined]> = [];
const provider = createLocalLinuxToolProvider({
launchDetached: launchesNoApp,
host: { env: { ...process.env, XDG_SESSION_TYPE: 'x11' }, cwd: process.cwd() },
whichCommand: async (cmd) => cmd === 'wmctrl',
runCommand: async (cmd, args, options) => {
Expand All @@ -162,9 +187,129 @@ test('local Linux desktop provider translates semantic lifecycle calls to host t
]);
});

// `open <binary>` used to run the app as a piped child of the daemon, which kept every
// byte the app printed in daemon memory for the app's whole life. The default launcher detaches,
// for a provider built over a host and for the ambient one a call outside any runtime resolves.
test.skipIf(!fs.existsSync('/proc/self/fd')).each([
[
'a host-built',
() =>
createLocalLinuxToolProvider({
host: { env: process.env, cwd: process.cwd() },
whichCommand: async (cmd) => cmd === 'fake-desktop-app',
}),
],
['the ambient', () => resolveLinuxToolProvider()],
] as const)(
'%s Linux desktop provider launches an app binary detached from daemon pipes',
async (_name, makeProvider) => {
const binDir = await mkdtempForTest('linux-open-binary-');
const report = path.join(binDir, 'stdout-target');
fs.writeFileSync(
path.join(binDir, 'fake-desktop-app'),
`#!/bin/sh\nreadlink /proc/self/fd/2 > '${report}.tmp' && mv '${report}.tmp' '${report}'\n`,
{ mode: 0o755 },
);
const originalPath = process.env['PATH'];
process.env['PATH'] = `${binDir}${path.delimiter}${originalPath ?? ''}`;
try {
await makeProvider().desktop.openTarget('fake-desktop-app');

await vi.waitFor(() => assert.ok(fs.existsSync(report)));
assert.equal(fs.readFileSync(report, 'utf8').trim(), '/dev/null');
} finally {
process.env['PATH'] = originalPath;
}
},
);

test('local Linux desktop provider launches an app binary through its detached launcher', async () => {
const launches: Array<[string, string[]]> = [];
const captured: string[] = [];
const provider = createLocalLinuxToolProvider({
host: { env: process.env, cwd: process.cwd() },
whichCommand: async (cmd) => cmd === 'demo-app',
runCommand: async (cmd) => {
captured.push(cmd);
return { exitCode: 0, stdout: '', stderr: '' };
},
launchDetached: (cmd, args) => {
launches.push([cmd, args]);
return { exited: new Promise(() => {}) };
},
});

await provider.desktop.openTarget('demo-app');

assert.deepEqual(launches, [['demo-app', []]]);
assert.deepEqual(captured, []);
});

/** The `linux_app_launch` events one `openTarget` writes, once its launch has exited. */
async function launchDiagnostics(exit: ExecDetachedExit): Promise<Record<string, unknown>[]> {
const logPath = path.join(await mkdtempForTest('linux-launch-diagnostics-'), 'request.ndjson');
let exited: Promise<ExecDetachedExit> | undefined;
const provider = createLocalLinuxToolProvider({
host: { env: process.env, cwd: process.cwd() },
whichCommand: async () => true,
launchDetached: () => {
exited = Promise.resolve(exit);
return { exited };
},
});
return await withDiagnosticsScope({ command: 'open', debug: true, logPath }, async () => {
await provider.desktop.openTarget('demo-app');
await exited;
const expected = countDiagnosticEventsByPhase(['linux_app_launch']);
const read = () =>
(fs.existsSync(logPath) ? fs.readFileSync(logPath, 'utf8').trim().split('\n') : [])
.filter((line) => line.length > 0)
.map((line) => JSON.parse(line) as { phase: string; data?: Record<string, unknown> })
.filter((event) => event.phase === 'linux_app_launch');
await vi.waitFor(() => assert.equal(read().length, expected));
return read().map((event) => event.data ?? {});
});
}

test.each([
[
'a start failure',
{ pid: 1, error: 'spawn demo-app ENOENT' },
{ error: 'spawn demo-app ENOENT' },
],
['a non-zero exit', { pid: 2, exitCode: 3 }, { exitCode: 3 }],
['a signal', { pid: 3, signal: 'SIGKILL' }, { signal: 'SIGKILL' }],
] as const)(
'local Linux desktop provider reports %s of a launched app once',
async (_name, exit, field) => {
assert.deepEqual(await launchDiagnostics(exit), [{ app: 'demo-app', ...field }]);
},
);

test('local Linux desktop provider reports nothing for a launched app that exits cleanly', async () => {
assert.deepEqual(await launchDiagnostics({ pid: 4, exitCode: 0 }), []);
});

// An injected executor owns process execution, so the type refuses one without its own launcher:
// the host-local detached runner must never stand in beside it. The directive fails typecheck if
// the refusal goes away.
test('a Linux provider that injects runCommand must also inject launchDetached', () => {
const runCommand: LinuxToolCommandExecutor = async () => ({
exitCode: 0,
stdout: '',
stderr: '',
});
// @ts-expect-error runCommand without launchDetached
const withoutLauncher: LinuxToolProviderOverrides = { runCommand };
const withLauncher: LinuxToolProviderOverrides = { runCommand, launchDetached: launchesNoApp };
assert.equal(withoutLauncher.launchDetached, undefined);
assert.equal(withLauncher.launchDetached, launchesNoApp);
});

test('local Linux desktop provider falls back to pkill when wmctrl is unavailable', async () => {
const commands: Array<[string, string[], boolean | undefined]> = [];
const provider = createLocalLinuxToolProvider({
launchDetached: launchesNoApp,
host: { env: { ...process.env, XDG_SESSION_TYPE: 'x11' }, cwd: process.cwd() },
whichCommand: async () => false,
runCommand: async (cmd, args, options) => {
Expand All @@ -181,6 +326,7 @@ test('local Linux desktop provider falls back to pkill when wmctrl is unavailabl
test('local Linux screenshot provider translates capture to available host tool', async () => {
const commands: Array<[string, string[]]> = [];
const provider = createLocalLinuxToolProvider({
launchDetached: launchesNoApp,
host: { env: { ...process.env, XDG_SESSION_TYPE: 'x11' }, cwd: process.cwd() },
whichCommand: async (cmd) => cmd === 'scrot',
runCommand: async (cmd, args) => {
Expand Down
Loading
Loading