Skip to content

Commit bfcfe56

Browse files
committed
fix(server): ship patched Node and repair service launcher upgrades
1 parent b5a226e commit bfcfe56

21 files changed

Lines changed: 998 additions & 75 deletions

‎.github/workflows/release-desktop.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ jobs:
263263
env:
264264
# The exact version, not a major: vp downloads it from nodejs.org/dist on
265265
# the runner, and only exact versions have a dist directory. Keep in
266-
# step with SEA_NODE_VERSION in apps/server/vite.config.ts.
267-
VP_NODE_VERSION: "26.8.2"
266+
# step with CLI_NODE_VERSION in scripts/lib/cli-runtime.ts.
267+
VP_NODE_VERSION: "26.12.1"
268268
# The executable bundles the server again, so it needs the same stamp
269269
# as release.yml's JS bundle.
270270
T3CODE_TELEMETRY_CHANNEL: ${{ github.repository == 'pingdotgg/t3code' && inputs.release_channel || 'dev' }}

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,65 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
22
import { assert, it } from "@effect/vitest";
33
import * as Effect from "effect/Effect";
44
import * as Layer from "effect/Layer";
5+
import * as FileSystem from "effect/FileSystem";
6+
import * as Path from "effect/Path";
7+
import * as TestConsole from "effect/testing/TestConsole";
58

69
import * as BootService from "../cloud/bootService.ts";
710
import { runDoctor } from "./doctor.ts";
811
import { DatabaseMaintenance } from "../persistence/DatabaseMaintenance.ts";
12+
import {
13+
makePersistedServerRuntimeState,
14+
persistServerRuntimeState,
15+
} from "../serverRuntimeState.ts";
16+
17+
it.effect("reports the CLI, running server and launcher Node versions independently", () =>
18+
Effect.gen(function* () {
19+
const fs = yield* FileSystem.FileSystem;
20+
const path = yield* Path.Path;
21+
const runtimeStatePath = path.join(yield* fs.makeTempDirectoryScoped(), "server-runtime.json");
22+
const state = yield* makePersistedServerRuntimeState({
23+
config: { host: undefined, devUrl: undefined },
24+
port: 3773,
25+
});
26+
yield* persistServerRuntimeState({
27+
path: runtimeStatePath,
28+
state: {
29+
...state,
30+
nodeVersion: "26.12.1",
31+
executablePath: "/isolated/new/t3",
32+
serviceManaged: true,
33+
launcherRuntime: {
34+
pid: process.pid,
35+
nodeVersion: "26.8.2",
36+
executablePath: "/isolated/old/t3",
37+
},
38+
},
39+
});
40+
yield* runDoctor("/test/statev2.sqlite", { fix: false, dryRun: true, runtimeStatePath });
41+
const output = (yield* TestConsole.logLines).join("\n");
42+
assert.include(output, `CLI: Node ${process.versions.node} (${process.execPath})`);
43+
assert.include(output, "Server: Node 26.12.1 (/isolated/new/t3");
44+
assert.include(output, "Service launcher: Node 26.8.2 (/isolated/old/t3");
45+
}).pipe(
46+
Effect.provide(
47+
Layer.mergeAll(
48+
NodeServices.layer,
49+
TestConsole.layer,
50+
Layer.mock(BootService.BootService)({}),
51+
Layer.mock(DatabaseMaintenance)({
52+
inspect: () =>
53+
Effect.succeed({
54+
databaseBytes: 0,
55+
reclaimableBytes: 0,
56+
incrementalVacuumEnabled: true,
57+
legacyDatabaseBytes: null,
58+
}),
59+
}),
60+
),
61+
),
62+
),
63+
);
964

