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 21, 06:00 UTC
fix(ssh): connect when ~/.t3 is a symlink to a missing directory (#39184)
Julius Marminge committed
Nov 19, 2026 at 08:33 UTC
8d5e0b241d71bec0736ae9719fe89ea63cb53e18
2 files changed
+33
packages/ssh/src/tunnel.test.ts
+23
@@ -1647,6 +1647,29 @@ const canBind = (port) =>
1647
}).pipe(Effect.provide(NodeServices.layer)),
1648
);
1649
1650
+ // An NFS home can carry a ~/.t3 symlink whose target exists only on another host.
1651
+ it.live.skipIf(windowsHost)("launches through a ~/.t3 symlink whose target is missing", () =>
1652
+ Effect.gen(function* () {
1653
+ const fs = yield* FileSystem.FileSystem;
1654
+ const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-dangling-home-" });
1655
+ const home = `${root}/home`;
1656
+ const target = `${root}/shared/t3`;
1657
+ yield* fs.makeDirectory(home, { recursive: true });
1658
+ yield* fs.symlink(target, `${home}/.t3`);
1659
+ const launch = `${root}/launch.sh`;
1660
+ yield* fs.writeFileString(
1661
+ launch,
1662
+ SshTunnel.buildRemoteLaunchScript({
1663
+ archiveVersion: "0.1.6",
1664
+ releaseBaseUrl: "http://127.0.0.1:9",
1665
+ }),
1666
+ );
1667
+ const result = yield* runScript(home, [launch, "test-state"]);
1668
+ assert.notInclude(result.stderr, "File exists");
1669
+ assert.isTrue(yield* fs.exists(`${target}/ssh-launch/test-state`), result.stderr);
1670
+ }).pipe(Effect.provide(NodeServices.layer)),
1671
+ );
1672
+
1673
it.live.skipIf(windowsHost)("a newer client still replaces an older managed server", () =>
1674
Effect.gen(function* () {
1675
const { connect, readServerVersion } = yield* prepareLaunch(["0.1.5", "0.1.6"]);
packages/ssh/src/tunnel.ts
+10
@@ -593,6 +593,12 @@ const REMOTE_MANAGED_SERVER_RUNNING_SCRIPT = `managed_server_running() {
593
! ps -ww -o args= -p "$$" >/dev/null 2>&1
594
}`;
595
596
+// NFS-shared homes can link ~/.t3 to a directory that does not exist yet, and
597
+// mkdir -p fails with EEXIST on a dangling symlink, so create its target first.
598
+const REMOTE_ENSURE_T3_HOME_SCRIPT = `if [ -L "$HOME/.t3" ] && [ ! -e "$HOME/.t3" ]; then
599
+ (cd "$HOME" && mkdir -p "$(readlink .t3)")
600
+fi`;
601
+
602
const REMOTE_LAUNCH_SCRIPT = `set -eu
603
@@T3_NODE_ENV_SCRIPT@@
604
STATE_KEY="$1"
@@ -608,6 +614,7 @@ RUNNER_FILE="$STATE_DIR/run-t3.sh"
614
RUNNER_NEXT="$STATE_DIR/run-t3.next.$$"
615
LAUNCH_LOCK="$DEFAULT_SERVER_HOME/ssh-launch/.launch.lock"
616
LAUNCH_BREAK_LOCK="$LAUNCH_LOCK.break"
617
+@@T3_ENSURE_T3_HOME_SCRIPT@@
618
mkdir -p "$STATE_DIR"
619
cleanup_launch() {
620
rm -f "$RUNNER_NEXT"
@@ -1030,6 +1037,7 @@ const REMOTE_PAIRING_SCRIPT = `set -eu
1037
STATE_DIR="$HOME/.t3/ssh-launch/@@T3_STATE_KEY@@"
1038
DEFAULT_SERVER_HOME="$HOME/.t3"
1039
RUNNER_FILE="$STATE_DIR/run-t3.sh"
1040
+@@T3_ENSURE_T3_HOME_SCRIPT@@
1041
mkdir -p "$STATE_DIR"
1042
cat >"$RUNNER_FILE" <<'SH'
1043
@@T3_RUNNER_SCRIPT@@
@@ -1141,6 +1149,7 @@ export function buildRemoteLaunchScript(input?: RemoteT3RunnerOptions): string {
1149
T3_PICK_PORT_SCRIPT: stripTrailingNewlines(REMOTE_PICK_PORT_SCRIPT),
1150
T3_WAIT_READY_SCRIPT: stripTrailingNewlines(REMOTE_WAIT_READY_SCRIPT),
1151
T3_MANAGED_SERVER_RUNNING_SCRIPT: REMOTE_MANAGED_SERVER_RUNNING_SCRIPT,
1152
+ T3_ENSURE_T3_HOME_SCRIPT: REMOTE_ENSURE_T3_HOME_SCRIPT,
1153
T3_DEFAULT_REMOTE_PORT: String(DEFAULT_REMOTE_PORT),
1154
T3_REMOTE_PORT_SCAN_WINDOW: String(REMOTE_PORT_SCAN_WINDOW),
1155
T3_READY_TIMEOUT_MS: String(REMOTE_READY_TIMEOUT_MS),
@@ -1156,6 +1165,7 @@ export function buildRemoteLaunchScript(input?: RemoteT3RunnerOptions): string {
1165
function buildRemotePairingScript(stateKey: string, input?: RemoteT3RunnerOptions): string {
1166
return applyScriptPlaceholders(REMOTE_PAIRING_SCRIPT, {
1167
T3_STATE_KEY: stateKey,
1168
+ T3_ENSURE_T3_HOME_SCRIPT: REMOTE_ENSURE_T3_HOME_SCRIPT,
1169
T3_RUNNER_SCRIPT: stripTrailingNewlines(buildRemoteT3RunnerScript(input)),
1170
});
1171
}