Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion apps/server/src/cli/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/cli/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export const offerCliInstall = Effect.fn("cli.install.offer")(function* <E, R, E
.readFileString(path.join(runtimeDir, "launchers"))
.pipe(Effect.orElseSucceed(() => ""));
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 ? ";" : ":")
Expand All @@ -332,7 +332,7 @@ export const offerCliInstall = Effect.fn("cli.install.offer")(function* <E, R, E
.flatMap((directory) => 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");
Expand Down
Loading