Skip to content

Commit 85c3e95

Browse files
Gourav224claude
andcommitted
fix(server): the suggested t3 command names this install, not another t3 on PATH
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 8a9d0e0 commit 85c3e95

2 files changed

Lines changed: 30 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
@@ -73,7 +73,15 @@ it.layer(NodeServices.layer)("root CLI commands", (it) => {
7373

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

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

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

Lines changed: 22 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

@@ -163,9 +163,25 @@ const resolveInstallLauncher = Effect.gen(function* () {
163163
: Option.none<string>();
164164
});
165165

166+
/**
167+
* A `t3` on PATH runs whichever install put it there, which may be an older npm global rather
168+
* than the desktop app that owns this server. It is this install's own only when it resolves to
169+
* the app's launcher; without a launcher to compare to, it is assumed to be.
170+
*/
171+
const pathCommandIsOtherInstall = Effect.fn("invocation.pathCommandIsOtherInstall")(function* (
172+
pathCommand: string,
173+
) {
174+
const shim = (yield* HostProcess.Environment).T3CODE_CLI_PATH?.trim();
175+
if (!shim) return false;
176+
const fs = yield* FileSystem.FileSystem;
177+
const real = (file: string) => fs.realPath(file).pipe(Effect.orElseSucceed(() => null));
178+
const shimReal = yield* real(shim);
179+
return shimReal !== null && shimReal !== (yield* real(pathCommand));
180+
});
181+
166182
/**
167183
* `t3 <subcommand> <args>` for a person to run on this host: `t3` when it is
168-
* on PATH, the package runner this process came from, or else the absolute
184+
* on PATH and is this install, the package runner this process came from, or else the absolute
169185
* path of the launcher for this install, such as the one the desktop app
170186
* installs. `args` are quoted for the host's shell: POSIX, or PowerShell on
171187
* Windows.
@@ -179,7 +195,10 @@ export const resolveHostCliCommand = Effect.fn("invocation.resolveHostCliCommand
179195
[prefix, ...args.map((arg) => hostShellWord(platform, arg))].join(" ");
180196
const command = yield* resolveCliCommand(subcommand);
181197
if (command !== `t3 ${subcommand}`) return { command: withArgs(command), launcher: false };
182-
if (yield* isCommandAvailable("t3")) return { command: withArgs(command), launcher: false };
198+
const onPath = yield* resolveCommandPath("t3");
199+
if (onPath !== null && !(yield* pathCommandIsOtherInstall(onPath))) {
200+
return { command: withArgs(command), launcher: false };
201+
}
183202
const launcher = yield* resolveInstallLauncher;
184203
if (Option.isNone(launcher)) return { command: withArgs(command), launcher: false };
185204
// PowerShell runs a quoted path only through the call operator.

0 commit comments

Comments
 (0)