The best way to control Claude Code, Codex and more from any computer or phone
fix(install): launch t3 by absolute path (#13794)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Theo Browne committed
Nov 14, 2026 at 13:09 UTC
7f7a1a447a2b86fa3e8b5318ecb38052e8a7a545
15 files changed
+403
-110
apps/server/src/cli/install.test.ts
+13
-17
@@ -9,6 +9,7 @@ import * as Path from "effect/Path";
9
import * as TestClock from "effect/testing/TestClock";
10
11
import packageJson from "../../package.json" with { type: "json" };
12
+import { posixLauncherScript } from "../cloud/pinnedRuntime.ts";
13
import { installCli, isForegroundProcStat, isForegroundPs, offerCliInstall } from "./install.ts";
14
15
const VERSION = packageJson.version;
@@ -47,7 +48,7 @@ const setup = Effect.gen(function* () {
48
});
49
50
it.layer(NodeServices.layer)("t3 install", (it) => {
50
- it.effect("links the running runtime, records it, and never replaces another t3", () =>
51
+ it.effect("installs the running runtime, records it, and never replaces another t3", () =>
52
Effect.gen(function* () {
53
const fs = yield* FileSystem.FileSystem;
54
const path = yield* Path.Path;
@@ -57,7 +58,7 @@ it.layer(NodeServices.layer)("t3 install", (it) => {
58
yield* fs.makeDirectory(path.dirname(link), { recursive: true });
59
yield* fs.symlink(older, link);
60
const installed = yield* provide(installCli());
60
- assert.equal(yield* fs.readLink(link), executable);
61
+ assert.equal(yield* fs.readFileString(link), posixLauncherScript(executable));
62
assert.isFalse(installed.onPath);
63
assert.include(installed.pathCommand, "$HOME/bin");
64
@@ -96,30 +97,25 @@ it.layer(NodeServices.layer)("t3 install", (it) => {
97
yield* fs.remove(link);
98
yield* fs.symlink(path.join(root, ".t3/bin/t3"), link);
99
yield* provide(installCli());
99
- assert.equal(yield* fs.readLink(link), executable);
100
+ assert.equal(yield* fs.readFileString(link), posixLauncherScript(executable));
101
101
- // A failed swap over our own link leaves a staging path it did not create alone.
102
- yield* fs.remove(link);
103
- yield* fs.symlink(older, link);
104
- const staging = `${link}.${process.pid}.tmp`;
105
- yield* fs.writeFileString(staging, "someone else's\n");
106
- const linkFailed = yield* provide(installCli()).pipe(Effect.flip);
107
- assert.include(linkFailed.message, "Could not link");
108
- assert.equal(yield* fs.readFileString(staging), "someone else's\n");
109
- yield* fs.remove(staging);
102
+ // A script an earlier install wrote is ours too.
103
+ yield* fs.writeFileString(link, posixLauncherScript(older));
104
+ yield* provide(installCli());
105
+ assert.equal(yield* fs.readFileString(link), posixLauncherScript(executable));
106
107
// An empty spot is created exclusively: a file that appears first is kept.
108
yield* fs.remove(link);
109
const racing = installCli().pipe(
110
Effect.provideService(FileSystem.FileSystem, {
111
...fs,
116
- symlink: (target, path) =>
112
+ link: (from, to) =>
113
fs
118
- .writeFileString(path, "#!/bin/sh\necho raced\n")
119
- .pipe(Effect.andThen(fs.symlink(target, path))),
114
+ .writeFileString(to, "#!/bin/sh\necho raced\n")
115
+ .pipe(Effect.andThen(fs.link(from, to))),
116
}),
117
);
122
- assert.include((yield* provide(racing).pipe(Effect.flip)).message, "Could not link");
118
+ assert.include((yield* provide(racing).pipe(Effect.flip)).message, "Could not write");
119
assert.equal(yield* fs.readFileString(link), "#!/bin/sh\necho raced\n");
120
yield* fs.remove(link);
121
@@ -235,7 +231,7 @@ it.layer(NodeServices.layer)("t3 install", (it) => {
231
yield* fs.writeFileString(path.join(runtimeDir, "install-prompt-declined"), "0.0\n");
232
yield* offer(true);
233
assert.equal(asked, 2);
238
- assert.equal(yield* fs.readLink(link), executable);
234
+ assert.equal(yield* fs.readFileString(link), posixLauncherScript(executable));
235
236
yield* fs.remove(path.join(runtimeDir, "install-prompt-declined"));
237
yield* offer(true);
apps/server/src/cli/install.ts
+9
-16
@@ -15,7 +15,9 @@ import packageJson from "../../package.json" with { type: "json" };
15
import {
16
generatedWindowsShimTarget,
17
isVersionExecutable,
18
+ readPosixLauncherTarget,
19
recordPinnedRuntimeLauncher,
20
+ writePosixLauncher,
21
} from "../cloud/pinnedRuntime.ts";
22
import { detectCliRunner, resolveCliCommand, resolveEntryPath } from "./invocation.ts";
23
@@ -41,7 +43,7 @@ const standaloneRuntime = Effect.gen(function* () {
43
return Option.some({ executable, versionsDir, runtimeDir });
44
});
45
44
-/** Links this runtime as the `t3` command the way the install scripts do, replacing only our own link. */
46
+/** Installs this runtime as the `t3` command the way the install scripts do, replacing only our own launcher. */
47
export const installCli = Effect.fn("cli.install.install")(function* () {
48
const fs = yield* FileSystem.FileSystem;
49
const path = yield* Path.Path;
@@ -84,7 +86,10 @@ export const installCli = Effect.fn("cli.install.install")(function* () {
86
Effect.flatMap((target) =>
87
fs.realPath(link).pipe(Effect.orElseSucceed(() => path.resolve(binDir, target))),
88
),
89
+ // Not a link: the script this command and the install scripts write.
90
+ Effect.catch(() => readPosixLauncherTarget(link)),
91
Effect.option,
92
+ Effect.map(Option.filter((target) => target !== undefined)),
93
);
94
// A dangling symlink is occupied too: writing the shim would follow it.
95
const occupied =
@@ -115,22 +120,10 @@ export const installCli = Effect.fn("cli.install.install")(function* () {
120
yield* fs
121
.writeFileString(link, `@echo off\r\n"${executable}" %*`, occupied ? {} : { flag: "wx" })
122
.pipe(Effect.mapError(failed(`Could not write ${link}.`)));
118
- } else if (!occupied) {
119
- yield* fs.symlink(executable, link).pipe(Effect.mapError(failed(`Could not link ${link}.`)));
123
} else {
121
- // Swap a temporary link into place so a running `t3` never sees the command missing.
122
- const staging = `${link}.${process.pid}.tmp`;
123
- // Clean up only a staging link this call made, never a file that was already there.
124
- yield* fs
125
- .symlink(executable, staging)
126
- .pipe(
127
- Effect.andThen(
128
- fs
129
- .rename(staging, link)
130
- .pipe(Effect.tapError(() => fs.remove(staging, { force: true }).pipe(Effect.ignore))),
131
- ),
132
- Effect.mapError(failed(`Could not link ${link}.`)),
133
- );
124
+ yield* writePosixLauncher({ launcher: link, executable, exclusive: !occupied }).pipe(
125
+ Effect.mapError(failed(`Could not write ${link}.`)),
126
+ );
127
}
128
129
// Pruning keeps what recorded launchers point at; a background service cannot see binDir otherwise.
apps/server/src/cli/invocation.test.ts
+18
-3
@@ -6,6 +6,7 @@ import * as FileSystem from "effect/FileSystem";
6
import * as Path from "effect/Path";
7
8
import packageJson from "../../package.json" with { type: "json" };
9
+import { posixLauncherScript } from "../cloud/pinnedRuntime.ts";
10
import {
11
resolveHostCliCommand,
12
resolveRootCliCommand,
@@ -291,7 +292,7 @@ it.layer(NodeServices.layer)("manual server installation ownership", (it) => {
292
}),
293
);
294
294
- it.effect("names the launcher symlink that started a downloaded runtime", () =>
295
+ it.effect("names the launcher that started a downloaded runtime", () =>
296
Effect.gen(function* () {
297
const fs = yield* FileSystem.FileSystem;
298
const path = yield* Path.Path;
@@ -310,13 +311,14 @@ it.layer(NodeServices.layer)("manual server installation ownership", (it) => {
311
yield* fs.makeDirectory(path.join(root, "shadow-dir/t3"), { recursive: true });
312
yield* fs.makeDirectory(path.join(root, "shadow-file"));
313
yield* fs.writeFileString(path.join(root, "shadow-file/t3"), "");
313
- const resolve = (invokedAs: string) =>
314
+ const resolve = (invokedAs: string, PATH = "shadow-dir:shadow-file:bin") =>
315
resolveServerInstallation.pipe(
316
Effect.provideService(HostProcess.ExecutablePath, executable),
317
Effect.provideService(HostProcess.IsExecutable, true),
318
Effect.provideService(HostProcess.InvokedAs, invokedAs),
319
Effect.provideService(HostProcess.WorkingDirectory, root),
319
- Effect.provideService(HostProcess.Environment, { PATH: "shadow-dir:shadow-file:bin" }),
320
+ Effect.provideService(HostProcess.Environment, { PATH }),
321
+ Effect.provideService(HostProcess.HomeDirectory, root),
322
Effect.provideService(HostProcess.Platform, "linux"),
323
);
324
const baseDir = path.join(root, ".t3");
@@ -325,6 +327,19 @@ it.layer(NodeServices.layer)("manual server installation ownership", (it) => {
327
expect(yield* resolve(launcher)).toEqual({ kind: "t3-launcher", launcher, baseDir });
328
expect(yield* resolve(executable)).toBeNull();
329
expect(yield* resolve(copy)).toBeNull();
330
+
331
+ // The script launcher execs the runtime by absolute path, so argv0 names the runtime.
332
+ yield* fs.remove(launcher);
333
+ yield* fs.writeFileString(
334
+ launcher,
335
+ posixLauncherScript(path.join(root, ".t3/runtime/versions/1.0.0/t3")),
336
+ { mode: 0o755 },
337
+ );
338
+ expect(yield* resolve(executable, path.join(root, "bin"))).toEqual({
339
+ kind: "t3-launcher",
340
+ launcher,
341
+ baseDir,
342
+ });
343
}),
344
);
345
apps/server/src/cli/invocation.ts
+21
-6
@@ -9,7 +9,11 @@ import * as HostProcess from "@t3tools/shared/HostProcess";
9
import { resolveCommandPath } from "@t3tools/shared/shell";
10
11
import packageJson from "../../package.json" with { type: "json" };
12
-import { resolveLauncherPath } from "../cloud/pinnedRuntime.ts";
12
+import {
13
+ findPosixLauncher,
14
+ readPosixLauncherTarget,
15
+ resolveLauncherPath,
16
+} from "../cloud/pinnedRuntime.ts";
17
18
const PINNED_RUNTIME_ENTRY = /^(.*)\/runtime\/versions\/[^/]+\/t3$/;
19
@@ -72,12 +76,23 @@ export const resolveServerInstallation = Effect.gen(function* () {
76
const entry = yield* fs.realPath(yield* resolveEntryPath);
77
const runtime = PINNED_RUNTIME_ENTRY.exec(entry);
78
if (runtime) {
75
- const launcher = yield* resolveLauncherPath;
79
+ const launchedAs = yield* resolveLauncherPath;
80
+ if (launchedAs === undefined) return null;
81
+ const link = yield* fs.readLink(launchedAs).pipe(Effect.option);
82
+ // A launcher script execs the runtime itself, so look for the script that runs it.
83
+ const launcher = Option.isSome(link)
84
+ ? launchedAs
85
+ : yield* findPosixLauncher({
86
+ launchedAs,
87
+ versionsDir: path.join(runtime[1] || "/", "runtime/versions"),
88
+ });
89
+ // None for a runtime started directly, as SSH launches do, or through a copy.
90
if (launcher === undefined) return null;
77
- // Fails for a runtime started directly, as SSH launches do, or through a copy.
78
- const link = yield* fs.readLink(launcher);
79
- // Keep the home as the link spells it; `t3 update` only repoints links into that spelling.
80
- const linked = PINNED_RUNTIME_ENTRY.exec(path.resolve(path.dirname(launcher), link));
91
+ const target = Option.isSome(link)
92
+ ? path.resolve(path.dirname(launcher), link.value)
93
+ : yield* readPosixLauncherTarget(launcher);
94
+ // Keep the home as the launcher spells it; `t3 update` only repoints launchers into that spelling.
95
+ const linked = target === undefined ? null : PINNED_RUNTIME_ENTRY.exec(target);
96
if (!linked || (yield* fs.realPath(linked[1] || "/")) !== (runtime[1] || "/")) return null;
97
return {
98
kind: "t3-launcher",
apps/server/src/cli/uninstall.test.ts
+31
-3
@@ -14,6 +14,7 @@ import { afterEach, vi } from "vite-plus/test";
14
15
import packageJson from "../../package.json" with { type: "json" };
16
import * as BootService from "../cloud/bootService.ts";
17
+import { posixLauncherScript } from "../cloud/pinnedRuntime.ts";
18
import {
19
findOwnedLauncher,
20
findRecordedLaunchers,
@@ -102,6 +103,19 @@ it.layer(NodeServices.layer)("t3 uninstall launcher", (it) => {
103
assert.isUndefined(yield* findOwnedLauncher({ launchedAs: theirs, versionsDir }));
104
assert.isUndefined(yield* findOwnedLauncher({ launchedAs: copy, versionsDir }));
105
assert.isUndefined(yield* findOwnedLauncher({ launchedAs: undefined, versionsDir }));
106
+ // A script launcher execs by absolute path, so argv0 names the executable.
107
+ const scriptDir = path.join(root, "script-bin");
108
+ const script = path.join(scriptDir, "t3");
109
+ yield* fs.makeDirectory(scriptDir);
110
+ yield* fs.writeFileString(script, posixLauncherScript(exe), { mode: 0o755 });
111
+ assert.equal(
112
+ yield* findOwnedLauncher({ launchedAs: exe, versionsDir }).pipe(
113
+ Effect.provideService(HostProcess.Environment, { PATH: scriptDir }),
114
+ ),
115
+ script,
116
+ );
117
+ const editedScript = path.join(scriptDir, "t3-edited");
118
+ yield* fs.writeFileString(editedScript, `${posixLauncherScript(exe)}# mine\n`);
119
120
// On Windows, only the shim exactly as written is ours; a user's wrapper stays.
121
const shimDir = path.join(root, "win-bin");
@@ -130,11 +144,25 @@ it.layer(NodeServices.layer)("t3 uninstall launcher", (it) => {
144
yield* fs.symlink(path.join(versionsDir, "1.0.0/node"), sibling);
145
yield* fs.writeFileString(
146
path.join(root, "runtime/launchers"),
133
- [ours, theirs, copy, throughAlias, pruned, sibling, path.join(root, "missing")].join("\n") +
134
- "\n",
147
+ [
148
+ ours,
149
+ theirs,
150
+ copy,
151
+ throughAlias,
152
+ pruned,
153
+ sibling,
154
+ script,
155
+ editedScript,
156
+ path.join(root, "missing"),
157
+ ].join("\n") + "\n",
158
);
159
for (const dir of [versionsDir, path.join(root, "alias/runtime/versions")]) {
137
- assert.deepStrictEqual(yield* findRecordedLaunchers(dir), [ours, throughAlias, pruned]);
160
+ assert.deepStrictEqual(yield* findRecordedLaunchers(dir), [
161
+ ours,
162
+ throughAlias,
163
+ pruned,
164
+ script,
165
+ ]);
166
}
167
168
// On Windows only an unedited t3.cmd is ours; a hand-edited wrapper belongs to the user.
apps/server/src/cli/uninstall.ts
+5
-5
@@ -13,9 +13,11 @@ import { Command, Flag, GlobalFlag, Prompt } from "effect/cli";
13
14
import * as BootService from "../cloud/bootService.ts";
15
import {
16
+ findPosixLauncher,
17
generatedWindowsShimTarget,
18
isVersionExecutable,
19
pinnedRuntimeVersionsDir,
20
+ readPosixLauncherTarget,
21
resolveLauncherPath,
22
} from "../cloud/pinnedRuntime.ts";
23
import { projectLocationFlags, resolveCliAuthConfig } from "./config.ts";
@@ -58,13 +60,10 @@ export const findOwnedLauncher = Effect.fn("cli.uninstall.find_launcher")(functi
60
? shimPath
61
: undefined;
62
}
61
- const linkTarget = yield* fs.readLink(input.launchedAs).pipe(Effect.option);
62
- if (Option.isNone(linkTarget)) return undefined;
63
- const resolved = path.resolve(path.dirname(input.launchedAs), linkTarget.value);
64
- return isVersionExecutable(path, input.versionsDir, resolved) ? input.launchedAs : undefined;
63
+ return yield* findPosixLauncher({ launchedAs: input.launchedAs, versionsDir: input.versionsDir });
64
});
65
67
-/** Whether `launcher` is a link or unedited `t3.cmd` into this home's runtime/versions. */
66
+/** Whether `launcher` is a link, unedited `t3` script, or unedited `t3.cmd` into this home's runtime/versions. */
67
const ownsLauncher = Effect.fn("cli.uninstall.owns_launcher")(function* (
68
launcher: string,
69
versionsDir: string,
@@ -91,6 +90,7 @@ const ownsLauncher = Effect.fn("cli.uninstall.owns_launcher")(function* (
90
Effect.orElseSucceed(() => undefined),
91
),
92
yield* fs.realPath(launcher).pipe(Effect.orElseSucceed(() => undefined)),
93
+ yield* readPosixLauncherTarget(launcher),
94
];
95
return targets.some(
96
(target) =>
apps/server/src/cli/update.test.ts
+82
-7
@@ -12,6 +12,7 @@ import * as Path from "effect/Path";
12
import * as TestClock from "effect/testing/TestClock";
13
import * as TestConsole from "effect/testing/TestConsole";
14
import { HttpClient, HttpClientResponse } from "effect/http";
15
+import * as ChildProcess from "effect/process/ChildProcess";
16
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
17
import { afterEach, vi } from "vite-plus/test";
18
@@ -19,7 +20,9 @@ import packageJson from "../../package.json" with { type: "json" };
20
import * as BootService from "../cloud/bootService.ts";
21
import {
22
pinnedRuntimePaths,
23
+ posixLauncherScript,
24
prunePinnedRuntimes,
25
+ readPosixLauncherTarget,
26
resolveLauncherPath,
27
} from "../cloud/pinnedRuntime.ts";
28
import * as ManagedPolicy from "../policy/ManagedPolicy.ts";
@@ -196,7 +199,7 @@ it.layer(NodeServices.layer)("t3 update under a managed policy", (it) => {
199
});
200
201
it.layer(NodeServices.layer)("t3 update launcher", (it) => {
199
- it.effect("repoints a symlink that lives in a runtime versions tree", () =>
202
+ it.effect("replaces a legacy symlink with a script that execs the new version", () =>
203
Effect.gen(function* () {
204
const fs = yield* FileSystem.FileSystem;
205
const path = yield* Path.Path;
@@ -218,8 +221,81 @@ it.layer(NodeServices.layer)("t3 update launcher", (it) => {
221
});
222
223
assert.deepStrictEqual(Option.getOrUndefined(repointed), launcher);
221
- assert.equal(yield* fs.readLink(launcher), newExe);
222
- }).pipe(Effect.provideService(HostProcess.Platform, "linux")),
224
+ assert.equal(yield* fs.readFileString(launcher), posixLauncherScript(newExe));
225
+ // Replaced, not written through.
226
+ assert.equal(yield* fs.readFileString(oldExe), "");
227
+ }).pipe(Effect.scoped, Effect.provideService(HostProcess.Platform, "linux")),
228
+ );
229
+
230
+ it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
231
+ "finds the script that ran this executable and rewrites it, keeping aliases and arguments",
232
+ () =>
233
+ Effect.gen(function* () {
234
+ const fs = yield* FileSystem.FileSystem;
235
+ const path = yield* Path.Path;
236
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
237
+ const root = yield* fs.realPath(
238
+ yield* fs.makeTempDirectoryScoped({ prefix: "t3-update-" }),
239
+ );
240
+ // A quote and a space in the home path exercise the script's quoting.
241
+ const home = path.join(root, "it's home");
242
+ const entry = (version: string) => path.join(home, "runtime/versions", version, "t3");
243
+ for (const version of ["1.0.0", "2.0.0"]) {
244
+ yield* fs.makeDirectory(path.dirname(entry(version)), { recursive: true });
245
+ yield* fs.writeFileString(entry(version), '#!/bin/sh\nprintf \'[%s]\\n\' "$0" "$@"\n', {
246
+ mode: 0o755,
247
+ });
248
+ }
249
+ const launcher = path.join(root, "bin/t3");
250
+ const alias = path.join(root, "alias/t3");
251
+ yield* fs.makeDirectory(path.dirname(launcher), { recursive: true });
252
+ yield* fs.makeDirectory(path.dirname(alias), { recursive: true });
253
+ yield* fs.writeFileString(launcher, posixLauncherScript(entry("1.0.0")), { mode: 0o755 });
254
+ yield* fs.symlink(launcher, alias);
255
+ const repoint = (environment: Record<string, string>) =>
256
+ repointLauncher({
257
+ // The script execs by absolute path, so argv0 names the executable.
258
+ launchedAs: entry("1.0.0"),
259
+ baseDir: home,
260
+ targetEntryPath: entry("2.0.0"),
261
+ }).pipe(Effect.provideService(HostProcess.Environment, environment));
262
+
263
+ assert.equal(
264
+ Option.getOrUndefined(yield* repoint({ PATH: path.dirname(alias) })),
265
+ launcher,
266
+ );
267
+ assert.equal(yield* fs.readLink(alias), launcher);
268
+ const args = ["two words", "it's quoted", "", "*", "$HOME"];
269
+ assert.equal(
270
+ yield* spawner.string(ChildProcess.make(alias, args, { cwd: root })),
271
+ [entry("2.0.0"), ...args].map((arg) => `[${arg}]\n`).join(""),
272
+ );
273
+
274
+ // Like the shell, a relative PATH entry resolves from the working directory, and a
275
+ // script nobody can execute is passed over.
276
+ const unrunnable = path.join(root, "unrunnable/t3");
277
+ yield* fs.makeDirectory(path.dirname(unrunnable), { recursive: true });
278
+ yield* fs.writeFileString(unrunnable, posixLauncherScript(entry("2.0.0")), { mode: 0o644 });
279
+ yield* fs.writeFileString(launcher, posixLauncherScript(entry("2.0.0")), { mode: 0o755 });
280
+ const relative = yield* repointLauncher({
281
+ launchedAs: entry("2.0.0"),
282
+ baseDir: home,
283
+ targetEntryPath: entry("1.0.0"),
284
+ }).pipe(
285
+ Effect.provideService(HostProcess.Environment, {
286
+ PATH: `${path.dirname(unrunnable)}:bin`,
287
+ }),
288
+ Effect.provideService(HostProcess.WorkingDirectory, root),
289
+ );
290
+ assert.equal(Option.getOrUndefined(relative), launcher);
291
+ assert.equal(yield* fs.readFileString(unrunnable), posixLauncherScript(entry("2.0.0")));
292
+
293
+ // An edited script is the user's own wrapper now.
294
+ const edited = `${posixLauncherScript(entry("1.0.0"))}# mine\n`;
295
+ yield* fs.writeFileString(launcher, edited);
296
+ assert.isTrue(Option.isNone(yield* repoint({ PATH: path.dirname(launcher) })));
297
+ assert.equal(yield* fs.readFileString(launcher), edited);
298
+ }).pipe(Effect.scoped, Effect.provideService(HostProcess.Platform, "linux")),
299
);
300
301
it.effect.each([
@@ -280,10 +356,9 @@ it.layer(NodeServices.layer)("t3 update launcher", (it) => {
356
);
357
358
assert.deepStrictEqual(removed, ["1.0.0"]);
283
- // macOS temp dirs sit behind the /var -> /private/var symlink, so compare canonical paths.
359
assert.equal(
285
- yield* fs.realPath(launcher),
286
- yield* fs.realPath(path.join(root, "runtime/versions/2.0.0/t3")),
360
+ yield* readPosixLauncherTarget(launcher),
361
+ path.join(root, "runtime/versions/2.0.0/t3"),
362
);
363
}).pipe(Effect.provideService(HostProcess.Platform, "linux")),
364
);
@@ -363,7 +438,7 @@ it.layer(NodeServices.layer)("t3 update launcher", (it) => {
438
Effect.exit,
439
);
440
366
- const repointed = (yield* fs.readLink(launcher)) === newExe;
441
+ const repointed = (yield* readPosixLauncherTarget(launcher)) === newExe;
442
const recorded = (yield* fs
443
.readFileString(launchersFile)
444
.pipe(Effect.orElseSucceed(() => "")))
apps/server/src/cli/update.ts
+14
-11
@@ -24,6 +24,7 @@ import packageJson from "../../package.json" with { type: "json" };
24
import * as BootService from "../cloud/bootService.ts";
25
import {
26
ensurePinnedRuntimeInstalled,
27
+ findPosixLauncher,
28
launcherOwnsVersionsDir,
29
pinnedRuntimeCommand,
30
isUnpublishedRelease,
@@ -34,6 +35,7 @@ import {
35
recordPinnedRuntimeLauncher,
36
resolveLauncherPath,
37
windowsShimTarget,
38
+ writePosixLauncher,
39
} from "../cloud/pinnedRuntime.ts";
40
import { compareExactServiceVersions, isExactServiceVersion } from "../cloud/serviceProtocol.ts";
41
import * as ManagedPolicy from "../policy/ManagedPolicy.ts";
@@ -46,6 +48,7 @@ import * as CliService from "./service.ts";
48
49
export class CliUpdateError extends Schema.TaggedError<CliUpdateError>()("CliUpdateError", {
50
reason: Schema.String,
51
+ cause: Schema.optional(Schema.Defect()),
52
}) {
53
override get message(): string {
54
return this.reason;
@@ -179,20 +182,20 @@ export const repointLauncher = Effect.fn("cli.update.repoint_launcher")(function
182
return Option.some(shimPath);
183
}
184
182
- const linkTarget = yield* fs.readLink(input.launchedAs).pipe(Effect.option);
183
- if (Option.isNone(linkTarget)) return Option.none<string>();
184
- const resolvedTarget = path.resolve(path.dirname(input.launchedAs), linkTarget.value);
185
- if (!ownsTarget(resolvedTarget)) return Option.none<string>();
186
- yield* remember(input.launchedAs);
187
- const tempLink = `${input.launchedAs}.${process.pid}.tmp`;
188
- yield* fs.symlink(input.targetEntryPath, tempLink).pipe(
189
- Effect.andThen(fs.rename(tempLink, input.launchedAs)),
185
+ const launcher = yield* findPosixLauncher({ launchedAs: input.launchedAs, versionsDir });
186
+ if (launcher === undefined) return Option.none<string>();
187
+ yield* remember(launcher);
188
+ yield* writePosixLauncher({
189
+ launcher,
190
+ executable: input.targetEntryPath,
191
+ exclusive: false,
192
+ }).pipe(
193
Effect.mapError(
191
- () =>
192
- new CliUpdateError({ reason: `Could not repoint the t3 launcher at ${input.launchedAs}.` }),
194
+ (cause) =>
195
+ new CliUpdateError({ reason: `Could not repoint the t3 launcher at ${launcher}.`, cause }),
196
),
197
);
195
- return Option.some(input.launchedAs);
198
+ return Option.some(launcher);
199
});
200
201
/** Windows executables see their own path, so find the installer shim by matching t3.cmd targets on PATH. */
apps/server/src/cloud/pinnedRuntime.ts
+110
-2
@@ -514,6 +514,107 @@ export const windowsShimTarget = (contents: string) => /^"([^"]+)"/m.exec(conten
514
export const generatedWindowsShimTarget = (contents: string) =>
515
/^@echo off\r?\n"([^"]+)" %\*\s*$/.exec(contents)?.[1];
516
517
+/**
518
+ * The `t3` script the install scripts and `t3 update` write on macOS and Linux. Exec by absolute
519
+ * path: through a symlink, argv0 is the link, and the Cursor SDK looks for its helpers beside it.
520
+ */
521
+export const posixLauncherScript = (executable: string) =>
522
+ `#!/bin/sh\nexec '${executable.replaceAll("'", "'\\''")}' "$@"\n`;
523
+
524
+/** The executable a script exactly as {@link posixLauncherScript} writes it runs; never a user's wrapper. */
525
+export const readPosixLauncherTarget = Effect.fn("cloud.pinned_runtime.read_posix_launcher")(
526
+ function* (launcher: string) {
527
+ const fs = yield* FileSystem.FileSystem;
528
+ // Stat first so a runtime binary found the same way is never read whole.
529
+ const info = yield* fs.stat(launcher).pipe(Effect.option);
530
+ if (Option.isNone(info) || info.value.type !== "File" || info.value.size > 4096n) {
531
+ return undefined;
532
+ }
533
+ const contents = yield* fs.readFileString(launcher).pipe(Effect.option);
534
+ if (Option.isNone(contents)) return undefined;
535
+ const quoted = /^#!\/bin\/sh\nexec '((?:[^']|'\\'')*)' "\$@"\n$/.exec(contents.value)?.[1];
536
+ return quoted?.replaceAll("'\\''", "'");
537
+ },
538
+);
539
+
540
+/**
541
+ * The `t3` this executable was started through on macOS or Linux: a legacy symlink into this
542
+ * home's runtime/versions, or, since a script execs the executable and argv0 names it, an unedited
543
+ * {@link posixLauncherScript} that runs it.
544
+ */
545
+export const findPosixLauncher = Effect.fn("cloud.pinned_runtime.find_posix_launcher")(
546
+ function* (input: { readonly launchedAs: string; readonly versionsDir: string }) {
547
+ const fs = yield* FileSystem.FileSystem;
548
+ const path = yield* Path.Path;
549
+ const environment = yield* HostProcess.Environment;
550
+ const linkTarget = yield* fs.readLink(input.launchedAs).pipe(Effect.option);
551
+ if (Option.isSome(linkTarget)) {
552
+ const resolved = path.resolve(path.dirname(input.launchedAs), linkTarget.value);
553
+ return isVersionExecutable(path, input.versionsDir, resolved) ? input.launchedAs : undefined;
554
+ }
555
+ const realPath = (file: string) =>
556
+ fs.realPath(file).pipe(Effect.orElseSucceed(() => undefined));
557
+ const executable = yield* realPath(input.launchedAs);
558
+ const realVersionsDir = yield* realPath(input.versionsDir);
559
+ if (
560
+ executable === undefined ||
561
+ realVersionsDir === undefined ||
562
+ !isVersionExecutable(path, realVersionsDir, executable)
563
+ ) {
564
+ return undefined;
565
+ }
566
+ const recorded = yield* fs
567
+ .readFileString(path.join(path.dirname(input.versionsDir), "launchers"))
568
+ .pipe(Effect.orElseSucceed(() => ""));
569
+ const cwd = yield* HostProcess.WorkingDirectory;
570
+ const candidates = [
571
+ // PATH first, resolved like the shell does: it decides which t3 the user runs.
572
+ ...(environment["PATH"] ?? "")
573
+ .split(":")
574
+ .filter((directory) => directory.length > 0)
575
+ .map((directory) => path.resolve(cwd, directory, "t3")),
576
+ path.join(
577
+ environment["T3CODE_INSTALL_BIN_DIR"] ||
578
+ path.join(yield* HostProcess.HomeDirectory, ".local", "bin"),
579
+ "t3",
580
+ ),
581
+ ...recorded.split(/\r?\n/),
582
+ ].filter((candidate) => path.isAbsolute(candidate));
583
+ for (const candidate of candidates) {
584
+ // The script itself, so an alias that links to it keeps working.
585
+ const script = yield* realPath(candidate);
586
+ if (script === undefined) continue;
587
+ // Like the shell, pass over a script nobody can execute.
588
+ const info = yield* fs.stat(script).pipe(Effect.option);
589
+ if (Option.isNone(info) || (info.value.mode & 0o111) === 0) continue;
590
+ const target = yield* readPosixLauncherTarget(script);
591
+ if (target !== undefined && (yield* realPath(target)) === executable) return script;
592
+ }
593
+ return undefined;
594
+ },
595
+);
596
+
597
+/** Writes {@link posixLauncherScript} at `launcher` in one rename, replacing a legacy symlink rather than writing through it. */
598
+export const writePosixLauncher = Effect.fn("cloud.pinned_runtime.write_posix_launcher")(
599
+ function* (input: {
600
+ readonly launcher: string;
601
+ readonly executable: string;
602
+ /** Fail instead of replacing a file that is there, even one created after the caller looked. */
603
+ readonly exclusive: boolean;
604
+ }) {
605
+ const fs = yield* FileSystem.FileSystem;
606
+ const path = yield* Path.Path;
607
+ const staging = yield* fs.makeTempFileScoped({
608
+ directory: path.dirname(input.launcher),
609
+ prefix: ".t3-",
610
+ });
611
+ yield* fs.writeFileString(staging, posixLauncherScript(input.executable));
612
+ yield* fs.chmod(staging, 0o755);
613
+ yield* input.exclusive ? fs.link(staging, input.launcher) : fs.rename(staging, input.launcher);
614
+ },
615
+ Effect.scoped,
616
+);
617
+
618
/** Where the `t3` launchers written by the install scripts and `t3 update` point. */
619
const shellLauncherTargets = Effect.fn("cloud.pinned_runtime.shell_launcher_targets")(function* (
620
baseDir: string,
@@ -544,7 +645,7 @@ const shellLauncherTargets = Effect.fn("cloud.pinned_runtime.shell_launcher_targ
645
const unrecorded: Array<string> = [];
646
const targets: Array<string> = [];
647
for (const launcher of [...recorded, ...found]) {
547
- const target =
648
+ const resolved =
649
platform === "win32"
650
? yield* fs.readFileString(launcher).pipe(
651
Effect.map(windowsShimTarget),
@@ -552,13 +653,20 @@ const shellLauncherTargets = Effect.fn("cloud.pinned_runtime.shell_launcher_targ
653
)
654
: // Fully resolved, through chained links and a symlinked T3 home alike.
655
yield* fs.realPath(launcher).pipe(Effect.orElseSucceed(() => undefined));
555
- if (target === undefined) continue;
656
+ if (resolved === undefined) continue;
657
+ const scriptTarget =
658
+ platform === "win32" ? undefined : yield* readPosixLauncherTarget(resolved);
659
+ const target =
660
+ scriptTarget === undefined
661
+ ? resolved
662
+ : yield* fs.realPath(scriptTarget).pipe(Effect.orElseSucceed(() => scriptTarget));
663
// A runtime's own entry, on the macOS service PATH or recorded by an earlier prune, is no launcher.
664
// It is named as `versions/<version>/t3`, and neither it nor its directory is a link.
665
const entryDir = path.dirname(path.resolve(launcher));
666
const parent = path.dirname(entryDir);
667
if (
668
platform !== "win32" &&
669
+ scriptTarget === undefined &&
670
(parent === versionsDir || parent === realVersionsDir) &&
671
target === path.join(realVersionsDir, path.basename(entryDir), path.basename(launcher))
672
) {
apps/server/src/cloud/serviceLauncherClient.test.ts
+7
-5
@@ -14,6 +14,7 @@ import {
14
type ServiceLauncherChildMessage,
15
type ServiceLauncherParentMessage,
16
} from "./serviceProtocol.ts";
17
+import { posixLauncherScript } from "./pinnedRuntime.ts";
18
import * as ServiceLauncherClient from "./serviceLauncherClient.ts";
19
20
class FakeLauncherProcess {
@@ -98,7 +99,7 @@ it.effect.each([3, SERVICE_LAUNCHER_PROTOCOL])(
99
};
100
host.emit({ type: "committed", updateId: committed.id });
101
expect(yield* Fiber.join(prepared)).toEqual(committed);
101
- assert.equal(yield* fs.readLink(installed), exe("1.1.0"));
102
+ assert.equal(yield* fs.readFileString(installed), posixLauncherScript(exe("1.1.0")));
103
104
// A later start replays the stored outcome; user pins made since then stay put.
105
yield* fs.remove(installed);
@@ -224,7 +225,7 @@ it.layer(NodeServices.layer)("self-update launchers", (it) => {
225
yield* fs.writeFileString(file, "");
226
}
227
yield* fs.makeDirectory(path.dirname(installed), { recursive: true });
227
- yield* fs.symlink(exe("1.5.0"), installed);
228
+ yield* fs.writeFileString(installed, posixLauncherScript(exe("1.5.0")), { mode: 0o755 });
229
yield* fs.makeDirectory(path.dirname(onPath), { recursive: true });
230
yield* fs.symlink(exe("1.0.0"), onPath);
231
@@ -236,8 +237,9 @@ it.layer(NodeServices.layer)("self-update launchers", (it) => {
237
}),
238
);
239
239
- assert.equal(yield* fs.readLink(installed), exe("2.0.0"));
240
- assert.equal(yield* fs.readLink(onPath), exe("2.0.0"));
240
+ // The script is rewritten and the legacy symlink becomes one.
241
+ assert.equal(yield* fs.readFileString(installed), posixLauncherScript(exe("2.0.0")));
242
+ assert.equal(yield* fs.readFileString(onPath), posixLauncherScript(exe("2.0.0")));
243
}).pipe(Effect.provideService(HostProcess.Platform, "linux")),
244
);
245
@@ -291,7 +293,7 @@ it.layer(NodeServices.layer)("self-update launchers", (it) => {
293
assert.lengthOf(warnings, 1);
294
assert.include(JSON.stringify(warnings), installed);
295
assert.equal(yield* fs.readLink(installed), exe("1.0.0"));
294
- assert.equal(yield* fs.readLink(onPath), exe("2.0.0"));
296
+ assert.equal(yield* fs.readFileString(onPath), posixLauncherScript(exe("2.0.0")));
297
}).pipe(Effect.provideService(HostProcess.Platform, "linux")),
298
);
299
apps/server/src/cloud/serviceLauncherClient.ts
+17
-13
@@ -10,7 +10,12 @@ import * as Path from "effect/Path";
10
import * as Schema from "effect/Schema";
11
12
import packageJson from "../../package.json" with { type: "json" };
13
-import { pinnedRuntimePaths, pinnedRuntimeVersionsDir } from "./pinnedRuntime.ts";
13
+import {
14
+ pinnedRuntimePaths,
15
+ pinnedRuntimeVersionsDir,
16
+ readPosixLauncherTarget,
17
+ writePosixLauncher,
18
+} from "./pinnedRuntime.ts";
19
import {
20
decodeServiceLauncherContext,
21
decodeServiceLauncherParentMessage,
@@ -110,7 +115,7 @@ export class ServiceLauncherClient extends Context.Service<
115
readonly targetVersion: string;
116
readonly dbPath: string;
117
}) => Effect.Effect<string, ServiceLauncherClientError | ServiceLauncherRejectedError>;
113
- /** Owned `t3` symlinks move to the new runtime only when this start commits the trial. */
118
+ /** Owned `t3` launchers move to the new runtime only when this start commits the trial. */
119
readonly prepareTrial: (input: {
120
readonly baseDir: string;
121
}) => Effect.Effect<ServerSelfUpdateOutcome | undefined, ServiceLauncherClientError>;
@@ -189,11 +194,12 @@ export const repointLaunchers = Effect.fn("cloud.service_launcher_client.repoint
194
() => Effect.succeedNone,
195
),
196
);
192
- if (Option.isNone(linkTarget)) return;
193
- const relative = path.relative(
194
- versionsDir,
195
- path.resolve(path.dirname(launchedAs), linkTarget.value),
196
- );
197
+ // A legacy symlink, or the script install.sh and `t3 update` write.
198
+ const current = Option.isSome(linkTarget)
199
+ ? path.resolve(path.dirname(launchedAs), linkTarget.value)
200
+ : yield* readPosixLauncherTarget(launchedAs);
201
+ if (current === undefined) return;
202
+ const relative = path.relative(versionsDir, current);
203
if (
204
relative.length === 0 ||
205
relative === ".." ||
@@ -201,13 +207,11 @@ export const repointLaunchers = Effect.fn("cloud.service_launcher_client.repoint
207
path.isAbsolute(relative)
208
)
209
return;
204
- const temporary = yield* fs.makeTempDirectoryScoped({
205
- directory: path.dirname(launchedAs),
206
- prefix: ".t3-launcher-",
210
+ yield* writePosixLauncher({
211
+ launcher: launchedAs,
212
+ executable: target.entryPath,
213
+ exclusive: false,
214
});
208
- const link = path.join(temporary, "t3");
209
- yield* fs.symlink(target.entryPath, link);
210
- yield* fs.rename(link, launchedAs);
215
}),
216
).pipe(
217
Effect.catchCause((cause) =>
docs/user/install.md
+1
-1
@@ -20,7 +20,7 @@ On Windows, in PowerShell:
20
irm https://t3.codes/install.ps1 | iex
21
```
22
23
-This installs the `t3` binary to `~/.local/bin`. If that folder is not on your
23
+This installs the `t3` command to `~/.local/bin`. If that folder is not on your
24
`PATH` yet, the installer says so and, for zsh, bash on Linux, and fish, prints
25
a command to add it. On Windows, `t3` works in the same PowerShell window right
26
away; add the folder to your `PATH` for new windows. If a `t3` that the
packages/contracts/src/environment.ts
+1
-1
@@ -67,7 +67,7 @@ const InstalledPath = Schema.String.check(Schema.isNonEmpty());
67
export const ServerInstallation = Schema.Union([
68
Schema.Struct({ kind: Schema.Literals(["npx", "pnpm-dlx", "bunx"]) }),
69
Schema.Struct({ kind: Schema.Literal("npm-global"), prefix: TrimmedNonEmptyString }),
70
- // A launcher symlink into a downloaded runtime, as the install script and `t3 update` leave.
70
+ // A launcher (script, or a legacy symlink) into a downloaded runtime, as the install script and `t3 update` leave.
71
Schema.Struct({
72
kind: Schema.Literal("t3-launcher"),
73
launcher: InstalledPath,
scripts/install.sh
+45
-9
@@ -9,7 +9,7 @@
9
# (default: stable; preview is a maintainers' test train)
10
# T3CODE_VERSION exact version to install (overrides T3CODE_CHANNEL)
11
# T3CODE_HOME T3 home directory (default: ~/.t3)
12
-# T3CODE_INSTALL_BIN_DIR where the `t3` symlink goes (default: ~/.local/bin)
12
+# T3CODE_INSTALL_BIN_DIR where the `t3` command goes (default: ~/.local/bin)
13
# T3CODE_RELEASE_BASE_URL mirror for releases/download (default: GitHub)
14
#
15
# The archive is unpacked into $T3CODE_HOME/runtime/versions/<version>, the
@@ -267,8 +267,31 @@ fi
267
268
step "Setting up the t3 command..."
269
mkdir -p "$bin_dir"
270
-# Replace only this home's own t3 links: into its versions, or the desktop app's launcher.
271
-# Anything that is not a symlink (a script, a copied binary) belongs to someone else.
270
+# Exec by absolute path: through a symlink, argv0 is the link, and the Cursor SDK looks for its
271
+# helpers beside it. t3 update and t3 install write the same script.
272
+nl='
273
+'
274
+launcher_head="#!/bin/sh${nl}exec '"
275
+launcher_tail="' \"\$@\"${nl}"
276
+# The x keeps a trailing newline in the path through command substitution.
277
+launcher_script() {
278
+ quoted="$(printf '%sx' "$1" | sed "s/'/'\\\\''/g")"
279
+ printf '%s%s%s' "$launcher_head" "${quoted%x}" "$launcher_tail"
280
+}
281
+# The executable an unedited launcher script at $1 runs; a user's own wrapper prints nothing.
282
+script_t3() {
283
+ [ -f "$1" ] && [ ! -L "$1" ] && [ "$(wc -c < "$1")" -le 4096 ] || return 0
284
+ contents="$(cat "$1"; printf x)"
285
+ contents="${contents%x}"
286
+ case "$contents" in "$launcher_head"*"$launcher_tail") ;; *) return 0 ;; esac
287
+ quoted="${contents#"$launcher_head"}"
288
+ unquoted="$(printf '%sx' "${quoted%"$launcher_tail"}" | sed "s/'\\\\''/'/g")"
289
+ unquoted="${unquoted%x}"
290
+ [ -n "$unquoted" ] && [ "$(launcher_script "$unquoted"; printf x)" = "${contents}x" ] && printf '%s' "$unquoted"
291
+ return 0
292
+}
293
+# Replace only this home's own t3 launchers: into its versions, or the desktop app's launcher.
294
+# Anything else (a user's script, a copied binary) belongs to someone else.
295
# Exactly <versions>/<version>/t3 ($1 under $2), never another program inside a version.
296
version_t3() {
297
case "$1" in "$2"/*) ;; *) return 1 ;; esac
@@ -278,13 +301,17 @@ slot_empty=true
301
if [ -e "${bin_dir}/t3" ] || [ -L "${bin_dir}/t3" ]; then
302
slot_empty=false
303
owned=false
304
+ real_versions_dir="$(CDPATH='' cd -P -- "$versions_dir" && pwd)"
305
if [ -L "${bin_dir}/t3" ]; then
306
existing="$(readlink "${bin_dir}/t3" 2>/dev/null || true)"
307
case "$existing" in /*) ;; *) existing="${bin_dir}/${existing}" ;; esac
284
- real_versions_dir="$(CDPATH='' cd -P -- "$versions_dir" && pwd)"
285
- # Through a symlinked T3 home the link text names the alias; resolve its folder to compare.
308
+ else
309
+ existing="$(script_t3 "${bin_dir}/t3")"
310
+ fi
311
+ if [ -n "$existing" ]; then
312
+ # Through a symlinked T3 home the path names the alias; resolve its folder to compare.
313
existing_dir="$(CDPATH='' cd -P -- "$(dirname -- "$existing")" 2>/dev/null && pwd || true)"
287
- # The text alone counts only without . or .. segments (a pruned version leaves a dangling link).
314
+ # The text alone counts only without . or .. segments (a pruned version leaves a dangling path).
315
case "$existing" in
316
*/./* | */../* | */. | */..) ;;
317
*)
@@ -298,13 +325,22 @@ if [ -e "${bin_dir}/t3" ] || [ -L "${bin_dir}/t3" ]; then
325
fi
326
"$owned" || fail "another t3 is already at ${bin_dir}/t3. Remove it and run this again, or run ${target_dir}/t3 directly."
327
fi
301
-# An empty spot is linked without -f, so a file that appears after the check above is kept.
328
+launcher_tmp="$(mktemp "${bin_dir}/.t3.XXXXXX")"
329
+trap 'rm -f "$launcher_tmp"' EXIT
330
+trap 'exit 130' INT
331
+trap 'exit 143' TERM
332
+launcher_script "${target_dir}/t3" > "$launcher_tmp"
333
+chmod 755 "$launcher_tmp"
334
+# An empty spot is hard-linked without -f, so a file that appears after the check above is kept.
335
if "$slot_empty"; then
303
- ln -s "${target_dir}/t3" "${bin_dir}/t3" || fail "could not link ${bin_dir}/t3; something else was created there."
336
+ ln "$launcher_tmp" "${bin_dir}/t3" || fail "could not write ${bin_dir}/t3; something else was created there."
337
else
338
# Known race, accepted: a file written here after the ownership check above is overwritten.
306
- ln -sfn "${target_dir}/t3" "${bin_dir}/t3"
339
+ # mv replaces a legacy symlink rather than writing through it.
340
+ mv -f "$launcher_tmp" "${bin_dir}/t3"
341
fi
342
+rm -f "$launcher_tmp"
343
+trap - EXIT
344
# Pruning keeps what this launcher points at; a background service cannot see bin_dir otherwise.
345
launcher="$(CDPATH='' cd -P -- "$bin_dir" && pwd)/t3"
346
launchers="${t3_home}/runtime/launchers"
scripts/install.test.ts
+29
-11
@@ -8,6 +8,10 @@ import * as NodeOS from "node:os";
8
import * as NodePath from "node:path";
9
import { describe, expect, it } from "vite-plus/test";
10
11
+/** The launcher install.sh, `t3 install`, and `t3 update` write; exec by absolute path. */
12
+const launcherScript = (executable: string) =>
13
+ `#!/bin/sh\nexec '${executable.replaceAll("'", "'\\''")}' "$@"\n`;
14
+
15
const nightlies = Array.from({ length: 100 }, (_, index) => ({
16
tag_name: `v1.2.4-nightly.20261020.${200 - index}`,
17
}));
@@ -29,10 +33,8 @@ describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer home
33
await NodeFSP.writeFile(NodePath.join(target, "t3"), "#!/bin/sh\necho 't3 v1.2.3'\n", {
34
mode: 0o755,
35
});
32
- const { status, stdout, stderr } = NodeChildProcess.spawnSync(
33
- "sh",
34
- [NodePath.resolve(import.meta.dirname, "install.sh")],
35
- {
36
+ const install = () =>
37
+ NodeChildProcess.spawnSync("sh", [NodePath.resolve(import.meta.dirname, "install.sh")], {
38
cwd: root,
39
env: {
40
...process.env,
@@ -43,11 +45,16 @@ describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer home
45
T3CODE_RELEASE_BASE_URL: "http://127.0.0.1:1",
46
},
47
encoding: "utf8",
46
- },
47
- );
48
+ });
49
+ // The second run replaces the launcher the first wrote, newlines in its path and all.
50
+ const first = install();
51
+ expect(first.status, first.stdout + first.stderr).toBe(0);
52
+ const { status, stdout, stderr } = install();
53
expect(status, stdout + stderr).toBe(0);
54
expect(stderr).toContain(`Installed T3 Code ${version}`);
50
- expect(await NodeFSP.readlink(launcher)).toBe(NodePath.join(target, "t3"));
55
+ expect(await NodeFSP.readFile(launcher, "utf8")).toBe(
56
+ launcherScript(NodePath.join(target, "t3")),
57
+ );
58
expect(
59
NodeChildProcess.execFileSync(launcher, ["--version"], {
60
cwd: NodeOS.tmpdir(),
@@ -215,7 +222,7 @@ async function installOver(input: {
222
}
223
224
describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("install.sh t3 command", () => {
218
- it("replaces only this home's own links and prints a PATH command", async () => {
225
+ it("replaces only this home's own launchers and prints a PATH command", async () => {
226
const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-install-link-"));
227
try {
228
const home = NodePath.join(root, "home");
@@ -267,8 +274,8 @@ describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("install.sh t3
274
env: { HOME: root, SHELL: "/bin/zsh", PATH: "/usr/bin:/bin" },
275
});
276
expect(upgrade.code, upgrade.output).toBe(0);
270
- expect(await NodeFSP.readlink(link)).toBe(
271
- NodePath.join(root, "alias/runtime/versions/1.2.3/t3"),
277
+ expect(await NodeFSP.readFile(link, "utf8")).toBe(
278
+ launcherScript(NodePath.join(root, "alias/runtime/versions/1.2.3/t3")),
279
);
280
expect(upgrade.output).toContain(
281
`printf '\\n%s\\n' 'export PATH="$PATH:$HOME/bin"' >> ~/.zshrc`,
@@ -305,6 +312,13 @@ describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("install.sh t3
312
expect(relative.code, relative.output).toBe(0);
313
expect(relative.output).toContain(`'export PATH="$PATH:$HOME/bin"'`);
314
315
+ // A launcher script someone edited is theirs now.
316
+ const edited = `${launcherScript(NodePath.join(home, "runtime/versions/1.2.3/t3"))}# mine\n`;
317
+ await NodeFSP.writeFile(link, edited);
318
+ const overEdited = await installOver({ script: "install.sh", home, binDir });
319
+ expect(overEdited.code).not.toBe(0);
320
+ expect(await NodeFSP.readFile(link, "utf8")).toBe(edited);
321
+
322
await NodeFSP.rm(link);
323
await NodeFSP.symlink(NodePath.join(home, "bin/t3"), link);
324
const overDesktop = await installOver({
@@ -313,7 +327,9 @@ describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("install.sh t3
327
binDir: `${binDir}/`,
328
});
329
expect(overDesktop.code, overDesktop.output).toBe(0);
316
- expect(await NodeFSP.readlink(link)).toBe(NodePath.join(home, "runtime/versions/1.2.3/t3"));
330
+ expect(await NodeFSP.readFile(link, "utf8")).toBe(
331
+ launcherScript(NodePath.join(home, "runtime/versions/1.2.3/t3")),
332
+ );
333
} finally {
334
await NodeFSP.rm(root, { recursive: true, force: true });
335
}
@@ -439,6 +455,8 @@ describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer chec
455
"rm",
456
"mv",
457
"ln",
458
+ "chmod",
459
+ "sed",
460
checksumTool,
461
]) {
462
const executable = NodeChildProcess.execFileSync(