@@ -17,6 +17,56 @@ import {
1717const exec = NodeUtil . promisify ( NodeChildProcess . execFile ) ;
1818
1919describe ( "host-bound agent commands" , ( ) => {
20+ it . effect . skipIf ( HostProcess . Platform . defaultValue ( ) === "win32" ) (
21+ "runs both desktop hops as Node with a stripped environment, preserving arguments and exit code" ,
22+ ( ) =>
23+ Effect . gen ( function * ( ) {
24+ const fs = yield * FileSystem . FileSystem ;
25+ const path = yield * Path . Path ;
26+ const temp = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-device-target-" } ) ;
27+ const dir = path . join ( temp , "quotes '\" $HOME `literal`" ) ;
28+ yield * fs . makeDirectory ( dir ) ;
29+ const desktopApp = path . join ( dir , "T3 Code" ) ;
30+ // Dropping Node mode after checking it forces each hop to set it independently.
31+ yield * fs . writeFileString (
32+ desktopApp ,
33+ `#!/bin/sh
34+ if [ "\${ELECTRON_RUN_AS_NODE:-}" != "1" ]; then
35+ echo "started the desktop app" >&2
36+ exit 134
37+ fi
38+ unset ELECTRON_RUN_AS_NODE
39+ exec '${ process . execPath . replaceAll ( "'" , "'\"'\"'" ) } ' "$@"
40+ ` ,
41+ ) ;
42+ yield * fs . chmod ( desktopApp , 0o755 ) ;
43+ const entryPath = path . join ( dir , "cli.mjs" ) ;
44+ yield * fs . writeFileString (
45+ entryPath ,
46+ "console.log(JSON.stringify(process.argv.slice(2))); process.exitCode = 23;" ,
47+ ) ;
48+ const shim = yield * ensureAgentDeviceShim ( { entryPath, stateDir : dir } ) . pipe (
49+ Effect . provideService ( HostProcess . ExecutablePath , desktopApp ) ,
50+ Effect . provideService ( HostProcess . IsExecutable , false ) ,
51+ ) ;
52+ const args = [
53+ "snapshot" ,
54+ "--config" ,
55+ path . join ( dir , "config.json" ) ,
56+ "--session" ,
57+ "a!b!c" ,
58+ "" ,
59+ ] ;
60+ yield * Effect . promise ( ( ) =>
61+ expect (
62+ exec ( path . join ( shim , "agent-device" ) , args , {
63+ env : { PATH : process . env . PATH ?? "" , HOME : temp } ,
64+ } ) ,
65+ ) . rejects . toMatchObject ( { code : 23 , stdout : `${ JSON . stringify ( args ) } \n` , stderr : "" } ) ,
66+ ) ;
67+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
68+ ) ;
69+
2070 it . effect ( "runs two hosts concurrently and only updates the reconnected host" , ( ) =>
2171 Effect . gen ( function * ( ) {
2272 const fs = yield * FileSystem . FileSystem ;
0 commit comments