Skip to content
TypeScript

fix(desktop): installing the t3 command no longer reports its own launcher as another t3 (#22375)

Gourav Kumar Dhimanb6fbd181cae4
diff --git a/apps/desktop/src/app/DesktopCliCommand.test.ts b/apps/desktop/src/app/DesktopCliCommand.test.ts
index 7141ebde705..8566613dd60 100644
--- a/apps/desktop/src/app/DesktopCliCommand.test.ts
+++ b/apps/desktop/src/app/DesktopCliCommand.test.ts
@@ -136,6 +136,14 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
yield* command.uninstall;
expect(yield* fs.readFileString(theirs)).toBe("npm's t3\n");
expect(yield* fs.readLink(path.join(home, "bin", "t3"))).toBe(path.join(home, "gone"));
+
+ const launcher = path.join(home, ".t3", "bin", "t3");
+ yield* fs.writeFileString(launcher, "npm's t3\n");
+ process.env.PATH = path.dirname(launcher);
+ expect(yield* command.state).toMatchObject({ onPath: false, shadowedBy: launcher });
+ expect((yield* Effect.flip(command.install)).message).toContain("Could not set up");
+ yield* command.uninstall;
+ expect(yield* fs.readFileString(launcher)).toBe("npm's t3\n");
}).pipe(Effect.scoped),
);
@@ -217,6 +225,34 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
}).pipe(Effect.scoped),
);
+ it.effect("does not treat its own launcher as another t3 when its folder is first on PATH", () =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const home = yield* fs.makeTempDirectoryScoped();
+ const launcher = path.join(home, ".t3", "bin", "t3");
+ process.env.PATH = [path.dirname(launcher), path.join(home, ".local", "bin")].join(":");
+
+ const command = yield* commandIn({ home });
+ const installed = yield* command.install;
+
+ expect(yield* fs.exists(launcher)).toBe(true);
+ expect(installed).toMatchObject({
+ onPath: true,
+ installedPath: path.join(home, ".local", "bin", "t3"),
+ });
+ expect(installed.shadowedBy).toBeUndefined();
+ expect(yield* command.state).toEqual(installed);
+
+ const removed = yield* command.uninstall;
+ expect(removed.installedPath).toBeNull();
+ expect(removed.onPath).toBe(true);
+ expect(yield* command.state).toEqual(removed);
+ expect(yield* fs.exists(installed.installedPath!)).toBe(false);
+ expect(yield* fs.exists(launcher)).toBe(true);
+ }).pipe(Effect.scoped),
+ );
+
it.effect("leaves the Windows PATH alone when it cannot be read", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
diff --git a/apps/desktop/src/app/DesktopCliCommand.ts b/apps/desktop/src/app/DesktopCliCommand.ts
index 8a89a366814..f53895a60a5 100644
--- a/apps/desktop/src/app/DesktopCliCommand.ts
+++ b/apps/desktop/src/app/DesktopCliCommand.ts
@@ -92,6 +92,19 @@ export const make = Effect.gen(function* () {
Effect.orElseSucceed(() => false),
);
+ // PATH can reach the regular launcher directly; removal still requires isOurLink.
+ const runsOurLauncher = Effect.fn("DesktopCliCommand.runsOurLauncher")(
+ function* (candidate: string) {
+ if (yield* isOurLink(candidate)) return true;
+ const [resolved, ours] = yield* Effect.all([fs.realPath(candidate), fs.realPath(launcher)]);
+ if (resolved !== ours) return false;
+ const info = yield* fs.stat(candidate);
+ if (info.type !== "File" || Number(info.size) > 16_384) return false;
+ return (yield* fs.readFileString(candidate)).includes(DesktopCliShim.MARKER);
+ },
+ Effect.orElseSucceed(() => false),
+ );
+
const powershell = (env: Record<string, string>) =>
Effect.scoped(
Effect.gen(function* () {
@@ -141,7 +154,7 @@ export const make = Effect.gen(function* () {
const foreignFirstOnPath = Effect.gen(function* () {
if (windows) return Option.none<string>();
const first = yield* firstOnPath;
- if (Option.isNone(first) || (yield* isOurLink(first.value))) return Option.none<string>();
+ if (Option.isNone(first) || (yield* runsOurLauncher(first.value))) return Option.none<string>();
return first;
});
@@ -168,12 +181,17 @@ export const make = Effect.gen(function* () {
const installed = yield* installedAt;
const shadowedBy = yield* foreignFirstOnPath;
const shadow = Option.isSome(shadowedBy) ? { shadowedBy: shadowedBy.value } : {};
- if (Option.isNone(installed)) {
- return { supported: true, installedPath: null, onPath: false, launcherPath, ...shadow };
- }
const first = yield* firstOnPath;
- const onPath = windows || (Option.isSome(first) && (yield* isOurLink(first.value)));
- return { supported: true, installedPath: installed.value, onPath, launcherPath, ...shadow };
+ const onPath = windows
+ ? Option.isSome(installed)
+ : Option.isSome(first) && (yield* runsOurLauncher(first.value));
+ return {
+ supported: true,
+ installedPath: Option.getOrNull(installed),
+ onPath,
+ launcherPath,
+ ...shadow,
+ };
}).pipe(
Effect.orElseSucceed(() => ({
supported: false,