diff --git a/apps/server/src/cli/install.test.ts b/apps/server/src/cli/install.test.ts index f7aaeca3120cc..f7d8b1df86d76 100644 --- a/apps/server/src/cli/install.test.ts +++ b/apps/server/src/cli/install.test.ts @@ -212,17 +212,32 @@ it.layer(NodeServices.layer)("t3 install", (it) => { const globalBin = path.join(root, "global-bin"); yield* fs.makeDirectory(globalBin); yield* fs.writeFileString(path.join(globalBin, "t3"), ""); + yield* fs.chmod(path.join(globalBin, "t3"), 0o755); yield* offer(false, { env: { PATH: globalBin } }); assert.equal(asked, 0); assert.isFalse(yield* fs.exists(link)); - // A runner's own .bin on PATH is not an installed t3. + // A directory or non-executable file named `t3` on PATH is not an installed t3. + const dirBin = path.join(root, "dir-bin"); + yield* fs.makeDirectory(path.join(dirBin, "t3"), { recursive: true }); + const nonExecBin = path.join(root, "non-exec-bin"); + yield* fs.makeDirectory(nonExecBin); + yield* fs.writeFileString(path.join(nonExecBin, "t3"), ""); + assert.isFalse(yield* offer(undefined, { env: { PATH: dirBin } })); + assert.equal(asked, 1); + assert.isFalse(yield* offer(undefined, { env: { PATH: nonExecBin } })); + assert.equal(asked, 2); + asked = 0; + + // A runner's own .bin on PATH, even found through a bare launcher record, is not an installed t3. const npxBin = path.join(npmPackage, "../.bin"); const pnpmBin = path.join(root, ".cache/pnpm/dlx/abc/node_modules/.bin"); for (const bin of [npxBin, pnpmBin]) { yield* fs.makeDirectory(bin, { recursive: true }); yield* fs.writeFileString(path.join(bin, "t3"), ""); + yield* fs.chmod(path.join(bin, "t3"), 0o755); } + yield* fs.writeFileString(path.join(runtimeDir, "launchers"), "t3\n"); assert.isFalse(yield* offer(undefined, { env: { PATH: `${npxBin}:${pnpmBin}` } })); assert.equal(asked, 1); assert.isFalse(yield* fs.exists(path.join(runtimeDir, "install-prompt-declined"))); diff --git a/apps/server/src/cli/install.ts b/apps/server/src/cli/install.ts index 4e6420842dc9d..b789930b2cfbb 100644 --- a/apps/server/src/cli/install.ts +++ b/apps/server/src/cli/install.ts @@ -322,7 +322,7 @@ export const offerCliInstall = Effect.fn("cli.install.offer")(function* "")); const candidates = [ - ...launchers.split(/\r?\n/).filter(Boolean), + ...launchers.split(/\r?\n/).filter((launcher) => path.isAbsolute(launcher)), path.join(path.dirname(runtimeDir), "bin", windows ? "t3.cmd" : "t3"), ...(environment.PATH ?? environment.Path ?? "") .split(windows ? ";" : ":") @@ -332,7 +332,7 @@ export const offerCliInstall = Effect.fn("cli.install.offer")(function* names.map((name) => path.join(directory, name))), ]; for (const candidate of candidates) { - if (yield* fs.exists(candidate).pipe(Effect.orElseSucceed(() => false))) return true; + if (yield* resolveCommandPath(candidate, { env: environment })) return true; } const declinedFile = path.join(runtimeDir, "install-prompt-declined");