Skip to content

Commit b63b559

Browse files
fix(server): browser setup command names the running t3 executable, not another t3 on PATH (pingdotgg#34936)
1 parent 34de974 commit b63b559

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,37 @@ it.layer(NodeServices.layer)("root CLI commands", (it) => {
109109
}),
110110
).toBe("sudo /opt/t3/t3 browser setup");
111111

112+
// A standalone executable started directly (systemd, no launcher) is still this install.
113+
expect(
114+
yield* rootCommand({
115+
node: "/opt/t3/t3",
116+
entry: "/opt/t3/t3",
117+
executable: true,
118+
path: yield* pathWithT3,
119+
}),
120+
).toBe("sudo /opt/t3/t3 browser setup");
121+
122+
// A global npm launcher runs the downloaded executable; PATH's `t3` is that launcher.
123+
const prefix = path.join(home, "npm");
124+
const npmLauncher = path.join(prefix, "lib/node_modules/t3/bin/t3.mjs");
125+
yield* fs.makeDirectory(path.dirname(npmLauncher), { recursive: true });
126+
yield* fs.makeDirectory(path.join(prefix, "bin"));
127+
yield* fs.writeFileString(npmLauncher, "", { mode: 0o755 });
128+
yield* fs.writeFileString(
129+
path.join(prefix, "lib/node_modules/t3/package.json"),
130+
`{"name":"t3","version":"${packageJson.version}"}`,
131+
);
132+
yield* fs.symlink(npmLauncher, path.join(prefix, "bin/t3"));
133+
expect(
134+
yield* rootCommand({
135+
node: "/home/theo/.t3/runtime/versions/1.0.0/t3",
136+
entry: "/home/theo/.t3/runtime/versions/1.0.0/t3",
137+
executable: true,
138+
path: path.join(prefix, "bin"),
139+
env: { T3CODE_NPM_LAUNCHER_PATH: npmLauncher },
140+
}),
141+
).toBe('sudo env "PATH=$PATH" t3 browser setup');
142+
112143
expect(
113144
yield* rootCommand({ ...desktop, env: { T3CODE_CLI_PATH: path.join(home, "gone") } }),
114145
).toBe('sudo env "PATH=$PATH" t3 browser setup');

‎apps/server/src/cli/invocation.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,17 @@ export const resolveHostCliCommand = Effect.fn("invocation.resolveHostCliCommand
160160
const shim = (yield* HostProcess.Environment).T3CODE_CLI_PATH?.trim();
161161
const fs = yield* FileSystem.FileSystem;
162162
const real = (file: string) => fs.realPath(file).pipe(Effect.orElseSucceed(() => null));
163-
const shimReal = shim ? yield* real(shim) : null;
164-
if (shimReal === null || shimReal === (yield* real(onPath))) {
163+
// Windows `t3.cmd` shims are text files that never realpath to the executable they run.
164+
const own = shim
165+
? yield* real(shim)
166+
: platform !== "win32" && (yield* HostProcess.IsExecutable)
167+
? yield* resolveEntryPath.pipe(
168+
Effect.flatMap((entry) =>
169+
real(entry).pipe(Effect.map((resolved) => resolved ?? entry)),
170+
),
171+
)
172+
: null;
173+
if (own === null || own === (yield* real(onPath))) {
165174
return { command: withArgs(command), launcher: false };
166175
}
167176
}

0 commit comments

Comments
 (0)