@@ -11,6 +11,7 @@ import * as Effect from "effect/Effect";
1111import * as FileSystem from "effect/FileSystem" ;
1212import * as Sink from "effect/Sink" ;
1313import * as Stream from "effect/Stream" ;
14+ import type * as ChildProcess from "effect/process/ChildProcess" ;
1415import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner" ;
1516
1617import * as ProcessRunner from "../processRunner.ts" ;
@@ -122,13 +123,13 @@ it.each([
122123 expect ( ServiceProtection . loadedRemoteAccessUnits ( shown ) ) . toEqual ( expected ) ;
123124} ) ;
124125
125- const fakeSudo = ( exitCode : number , onRun : ( ) => void ) =>
126+ const fakeSudo = ( exitCode : number , onRun : ( command : ChildProcess . StandardCommand ) => void ) =>
126127 ChildProcessSpawner . make ( ( command ) =>
127128 Effect . gen ( function * ( ) {
128129 if ( command . _tag !== "StandardCommand" || command . command !== "sudo" ) {
129130 return yield * Effect . die ( "Unexpected command" ) ;
130131 }
131- onRun ( ) ;
132+ onRun ( command ) ;
132133 return ChildProcessSpawner . makeHandle ( {
133134 pid : ChildProcessSpawner . ProcessId ( 123 ) ,
134135 stdout : Stream . empty ,
@@ -180,19 +181,21 @@ it.effect("lowers no score before the manager default is in place, and undoes in
180181 writesManagerDropIn = false ,
181182 ) => {
182183 let atSudo : ReturnType < typeof present > | undefined ;
184+ let sudoOptions : ChildProcess . CommandOptions | undefined ;
183185 return effect . pipe (
184186 Effect . provideService (
185187 ChildProcessSpawner . ChildProcessSpawner ,
186- fakeSudo ( exitCode , ( ) => {
188+ fakeSudo ( exitCode , ( command ) => {
187189 atSudo = present ( ) ;
190+ sudoOptions = command . options ;
188191 if ( writesManagerDropIn ) {
189192 NodeFS . mkdirSync ( NodePath . dirname ( managerDropIn ) , { recursive : true } ) ;
190193 NodeFS . writeFileSync ( managerDropIn , "[Service]\nOOMScoreAdjust=-900\n" ) ;
191194 }
192195 } ) ,
193196 ) ,
194197 Effect . exit ,
195- Effect . map ( ( exit ) => ( { exit, atSudo } ) ) ,
198+ Effect . map ( ( exit ) => ( { exit, atSudo, sudoOptions } ) ) ,
196199 ) ;
197200 } ;
198201 const refused = yield * withSudo ( ServiceProtection . applyProtection ( plan ) , 1 ) ;
@@ -209,6 +212,8 @@ it.effect("lowers no score before the manager default is in place, and undoes in
209212
210213 const applied = yield * withSudo ( ServiceProtection . applyProtection ( plan ) , 0 ) ;
211214 expect ( applied . atSudo ) . toEqual ( { managerDefaults : true , user : 0 } ) ;
215+ // sudo needs the controlling terminal to ask for a password.
216+ expect ( applied . sudoOptions ) . toMatchObject ( { detached : false , stdin : "inherit" } ) ;
212217 expect ( present ( ) ) . toEqual ( { managerDefaults : true , user : plan . user . length } ) ;
213218
214219 const removed = yield * withSudo ( ServiceProtection . removeProtection ( plan ) , 0 ) ;
0 commit comments