Skip to content

Commit b845e84

Browse files
feat(cli): add t3 update for self-contained installs
A self-contained t3 had no way to move to a newer release short of re-running the install script and then running service update from the new executable. `t3 update [version] [--channel]` does that in one step: it resolves the newest release on the channel the running t3 came from (or the one given), installs it through the same pinned-runtime path the in-app update uses, repoints the launcher symlink or shim the install scripts left behind, and runs service update from the new executable when a background service is installed for the same T3 home. Versions that are only on npm are refused with the npm command to run instead, so the command never reintroduces the Node dependency it exists to remove. BootService.status now reports the T3 home the installed unit serves, and update only touches the service when that matches its own base dir: the unit name is per user, not per home, and an early test run restarted the live server of the machine it ran on. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent e501b34 commit b845e84

9 files changed

Lines changed: 545 additions & 1 deletion

File tree

‎apps/server/src/bin.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { isEntrypoint } from "./entrypoint.ts";
1717
import { projectCommand } from "./cli/project.ts";
1818
import { runServerCommand, serveCommand, startCommand } from "./cli/server.ts";
1919
import { serviceCommand } from "./cli/service.ts";
20+
import { updateCommand } from "./cli/update.ts";
2021
import { claudeHistoryCommand } from "./cli/claudeHistory.ts";
2122
import { serviceLauncherCommand } from "./cli/serviceLauncher.ts";
2223
import { servicePreflightCommand } from "./cli/servicePreflight.ts";
@@ -62,6 +63,7 @@ export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
6263
authCommand,
6364
projectCommand,
6465
serviceCommand,
66+
updateCommand,
6567
serviceLauncherCommand,
6668
claudeHistoryCommand,
6769
servicePreflightCommand,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ const serviceInstallCommand = Command.make("install", serviceReconcileFlags).pip
140140

141141
const serviceUpdateCommand = Command.make("update", serviceReconcileFlags).pipe(
142142
Command.withDescription(
143-
"Update or repair the background service using this CLI version. Use `npx t3@latest service update` for the latest release.",
143+
"Update or repair the background service using this CLI version. Use `t3 update` to move to a newer release first.",
144144
),
145145
Command.withHandler((flags) =>
146146
runServiceCommand(

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import * as NodeServices from "@effect/platform-node/NodeServices";
2+
import { assert, it } from "@effect/vitest";
3+
import * as Effect from "effect/Effect";
4+
import * as FileSystem from "effect/FileSystem";
5+
import * as Option from "effect/Option";
6+
import * as Path from "effect/Path";
7+
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
8+
9+
import { repointLauncher } from "./update.ts";
10+
11+
it.layer(NodeServices.layer)("t3 update launcher", (it) => {
12+
it.effect("repoints a symlink that lives in a runtime versions tree", () =>
13+
Effect.gen(function* () {
14+
const fs = yield* FileSystem.FileSystem;
15+
const path = yield* Path.Path;
16+
const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-update-" });
17+
const oldExe = path.join(root, "runtime/versions/1.0.0/t3");
18+
const newExe = path.join(root, "runtime/versions/2.0.0/t3");
19+
const launcher = path.join(root, "bin/t3");
20+
for (const file of [oldExe, newExe]) {
21+
yield* fs.makeDirectory(path.dirname(file), { recursive: true });
22+
yield* fs.writeFileString(file, "");
23+
}
24+
yield* fs.makeDirectory(path.dirname(launcher), { recursive: true });
25+
yield* fs.symlink(oldExe, launcher);
26+
27+
const repointed = yield* repointLauncher({ launchedAs: launcher, targetEntryPath: newExe });
28+
29+
assert.deepStrictEqual(Option.getOrUndefined(repointed), launcher);
30+
assert.equal(yield* fs.readLink(launcher), newExe);
31+
}).pipe(Effect.scoped, Effect.provideService(HostProcessPlatform, "linux")),
32+
);
33+
34+
it.effect("leaves a plain copy or a foreign symlink alone", () =>
35+
Effect.gen(function* () {
36+
const fs = yield* FileSystem.FileSystem;
37+
const path = yield* Path.Path;
38+
const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-update-" });
39+
const newExe = path.join(root, "runtime/versions/2.0.0/t3");
40+
const copy = path.join(root, "copy/t3");
41+
const foreign = path.join(root, "foreign/t3");
42+
const elsewhere = path.join(root, "elsewhere/t3");
43+
for (const file of [newExe, copy, elsewhere]) {
44+
yield* fs.makeDirectory(path.dirname(file), { recursive: true });
45+
yield* fs.writeFileString(file, "");
46+
}
47+
yield* fs.makeDirectory(path.dirname(foreign), { recursive: true });
48+
yield* fs.symlink(elsewhere, foreign);
49+
50+
for (const launchedAs of [copy, foreign, undefined]) {
51+
const repointed = yield* repointLauncher({ launchedAs, targetEntryPath: newExe });
52+
assert.equal(repointed._tag, "None", launchedAs ?? "undefined");
53+
}
54+
assert.equal(yield* fs.readLink(foreign), elsewhere);
55+
}).pipe(Effect.scoped, Effect.provideService(HostProcessPlatform, "linux")),
56+
);
57+
});

0 commit comments

Comments
 (0)