Skip to content

Commit 0070b27

Browse files
Gourav224claudemaria-rcks
authored
fix(server): the suggested t3 command names this install, not another t3 on PATH (#22639)
Co-authored-by: Claude Sonnet 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent a8d6b0e commit 0070b27

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,15 @@ it.layer(NodeServices.layer)("root CLI commands", (it) => {
7171

7272
expect(yield* rootCommand(desktop)).toBe(`sudo '${shim}' browser setup`);
7373

74+
// An unrelated `t3` on PATH, such as an older npm global, is another install's CLI.
7475
expect(yield* rootCommand({ ...desktop, path: yield* pathWithT3 })).toBe(
76+
`sudo '${shim}' browser setup`,
77+
);
78+
79+
// The link the app installs onto PATH leads to its own launcher, so plain `t3` is right.
80+
const linked = yield* fs.makeTempDirectoryScoped();
81+
yield* fs.symlink(shim, path.join(linked, "t3"));
82+
expect(yield* rootCommand({ ...desktop, path: linked })).toBe(
7583
'sudo env "PATH=$PATH" t3 browser setup',
7684
);
7785

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as Schema from "effect/Schema";
66

77
import type { ServerInstallation } from "@t3tools/contracts";
88
import * as HostProcess from "@t3tools/shared/HostProcess";
9-
import { isCommandAvailable } from "@t3tools/shared/shell";
9+
import { resolveCommandPath } from "@t3tools/shared/shell";
1010

1111
import packageJson from "../../package.json" with { type: "json" };
1212

@@ -143,7 +143,7 @@ const resolveInstallLauncher = Effect.gen(function* () {
143143
});
144144

145145
/**
146-
* Uses `t3` on PATH, the originating package runner, or this install's absolute launcher path.
146+
* Uses this install's `t3` on PATH, the originating runner, or its absolute launcher path.
147147
* Arguments are quoted for POSIX shells or PowerShell on Windows.
148148
*/
149149
export const resolveHostCliCommand = Effect.fn("invocation.resolveHostCliCommand")(function* (
@@ -155,7 +155,16 @@ export const resolveHostCliCommand = Effect.fn("invocation.resolveHostCliCommand
155155
[prefix, ...args.map((arg) => hostShellWord(platform, arg))].join(" ");
156156
const command = yield* resolveCliCommand(subcommand);
157157
if (command !== `t3 ${subcommand}`) return { command: withArgs(command), launcher: false };
158-
if (yield* isCommandAvailable("t3")) return { command: withArgs(command), launcher: false };
158+
const onPath = yield* resolveCommandPath("t3");
159+
if (onPath !== null) {
160+
const shim = (yield* HostProcess.Environment).T3CODE_CLI_PATH?.trim();
161+
const fs = yield* FileSystem.FileSystem;
162+
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))) {
165+
return { command: withArgs(command), launcher: false };
166+
}
167+
}
159168
const launcher = yield* resolveInstallLauncher;
160169
if (Option.isNone(launcher)) return { command: withArgs(command), launcher: false };
161170
// PowerShell runs a quoted path only through the call operator.

0 commit comments

Comments
 (0)