@@ -12,11 +12,19 @@ import {
1212 createLocalLinuxToolProvider ,
1313 resolveLinuxToolProvider ,
1414 withLinuxToolProvider ,
15+ type LinuxToolCommandExecutor ,
16+ type LinuxToolDetachedLauncher ,
17+ type LinuxToolProviderOverrides ,
1518} from '../tool-provider.ts' ;
1619import type { ExecDetachedExit } from '@agent-device/host-kit/command' ;
1720
1821bindTestCommandHost ( ) ;
1922
23+ /** For a provider that injects an executor and launches no app in the scenario. */
24+ const launchesNoApp : LinuxToolDetachedLauncher = ( cmd ) => {
25+ throw new Error ( `this scenario launches no app: ${ cmd } ` ) ;
26+ } ;
27+
2028const originalPlatform = process . platform ;
2129const originalEnv = { ...process . env } ;
2230
@@ -29,6 +37,7 @@ beforeEach(() => {
2937test ( 'scoped Linux tool provider handles input discovery and command execution' , async ( ) => {
3038 const commands : Array < [ string , string [ ] ] > = [ ] ;
3139 const provider = createLocalLinuxToolProvider ( {
40+ launchDetached : launchesNoApp ,
3241 host : { env : { ...process . env , XDG_SESSION_TYPE : 'x11' } , cwd : process . cwd ( ) } ,
3342 whichCommand : async ( cmd ) => cmd === 'xdotool' ,
3443 runCommand : async ( cmd , args ) => {
@@ -52,6 +61,7 @@ test('scoped Linux tool provider handles input discovery and command execution',
5261test ( 'xdotool press skips the --sync move when the pointer already sits on the target' , async ( ) => {
5362 const commands : Array < [ string , string [ ] ] > = [ ] ;
5463 const provider = createLocalLinuxToolProvider ( {
64+ launchDetached : launchesNoApp ,
5565 host : { env : { ...process . env , XDG_SESSION_TYPE : 'x11' } , cwd : process . cwd ( ) } ,
5666 whichCommand : async ( cmd ) => cmd === 'xdotool' ,
5767 runCommand : async ( cmd , args ) => {
@@ -75,6 +85,7 @@ test('xdotool press skips the --sync move when the pointer already sits on the t
7585test ( 'scoped Linux input provider handles semantic input without host tool discovery' , async ( ) => {
7686 const inputCalls : Array < [ string , string , string , string ] > = [ ] ;
7787 const provider = createLocalLinuxToolProvider ( {
88+ launchDetached : launchesNoApp ,
7889 host : { env : { ...process . env , XDG_SESSION_TYPE : 'x11' } , cwd : process . cwd ( ) } ,
7990 whichCommand : async ( cmd ) => {
8091 throw new Error ( `unexpected input discovery: ${ cmd } ` ) ;
@@ -104,6 +115,7 @@ test('scoped Linux input provider handles semantic input without host tool disco
104115
105116test ( 'Linux tool provider scopes do not share cached input tool resolution' , async ( ) => {
106117 const providerA = createLocalLinuxToolProvider ( {
118+ launchDetached : launchesNoApp ,
107119 host : {
108120 env : { ...process . env , XDG_SESSION_TYPE : 'x11' , WAYLAND_DISPLAY : '' } ,
109121 cwd : process . cwd ( ) ,
@@ -112,6 +124,7 @@ test('Linux tool provider scopes do not share cached input tool resolution', asy
112124 runCommand : async ( ) => ( { exitCode : 0 , stdout : '' , stderr : '' } ) ,
113125 } ) ;
114126 const providerB = createLocalLinuxToolProvider ( {
127+ launchDetached : launchesNoApp ,
115128 host : {
116129 env : { ...process . env , XDG_SESSION_TYPE : 'wayland' , WAYLAND_DISPLAY : 'wayland-0' } ,
117130 cwd : process . cwd ( ) ,
@@ -154,6 +167,7 @@ test('Linux tool provider scopes do not share cached input tool resolution', asy
154167test ( 'local Linux desktop provider translates semantic lifecycle calls to host tools' , async ( ) => {
155168 const commands : Array < [ string , string [ ] , boolean | undefined ] > = [ ] ;
156169 const provider = createLocalLinuxToolProvider ( {
170+ launchDetached : launchesNoApp ,
157171 host : { env : { ...process . env , XDG_SESSION_TYPE : 'x11' } , cwd : process . cwd ( ) } ,
158172 whichCommand : async ( cmd ) => cmd === 'wmctrl' ,
159173 runCommand : async ( cmd , args , options ) => {
@@ -276,25 +290,26 @@ test('local Linux desktop provider reports nothing for a launched app that exits
276290 assert . deepEqual ( await launchDiagnostics ( { pid : 4 , exitCode : 0 } ) , [ ] ) ;
277291} ) ;
278292
279- test ( 'local Linux desktop provider launches through an injected executor when it injects no launcher' , async ( ) => {
280- const commands : Array < [ string , string [ ] , boolean | undefined ] > = [ ] ;
281- const provider = createLocalLinuxToolProvider ( {
282- host : { env : process . env , cwd : process . cwd ( ) } ,
283- whichCommand : async ( cmd ) => cmd === 'demo-app' ,
284- runCommand : async ( cmd , args , options ) => {
285- commands . push ( [ cmd , args , options ?. allowFailure ] ) ;
286- return { exitCode : 0 , stdout : '' , stderr : '' } ;
287- } ,
293+ // An injected executor owns process execution, so the type refuses one without its own launcher:
294+ // the host-local detached runner must never stand in beside it. The directive fails typecheck if
295+ // the refusal goes away.
296+ test ( 'a Linux provider that injects runCommand must also inject launchDetached' , ( ) => {
297+ const runCommand : LinuxToolCommandExecutor = async ( ) => ( {
298+ exitCode : 0 ,
299+ stdout : '' ,
300+ stderr : '' ,
288301 } ) ;
289-
290- await provider . desktop . openTarget ( 'demo-app' ) ;
291-
292- assert . deepEqual ( commands , [ [ 'demo-app' , [ ] , true ] ] ) ;
302+ // @ts -expect-error runCommand without launchDetached
303+ const withoutLauncher : LinuxToolProviderOverrides = { runCommand } ;
304+ const withLauncher : LinuxToolProviderOverrides = { runCommand, launchDetached : launchesNoApp } ;
305+ assert . equal ( withoutLauncher . launchDetached , undefined ) ;
306+ assert . equal ( withLauncher . launchDetached , launchesNoApp ) ;
293307} ) ;
294308
295309test ( 'local Linux desktop provider falls back to pkill when wmctrl is unavailable' , async ( ) => {
296310 const commands : Array < [ string , string [ ] , boolean | undefined ] > = [ ] ;
297311 const provider = createLocalLinuxToolProvider ( {
312+ launchDetached : launchesNoApp ,
298313 host : { env : { ...process . env , XDG_SESSION_TYPE : 'x11' } , cwd : process . cwd ( ) } ,
299314 whichCommand : async ( ) => false ,
300315 runCommand : async ( cmd , args , options ) => {
@@ -311,6 +326,7 @@ test('local Linux desktop provider falls back to pkill when wmctrl is unavailabl
311326test ( 'local Linux screenshot provider translates capture to available host tool' , async ( ) => {
312327 const commands : Array < [ string , string [ ] ] > = [ ] ;
313328 const provider = createLocalLinuxToolProvider ( {
329+ launchDetached : launchesNoApp ,
314330 host : { env : { ...process . env , XDG_SESSION_TYPE : 'x11' } , cwd : process . cwd ( ) } ,
315331 whichCommand : async ( cmd ) => cmd === 'scrot' ,
316332 runCommand : async ( cmd , args ) => {
0 commit comments