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 22, 20:45 UTC
fix(server): t3 pair in a worktree no longer falls back to the live install (#22855)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 21, 2026 at 05:31 UTC
448b8a918694e84137f850c6526d75aacfb2292d
2 files changed
+57
-7
apps/server/src/cli/pair.test.ts
+41
@@ -9,6 +9,7 @@ import { AuthStandardClientScopes } from "@t3tools/contracts";
9
import * as NetService from "@t3tools/shared/Net";
10
import * as HostProcess from "@t3tools/shared/HostProcess";
11
import { assert, describe, expect, it } from "@effect/vitest";
12
+import * as ConfigProvider from "effect/ConfigProvider";
13
import * as Effect from "effect/Effect";
14
import * as Layer from "effect/Layer";
15
import * as Sink from "effect/Sink";
@@ -287,6 +288,46 @@ describe("t3 pair", () => {
288
).pipe(Effect.provide(NodeServices.layer)),
289
);
290
291
+ // regression: #10516 minting opens the target database with this checkout's
292
+ // migrations, so a worktree must never fall back to the live install.
293
+ it.effect("does not fall back to the shared home from a linked worktree", () =>
294
+ withDescriptorServer((origin) =>
295
+ Effect.gen(function* () {
296
+ const root = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-pair-worktree-test-"));
297
+ const worktree = NodePath.join(root, "worktree");
298
+ NodeFS.mkdirSync(worktree);
299
+ NodeFS.writeFileSync(
300
+ NodePath.join(worktree, ".git"),
301
+ `gitdir: ${NodePath.join(root, "repo", ".git", "worktrees", "worktree")}\n`,
302
+ );
303
+ const sharedHome = NodePath.join(root, "shared");
304
+ yield* persistServerRuntimeState({
305
+ path: NodePath.join(sharedHome, "userdata", "server-runtime.json"),
306
+ state: yield* makePersistedServerRuntimeState({
307
+ config: { host: "127.0.0.1", devUrl: undefined },
308
+ port: Number(new URL(origin).port),
309
+ }),
310
+ });
311
+
312
+ const error = yield* provideCliTestLayers(
313
+ runCli(["pair"]).pipe(
314
+ Effect.provideService(HostProcess.WorkingDirectory, worktree),
315
+ Effect.provide(
316
+ ConfigProvider.layer(ConfigProvider.fromEnv({ env: { T3CODE_HOME: sharedHome } })),
317
+ ),
318
+ Effect.flip,
319
+ ),
320
+ );
321
+
322
+ assert.include(String(error), "No running T3 Code server found.");
323
+ assert.notInclude(String(error), sharedHome);
324
+ assert.deepEqual(NodeFS.readdirSync(NodePath.join(sharedHome, "userdata")), [
325
+ "server-runtime.json",
326
+ ]);
327
+ }),
328
+ ).pipe(Effect.provide(NodeServices.layer)),
329
+ );
330
+
331
// Without the capability `tailscale serve` blocks on an enablement URL, so
332
// pairing must stop at status instead of spawning it.
333
it.effect("explains a tailnet without HTTPS serve instead of running tailscale serve", () =>
apps/server/src/cli/pair.ts
+16
-7
@@ -5,6 +5,7 @@ import {
5
PortSchema,
6
} from "@t3tools/contracts";
7
import { resolveWorktreeT3Home } from "@t3tools/shared/devHome";
8
+import * as HostProcess from "@t3tools/shared/HostProcess";
9
import { DEFAULT_SIGNAL_EXPORT } from "@t3tools/shared/observability";
10
import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
11
import {
@@ -61,12 +62,16 @@ export class NoRunningServerError extends Schema.TaggedError<NoRunningServerErro
62
"NoRunningServerError",
63
{
64
checkedStatePaths: Schema.Array(Schema.String),
65
+ inLinkedWorktree: Schema.Boolean,
66
},
67
) {
68
override get message(): string {
69
return [
70
"No running T3 Code server found.",
71
...this.checkedStatePaths.map((statePath) => ` checked ${statePath}`),
72
+ ...(this.inLinkedWorktree
73
+ ? ["In a linked worktree, pass --base-dir to pair with a server outside it."]
74
+ : []),
75
"Start one with `npx t3 serve`, or connect this machine with T3 Connect: `npx t3 connect`.",
76
].join("\n");
77
}
@@ -228,18 +233,22 @@ const discoverPairTarget = Effect.fn("pair.discoverPairTarget")(function* (
233
explicitBaseDir: string | undefined,
234
) {
235
const bases: Array<string> = [];
236
+ let inLinkedWorktree = false;
237
if (explicitBaseDir !== undefined && explicitBaseDir.trim().length > 0) {
238
bases.push(yield* resolveBaseDir(explicitBaseDir));
239
} else {
234
- // Same precedence as dev-runner: inside a linked worktree its own `.t3`
235
- // outranks the shared home, so `t3 pair` in a worktree pairs with the dev
236
- // server under test rather than the daily-driver install.
237
- const worktreeHome = yield* resolveWorktreeT3Home(process.cwd());
240
+ // Same precedence as dev-runner: inside a linked worktree only its own
241
+ // `.t3` counts. Minting opens the target database with this checkout's
242
+ // migrations, so falling back to the shared home could migrate the live
243
+ // install with unreleased schema.
244
+ const worktreeHome = yield* resolveWorktreeT3Home(yield* HostProcess.WorkingDirectory);
245
if (worktreeHome !== undefined) {
246
bases.push(worktreeHome);
247
+ inLinkedWorktree = true;
248
+ } else {
249
+ const envHome = yield* Config.String("T3CODE_HOME").pipe(Config.option);
250
+ bases.push(yield* resolveBaseDir(Option.getOrUndefined(envHome)));
251
}
241
- const envHome = yield* Config.String("T3CODE_HOME").pipe(Config.option);
242
- bases.push(yield* resolveBaseDir(Option.getOrUndefined(envHome)));
252
}
253
254
const checkedStatePaths: Array<string> = [];
@@ -274,7 +283,7 @@ const discoverPairTarget = Effect.fn("pair.discoverPairTarget")(function* (
283
} satisfies DiscoveredPairTarget;
284
}
285
}
277
- return yield* new NoRunningServerError({ checkedStatePaths });
286
+ return yield* new NoRunningServerError({ checkedStatePaths, inLinkedWorktree });
287
});
288
289
/**