1065
it.effect(
1166
"--fix reclaims space with the service paused and keeps the V1 database, and --dry-run changes nothing",

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

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { DATABASE_COMPACTION_RECOMMENDED_BYTES } from "@t3tools/contracts";
22
import * as Console from "effect/Console";
33
import * as Effect from "effect/Effect";
44
import * as Layer from "effect/Layer";
5+
import * as Option from "effect/Option";
56
import { Command, Flag, GlobalFlag, Prompt } from "effect/cli";
67

78
import * as BootService from "../cloud/bootService.ts";
89
import * as DatabaseMaintenance from "../persistence/DatabaseMaintenance.ts";
910
import { projectLocationFlags, resolveCliAuthConfig } from "./config.ts";
1011
import * as CliService from "./service.ts";
12+
import { isProcessAlive, readPersistedServerRuntimeState } from "../serverRuntimeState.ts";
1113

1214
const formatBytes = (bytes: number) =>
1315
bytes >= 1024 ** 3
@@ -18,8 +20,37 @@ const formatBytes = (bytes: number) =>
1820

1921
export const runDoctor = Effect.fn("runDoctor")(function* (
2022
databasePath: string,
21-
options: { readonly fix: boolean; readonly dryRun: boolean; readonly interactive?: boolean },
23+
options: {
24+
readonly fix: boolean;
25+
readonly dryRun: boolean;
26+
readonly interactive?: boolean;
27+
readonly runtimeStatePath?: string;
28+
},
2229
) {
30+
yield* Console.log(`CLI: Node ${process.versions.node} (${process.execPath})`);
31+
if (options.runtimeStatePath !== undefined) {
32+
const state = yield* readPersistedServerRuntimeState(options.runtimeStatePath);
33+
if (Option.isSome(state) && isProcessAlive(state.value.pid)) {
34+
const runtime = state.value;
35+
yield* Console.log(
36+
runtime.nodeVersion === undefined
37+
? "Server: Node runtime not recorded by this release."
38+
: `Server: Node ${runtime.nodeVersion} (${runtime.executablePath ?? "executable not recorded"}; pid ${String(runtime.pid)})`,
39+
);
40+
if (runtime.serviceManaged === true) {
41+
const launcher = runtime.launcherRuntime;
42+
yield* Console.log(
43+
launcher === undefined
44+
? "Service launcher: Node runtime not recorded. Reinstall the service with the updated CLI to replace an older launcher."
45+
: isProcessAlive(launcher.pid)
46+
? `Service launcher: Node ${launcher.nodeVersion} (${launcher.executablePath}; pid ${String(launcher.pid)})`
47+
: "Service launcher: recorded process is no longer running.",
48+
);
49+
}
50+
} else {
51+
yield* Console.log("Server: no running process recorded for this T3 home.");
52+
}
53+
}
2354
const maintenance = yield* DatabaseMaintenance.DatabaseMaintenance;
2455
const status = yield* maintenance.inspect(databasePath);
2556
yield* Console.log(
@@ -142,9 +173,11 @@ export const doctorCommand = Command.make("doctor", {
142173
Effect.gen(function* () {
143174
const logLevel = yield* GlobalFlag.LogLevel;
144175
const config = yield* resolveCliAuthConfig(flags, logLevel);
145-
yield* runDoctor(config.dbPath, { fix: flags.fix, dryRun: flags.dryRun }).pipe(
146-
Effect.provide(Layer.merge(DatabaseMaintenance.layer, CliService.layer(config))),
147-
);
176+
yield* runDoctor(config.dbPath, {
177+
fix: flags.fix,
178+
dryRun: flags.dryRun,
179+
runtimeStatePath: config.serverRuntimeStatePath,
180+
}).pipe(Effect.provide(Layer.merge(DatabaseMaintenance.layer, CliService.layer(config))));
148181
}),
149182
),
150183
);

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ export const servicePreflightCommand = Command.make("__service-preflight", {
1010
}).pipe(
1111
Command.unlisted,
1212
Command.withHandler(({ databasePath, launcherProtocol }) =>
13-
Console.log(JSON.stringify(runServicePreflight({ databasePath, launcherProtocol }))).pipe(
14-
Effect.asVoid,
15-
),
13+
Console.log(
14+
JSON.stringify({
15+
...runServicePreflight({ databasePath, launcherProtocol }),
16+
nodeVersion: process.versions.node,
17+
executablePath: process.execPath,
18+
}),
19+
).pipe(Effect.asVoid),
1620
),
1721
);

0 commit comments

Comments
 (0)