Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions apps/server/src/cli/service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
import {
HostProcessArguments,
HostProcessExecutablePath,
HostProcessIsExecutable,
HostProcessPlatform,
} from "@t3tools/shared/hostProcess";
import * as Console from "effect/Console";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
Expand Down Expand Up @@ -110,6 +115,12 @@ const runServiceCommand = Effect.fn("cli.service.run")(function* <A, E>(
return yield* run.pipe(Effect.provide(bootServiceLayer(config)));
});

/** The running CLI's path, so a stale `t3` earlier on PATH is visible. */
const runningCliPath = Effect.gen(function* () {
if (yield* HostProcessIsExecutable) return yield* HostProcessExecutablePath;
return (yield* HostProcessArguments)[1] ?? (yield* HostProcessExecutablePath);
});

const serviceReconcileFlags = {
...projectLocationFlags,
allowDowngrade: Flag.Boolean("allow-downgrade").pipe(
Expand All @@ -127,7 +138,7 @@ const serviceInstallCommand = Command.make("install", serviceReconcileFlags).pip
const result = yield* reconcileService({ allowDowngrade: flags.allowDowngrade });
if (!result.changed) {
yield* Console.log(
`T3 Code service is already installed with t3@${packageJson.version}.`,
`T3 Code service is already installed with t3@${packageJson.version} (${yield* runningCliPath}).`,
);
return;
}
Expand All @@ -153,7 +164,9 @@ const serviceUpdateCommand = Command.make("update", serviceReconcileFlags).pipe(
);
const result = yield* reconcileService({ allowDowngrade: flags.allowDowngrade });
if (!result.changed) {
yield* Console.log(`T3 Code service is already using t3@${packageJson.version}.`);
yield* Console.log(
`T3 Code service is already using t3@${packageJson.version} (${yield* runningCliPath}).`,
);
return;
}
yield* Console.log(
Expand Down
20 changes: 10 additions & 10 deletions apps/server/src/cloud/servicePreflight.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import { runServicePreflight } from "./servicePreflight.ts";
import { SERVICE_LAUNCHER_PROTOCOL } from "./serviceProtocol.ts";

it.each([1, 2])("blocks legacy launcher protocol %i", (launcherProtocol) => {
expect(
runServicePreflight({
databasePath: "/missing/state.sqlite",
launcherProtocol,
version: "1.2.3",
}),
).toEqual({
status: "blocked",
const result = runServicePreflight({
databasePath: "/missing/state.sqlite",
launcherProtocol,
version: "1.2.3",
reason:
"This release requires a newer T3 Code service launcher. Update it on the server machine.",
});
expect(result).toMatchObject({ status: "blocked", version: "1.2.3" });
const reason = result.status === "blocked" ? result.reason : "";
expect(reason).toContain(`needs service launcher protocol ${SERVICE_LAUNCHER_PROTOCOL}`);
expect(reason).toContain(`offered protocol ${launcherProtocol}`);
expect(reason).toContain("T3CODE_VERSION=1.2.3 sh");
expect(reason).toContain("`t3 service install`");
expect(reason).toContain("`which -a t3`");
});

it("accepts the current launcher protocol", () => {
Expand Down
8 changes: 6 additions & 2 deletions apps/server/src/cloud/servicePreflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ export function runServicePreflight(input: {
return {
status: "blocked",
version,
reason:
"This release requires a newer T3 Code service launcher. Update it on the server machine.",
reason: [
`t3@${version} needs service launcher protocol ${SERVICE_LAUNCHER_PROTOCOL}, but the service on the server machine offered protocol ${input.launcherProtocol}.`,
`On that machine, install this exact version with \`curl -fsSL https://t3.codes/install.sh | T3CODE_VERSION=${version} sh\`, then run \`t3 service install\`.`,
"`t3 service update` and `t3 update` without a version keep whichever `t3` is first on PATH, `npx t3@latest` installs the latest stable release instead, and upgrading the desktop app does not replace it.",
`If \`t3 --version\` does not print ${version}, check \`which -a t3\`.`,
].join(" "),
};
}

Expand Down
Loading