Implement server auth bootstrap and pairing flow (#1768)
Co-authored-by: codex <[email protected]> Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: cursor[bot] <206951365+cursor[bot]@users.noreply.github.com>
This commit is contained in:
155 files changed
+18713
-2954
No files matched your search
@@ -54,7 +54,6 @@ it.layer(NodeServices.layer)("dev-runner", (it) => {
|
||||
serverOffset: 0,
|
||||
webOffset: 0,
|
||||
t3Home: undefined,
|
||||
authToken: undefined,
|
||||
noBrowser: undefined,
|
||||
autoBootstrapProjectFromCwd: undefined,
|
||||
logWebSocketEvents: undefined,
|
||||
@@ -75,7 +74,6 @@ it.layer(NodeServices.layer)("dev-runner", (it) => {
|
||||
serverOffset: 0,
|
||||
webOffset: 0,
|
||||
t3Home: "/tmp/custom-t3",
|
||||
authToken: "secret",
|
||||
noBrowser: true,
|
||||
autoBootstrapProjectFromCwd: false,
|
||||
logWebSocketEvents: true,
|
||||
@@ -105,7 +103,6 @@ it.layer(NodeServices.layer)("dev-runner", (it) => {
|
||||
serverOffset: 0,
|
||||
webOffset: 0,
|
||||
t3Home: undefined,
|
||||
authToken: undefined,
|
||||
noBrowser: undefined,
|
||||
autoBootstrapProjectFromCwd: undefined,
|
||||
logWebSocketEvents: undefined,
|
||||
@@ -127,7 +124,6 @@ it.layer(NodeServices.layer)("dev-runner", (it) => {
|
||||
serverOffset: 0,
|
||||
webOffset: 0,
|
||||
t3Home: undefined,
|
||||
authToken: undefined,
|
||||
noBrowser: undefined,
|
||||
autoBootstrapProjectFromCwd: undefined,
|
||||
logWebSocketEvents: false,
|
||||
@@ -148,7 +144,6 @@ it.layer(NodeServices.layer)("dev-runner", (it) => {
|
||||
serverOffset: 0,
|
||||
webOffset: 0,
|
||||
t3Home: "/tmp/my-t3",
|
||||
authToken: undefined,
|
||||
noBrowser: undefined,
|
||||
autoBootstrapProjectFromCwd: undefined,
|
||||
logWebSocketEvents: undefined,
|
||||
@@ -161,13 +156,12 @@ it.layer(NodeServices.layer)("dev-runner", (it) => {
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("does not export backend bootstrap env for dev:desktop", () =>
|
||||
it.effect("pins desktop dev to a stable backend port and websocket url", () =>
|
||||
Effect.gen(function* () {
|
||||
const env = yield* createDevRunnerEnv({
|
||||
mode: "dev:desktop",
|
||||
baseEnv: {
|
||||
T3CODE_PORT: "3773",
|
||||
T3CODE_AUTH_TOKEN: "stale-token",
|
||||
T3CODE_MODE: "web",
|
||||
T3CODE_NO_BROWSER: "0",
|
||||
T3CODE_HOST: "0.0.0.0",
|
||||
@@ -176,7 +170,6 @@ it.layer(NodeServices.layer)("dev-runner", (it) => {
|
||||
serverOffset: 0,
|
||||
webOffset: 0,
|
||||
t3Home: "/tmp/my-t3",
|
||||
authToken: "fresh-token",
|
||||
noBrowser: true,
|
||||
autoBootstrapProjectFromCwd: undefined,
|
||||
logWebSocketEvents: undefined,
|
||||
@@ -187,14 +180,13 @@ it.layer(NodeServices.layer)("dev-runner", (it) => {
|
||||
|
||||
assert.equal(env.T3CODE_HOME, resolve("/tmp/my-t3"));
|
||||
assert.equal(env.PORT, "5733");
|
||||
assert.equal(env.ELECTRON_RENDERER_PORT, "5733");
|
||||
assert.equal(env.VITE_DEV_SERVER_URL, "http://localhost:5733");
|
||||
assert.equal(env.T3CODE_PORT, undefined);
|
||||
assert.equal(env.T3CODE_AUTH_TOKEN, undefined);
|
||||
assert.equal(env.VITE_DEV_SERVER_URL, "http://127.0.0.1:5733");
|
||||
assert.equal(env.HOST, "127.0.0.1");
|
||||
assert.equal(env.T3CODE_PORT, "4222");
|
||||
assert.equal(env.T3CODE_MODE, undefined);
|
||||
assert.equal(env.T3CODE_NO_BROWSER, undefined);
|
||||
assert.equal(env.T3CODE_HOST, undefined);
|
||||
assert.equal(env.VITE_WS_URL, undefined);
|
||||
assert.equal(env.VITE_WS_URL, "ws://127.0.0.1:4222");
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
+7
-20
@@ -13,6 +13,7 @@ const BASE_SERVER_PORT = 3773;
|
||||
const BASE_WEB_PORT = 5733;
|
||||
const MAX_HASH_OFFSET = 3000;
|
||||
const MAX_PORT = 65535;
|
||||
const DESKTOP_DEV_LOOPBACK_HOST = "127.0.0.1";
|
||||
|
||||
export const DEFAULT_T3_HOME = Effect.map(Effect.service(Path.Path), (path) =>
|
||||
path.join(homedir(), ".t3"),
|
||||
@@ -120,7 +121,6 @@ interface CreateDevRunnerEnvInput {
|
||||
readonly serverOffset: number;
|
||||
readonly webOffset: number;
|
||||
readonly t3Home: string | undefined;
|
||||
readonly authToken: string | undefined;
|
||||
readonly noBrowser: boolean | undefined;
|
||||
readonly autoBootstrapProjectFromCwd: boolean | undefined;
|
||||
readonly logWebSocketEvents: boolean | undefined;
|
||||
@@ -135,7 +135,6 @@ export function createDevRunnerEnv({
|
||||
serverOffset,
|
||||
webOffset,
|
||||
t3Home,
|
||||
authToken,
|
||||
noBrowser,
|
||||
autoBootstrapProjectFromCwd,
|
||||
logWebSocketEvents,
|
||||
@@ -152,8 +151,9 @@ export function createDevRunnerEnv({
|
||||
const output: NodeJS.ProcessEnv = {
|
||||
...baseEnv,
|
||||
PORT: String(webPort),
|
||||
ELECTRON_RENDERER_PORT: String(webPort),
|
||||
VITE_DEV_SERVER_URL: devUrl?.toString() ?? `http://localhost:${webPort}`,
|
||||
VITE_DEV_SERVER_URL:
|
||||
devUrl?.toString() ??
|
||||
`http://${isDesktopMode ? DESKTOP_DEV_LOOPBACK_HOST : "localhost"}:${webPort}`,
|
||||
T3CODE_HOME: resolvedBaseDir,
|
||||
};
|
||||
|
||||
@@ -161,9 +161,8 @@ export function createDevRunnerEnv({
|
||||
output.T3CODE_PORT = String(serverPort);
|
||||
output.VITE_WS_URL = `ws://localhost:${serverPort}`;
|
||||
} else {
|
||||
delete output.T3CODE_PORT;
|
||||
delete output.VITE_WS_URL;
|
||||
delete output.T3CODE_AUTH_TOKEN;
|
||||
output.T3CODE_PORT = String(serverPort);
|
||||
output.VITE_WS_URL = `ws://${DESKTOP_DEV_LOOPBACK_HOST}:${serverPort}`;
|
||||
delete output.T3CODE_MODE;
|
||||
delete output.T3CODE_NO_BROWSER;
|
||||
delete output.T3CODE_HOST;
|
||||
@@ -173,12 +172,6 @@ export function createDevRunnerEnv({
|
||||
output.T3CODE_HOST = host;
|
||||
}
|
||||
|
||||
if (!isDesktopMode && authToken !== undefined) {
|
||||
output.T3CODE_AUTH_TOKEN = authToken;
|
||||
} else if (!isDesktopMode) {
|
||||
delete output.T3CODE_AUTH_TOKEN;
|
||||
}
|
||||
|
||||
if (!isDesktopMode && noBrowser !== undefined) {
|
||||
output.T3CODE_NO_BROWSER = noBrowser ? "1" : "0";
|
||||
} else if (!isDesktopMode) {
|
||||
@@ -208,6 +201,7 @@ export function createDevRunnerEnv({
|
||||
}
|
||||
|
||||
if (isDesktopMode) {
|
||||
output.HOST = DESKTOP_DEV_LOOPBACK_HOST;
|
||||
delete output.T3CODE_DESKTOP_WS_URL;
|
||||
}
|
||||
|
||||
@@ -350,7 +344,6 @@ export function resolveModePortOffsets<R = NetService>({
|
||||
interface DevRunnerCliInput {
|
||||
readonly mode: DevMode;
|
||||
readonly t3Home: string | undefined;
|
||||
readonly authToken: string | undefined;
|
||||
readonly noBrowser: boolean | undefined;
|
||||
readonly autoBootstrapProjectFromCwd: boolean | undefined;
|
||||
readonly logWebSocketEvents: boolean | undefined;
|
||||
@@ -430,7 +423,6 @@ export function runDevRunnerWithInput(input: DevRunnerCliInput) {
|
||||
serverOffset,
|
||||
webOffset,
|
||||
t3Home: input.t3Home,
|
||||
authToken: input.authToken,
|
||||
noBrowser: resolveOptionalBooleanOverride(input.noBrowser, envOverrides.noBrowser),
|
||||
autoBootstrapProjectFromCwd: resolveOptionalBooleanOverride(
|
||||
input.autoBootstrapProjectFromCwd,
|
||||
@@ -503,11 +495,6 @@ const devRunnerCli = Command.make("dev-runner", {
|
||||
Flag.withDescription("Base directory for all T3 Code data (equivalent to T3CODE_HOME)."),
|
||||
Flag.withFallbackConfig(optionalStringConfig("T3CODE_HOME")),
|
||||
),
|
||||
authToken: Flag.string("auth-token").pipe(
|
||||
Flag.withDescription("Auth token (forwards to T3CODE_AUTH_TOKEN)."),
|
||||
Flag.withAlias("token"),
|
||||
Flag.withFallbackConfig(optionalStringConfig("T3CODE_AUTH_TOKEN")),
|
||||
),
|
||||
noBrowser: Flag.boolean("no-browser").pipe(
|
||||
Flag.withDescription("Browser auto-open toggle (equivalent to T3CODE_NO_BROWSER)."),
|
||||
Flag.withFallbackConfig(optionalBooleanConfig("T3CODE_NO_BROWSER")),
|
||||
|
||||
Reference in new issue
Block a user