Skip to content
This repository was archived by the owner on Oct 10, 2026. It is now read-only.

Commit 7a820ab

Browse files
t3dotggclaudejuliusmarmingecodex
authored
feat: add headless t3 connect setup for SSH hosts (pingdotgg#3749)
Co-authored-by: Claude Fable 5 <[email protected]> Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: codex <[email protected]>
1 parent 53e3c98 commit 7a820ab

35 files changed

Lines changed: 3017 additions & 144 deletions

‎.env.example‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
# Get this from your relay deployment. `infra/relay` deploys update it automatically.
1919
# T3CODE_RELAY_URL=https://relay.example.com
2020

21+
# Optional: hosted app origin used by the CLI's out-of-band OAuth flow.
22+
# Defaults to https://app.t3.codes; override to test against a staging deployment.
23+
# T3CODE_HOSTED_APP_URL=https://nightly.app.t3.codes
24+
2125
# Public, ingest-only mobile OpenTelemetry configuration.
2226
# T3CODE_MOBILE_OTLP_TRACES_URL=https://api.axiom.co/v1/traces
2327
# T3CODE_MOBILE_OTLP_TRACES_DATASET=t3-code-mobile-traces-dev

‎.plans/t3-connect-remote-setup.html‎

Lines changed: 257 additions & 0 deletions
Large diffs are not rendered by default.

‎apps/server/src/bin.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ it.layer(NodeServices.layer)("bin cli parsing", (it) => {
236236
}),
237237
);
238238

239-
it.effect("logs in to headless connect without enabling access", () =>
239+
it.effect("accepts the --headless login override without enabling access", () =>
240240
Effect.gen(function* () {
241241
const baseDir = NodeFS.mkdtempSync(
242242
NodePath.join(NodeOS.tmpdir(), "t3-cli-cloud-login-test-"),
@@ -254,7 +254,7 @@ it.layer(NodeServices.layer)("bin cli parsing", (it) => {
254254
);
255255

256256
const login = yield* captureStdout(
257-
runConnectCli(["connect", "login", "--base-dir", baseDir]),
257+
runConnectCli(["connect", "login", "--base-dir", baseDir, "--headless"]),
258258
);
259259
const status = yield* captureStdout(
260260
runConnectCli(["connect", "status", "--base-dir", baseDir, "--json"]),
@@ -265,7 +265,7 @@ it.layer(NodeServices.layer)("bin cli parsing", (it) => {
265265
readonly authenticated: boolean;
266266
};
267267

268-
assert.equal(login.output, "Signed in to T3 Connect.");
268+
assert.equal(login.output, "✓ Signed in");
269269
assert.isFalse(decoded.desired);
270270
assert.isTrue(decoded.authenticated);
271271
}),

‎apps/server/src/cli/connect.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,68 @@
11
import * as RelayClient from "@t3tools/shared/relayClient";
22
import { assert, it } from "@effect/vitest";
33
import * as Cause from "effect/Cause";
4+
import * as ConfigProvider from "effect/ConfigProvider";
45
import * as Console from "effect/Console";
56
import * as Effect from "effect/Effect";
67
import * as Exit from "effect/Exit";
78
import * as Logger from "effect/Logger";
89
import * as Option from "effect/Option";
910
import * as References from "effect/References";
11+
import * as Terminal from "effect/Terminal";
1012

1113
import {
1214
acquireRelayClientForLink,
15+
formatHeadlessAuthorizationPrompt,
16+
formatRelayClientReady,
17+
headlessSessionConfig,
1318
isPublishAgentActivityEnabledValue,
19+
recoverBootServiceOffer,
1420
reportCloudDisconnectResults,
1521
} from "./connect.ts";
1622

23+
it("explains how to complete headless authorization", () => {
24+
assert.equal(
25+
formatHeadlessAuthorizationPrompt("https://example.test/connect"),
26+
[
27+
"Headless authorization",
28+
"Open this URL on a device with a browser:",
29+
" https://example.test/connect",
30+
"",
31+
"After signing in, return here and enter the code shown in your browser.",
32+
].join("\n"),
33+
);
34+
});
35+
36+
it("formats relay readiness without printing its installation path", () => {
37+
assert.equal(formatRelayClientReady("2026.5.2"), "✓ Relay client ready · cloudflared 2026.5.2");
38+
});
39+
40+
const readHeadlessSessionConfig = (env: Record<string, string>) =>
41+
headlessSessionConfig.pipe(Effect.provide(ConfigProvider.layer(ConfigProvider.fromEnv({ env }))));
42+
1743
const managedExecutable = {
1844
status: "available",
1945
executablePath: "/tmp/cloudflared",
2046
source: "managed",
2147
version: RelayClient.CLOUDFLARED_VERSION,
2248
} as const;
2349

50+
it.effect("detects headless operation from individual SSH config values", () =>
51+
Effect.gen(function* () {
52+
assert.isFalse(yield* readHeadlessSessionConfig({}));
53+
assert.isFalse(yield* readHeadlessSessionConfig({ CI: "true" }));
54+
assert.isTrue(yield* readHeadlessSessionConfig({ SSH_CONNECTION: "client server" }));
55+
assert.isTrue(yield* readHeadlessSessionConfig({ SSH_TTY: "/dev/pts/1" }));
56+
}),
57+
);
58+
59+
it.effect("treats cancelling optional background setup as a successful skip", () =>
60+
Effect.gen(function* () {
61+
const result = yield* recoverBootServiceOffer(Effect.fail(new Terminal.QuitError({})));
62+
assert.isFalse(result);
63+
}),
64+
);
65+
2466
it.effect("does not install the relay client when the user declines the managed download", () =>
2567
Effect.gen(function* () {
2668
let installCalls = 0;

0 commit comments

Comments
 (0)