Skip to content

Commit 9a197b2

Browse files
fix(server): give Windows hosts Windows steps when an old service launcher blocks an update
A remote update blocked by an old launcher protocol always told the host to run `curl | sh`, `which -a t3` and `~/.local/bin/t3 service install`, none of which work on Windows, where `t3 service install` does not exist. The preflight now takes the host platform from HostProcess.Platform and, on Windows, names the PowerShell installer pinned to the target version, `where.exe`, the `t3.cmd` path to start the launcher from, and that remote updates never move a Windows launcher, so the swap repeats on each launcher protocol bump. Fixes #34435 AI-assisted; verified with the tests and tools listed above.
1 parent 6e2059e commit 9a197b2

3 files changed

Lines changed: 39 additions & 23 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as HostProcess from "@t3tools/shared/HostProcess";
12
import * as Console from "effect/Console";
23
import * as Effect from "effect/Effect";
34
import { Command, Flag } from "effect/cli";
@@ -10,8 +11,12 @@ export const servicePreflightCommand = Command.make("__service-preflight", {
1011
}).pipe(
1112
Command.unlisted,
1213
Command.withHandler(({ databasePath, launcherProtocol }) =>
13-
Console.log(JSON.stringify(runServicePreflight({ databasePath, launcherProtocol }))).pipe(
14-
Effect.asVoid,
14+
HostProcess.Platform.pipe(
15+
Effect.flatMap((platform) =>
16+
Console.log(
17+
JSON.stringify(runServicePreflight({ databasePath, launcherProtocol, platform })),
18+
),
19+
),
1520
),
1621
),
1722
);

‎apps/server/src/cloud/servicePreflight.test.ts‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ it.each([1])("blocks legacy launcher protocol %i with exact recovery steps", (la
2020
const result = runServicePreflight({
2121
databasePath: "/missing/state.sqlite",
2222
launcherProtocol,
23+
platform: "linux",
2324
version: "9.8.7",
2425
});
2526

@@ -35,23 +36,18 @@ it.each([1])("blocks legacy launcher protocol %i with exact recovery steps", (la
3536

3637
// regression: #34435 Windows hosts were told to run `curl | sh` and `~/.local/bin/t3 service install`
3738
it("gives Windows hosts recovery steps that run on Windows", () => {
38-
const platform = Object.getOwnPropertyDescriptor(process, "platform")!;
39-
Object.defineProperty(process, "platform", { ...platform, value: "win32" });
40-
try {
41-
const result = runServicePreflight({
42-
databasePath: "C:\\missing\\state.sqlite",
43-
launcherProtocol: 3,
44-
version: "9.8.7",
45-
});
46-
const reason = result.status === "blocked" ? result.reason : "";
47-
expect(reason).toMatch(new RegExp(`\\b${SERVICE_LAUNCHER_PROTOCOL}\\b`));
48-
expect(reason).toContain("9.8.7");
49-
expect(reason).not.toContain("| sh");
50-
expect(reason).not.toContain("which -a");
51-
expect(reason).not.toContain("~/.local/bin/t3");
52-
} finally {
53-
Object.defineProperty(process, "platform", platform);
54-
}
39+
const result = runServicePreflight({
40+
databasePath: "C:\\missing\\state.sqlite",
41+
launcherProtocol: 3,
42+
platform: "win32",
43+
version: "9.8.7",
44+
});
45+
const reason = result.status === "blocked" ? result.reason : "";
46+
expect(reason).toMatch(new RegExp(`\\b${SERVICE_LAUNCHER_PROTOCOL}\\b`));
47+
expect(reason).toContain("9.8.7");
48+
expect(reason).not.toContain("| sh");
49+
expect(reason).not.toContain("which -a");
50+
expect(reason).not.toContain("~/.local/bin/t3");
5551
});
5652

5753
it.layer(NodeServices.layer)("service preflight database", (it) => {
@@ -68,7 +64,11 @@ it.layer(NodeServices.layer)("service preflight database", (it) => {
6864
const insert = db.prepare("INSERT INTO effect_sql_migrations VALUES (?, ?)");
6965
for (const [id, name] of migrationManifest) insert.run(id, name);
7066
const preflight = () =>
71-
runServicePreflight({ databasePath, launcherProtocol: SERVICE_LAUNCHER_PROTOCOL });
67+
runServicePreflight({
68+
databasePath,
69+
launcherProtocol: SERVICE_LAUNCHER_PROTOCOL,
70+
platform: "linux",
71+
});
7272

7373
expect(preflight().status).toBe("ready");
7474
expect(databaseMigrationHead(databasePath)).toBe(BUILD_MIGRATION_HEAD);
@@ -90,6 +90,7 @@ it.layer(NodeServices.layer)("service preflight database", (it) => {
9090
runServicePreflight({
9191
databasePath: unreadable,
9292
launcherProtocol: SERVICE_LAUNCHER_PROTOCOL,
93+
platform: "linux",
9394
}).status,
9495
).toBe("blocked");
9596
// A missing database is a fresh install.

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type ServicePreflightResult =
1717
export function runServicePreflight(input: {
1818
readonly databasePath: string;
1919
readonly launcherProtocol: number;
20+
readonly platform: NodeJS.Platform;
2021
readonly version?: string;
2122
}): ServicePreflightResult {
2223
const version = input.version ?? packageJson.version;
@@ -28,9 +29,18 @@ export function runServicePreflight(input: {
2829
// reinstall itself and report success, so name the exact install and the path check.
2930
reason: [
3031
`The installed service launcher speaks protocol ${input.launcherProtocol}, but t3@${version} requires protocol ${SERVICE_LAUNCHER_PROTOCOL}.`,
31-
`On the server machine, install this exact CLI: \`curl -fsSL https://t3.codes/install.sh | T3CODE_VERSION=${version} sh\`.`,
32-
`Check that \`t3 --version\` prints ${version} and that \`which -a t3\` lists no older t3 (such as an npm or nvm install) first, then run \`~/.local/bin/t3 service install\` (the installer's default path).`,
33-
"Updating the desktop app does not update this CLI, and `t3 service update` only repairs the service with whichever CLI runs it.",
32+
...(input.platform === "win32"
33+
? [
34+
`On the server machine, install this exact CLI in PowerShell: \`$env:T3CODE_VERSION="${version}"; irm https://t3.codes/install.ps1 | iex\`.`,
35+
`Check that \`t3 --version\` prints ${version} and that \`where.exe t3\` lists no older t3 first.`,
36+
`Windows has no \`t3 service install\`, so change whatever runs \`t3 __service-launcher\` to start it from \`%USERPROFILE%\\.local\\bin\\t3.cmd\` (the installer's default path) and restart it. Remote updates do not move a Windows launcher, so repeat this whenever a release changes the launcher protocol.`,
37+
"Updating the desktop app does not update this CLI.",
38+
]
39+
: [
40+
`On the server machine, install this exact CLI: \`curl -fsSL https://t3.codes/install.sh | T3CODE_VERSION=${version} sh\`.`,
41+
`Check that \`t3 --version\` prints ${version} and that \`which -a t3\` lists no older t3 (such as an npm or nvm install) first, then run \`~/.local/bin/t3 service install\` (the installer's default path).`,
42+
"Updating the desktop app does not update this CLI, and `t3 service update` only repairs the service with whichever CLI runs it.",
43+
]),
3444
].join(" "),
3545
};
3646
}

0 commit comments

Comments
 (0)