From 25266837a737540b3b3e3cb17f4eed5ed62afd74 Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Tue, 24 Nov 2026 14:44:43 +0000 Subject: [PATCH 1/2] fix(cli): t3 install warns when a relative PATH entry shadows its launcher t3 install checked whether another t3 earlier on PATH runs first, but skipped relative and empty POSIX entries, which the shell searches from the working directory. Resolve them against the working directory, count a PATH folder or t3 that reaches this launcher by real path as this install, and skip relative entries when the working directory is gone. Windows is unchanged. --- apps/server/src/cli/install.test.ts | 47 +++++++++++++++++++++++++---- apps/server/src/cli/install.ts | 24 ++++++++++----- 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/apps/server/src/cli/install.test.ts b/apps/server/src/cli/install.test.ts index f7d8b1df86d76..33500cd145e3d 100644 --- a/apps/server/src/cli/install.test.ts +++ b/apps/server/src/cli/install.test.ts @@ -70,15 +70,50 @@ it.layer(NodeServices.layer)("t3 install", (it) => { const onPath = yield* provide(installCli(), { PATH: `/usr/bin:${path.join(root, "bin")}/` }); assert.isTrue(onPath.onPath); // Another t3 earlier on PATH still runs first, so `t3` would not run this one. + const binDir = path.join(root, "bin"); const otherBin = path.join(root, "other-bin"); yield* fs.makeDirectory(otherBin); yield* fs.writeFileString(path.join(otherBin, "t3"), "", { mode: 0o755 }); - const shadowed = yield* provide(installCli(), { - PATH: `${otherBin}:${path.join(root, "bin")}`, - }); - assert.isFalse(shadowed.onPath); - assert.equal(shadowed.shadowedBy, path.join(otherBin, "t3")); - assert.isUndefined(shadowed.pathCommand); + const installIn = (cwd: string, PATH: string) => + provide(installCli().pipe(Effect.provideService(HostProcess.WorkingDirectory, cwd)), { + PATH, + }); + const assertShadowed = (result: Effect.Success>) => { + assert.isFalse(result.onPath); + assert.equal(result.shadowedBy, path.join(otherBin, "t3")); + assert.isUndefined(result.pathCommand); + }; + assertShadowed(yield* provide(installCli(), { PATH: `${otherBin}:${binDir}` })); + for (const [cwd, pathEnv] of [ + [root, `other-bin:${binDir}`], + [otherBin, `:${binDir}`], + [binDir, `:${otherBin}`], + ] as const) { + assertShadowed(yield* installIn(cwd, pathEnv)); + } + for (const [cwd, pathEnv] of [ + [otherBin, ""], + [binDir, ":/usr/bin"], + ] as const) { + const offPath = yield* installIn(cwd, pathEnv); + assert.isFalse(offPath.onPath); + assert.isUndefined(offPath.shadowedBy); + assert.isDefined(offPath.pathCommand); + } + yield* fs.remove(alias); + yield* fs.symlink(binDir, alias); + for (const pathEnv of [ + `alias:${binDir}`, + `${alias}:${otherBin}`, + `${alias}:/usr/bin`, + `bin:other-bin:${binDir}`, + ]) { + const installedOnPath = yield* installIn(root, pathEnv); + assert.isTrue(installedOnPath.onPath); + assert.isUndefined(installedOnPath.shadowedBy); + assert.isUndefined(installedOnPath.pathCommand); + } + yield* fs.remove(alias); yield* fs.remove(path.join(otherBin, "t3")); yield* fs.makeDirectory(path.join(otherBin, "t3")); const directory = yield* provide(installCli(), { diff --git a/apps/server/src/cli/install.ts b/apps/server/src/cli/install.ts index b789930b2cfbb..57e63c6002395 100644 --- a/apps/server/src/cli/install.ts +++ b/apps/server/src/cli/install.ts @@ -146,22 +146,32 @@ export const installCli = Effect.fn("cli.install.install")(function* () { const normalize = (value: string) => windows ? path.resolve(value).toLowerCase() : path.resolve(value); const same = (entry: string) => entry !== "" && normalize(entry) === normalize(binDir); - const entries = (environment.PATH ?? environment.Path ?? "").split(windows ? ";" : ":"); - const onPath = entries.some(same); + const rawPath = environment.PATH ?? environment.Path ?? ""; + const entries = rawPath === "" ? [] : rawPath.split(windows ? ";" : ":"); + let cwd = yield* Effect.catchDefect(HostProcess.WorkingDirectory, () => Effect.undefined); // A t3 earlier on PATH runs instead, and an added folder goes last. Runner caches (npx's own // .bin) are not installs. const firstOther = Effect.gen(function* () { for (const entry of entries) { - if (same(entry)) return undefined; - if (!path.isAbsolute(entry) || detectCliRunner(`${entry}/`) !== null) continue; + const absolute = path.isAbsolute(entry); + if ((windows || absolute) && same(entry)) return null; + const dir = absolute ? entry : windows || !cwd ? undefined : path.resolve(cwd, entry); + if (dir === undefined || detectCliRunner(`${dir}/`) !== null) continue; for (const name of windows ? ["t3.cmd", "t3.exe"] : ["t3"]) { - const candidate = path.join(entry, name); - if (yield* resolveCommandPath(candidate, { env: environment })) return candidate; + const candidate = path.join(dir, name); + if (!(yield* resolveCommandPath(candidate, { env: environment }))) continue; + if (windows) return candidate; + const resolved = yield* fs.realPath(candidate).pipe(Effect.orElseSucceed(() => candidate)); + if (normalize(resolved) !== normalize(recorded)) return candidate; + if (absolute) return null; + cwd = undefined; // Ours already won in cwd; later relative entries lose. } } return undefined; }); - const shadowedBy = yield* firstOther; + const found = yield* firstOther; + const onPath = found === null; + const shadowedBy = found ?? undefined; return { link, onPath: onPath && shadowedBy === undefined, From 3be208c64aeb3c942a0302d9efbe1da432e46080 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 24 Nov 2026 15:10:13 +0000 Subject: [PATCH 2/2] fix(cli): simplify install PATH result and trim tests Co-Authored-By: Claude Opus 5.5 --- apps/server/src/cli/install.test.ts | 32 ++++++++--------------------- apps/server/src/cli/install.ts | 9 ++++---- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/apps/server/src/cli/install.test.ts b/apps/server/src/cli/install.test.ts index 33500cd145e3d..2578d58a042c1 100644 --- a/apps/server/src/cli/install.test.ts +++ b/apps/server/src/cli/install.test.ts @@ -84,34 +84,20 @@ it.layer(NodeServices.layer)("t3 install", (it) => { assert.isUndefined(result.pathCommand); }; assertShadowed(yield* provide(installCli(), { PATH: `${otherBin}:${binDir}` })); - for (const [cwd, pathEnv] of [ - [root, `other-bin:${binDir}`], - [otherBin, `:${binDir}`], - [binDir, `:${otherBin}`], - ] as const) { - assertShadowed(yield* installIn(cwd, pathEnv)); - } - for (const [cwd, pathEnv] of [ - [otherBin, ""], - [binDir, ":/usr/bin"], - ] as const) { - const offPath = yield* installIn(cwd, pathEnv); - assert.isFalse(offPath.onPath); - assert.isUndefined(offPath.shadowedBy); - assert.isDefined(offPath.pathCommand); - } + // Relative and empty entries resolve against the working directory. + assertShadowed(yield* installIn(root, `other-bin:${binDir}`)); + assertShadowed(yield* installIn(otherBin, `:${binDir}`)); + // An empty PATH is not the working directory. + const offPath = yield* installIn(otherBin, ""); + assert.isUndefined(offPath.shadowedBy); + assert.isDefined(offPath.pathCommand); + // A symlink to binDir, or a relative entry to it that wins first, is this install. yield* fs.remove(alias); yield* fs.symlink(binDir, alias); - for (const pathEnv of [ - `alias:${binDir}`, - `${alias}:${otherBin}`, - `${alias}:/usr/bin`, - `bin:other-bin:${binDir}`, - ]) { + for (const pathEnv of [`${alias}:${otherBin}`, `bin:other-bin:${binDir}`]) { const installedOnPath = yield* installIn(root, pathEnv); assert.isTrue(installedOnPath.onPath); assert.isUndefined(installedOnPath.shadowedBy); - assert.isUndefined(installedOnPath.pathCommand); } yield* fs.remove(alias); yield* fs.remove(path.join(otherBin, "t3")); diff --git a/apps/server/src/cli/install.ts b/apps/server/src/cli/install.ts index 57e63c6002395..abd32cf0d844d 100644 --- a/apps/server/src/cli/install.ts +++ b/apps/server/src/cli/install.ts @@ -169,15 +169,14 @@ export const installCli = Effect.fn("cli.install.install")(function* () { } return undefined; }); + // null: this launcher runs first; a path: another t3 does; undefined: no t3 on PATH. const found = yield* firstOther; - const onPath = found === null; - const shadowedBy = found ?? undefined; return { link, - onPath: onPath && shadowedBy === undefined, - shadowedBy, + onPath: found === null, + shadowedBy: found ?? undefined, pathCommand: - onPath || shadowedBy !== undefined + found !== undefined ? undefined : windows ? // PowerShell; it covers this window only, since changing the saved PATH would flatten