Skip to content

Commit 7323da5

Browse files
hieu-leeclaude
andcommitted
fix(server): report the verified launcher path and skip non-executable PATH entries
A bare launcher name let the host's shell pick a different `t3`, whose update would leave the server's launcher on the old version. Report the absolute launcher already verified to point into the runtime's home. Launcher lookup on PATH now passes over directories and non-executable files named `t3`, as the shell does, so an earlier stray entry no longer hides the real launcher. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a964099 commit 7323da5

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

‎apps/server/src/cli/invocation.test.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,22 +271,26 @@ it.layer(NodeServices.layer)("manual server installation ownership", (it) => {
271271
const copy = path.join(root, "bin/t3-copy");
272272
yield* fs.makeDirectory(path.dirname(executable), { recursive: true });
273273
yield* fs.makeDirectory(path.dirname(launcher), { recursive: true });
274-
yield* fs.writeFileString(executable, "");
275-
yield* fs.writeFileString(copy, "");
274+
yield* fs.writeFileString(executable, "", { mode: 0o755 });
275+
yield* fs.writeFileString(copy, "", { mode: 0o755 });
276276
yield* fs.symlink(path.join(root, "data/t3"), path.join(root, ".t3"));
277277
yield* fs.symlink(path.join(root, ".t3/runtime/versions/1.0.0/t3"), launcher);
278+
// Earlier PATH entries hold a directory and a non-executable file named t3.
279+
yield* fs.makeDirectory(path.join(root, "shadow-dir/t3"), { recursive: true });
280+
yield* fs.makeDirectory(path.join(root, "shadow-file"));
281+
yield* fs.writeFileString(path.join(root, "shadow-file/t3"), "");
278282
const resolve = (invokedAs: string) =>
279283
resolveServerInstallation.pipe(
280284
Effect.provideService(HostProcess.ExecutablePath, executable),
281285
Effect.provideService(HostProcess.IsExecutable, true),
282286
Effect.provideService(HostProcess.InvokedAs, invokedAs),
283287
Effect.provideService(HostProcess.WorkingDirectory, root),
284-
Effect.provideService(HostProcess.Environment, { PATH: "bin" }),
288+
Effect.provideService(HostProcess.Environment, { PATH: "shadow-dir:shadow-file:bin" }),
285289
Effect.provideService(HostProcess.Platform, "linux"),
286290
);
287291
const baseDir = path.join(root, ".t3");
288292

289-
expect(yield* resolve("t3")).toEqual({ kind: "t3-launcher", launcher: "t3", baseDir });
293+
expect(yield* resolve("t3")).toEqual({ kind: "t3-launcher", launcher, baseDir });
290294
expect(yield* resolve(launcher)).toEqual({ kind: "t3-launcher", launcher, baseDir });
291295
expect(yield* resolve(executable)).toBeNull();
292296
expect(yield* resolve(copy)).toBeNull();

‎apps/server/src/cli/invocation.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,9 @@ export const resolveServerInstallation = Effect.gen(function* () {
7979
// Keep the home as the link spells it; `t3 update` only repoints links into that spelling.
8080
const linked = PINNED_RUNTIME_ENTRY.exec(path.resolve(path.dirname(launcher), link));
8181
if (!linked || (yield* fs.realPath(linked[1] || "/")) !== (runtime[1] || "/")) return null;
82-
// PATH is hydrated before this runs; a bare name lets the host's shell find its own launcher.
83-
const invokedAs = yield* HostProcess.InvokedAs;
8482
return {
8583
kind: "t3-launcher",
86-
launcher: /[\\/]/.test(invokedAs) ? launcher : invokedAs,
84+
launcher,
8785
baseDir: linked[1] || "/",
8886
} satisfies ServerInstallation;
8987
}

‎apps/server/src/cli/update.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ it.layer(NodeServices.layer)("t3 update launcher", (it) => {
338338
const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-update-" });
339339
const launcher = path.join(root, "bin/t3");
340340
yield* fs.makeDirectory(path.dirname(launcher), { recursive: true });
341-
yield* fs.writeFileString(launcher, "");
341+
yield* fs.writeFileString(launcher, "", { mode: 0o755 });
342342

343343
const bare = yield* resolveLauncherPath.pipe(
344344
Effect.provideService(HostProcess.InvokedAs, "t3"),

‎apps/server/src/cloud/pinnedRuntime.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,13 @@ export const resolveLauncherPath = Effect.gen(function* () {
408408
for (const directory of (environment["PATH"] ?? "").split(delimiter)) {
409409
if (directory.length === 0) continue;
410410
const candidate = path.resolve(cwd, directory, invokedAs);
411-
if (yield* fs.exists(candidate).pipe(Effect.orElseSucceed(() => false))) {
411+
const info = yield* fs.stat(candidate).pipe(Effect.option);
412+
// Like the shell, pass over directories and non-executable files named the same.
413+
if (
414+
Option.isSome(info) &&
415+
info.value.type === "File" &&
416+
(platform === "win32" || (info.value.mode & 0o111) !== 0)
417+
) {
412418
return candidate;
413419
}
414420
}

0 commit comments

Comments
 (0)