@devries-cameron20 / t3code Mirror · read-only / commits / 22910ffdd2
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 21, 19:45 UTC

fix(ssh): an ssh config alias keeps following its Port after it changes (#35063)

Julius Marminge committed Nov 12, 2026 at 02:38 UTC 22910ffdd2f2fd594127afb61a8f21595db1ba47
2 files changed +45 -1
packages/ssh/src/tunnel.test.ts
+43
@@ -468,6 +468,49 @@ describe("ssh tunnel scripts", () => {
468 }),
469 );
470
471 + it.effect("reconnects a saved alias through the port its ssh config names now", () =>
472 + Effect.gen(function* () {
473 + let configPort = 53_791;
474 + const tunnelPorts: Array<string | undefined> = [];
475 + const spawner = ChildProcessSpawner.make((command) => {
476 + const args = commandArgs(command);
477 + if (args.includes("-G")) {
478 + return Effect.succeed(
479 + makeSuccessfulProcess(`hostname 127.0.0.1\nuser developer\nport ${configPort}\n`),
480 + );
481 + }
482 + if (args.includes("-N")) {
483 + tunnelPorts.push(args[args.indexOf("-p") + 1]);
484 + return Effect.succeed(makeRunningProcess(() => undefined));
485 + }
486 + return Effect.succeed(makeSuccessfulProcess('{"remotePort":3773}\n'));
487 + });
488 + const layer = Layer.mergeAll(
489 + NodeServices.layer,
490 + NodeCrypto.layer,
491 + Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, spawner),
492 + Layer.succeed(HttpClient.HttpClient, testHttpClient),
493 + Layer.succeed(NetService.NetService, testNetService),
494 + SshAuth.SshPasswordPrompt.disabledLayer,
495 + SshTunnel.SshEnvironmentManager.layer({ resolveCliRunner: Effect.succeed(ARCHIVE) }),
496 + );
497 + yield* Effect.gen(function* () {
498 + const manager = yield* SshTunnel.SshEnvironmentManager;
499 + const added = yield* manager.ensureEnvironment({
500 + alias: "lima-sandbox",
501 + hostname: "lima-sandbox",
502 + username: null,
503 + port: null,
504 + });
505 + // The VM restarts on a new port; the client reconnects with the target it saved.
506 + yield* manager.disconnectEnvironment(added.target);
507 + configPort = 53_812;
508 + yield* manager.ensureEnvironment(added.target);
509 + assert.deepStrictEqual(tunnelPorts, ["53791", "53812"]);
510 + }).pipe(Effect.provide(layer), Effect.scoped);
511 + }),
512 + );
513 +
514 it.effect("fails with a readiness error when ssh never connects", () =>
515 Effect.gen(function* () {
516 const tunnelSpawned = yield* Deferred.make<void>();
packages/ssh/src/tunnel.ts
+2 -1
@@ -1870,7 +1870,8 @@ const makeSshEnvironmentManager = Effect.fn("ssh/tunnel.SshEnvironmentManager.ma
1870 issuedPairingToken: pairingToken !== null,
1871 });
1872 return {
1873 - target: entry.target,
1873 + // Callers save this target; a port ssh -G resolved would pin the alias's current Port.
1874 + target: { ...entry.target, port: target.port },
1875 httpBaseUrl: entry.httpBaseUrl,
1876 wsBaseUrl: entry.wsBaseUrl,
1877 pairingToken,