From f9084485de89a0621362621dc94653deb391feea Mon Sep 17 00:00:00 2001 From: Zack Jackson <25274700+ScriptedAlchemy@users.noreply.github.com> Date: Sun, 8 Nov 2026 01:36:45 -0800 Subject: [PATCH 1/2] fix(ssh): detect installed services without a user manager --- packages/ssh/src/tunnel.test.ts | 27 +++++++++++++++++++++++++-- packages/ssh/src/tunnel.ts | 8 +++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/packages/ssh/src/tunnel.test.ts b/packages/ssh/src/tunnel.test.ts index 6f4f14ea9eb64..5be3d60fd9458 100644 --- a/packages/ssh/src/tunnel.test.ts +++ b/packages/ssh/src/tunnel.test.ts @@ -142,7 +142,15 @@ const runArchiveRunner = Effect.fn("test.runArchiveRunner")( ); describe("ssh tunnel scripts", () => { - it.live.each(["launchd", "systemd", "none"] as const)( + const serviceManagers = [ + "launchd", + "systemd", + "systemd-unavailable", + "systemd-unavailable-xdg", + "systemd-unavailable-relative-xdg", + "none", + ] as const; + it.live.each(serviceManagers)( "respects %s service ownership when the server is stopped", (manager) => Effect.gen(function* () { @@ -175,12 +183,27 @@ esac yield* fs.makeDirectory(agents, { recursive: true }); yield* fs.writeFileString(`${agents}/com.t3tools.t3code.service.plist`, "installed"); } + const xdgConfigHome = + manager === "systemd-unavailable-xdg" + ? `${root}/custom config` + : manager === "systemd-unavailable-relative-xdg" + ? "relative-config" + : undefined; + if (manager.startsWith("systemd-unavailable")) { + const units = `${manager === "systemd-unavailable-xdg" ? xdgConfigHome : `${root}/.config`}/systemd/user`; + yield* fs.makeDirectory(units, { recursive: true }); + yield* fs.writeFileString(`${units}/t3code.service`, "installed"); + } const ssh = ChildProcessSpawner.make((command) => { if (command._tag !== "StandardCommand") return Effect.die("Expected SSH command"); return spawner.spawn( ChildProcess.make("sh", ["-s", "--", "test-peer"], { ...command.options, - env: { HOME: root, PATH: `${bin}:/usr/bin:/bin` }, + env: { + HOME: root, + PATH: `${bin}:/usr/bin:/bin`, + ...(xdgConfigHome === undefined ? {} : { XDG_CONFIG_HOME: xdgConfigHome }), + }, extendEnv: false, }), ); diff --git a/packages/ssh/src/tunnel.ts b/packages/ssh/src/tunnel.ts index cb08ae9851c4e..2b491772472d5 100644 --- a/packages/ssh/src/tunnel.ts +++ b/packages/ssh/src/tunnel.ts @@ -744,7 +744,13 @@ if [ -z "$REMOTE_PORT" ]; then fi ;; Linux) - if command -v systemctl >/dev/null 2>&1 && systemctl --user cat t3code.service >/dev/null 2>&1; then + case "\${XDG_CONFIG_HOME:-}" in + /*) SERVICE_CONFIG_HOME="$XDG_CONFIG_HOME" ;; + *) SERVICE_CONFIG_HOME="$HOME/.config" ;; + esac + # SSH sessions can lack a reachable user manager while its unit remains installed. + if [ -f "$SERVICE_CONFIG_HOME/systemd/user/t3code.service" ] || + { command -v systemctl >/dev/null 2>&1 && systemctl --user cat t3code.service >/dev/null 2>&1; }; then SERVICE_INSTALLED=1 fi ;; From 4a0c2628891bf483adf318e86d0391e06bc1025b Mon Sep 17 00:00:00 2001 From: Zack Jackson <25274700+ScriptedAlchemy@users.noreply.github.com> Date: Sun, 8 Nov 2026 11:51:29 -0800 Subject: [PATCH 2/2] fix(ssh): find the installed unit across login config homes --- packages/ssh/src/tunnel.test.ts | 3 ++- packages/ssh/src/tunnel.ts | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/ssh/src/tunnel.test.ts b/packages/ssh/src/tunnel.test.ts index 5be3d60fd9458..5f0f1d7b94692 100644 --- a/packages/ssh/src/tunnel.test.ts +++ b/packages/ssh/src/tunnel.test.ts @@ -148,6 +148,7 @@ describe("ssh tunnel scripts", () => { "systemd-unavailable", "systemd-unavailable-xdg", "systemd-unavailable-relative-xdg", + "systemd-unavailable-login-xdg", "none", ] as const; it.live.each(serviceManagers)( @@ -184,7 +185,7 @@ esac yield* fs.writeFileString(`${agents}/com.t3tools.t3code.service.plist`, "installed"); } const xdgConfigHome = - manager === "systemd-unavailable-xdg" + manager === "systemd-unavailable-xdg" || manager === "systemd-unavailable-login-xdg" ? `${root}/custom config` : manager === "systemd-unavailable-relative-xdg" ? "relative-config" diff --git a/packages/ssh/src/tunnel.ts b/packages/ssh/src/tunnel.ts index 2b491772472d5..7e0b94f155a5d 100644 --- a/packages/ssh/src/tunnel.ts +++ b/packages/ssh/src/tunnel.ts @@ -744,12 +744,13 @@ if [ -z "$REMOTE_PORT" ]; then fi ;; Linux) + SERVICE_UNIT="systemd/user/t3code.service" + SERVICE_CONFIG_HOME="$HOME/.config" case "\${XDG_CONFIG_HOME:-}" in /*) SERVICE_CONFIG_HOME="$XDG_CONFIG_HOME" ;; - *) SERVICE_CONFIG_HOME="$HOME/.config" ;; esac - # SSH sessions can lack a reachable user manager while its unit remains installed. - if [ -f "$SERVICE_CONFIG_HOME/systemd/user/t3code.service" ] || + # The SSH login may have a different XDG home and no connection to the user manager. + if [ -f "$SERVICE_CONFIG_HOME/$SERVICE_UNIT" ] || [ -f "$HOME/.config/$SERVICE_UNIT" ] || { command -v systemctl >/dev/null 2>&1 && systemctl --user cat t3code.service >/dev/null 2>&1; }; then SERVICE_INSTALLED=1 fi