@devries-cameron20 / t3code Mirror · read-only / commits / b1913b99c8
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 07:00 UTC

fix(server): honor relocated systemd user configuration (#29244)

Lakshmi Tanmay committed Nov 3, 2026 at 07:08 UTC b1913b99c8c77e5b8096f84f02e90505033db8b5
2 files changed +140 -22
apps/server/src/cloud/bootService.test.ts
+84 -13
@@ -90,10 +90,19 @@ const macInstallerPath =
90 const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
91 platform: NodeJS.Platform = "linux",
92 installerPath = macInstallerPath,
93 + xdgConfigHome?: string,
94 + managerXdgConfigHome = xdgConfigHome,
95 ) {
96 const fs = yield* FileSystem.FileSystem;
97 const path = yield* Path.Path;
98 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 + );
106 const baseDir = path.join(home, ".t3");
107 const statePath = path.join(baseDir, "runtime", "service-state.json");
108 const runtime = pinnedRuntimePaths(path, baseDir, "1.2.3", platform);
@@ -140,15 +149,26 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
149 }
150 return {
151 stdout:
143 - input.args[0] === "--version"
144 - ? `t3 v${/versions\/([^/]+)\//.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${/versions\/([^/]+)\//.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 + : "",
172 stderr: "",
173 code: ChildProcessSpawner.ExitCode(
174 failed ||
@@ -198,6 +218,7 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
218 ConfigProvider.fromEnv({
219 env: {
220 HOME: home,
221 + ...(xdgConfigHome === undefined ? {} : { XDG_CONFIG_HOME: xdgConfigHome }),
222 ...(environmentPath === undefined || environmentPath === ""
223 ? {}
224 : { PATH: environmentPath }),
@@ -213,6 +234,7 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
234 service,
235 makeService,
236 fs,
237 + home,
238 baseDir,
239 statePath,
240 commands,
@@ -315,10 +337,52 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
337 }),
338 );
339
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) =>
349 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 });
379 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();
386
387 expect(parseServiceState(yield* fs.readFileString(statePath))).toEqual({
388 protocol: SERVICE_LAUNCHER_PROTOCOL,
@@ -332,6 +396,12 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
396 current: true,
397 installedVersion: "1.2.3",
398 });
399 + expect(yield* discoveredService.status).toMatchObject({
400 + installed: true,
401 + current: true,
402 + unitPath,
403 + });
404 + expect(yield* discoveredService.restart).toBe("restarted");
405 const pendingState = JSON.stringify({
406 protocol: SERVICE_LAUNCHER_PROTOCOL,
407 activeVersion: "1.2.3",
@@ -345,8 +415,9 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
415 });
416 yield* fs.writeFileString(statePath, pendingState);
417 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);
421 // systemd can take 90s to stop, exceeding the runner's 60s default.
422 expect(timeouts.get("systemctl --user disable --now t3code.service")).toEqual(
423 Duration.seconds(120),
apps/server/src/cloud/bootService.ts
+56 -9
@@ -213,15 +213,9 @@ export interface BootServiceManager {
213
214 function systemdManager(input: {
215 readonly path: Path.Path;
216 - readonly homeDir: string;
216 + readonly unitDir: string;
217 }): BootServiceManager {
218 - const unitPath = input.path.join(
219 - input.homeDir,
220 - ".config",
221 - "systemd",
222 - "user",
223 - BOOT_SERVICE_UNIT_FILE,
224 - );
218 + const unitPath = input.path.join(input.unitDir, BOOT_SERVICE_UNIT_FILE);
219 const prepareActivation = [
220 {
221 step: "reloading systemd user units",
@@ -358,6 +352,8 @@ function launchdManager(input: {
352 function selectBootServiceManager(input: {
353 readonly platform: NodeJS.Platform;
354 readonly homeDir: string;
355 + readonly xdgConfigHome: string;
356 + readonly systemdUnitDir: string | undefined;
357 readonly uid: number | undefined;
358 readonly path: Path.Path;
359 readonly environmentPath: string;
@@ -366,7 +362,18 @@ function selectBootServiceManager(input: {
362 return undefined;
363 }
364 if (input.platform === "linux") {
369 - return systemdManager({ path: input.path, homeDir: input.homeDir });
365 + return systemdManager({
366 + path: input.path,
367 + unitDir:
368 + input.systemdUnitDir ??
369 + input.path.join(
370 + input.path.isAbsolute(input.xdgConfigHome)
371 + ? input.xdgConfigHome
372 + : input.path.join(input.homeDir, ".config"),
373 + "systemd",
374 + "user",
375 + ),
376 + });
377 }
378 if (input.platform === "darwin" && input.uid !== undefined) {
379 return launchdManager({
@@ -379,6 +386,42 @@ function selectBootServiceManager(input: {
386 return undefined;
387 }
388
389 +const decodeSystemdUnitPaths = Schema.decodeUnknownEffect(
390 + Schema.fromJsonString(Schema.Struct({ data: Schema.Array(Schema.String) })),
391 +);
392 +
393 +// The manager may not share the installer's environment; JSON preserves spaces in its paths.
394 +const readSystemdUnitDirectory = Effect.fn("cloud.boot_service.read_systemd_unit_directory")(
395 + function* () {
396 + const runner = yield* ProcessRunner.ProcessRunner;
397 + const path = yield* Path.Path;
398 + const result = yield* runner.run({
399 + command: "busctl",
400 + args: [
401 + "--user",
402 + "--json=short",
403 + "get-property",
404 + "org.freedesktop.systemd1",
405 + "/org/freedesktop/systemd1",
406 + "org.freedesktop.systemd1.Manager",
407 + "UnitPath",
408 + ],
409 + timeout: Duration.seconds(5),
410 + });
411 + if (result.code !== 0) return undefined;
412 + const { data } = yield* decodeSystemdUnitPaths(result.stdout);
413 + // The persistent control directory identifies the manager's config root despite UnitPath overrides.
414 + const controlDirectory = data.find(
415 + (directory) =>
416 + path.isAbsolute(directory) &&
417 + directory.endsWith("/systemd/user.control") &&
418 + data.includes(directory.slice(0, -".control".length)),
419 + );
420 + return controlDirectory?.slice(0, -".control".length);
421 + },
422 + Effect.orElseSucceed(() => undefined),
423 +);
424 +
425 export class BootServiceUnsupportedError extends Schema.TaggedError<BootServiceUnsupportedError>()(
426 "BootServiceUnsupportedError",
427 { platform: Schema.String },
@@ -536,6 +579,7 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
579 yield* Config.String(CLI_RELEASE_BASE_URL_ENV).pipe(Config.option),
580 );
581 const homeDir = yield* Config.String("HOME").pipe(Config.withDefault(""));
582 + const xdgConfigHome = yield* Config.String("XDG_CONFIG_HOME").pipe(Config.withDefault(""));
583 const installerPath = yield* Config.String("PATH").pipe(Config.withDefault(""));
584 const runningInsideService =
585 (yield* Config.String(BOOT_SERVICE_UNIT_ENV).pipe(Config.withDefault(""))) ===
@@ -573,9 +617,12 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
617 ),
618 ).join(":");
619
620 + const systemdUnitDir = platform === "linux" ? yield* readSystemdUnitDirectory() : undefined;
621 const detectedManager = selectBootServiceManager({
622 platform,
623 homeDir,
624 + xdgConfigHome,
625 + systemdUnitDir,
626 uid,
627 path,
628 environmentPath,