@@ -120,13 +120,16 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
120120 /** `undefined` makes `loginctl show-user` fail, as when logind does not know the user. */
121121 linger : string | undefined ;
122122 managerReachable : boolean ;
123+ /** The user bus is found only through `XDG_RUNTIME_DIR`, as without a login session. */
124+ busNeedsRuntimeDir : boolean ;
123125 lingerStartsManager : boolean ;
124126 enabled : boolean ;
125127 active : boolean ;
126128 } = {
127129 failCommand : undefined ,
128130 linger : "yes" ,
129131 managerReachable : true ,
132+ busNeedsRuntimeDir : false ,
130133 lingerStartsManager : true ,
131134 enabled : true ,
132135 active : true ,
@@ -186,7 +189,8 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
186189 failed ||
187190 unitOutsideManager ||
188191 ( ( command === "systemctl --user show-environment" || input . command === "busctl" ) &&
189- ! control . managerReachable ) ||
192+ ( ! control . managerReachable ||
193+ ( control . busNeedsRuntimeDir && input . env ?. XDG_RUNTIME_DIR === undefined ) ) ) ||
190194 ( input . command === "loginctl" &&
191195 input . args [ 0 ] === "show-user" &&
192196 control . linger === undefined ) ||
@@ -377,6 +381,20 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
377381 } ) ,
378382 ) ;
379383
384+ it . effect ( "does not reach a running root user manager under sudo" , ( ) =>
385+ Effect . gen ( function * ( ) {
386+ const { makeService, commands, control } = yield * makeHarness ( ) ;
387+ control . busNeedsRuntimeDir = true ;
388+ const service = yield * makeService ( undefined , "1.2.3" , undefined , false , undefined , true ) ;
389+
390+ expect ( yield * service . install ( ) . pipe ( Effect . flip ) ) . toMatchObject ( {
391+ _tag : "BootServicePrerequisiteError" ,
392+ problem : "user-manager-unavailable" ,
393+ } ) ;
394+ expect ( commands ) . not . toContain ( "systemctl --user enable t3code.service" ) ;
395+ } ) ,
396+ ) ;
397+
380398 it . effect ( "does not enable lingering for root under sudo" , ( ) =>
381399 Effect . gen ( function * ( ) {
382400 const { makeService, commands, control } = yield * makeHarness ( ) ;
0 commit comments