Skip to content

Commit 58a5d1d

Browse files
fix(server): make stale CLI service recovery actionable (pingdotgg#23541)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 9f660d3 commit 58a5d1d

5 files changed

Lines changed: 71 additions & 19 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const decodeInstallManifest = Schema.decodeUnknownEffect(Schema.fromJsonString(I
4848
* counts only when its package is this exact version: a different `t3` run
4949
* from an agent's shell must not claim to be the npm install.
5050
*/
51-
const resolveEntryPath = Effect.gen(function* () {
51+
export const resolveEntryPath = Effect.gen(function* () {
5252
const npmLauncher = (yield* HostProcess.Environment).T3CODE_NPM_LAUNCHER_PATH?.trim();
5353
if (npmLauncher) {
5454
const fs = yield* FileSystem.FileSystem;

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as Effect from "effect/Effect";
77
import * as FileSystem from "effect/FileSystem";
88
import * as Layer from "effect/Layer";
99
import * as Terminal from "effect/Terminal";
10+
import * as TestConsole from "effect/testing/TestConsole";
1011
import { Command } from "effect/cli";
1112
import { afterEach, vi } from "vite-plus/test";
1213

@@ -88,6 +89,44 @@ it.layer(Layer.mergeAll(NodeServices.layer, NetService.layer))("service commands
8889
expect(installOptions).toEqual([]);
8990
}),
9091
);
92+
93+
// regression: #13239 a stale nvm-installed CLI reported "already using" its own version
94+
it.effect.each(["install", "update"] as const)(
95+
"%s names the CLI that found nothing to change",
96+
(command) =>
97+
Effect.gen(function* () {
98+
const fs = yield* FileSystem.FileSystem;
99+
const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-service-cli-test-" });
100+
const { service, installOptions } = makeTestService(status);
101+
vi.spyOn(BootService, "layer").mockReturnValue(
102+
Layer.succeed(BootService.BootService, service),
103+
);
104+
const node = "/home/me/.nvm/versions/node/v26.8.2/bin/node";
105+
const script = "/home/me/.nvm/versions/node/v26.8.2/lib/node_modules/t3/dist/bin.mjs";
106+
107+
const output = yield* Command.runWith(serviceCommand, { version: packageJson.version })([
108+
command,
109+
"--base-dir",
110+
baseDir,
111+
]).pipe(
112+
Effect.andThen(TestConsole.logLines),
113+
Effect.map((lines) => lines.join("\n")),
114+
Effect.provideService(HostProcess.Environment, {}),
115+
Effect.provideService(HostProcess.IsExecutable, false),
116+
Effect.provideService(HostProcess.ExecutablePath, node),
117+
Effect.provideService(HostProcess.Arguments, [node, script, "service", command]),
118+
Effect.provide(
119+
Layer.mergeAll(
120+
ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })),
121+
Layer.fresh(TestConsole.layer),
122+
),
123+
),
124+
);
125+
expect(output).toContain(`t3@${packageJson.version}`);
126+
expect(output).toContain(script);
127+
expect(installOptions).toEqual([]);
128+
}),
129+
);
91130
});
92131

93132
it.effect("leaves a newer service unchanged during onboarding without prompting", () =>

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { compareExactServiceVersions } from "../cloud/serviceProtocol.ts";
1212
import type * as ServerConfig from "../config.ts";
1313
import * as ProcessRunner from "../processRunner.ts";
1414
import { projectLocationFlags, resolveCliAuthConfig } from "./config.ts";
15+
import { resolveEntryPath } from "./invocation.ts";
1516

1617
export const layer = (config: ServerConfig.ServerConfig["Service"]) =>
1718
BootService.layer({
@@ -102,9 +103,9 @@ function formatServiceStatus(status: BootService.BootServiceStatus, cliVersion:
102103
].join("\n");
103104
}
104105

105-
const runServiceCommand = Effect.fn("cli.service.run")(function* <A, E>(
106+
const runServiceCommand = Effect.fn("cli.service.run")(function* <A, E, R>(
106107
flags: { readonly baseDir: Parameters<typeof resolveCliAuthConfig>[0]["baseDir"] },
107-
run: Effect.Effect<A, E, BootService.BootService>,
108+
run: Effect.Effect<A, E, R>,
108109
) {
109110
const logLevel = yield* GlobalFlag.LogLevel;
110111
const config = yield* resolveCliAuthConfig(flags, logLevel);
@@ -128,7 +129,7 @@ const serviceInstallCommand = Command.make("install", serviceReconcileFlags).pip
128129
const result = yield* reconcileService({ allowDowngrade: flags.allowDowngrade });
129130
if (!result.changed) {
130131
yield* Console.log(
131-
`T3 Code service is already installed with t3@${packageJson.version}.`,
132+
`T3 Code service is already installed with t3@${packageJson.version} (${yield* resolveEntryPath}).`,
132133
);
133134
return;
134135
}
@@ -150,7 +151,9 @@ const serviceUpdateCommand = Command.make("update", serviceReconcileFlags).pipe(
150151
);
151152
const result = yield* reconcileService({ allowDowngrade: flags.allowDowngrade });
152153
if (!result.changed) {
153-
yield* Console.log(`T3 Code service is already using t3@${packageJson.version}.`);
154+
yield* Console.log(
155+
`T3 Code service is already using t3@${packageJson.version} (${yield* resolveEntryPath}).`,
156+
);
154157
return;
155158
}
156159
yield* Console.log(formatServiceChange(result));
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import { expect, it } from "@effect/vitest";
22

33
import { runServicePreflight } from "./servicePreflight.ts";
4+
import { SERVICE_LAUNCHER_PROTOCOL } from "./serviceProtocol.ts";
45

5-
it.each([1])("blocks legacy launcher protocol %i", (launcherProtocol) => {
6-
expect(
7-
runServicePreflight({
8-
databasePath: "/missing/state.sqlite",
9-
launcherProtocol,
10-
version: "1.2.3",
11-
}),
12-
).toEqual({
13-
status: "blocked",
14-
version: "1.2.3",
15-
reason:
16-
"This release requires a newer T3 Code service launcher. Update it on the server machine.",
6+
// regression: #13239 a stale CLI shadowing the updated one kept "updating" to itself
7+
it.each([1])("blocks legacy launcher protocol %i with exact recovery steps", (launcherProtocol) => {
8+
const result = runServicePreflight({
9+
databasePath: "/missing/state.sqlite",
10+
launcherProtocol,
11+
version: "9.8.7",
1712
});
13+
14+
expect(result).toMatchObject({ status: "blocked", version: "9.8.7" });
15+
const reason = result.status === "blocked" ? result.reason : "";
16+
expect(reason).toMatch(new RegExp(`\\b${launcherProtocol}\\b`));
17+
expect(reason).toMatch(new RegExp(`\\b${SERVICE_LAUNCHER_PROTOCOL}\\b`));
18+
expect(reason).toContain("curl -fsSL https://t3.codes/install.sh | T3CODE_VERSION=9.8.7 sh");
19+
expect(reason).toContain("~/.local/bin/t3 service install");
20+
expect(reason).toContain("t3 --version");
21+
expect(reason).toContain("which -a t3");
1822
});

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ export function runServicePreflight(input: {
2323
return {
2424
status: "blocked",
2525
version,
26-
reason:
27-
"This release requires a newer T3 Code service launcher. Update it on the server machine.",
26+
// A stale `t3` earlier on PATH (an old npm/nvm global) makes `t3 service install`
27+
// reinstall itself and report success, so name the exact install and the path check.
28+
reason: [
29+
`The installed service launcher speaks protocol ${input.launcherProtocol}, but t3@${version} requires protocol ${SERVICE_LAUNCHER_PROTOCOL}.`,
30+
`On the server machine, install this exact CLI: \`curl -fsSL https://t3.codes/install.sh | T3CODE_VERSION=${version} sh\`.`,
31+
`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).`,
32+
"Updating the desktop app does not update this CLI, and `t3 service update` only repairs the service with whichever CLI runs it.",
33+
].join(" "),
2834
};
2935
}
3036

0 commit comments

Comments
 (0)