@@ -90,10 +90,19 @@ const macInstallerPath =
9090const makeHarness = Effect . fn ( "test.make_boot_service_harness" ) ( function * (
9191 platform : NodeJS . Platform = "linux" ,
9292 installerPath = macInstallerPath ,
93+ xdgConfigHome ?: string ,
94+ managerXdgConfigHome = xdgConfigHome ,
9395) {
9496 const fs = yield * FileSystem . FileSystem ;
9597 const path = yield * Path . Path ;
9698 const home = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-boot-service-test-" } ) ;
99+ const managerUnitDir = path . join (
100+ managerXdgConfigHome !== undefined && path . isAbsolute ( managerXdgConfigHome )
101+ ? managerXdgConfigHome
102+ : path . join ( home , ".config" ) ,
103+ "systemd" ,
104+ "user" ,
105+ ) ;
97106 const baseDir = path . join ( home , ".t3" ) ;
98107 const statePath = path . join ( baseDir , "runtime" , "service-state.json" ) ;
99108 const runtime = pinnedRuntimePaths ( path , baseDir , "1.2.3" , platform ) ;
@@ -140,15 +149,26 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
140149 }
141150 return {
142151 stdout :
143- input . args [ 0 ] === "--version"
144- ? `t3 v${ / v e r s i o n s \/ ( [ ^ / ] + ) \/ / . exec ( input . command ) ?. [ 1 ] ?? "1.2.3" } \n`
145- : input . command === "loginctl" && input . args [ 0 ] === "show-user"
146- ? `${ control . linger } \n`
147- : input . args [ 1 ] === "is-enabled"
148- ? control . enabled
149- ? "enabled\n"
150- : "disabled\n"
151- : "" ,
152+ input . command === "busctl"
153+ ? JSON . stringify ( {
154+ type : "as" ,
155+ data : [
156+ "/usr/lib/systemd/user" ,
157+ `${ managerUnitDir } .control` ,
158+ "/run/user/501/systemd/transient" ,
159+ managerUnitDir ,
160+ "/etc/systemd/user" ,
161+ ] ,
162+ } )
163+ : input . args [ 0 ] === "--version"
164+ ? `t3 v${ / v e r s i o n s \/ ( [ ^ / ] + ) \/ / . exec ( input . command ) ?. [ 1 ] ?? "1.2.3" } \n`
165+ : input . command === "loginctl" && input . args [ 0 ] === "show-user"
166+ ? `${ control . linger } \n`
167+ : input . args [ 1 ] === "is-enabled"
168+ ? control . enabled
169+ ? "enabled\n"
170+ : "disabled\n"
171+ : "" ,
152172 stderr : "" ,
153173 code : ChildProcessSpawner . ExitCode (
154174 failed ||
@@ -198,6 +218,7 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
198218 ConfigProvider . fromEnv ( {
199219 env : {
200220 HOME : home ,
221+ ...( xdgConfigHome === undefined ? { } : { XDG_CONFIG_HOME : xdgConfigHome } ) ,
201222 ...( environmentPath === undefined || environmentPath === ""
202223 ? { }
203224 : { PATH : environmentPath } ) ,
@@ -213,6 +234,7 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
213234 service,
214235 makeService,
215236 fs,
237+ home,
216238 baseDir,
217239 statePath,
218240 commands,
@@ -315,10 +337,52 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
315337 } ) ,
316338 ) ;
317339
318- it . effect ( "installs, reports current state, and uninstalls" , ( ) =>
340+ it . effect . each ( [
341+ "unset" ,
342+ "empty" ,
343+ "relative" ,
344+ "relocated" ,
345+ "shell-only" ,
346+ "manager-only" ,
347+ "manager-unavailable" ,
348+ ] as const ) ( "installs, discovers, restarts, and uninstalls with $XDG_CONFIG_HOME %s" , ( setting ) =>
319349 Effect . gen ( function * ( ) {
320- const { service, fs, statePath, timeouts, runtime } = yield * makeHarness ( ) ;
350+ const path = yield * Path . Path ;
351+ const fs = yield * FileSystem . FileSystem ;
352+ const configRoot = yield * fs . makeTempDirectoryScoped ( { prefix : "t3-xdg-config-" } ) ;
353+ const xdgConfigHome = {
354+ unset : undefined ,
355+ empty : "" ,
356+ relative : "relative-config" ,
357+ relocated : path . join ( configRoot , "config root" ) ,
358+ "shell-only" : path . join ( configRoot , "config root" ) ,
359+ "manager-only" : undefined ,
360+ "manager-unavailable" : path . join ( configRoot , "config root" ) ,
361+ } [ setting ] ;
362+ const managerXdgConfigHome =
363+ setting === "shell-only"
364+ ? ""
365+ : setting === "manager-only"
366+ ? path . join ( configRoot , "config root" )
367+ : undefined ;
368+ const { service, makeService, home, statePath, timeouts, runtime, control } =
369+ yield * makeHarness ( "linux" , undefined , xdgConfigHome , managerXdgConfigHome ) ;
370+ const unitPath = path . join (
371+ setting === "relocated" || setting === "manager-only" || setting === "manager-unavailable"
372+ ? path . join ( configRoot , "config root" )
373+ : path . join ( home , ".config" ) ,
374+ "systemd" ,
375+ "user" ,
376+ "t3code.service" ,
377+ ) ;
378+ expect ( yield * service . status ) . toMatchObject ( { installed : false , unitPath } ) ;
321379 const plan = yield * service . install ( ) ;
380+ expect ( plan . unitPath ) . toBe ( unitPath ) ;
381+ if ( setting === "manager-unavailable" ) {
382+ control . failCommand =
383+ "busctl --user --json=short get-property org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager UnitPath" ;
384+ }
385+ const discoveredService = yield * makeService ( ) ;
322386
323387 expect ( parseServiceState ( yield * fs . readFileString ( statePath ) ) ) . toEqual ( {
324388 protocol : SERVICE_LAUNCHER_PROTOCOL ,
@@ -332,6 +396,12 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
332396 current : true ,
333397 installedVersion : "1.2.3" ,
334398 } ) ;
399+ expect ( yield * discoveredService . status ) . toMatchObject ( {
400+ installed : true ,
401+ current : true ,
402+ unitPath,
403+ } ) ;
404+ expect ( yield * discoveredService . restart ) . toBe ( "restarted" ) ;
335405 const pendingState = JSON . stringify ( {
336406 protocol : SERVICE_LAUNCHER_PROTOCOL ,
337407 activeVersion : "1.2.3" ,
@@ -345,8 +415,9 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
345415 } ) ;
346416 yield * fs . writeFileString ( statePath , pendingState ) ;
347417 expect ( ( yield * service . status ) . current ) . toBe ( false ) ;
348- expect ( yield * service . uninstall ) . toBe ( true ) ;
349- expect ( ( yield * service . status ) . installed ) . toBe ( false ) ;
418+ expect ( yield * discoveredService . uninstall ) . toBe ( true ) ;
419+ expect ( yield * fs . exists ( unitPath ) ) . toBe ( false ) ;
420+ expect ( ( yield * discoveredService . status ) . installed ) . toBe ( false ) ;
350421 // systemd can take 90s to stop, exceeding the runner's 60s default.
351422 expect ( timeouts . get ( "systemctl --user disable --now t3code.service" ) ) . toEqual (
352423 Duration . seconds ( 120 ) ,
0 commit comments