Skip to content
TypeScript

fix(cli): t3 pair's no-running-server hint keeps --base-dir (#30689)

Alex Southwell6f96d0ea0826
diff --git a/apps/server/src/cli/pair.test.ts b/apps/server/src/cli/pair.test.ts
index e912576caf9..e626461914a 100644
--- a/apps/server/src/cli/pair.test.ts
+++ b/apps/server/src/cli/pair.test.ts
@@ -34,6 +34,7 @@ import {
persistServerRuntimeState,
type PersistedServerRuntimeState,
} from "../serverRuntimeState.ts";
+import { resolveHostCliCommand } from "./invocation.ts";
import { DevServerNotProxiableError, resolveTailscaleLocalTarget } from "./pair.ts";
import packageJson from "../../package.json" with { type: "json" };
@@ -315,7 +316,7 @@ describe("t3 pair", () => {
it.effect("ignores runtime state whose recorded pid is no longer alive", () =>
withDescriptorServer((origin) =>
Effect.gen(function* () {
- const baseDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-pair-pid-test-"));
+ const baseDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3 pair pid test-"));
const statePath = NodePath.join(baseDir, "userdata", "server-runtime.json");
const state = yield* makePersistedServerRuntimeState({
config: { host: "127.0.0.1", devUrl: undefined },
@@ -334,6 +335,10 @@ describe("t3 pair", () => {
typeof error === "object" && error !== null && "cause" in error ? error.cause : error,
);
assert.include(rendered, "No running T3 Code server found.");
+ for (const subcommand of ["serve", "connect"]) {
+ const { command } = yield* resolveHostCliCommand(subcommand, ["--base-dir", baseDir]);
+ assert.include(rendered, `\`${command}\``);
+ }
}),
).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
);
diff --git a/apps/server/src/cli/pair.ts b/apps/server/src/cli/pair.ts
index 168946adc5e..904182ad29c 100644
--- a/apps/server/src/cli/pair.ts
+++ b/apps/server/src/cli/pair.ts
@@ -48,6 +48,7 @@ import {
} from "../startupAccess.ts";
import { authScopesFlag } from "./authScopes.ts";
import { baseDirFlag, DurationFromString } from "./config.ts";
+import { resolveHostCliCommand } from "./invocation.ts";
const WELL_KNOWN_ENVIRONMENT_PATH = "/.well-known/t3/environment";
const PAIR_PROBE_TIMEOUT = Duration.millis(2_500);
@@ -65,6 +66,8 @@ export class NoRunningServerError extends Schema.TaggedError<NoRunningServerErro
{
checkedStatePaths: Schema.Array(Schema.String),
inLinkedWorktree: Schema.Boolean,
+ serveCommand: Schema.String,
+ connectCommand: Schema.String,
},
) {
override get message(): string {
@@ -74,7 +77,7 @@ export class NoRunningServerError extends Schema.TaggedError<NoRunningServerErro
...(this.inLinkedWorktree
? ["In a linked worktree, pass --base-dir to pair with a server outside it."]
: []),
- "Start one with `npx t3 serve`, or connect this machine with T3 Connect: `npx t3 connect`.",
+ `Start one with \`${this.serveCommand}\`, or connect this machine with T3 Connect: \`${this.connectCommand}\`.`,
].join("\n");
}
}
@@ -245,7 +248,8 @@ const discoverPairTarget = Effect.fn("pair.discoverPairTarget")(function* (
) {
const bases: Array<string> = [];
let inLinkedWorktree = false;
- if (explicitBaseDir !== undefined && explicitBaseDir.trim().length > 0) {
+ const hasExplicitBaseDir = explicitBaseDir !== undefined && explicitBaseDir.trim().length > 0;
+ if (hasExplicitBaseDir) {
bases.push(yield* resolveBaseDir(explicitBaseDir));
} else {
// Same precedence as dev-runner: inside a linked worktree only its own
@@ -292,7 +296,13 @@ const discoverPairTarget = Effect.fn("pair.discoverPairTarget")(function* (
} satisfies DiscoveredPairTarget;
}
}
- return yield* new NoRunningServerError({ checkedStatePaths, inLinkedWorktree });
+ const baseDirArgs = hasExplicitBaseDir ? ["--base-dir", explicitBaseDir] : [];
+ return yield* new NoRunningServerError({
+ checkedStatePaths,
+ inLinkedWorktree,
+ serveCommand: (yield* resolveHostCliCommand("serve", baseDirArgs)).command,
+ connectCommand: (yield* resolveHostCliCommand("connect", baseDirArgs)).command,
+ });
});
/** Use the discovered state directory, independent of ambient config variables. */