Skip to content

Commit 3e42f1d

Browse files
Gourav224claude
andcommitted
fix(desktop): installing the t3 command no longer reports its own launcher as another t3
When ~/.t3/bin was first on PATH, "Install t3 command" refused with "Another t3 at ~/.t3/bin/t3 runs first", because the PATH check only accepted a symlink to the launcher and the launcher itself is a regular file. Treat a first match that resolves to the launcher as ours, for the shadow check and the on-PATH state only. Installed links are still identified by symlink alone, so uninstall never removes the launcher. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 67c0fc0 commit 3e42f1d

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎apps/desktop/src/app/DesktopCliCommand.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,31 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
194194
}).pipe(Effect.scoped),
195195
);
196196

197+
it.effect("does not treat its own launcher as another t3 when its folder is first on PATH", () =>
198+
Effect.gen(function* () {
199+
const fs = yield* FileSystem.FileSystem;
200+
const path = yield* Path.Path;
201+
const home = yield* fs.makeTempDirectoryScoped();
202+
const launcher = path.join(home, ".t3", "bin", "t3");
203+
process.env.PATH = [path.dirname(launcher), path.join(home, ".local", "bin")].join(":");
204+
205+
const command = yield* commandIn({ home });
206+
const installed = yield* command.install;
207+
208+
expect(yield* fs.exists(launcher)).toBe(true);
209+
expect(installed).toMatchObject({
210+
onPath: true,
211+
installedPath: path.join(home, ".local", "bin", "t3"),
212+
});
213+
expect(installed.shadowedBy).toBeUndefined();
214+
expect((yield* command.state).shadowedBy).toBeUndefined();
215+
216+
// Reaching the launcher through PATH does not make it a link T3 may remove.
217+
expect((yield* command.uninstall).installedPath).toBeNull();
218+
expect(yield* fs.exists(launcher)).toBe(true);
219+
}).pipe(Effect.scoped),
220+
);
221+
197222
it.effect("leaves the Windows PATH alone when it cannot be read", () =>
198223
Effect.gen(function* () {
199224
const fs = yield* FileSystem.FileSystem;

‎apps/desktop/src/app/DesktopCliCommand.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ export const make = Effect.gen(function* () {
9595
Effect.orElseSucceed(() => false),
9696
);
9797

98+
// The launcher is itself a regular file, so a PATH that lists its folder reaches it with
99+
// no link in between. Only a link we made may be removed, which is why this stays apart
100+
// from `isOurLink`.
101+
const runsOurLauncher = Effect.fn("DesktopCliCommand.runsOurLauncher")(
102+
function* (candidate: string) {
103+
if (yield* isOurLink(candidate)) return true;
104+
const [resolved, ours] = yield* Effect.all([fs.realPath(candidate), fs.realPath(launcher)]);
105+
return resolved === ours;
106+
},
107+
Effect.orElseSucceed(() => false),
108+
);
109+
98110
const powershell = (env: Record<string, string>) =>
99111
Effect.scoped(
100112
Effect.gen(function* () {
@@ -135,7 +147,7 @@ export const make = Effect.gen(function* () {
135147
const foreignFirstOnPath = Effect.gen(function* () {
136148
if (windows) return Option.none<string>();
137149
const first = yield* firstOnPath;
138-
if (Option.isNone(first) || (yield* isOurLink(first.value))) return Option.none<string>();
150+
if (Option.isNone(first) || (yield* runsOurLauncher(first.value))) return Option.none<string>();
139151
return first;
140152
});
141153

@@ -165,7 +177,7 @@ export const make = Effect.gen(function* () {
165177
return { supported: true, installedPath: null, onPath: false, ...shadow };
166178
}
167179
const first = yield* firstOnPath;
168-
const onPath = windows || (Option.isSome(first) && (yield* isOurLink(first.value)));
180+
const onPath = windows || (Option.isSome(first) && (yield* runsOurLauncher(first.value)));
169181
return { supported: true, installedPath: installed.value, onPath, ...shadow };
170182
}).pipe(Effect.orElseSucceed(() => ({ supported: false, installedPath: null, onPath: false })));
171183

0 commit comments

Comments
 (0)