@@ -318,6 +318,70 @@ it.layer(NodeServices.layer)("service state persistence", (it) => {
318318 } ) ,
319319 ) ;
320320
321+ it . effect (
322+ "repoints the systemd unit the manager loads when environment.d moves XDG_CONFIG_HOME" ,
323+ ( ) =>
324+ Effect . gen ( function * ( ) {
325+ const fs = yield * FileSystem . FileSystem ;
326+ const path = yield * Path . Path ;
327+ const root = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-service-launcher-xdg-" } ) ;
328+ const home = path . join ( root , "home" ) ;
329+ const managerUnitDir = path . join ( home , ".config" , "systemd" , "user" ) ;
330+ const unitPath = path . join ( managerUnitDir , "t3code.service" ) ;
331+ const render = ( version : string ) =>
332+ renderBootServiceUnit ( { ...unitPlan ( root , version ) , unitPath } ) ;
333+ yield * fs . makeDirectory ( managerUnitDir , { recursive : true } ) ;
334+ yield * fs . writeFileString ( unitPath , render ( "1.0.0" ) ) ;
335+ // Fake manager: busctl reports the unit search path, systemctl reloads.
336+ const bin = path . join ( root , "bin" ) ;
337+ yield * fs . makeDirectory ( bin , { recursive : true } ) ;
338+ const unitPathJson = JSON . stringify ( {
339+ type : "as" ,
340+ data : [ `${ managerUnitDir } .control` , managerUnitDir , "/usr/lib/systemd/user" ] ,
341+ } ) ;
342+ yield * fs . writeFileString (
343+ path . join ( bin , "busctl" ) ,
344+ `#!/bin/sh\nprintf '%s\\n' '${ unitPathJson } '\n` ,
345+ ) ;
346+ yield * fs . writeFileString (
347+ path . join ( bin , "systemctl" ) ,
348+ `#!/bin/sh\necho reload >> '${ path . join ( root , "reloads" ) } '\n` ,
349+ ) ;
350+ yield * fs . chmod ( path . join ( bin , "busctl" ) , 0o755 ) ;
351+ yield * fs . chmod ( path . join ( bin , "systemctl" ) , 0o755 ) ;
352+ yield * writeFakeRuntime (
353+ fs ,
354+ path ,
355+ path . join ( root , "runtime" , "versions" , "1.1.0" ) ,
356+ "process.exit(0);\n" ,
357+ ) ;
358+ yield * Effect . promise ( ( ) =>
359+ writeServiceState ( path . join ( root , "runtime" , "service-state.json" ) , {
360+ protocol : SERVICE_LAUNCHER_PROTOCOL ,
361+ activeVersion : "1.1.0" ,
362+ update : {
363+ id : "update-1" ,
364+ fromVersion : "1.0.0" ,
365+ targetVersion : "1.1.0" ,
366+ status : "committed" ,
367+ } ,
368+ } ) ,
369+ ) ;
370+ vi . stubEnv ( "PATH" , bin ) ;
371+ vi . stubEnv ( "HOME" , home ) ;
372+ // environment.d changes what services inherit, not where the manager reads units.
373+ vi . stubEnv ( "XDG_CONFIG_HOME" , path . join ( home , "service-config" ) ) ;
374+ vi . stubEnv ( "T3_BOOT_SERVICE_UNIT" , "t3code.service" ) ;
375+
376+ yield * Effect . promise ( ( ) =>
377+ expect ( runLauncher ( root ) ) . rejects . toThrow ( "Active child exited unexpectedly (0)." ) ,
378+ ) ;
379+
380+ assert . equal ( yield * fs . readFileString ( unitPath ) , render ( "1.1.0" ) ) ;
381+ assert . equal ( yield * fs . readFileString ( path . join ( root , "reloads" ) ) , "reload\n" ) ;
382+ } ) ,
383+ ) ;
384+
321385 it . effect ( "keeps the service manager's append log bounded when it starts" , ( ) =>
322386 Effect . gen ( function * ( ) {
323387 const fs = yield * FileSystem . FileSystem ;
0 commit comments